Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.maven.its.v4api;

import org.apache.maven.api.plugin.MojoException;
import org.apache.maven.api.plugin.annotations.Mojo;

@Mojo(
name = "collection",
dependencyCollection = true,
dependencyResolutionPathScopes = "main-compile")
public class CollectionMojo implements org.apache.maven.api.plugin.Mojo {
@Override
public void execute() throws MojoException {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.maven.its.v4api;

import org.apache.maven.api.plugin.MojoException;
import org.apache.maven.api.plugin.annotations.Mojo;

@Mojo(name = "online", onlineRequired = true)
public class OnlineMojo implements org.apache.maven.api.plugin.Mojo {
@Override
public void execute() throws MojoException {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.maven.its.v4api;

import org.apache.maven.api.plugin.MojoException;
import org.apache.maven.api.plugin.annotations.Mojo;

@Mojo(name = "resolution", dependencyResolutionPathScopes = "main-compile")
public class ResolutionMojo implements org.apache.maven.api.plugin.Mojo {
@Override
public void execute() throws MojoException {}
}
11 changes: 11 additions & 0 deletions maven-plugin-plugin/src/it/v4api-4x/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,15 @@ assert parameter.expression.isEmpty()
assert new File( basedir, "target/classes/org/apache/maven/its/v4api/HelpMojo.class" ).isFile()
assert new File( basedir, "target/generated-sources/plugin/org/apache/maven/its/v4api/HelpMojo.java" ).isFile()

def collectionMojo = pluginDescriptor.mojos.mojo.find { it.goal.text() == 'collection' }
assert collectionMojo.dependencyCollection.text() == 'main-compile'
assert collectionMojo.dependencyResolution.isEmpty()

def resolutionMojo = pluginDescriptor.mojos.mojo.find { it.goal.text() == 'resolution' }
assert resolutionMojo.dependencyResolution.text() == 'main-compile'
assert resolutionMojo.dependencyCollection.isEmpty()

def onlineMojo = pluginDescriptor.mojos.mojo.find { it.goal.text() == 'online' }
assert onlineMojo.onlineRequired.text() == 'true'

return true;
Original file line number Diff line number Diff line change
Expand Up @@ -663,10 +663,7 @@ private List<MojoDescriptor> toMojoDescriptors(
mojoDescriptor.setInstantiationStrategy(mojo.instantiationStrategy().id());

mojoDescriptor.setAggregator(mojo.aggregator());
mojoDescriptor.setDependencyResolutionRequired(
mojo.requiresDependencyResolution().id());
mojoDescriptor.setDependencyCollectionRequired(
mojo.requiresDependencyCollection().id());
setDependencyRequirements(mojoDescriptor, mojo, mojoAnnotatedClass.isV4Api());

mojoDescriptor.setDirectInvocationOnly(mojo.requiresDirectInvocation());
mojoDescriptor.setDeprecated(mojo.getDeprecated());
Expand Down Expand Up @@ -774,6 +771,22 @@ private List<MojoDescriptor> toMojoDescriptors(
return mojoDescriptors;
}

private void setDependencyRequirements(
ExtendedMojoDescriptor mojoDescriptor, MojoAnnotationContent mojo, boolean isV4Api) {
mojoDescriptor.setDependencyResolutionRequired(
mojo.requiresDependencyResolution().id());
mojoDescriptor.setDependencyCollectionRequired(
mojo.requiresDependencyCollection().id());

if (isV4Api && StringUtils.isNotEmpty(mojo.getDependencyResolutionPathScopes())) {
if (mojo.isDependencyCollection()) {
mojoDescriptor.setDependencyCollectionRequired(mojo.getDependencyResolutionPathScopes());
} else {
mojoDescriptor.setDependencyResolutionRequired(mojo.getDependencyResolutionPathScopes());
}
}
}

protected MojoAnnotatedClass findClassWithExecuteAnnotationInParentHierarchy(
MojoAnnotatedClass mojoAnnotatedClass, Map<String, MojoAnnotatedClass> mojoAnnotatedClasses) {
if (mojoAnnotatedClass.getExecute() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ public class MojoAnnotationContent extends AnnotatedContent implements Mojo {

private boolean requiresOnline = false;

private boolean dependencyCollection;

private String dependencyResolutionPathScopes;

private boolean inheritByDefault = true;

private String configurator;
Expand Down Expand Up @@ -172,6 +176,26 @@ public void requiresOnline(boolean requiresOnline) {
this.requiresOnline = requiresOnline;
}

public void onlineRequired(boolean requiresOnline) {
this.requiresOnline = requiresOnline;
}

public boolean isDependencyCollection() {
return dependencyCollection;
}

public void dependencyCollection(boolean dependencyCollection) {
this.dependencyCollection = dependencyCollection;
}

public String getDependencyResolutionPathScopes() {
return dependencyResolutionPathScopes;
}

public void dependencyResolutionPathScopes(String dependencyResolutionPathScopes) {
this.dependencyResolutionPathScopes = dependencyResolutionPathScopes;
}

@Override
public boolean inheritByDefault() {
return inheritByDefault;
Expand Down