Skip to content

Commit

Permalink
Upgrade to Maven 4.0.0-alpha-10
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Dec 20, 2023
1 parent 37dff61 commit a0c4c74
Show file tree
Hide file tree
Showing 26 changed files with 473 additions and 284 deletions.
6 changes: 6 additions & 0 deletions maven-plugin-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@
<version>0.0.7</version>
</dependency>

<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>

<!-- tests -->
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
1 change: 1 addition & 0 deletions maven-plugin-plugin/src/it/ant-basic/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<artifactId>maven-plugin-plugin</artifactId>
<version>${pluginPluginVersion}</version>
<configuration>
<requiredMavenVersion>3.6.5</requiredMavenVersion>
<prefix>antBasic</prefix>
</configuration>
<dependencies>
Expand Down
1 change: 1 addition & 0 deletions maven-plugin-plugin/src/it/ant-reference-parameter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<artifactId>maven-plugin-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<requiredMavenVersion>3.6.5</requiredMavenVersion>
<goalPrefix>antWithRefs</goalPrefix>
</configuration>
<dependencies>
Expand Down
1 change: 1 addition & 0 deletions maven-plugin-plugin/src/it/ant-simple-usage/plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<version>${pluginPluginVersion}</version>
<configuration>
<prefix>antSimpleUsage</prefix>
<requiredMavenVersion>3.6.5</requiredMavenVersion>
</configuration>
<dependencies>
<dependency>
Expand Down
3 changes: 3 additions & 0 deletions maven-plugin-plugin/src/it/ant-since-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<requiredMavenVersion>3.6.5</requiredMavenVersion>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
Expand Down
1 change: 1 addition & 0 deletions maven-plugin-plugin/src/it/beanshell-simple/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<version>${pluginPluginVersion}</version>
<configuration>
<prefix>beanshellBasic</prefix>
<requiredMavenVersion>3.6.5</requiredMavenVersion>
</configuration>
<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@

import java.nio.file.Path;

import jakarta.inject.Inject;
import jakarta.inject.Named;
import org.apache.maven.api.MojoExecution;
import org.apache.maven.api.Project;
import org.apache.maven.api.ResolutionScope;
import org.apache.maven.api.Session;
import org.apache.maven.api.plugin.Log;
import org.apache.maven.api.plugin.MojoException;
import org.apache.maven.api.plugin.annotations.Component;
import org.apache.maven.api.plugin.annotations.Execute;
import org.apache.maven.api.plugin.annotations.LifecyclePhase;
import org.apache.maven.api.plugin.annotations.Mojo;
Expand All @@ -42,10 +42,7 @@
*
* @since 1.2
*/
@Mojo(
name = "first",
requiresDependencyResolution = ResolutionScope.TEST,
defaultPhase = LifecyclePhase.INTEGRATION_TEST)
@Mojo(name = "first", defaultPhase = LifecyclePhase.INTEGRATION_TEST)
@Execute(phase = LifecyclePhase.GENERATE_SOURCES, lifecycle = "cobertura")
public class FirstMojo implements org.apache.maven.api.plugin.Mojo {

Expand All @@ -66,23 +63,24 @@ public class FirstMojo implements org.apache.maven.api.plugin.Mojo {
@Parameter(name = "namedParam", alias = "alias")
private String aliasedParam;

@Component
@Inject
private Session session;

@Component
@Inject
private Project project;

@Component
@Inject
private MojoExecution mojo;

@Component
@Inject
private Settings settings;

@Component
@Inject
private Log log;

@Component(role = ArtifactInstaller.class, hint = "test")
private Object custom;
@Inject
@Named("test")
private ArtifactInstaller custom;

public void execute() throws MojoException {}
}
103 changes: 10 additions & 93 deletions maven-plugin-plugin/src/it/v4api/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -25,61 +25,22 @@ assert descriptorFile.isFile()
def pluginDescriptor = new XmlParser().parse( descriptorFile );

assert pluginDescriptor.requiredJavaVersion.text() == '1.8'
assert pluginDescriptor.requiredMavenVersion.text() == '4.0.0-alpha-4'
assert pluginDescriptor.requiredMavenVersion.text() == '4.0.0-alpha-10'

def mojo = pluginDescriptor.mojos.mojo.findAll{ it.goal.text() == "first" }[0]

assert mojo.goal.text() == 'first'
assert mojo.implementation.text() == 'org.apache.maven.its.v4api.FirstMojo'
assert mojo.language.text() == 'java'
assert mojo.description.text().startsWith('Test mojo for the v4 api plugin descriptor generation.')
assert mojo.requiresDependencyResolution.text() == 'test'
assert mojo.requiresDependencyCollection.text() == ''
assert mojo.requiresProject.text() == 'true'
assert mojo.requiresOnline.text() == 'false'
assert mojo.requiresDirectInvocation.text() == 'false'
assert mojo.projectRequired.text() == 'true'
assert mojo.onlineRequired.text() == 'false'
assert mojo.aggregator.text() == 'false'
assert mojo.threadSafe.text() == 'false'
assert mojo.phase.text() == 'integration-test'
assert mojo.executePhase.text() == 'generate-sources'
assert mojo.executeLifecycle.text() == 'cobertura'
assert mojo.v4Api.text() == 'true'

assert mojo.configuration.basedir[0].text() == ''
assert mojo.configuration.basedir[0].'@implementation' == 'java.nio.file.Path'
assert mojo.configuration.basedir[0].'@default-value' == '${basedir}'

assert mojo.configuration.touchFile[0].text() == '${first.touchFile}'
assert mojo.configuration.touchFile[0].'@implementation' == 'java.nio.file.Path'
assert mojo.configuration.touchFile[0].'@default-value' == '${project.build.directory}/touch.txt'

assert mojo.configuration.session[0].text() == ''
assert mojo.configuration.session[0].'@implementation' == 'org.apache.maven.api.Session'
assert mojo.configuration.session[0].'@default-value' == '${session}'

assert mojo.configuration.project[0].text() == ''
assert mojo.configuration.project[0].'@implementation' == 'org.apache.maven.api.Project'
assert mojo.configuration.project[0].'@default-value' == '${project}'

assert mojo.configuration.mojo[0].text() == ''
assert mojo.configuration.mojo[0].'@implementation' == 'org.apache.maven.api.MojoExecution'
assert mojo.configuration.mojo[0].'@default-value' == '${mojoExecution}'

assert mojo.configuration.settings[0].text() == ''
assert mojo.configuration.settings[0].'@implementation' == 'org.apache.maven.api.settings.Settings'
assert mojo.configuration.settings[0].'@default-value' == '${settings}'

assert mojo.requirements.requirement.size() == 2

assert mojo.requirements.requirement[0].role.text() == 'org.apache.maven.api.services.ArtifactInstaller'
assert mojo.requirements.requirement[0].'role-hint'.text() == 'test'
assert mojo.requirements.requirement[0].'field-name'.text() == 'custom'

assert mojo.requirements.requirement[1].role.text() == 'org.apache.maven.api.plugin.Log'
assert mojo.requirements.requirement[1].'role-hint'.isEmpty()
assert mojo.requirements.requirement[1].'field-name'.text() == 'log'

assert mojo.parameters.parameter.size() == 7
assert mojo.parameters.parameter.size() == 3

parameter = mojo.parameters.parameter.findAll{ it.name.text() == "basedir" }[0]
assert parameter.name.text() == 'basedir'
Expand All @@ -90,6 +51,8 @@ assert parameter.deprecated.isEmpty()
assert parameter.required.text() == 'false'
assert parameter.editable.text() == 'false'
assert parameter.description.text() == 'Project directory.'
assert parameter.defaultValue.text() == '${basedir}'
assert parameter.expression.isEmpty()

parameter = mojo.parameters.parameter.findAll{ it.name.text() == "touchFile" }[0]
assert parameter.name.text() == 'touchFile'
Expand All @@ -100,16 +63,8 @@ assert parameter.deprecated.isEmpty()
assert parameter.required.text() == 'true'
assert parameter.editable.text() == 'true'
assert parameter.description.text() == ''

parameter = mojo.parameters.parameter.findAll{ it.name.text() == "mojo" }[0]
assert parameter.name.text() == 'mojo'
assert parameter.alias.isEmpty()
assert parameter.type.text() == 'org.apache.maven.api.MojoExecution'
assert parameter.since.isEmpty()
assert parameter.deprecated.isEmpty()
assert parameter.required.text() == 'true'
assert parameter.editable.text() == 'false'
assert parameter.description.text() == ''
assert parameter.defaultValue.text() == '${project.build.directory}/touch.txt'
assert parameter.expression.text() == '${first.touchFile}'

parameter = mojo.parameters.parameter.findAll{ it.name.text() == "namedParam" }[0]
assert parameter.name.text() == 'namedParam'
Expand All @@ -120,46 +75,8 @@ assert parameter.deprecated.text() == 'As of 0.2'
assert parameter.required.text() == 'false'
assert parameter.editable.text() == 'true'
assert parameter.description.text() == ''

parameter = mojo.parameters.parameter.findAll{ it.name.text() == "session" }[0]
assert parameter.name.text() == 'session'
assert parameter.alias.isEmpty()
assert parameter.type.text() == 'org.apache.maven.api.Session'
assert parameter.since.isEmpty()
assert parameter.deprecated.isEmpty()
assert parameter.required.text() == 'true'
assert parameter.editable.text() == 'false'
assert parameter.description.text() == ''

parameter = mojo.parameters.parameter.findAll{ it.name.text() == "project" }[0]
assert parameter.name.text() == 'project'
assert parameter.alias.isEmpty()
assert parameter.type.text() == 'org.apache.maven.api.Project'
assert parameter.since.isEmpty()
assert parameter.deprecated.isEmpty()
assert parameter.required.text() == 'true'
assert parameter.editable.text() == 'false'
assert parameter.description.text() == ''

parameter = mojo.parameters.parameter.findAll{ it.name.text() == "mojo" }[0]
assert parameter.name.text() == 'mojo'
assert parameter.alias.isEmpty()
assert parameter.type.text() == 'org.apache.maven.api.MojoExecution'
assert parameter.since.isEmpty()
assert parameter.deprecated.isEmpty()
assert parameter.required.text() == 'true'
assert parameter.editable.text() == 'false'
assert parameter.description.text() == ''

parameter = mojo.parameters.parameter.findAll{ it.name.text() == "settings" }[0]
assert parameter.name.text() == 'settings'
assert parameter.alias.isEmpty()
assert parameter.type.text() == 'org.apache.maven.api.settings.Settings'
assert parameter.since.isEmpty()
assert parameter.deprecated.isEmpty()
assert parameter.required.text() == 'true'
assert parameter.editable.text() == 'false'
assert parameter.description.text() == ''
assert parameter.defaultValue.isEmpty()
assert parameter.expression.isEmpty()

// check help mojo source and class
assert new File( basedir, "target/classes/org/apache/maven/its/v4api/HelpMojo.class" ).isFile()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ public class DescriptorGeneratorMojo extends AbstractGeneratorMojo {
protected BuildContext buildContext;

public void generate() throws MojoExecutionException {

if (!"maven-plugin".equalsIgnoreCase(project.getArtifactId())
&& project.getArtifactId().toLowerCase().startsWith("maven-")
&& project.getArtifactId().toLowerCase().endsWith("-plugin")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,7 @@ public PlexusConfiguration buildConfiguration(Reader reader) throws PlexusConfig
@Override
public PluginDescriptor build(Reader reader, String source) throws PlexusConfigurationException {
PluginDescriptor pluginDescriptor = super.build(reader, source);
// elements added in plugin descriptor 1.1
ExtendedPluginDescriptor extendedPluginDescriptor = new ExtendedPluginDescriptor(pluginDescriptor);
extendedPluginDescriptor.setRequiredJavaVersion(
configuration.getChild("requiredJavaVersion").getValue());
extendedPluginDescriptor.setRequiredMavenVersion(
configuration.getChild("requiredMavenVersion").getValue());
return extendedPluginDescriptor;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
import org.apache.maven.tools.plugin.extractor.annotations.scanner.MojoAnnotationsScanner;
import org.apache.maven.tools.plugin.extractor.annotations.scanner.MojoAnnotationsScannerRequest;
import org.apache.maven.tools.plugin.javadoc.JavadocLinkGenerator;
import org.apache.maven.tools.plugin.util.PluginUtils;
import org.codehaus.plexus.archiver.ArchiverException;
import org.codehaus.plexus.archiver.UnArchiver;
import org.codehaus.plexus.archiver.manager.ArchiverManager;
Expand All @@ -89,6 +88,8 @@
import org.eclipse.aether.resolution.ArtifactResult;
import org.objectweb.asm.Opcodes;

import static org.apache.maven.tools.plugin.util.PluginUtils.MAVEN_COMPONENTS;

/**
* JavaMojoDescriptorExtractor, a MojoDescriptor extractor to read descriptors from java classes with annotations.
* Notice that source files are also parsed to get description, since and deprecation information.
Expand Down Expand Up @@ -769,6 +770,14 @@ private List<MojoDescriptor> toMojoDescriptors(
parameter.setRequired(parameterAnnotationContent.required());

mojoDescriptor.addParameter(parameter);

if (MAVEN_COMPONENTS.values().contains(parameter.getExpression())) {
getLogger()
.warn("Deprecated @Parameter(expression = " + parameter.getExpression()
+ ") annotation for '" + parameter.getName() + "' field in "
+ mojoAnnotatedClass.getClassName()
+ ": replace with @Component or @Inject");
}
}

// Component annotations
Expand All @@ -781,18 +790,13 @@ private List<MojoDescriptor> toMojoDescriptors(
parameter.setName(componentAnnotationContent.getFieldName());

// recognize Maven-injected objects as components annotations instead of parameters
String expression = PluginUtils.MAVEN_COMPONENTS.get(componentAnnotationContent.getRoleClassName());
String expression = MAVEN_COMPONENTS.get(componentAnnotationContent.getRoleClassName());
if (expression == null) {
// normal component
parameter.setRequirement(new Requirement(
componentAnnotationContent.getRoleClassName(), componentAnnotationContent.hint()));
} else {
// not a component but a Maven object to be transformed into an expression/property: deprecated
getLogger()
.warn("Deprecated @Component annotation for '" + parameter.getName() + "' field in "
+ mojoAnnotatedClass.getClassName()
+ ": replace with @Parameter( defaultValue = \"" + expression
+ "\", readonly = true )");
parameter.setDefaultValue(expression);
parameter.setType(componentAnnotationContent.getRoleClassName());
parameter.setRequired(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ public void requiresDependencyResolution(String requiresDependencyResolution) {
this.requiresDependencyResolution = ResolutionScope.valueOf(requiresDependencyResolution);
}

public void dependencyResolutionRequired(String dependencyResolutionRequired) {
this.requiresDependencyResolution = ResolutionScope.valueOf(dependencyResolutionRequired);
}

@Override
public ResolutionScope requiresDependencyCollection() {
return requiresDependencyCollection;
Expand Down Expand Up @@ -117,6 +121,10 @@ public void requiresProject(boolean requiresProject) {
this.requiresProject = requiresProject;
}

public void projectRequired(boolean requiresProject) {
this.requiresProject = requiresProject;
}

@Override
public boolean requiresReports() {
return requiresReports;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
Expand Down Expand Up @@ -88,15 +89,23 @@ public Map<String, MojoAnnotatedClass> scan(MojoAnnotationsScannerRequest reques
Map<String, MojoAnnotatedClass> mojoAnnotatedClasses = new HashMap<>();

try {
String mavenApiVersion = null;
for (Artifact dependency : request.getDependencies()) {
scan(mojoAnnotatedClasses, dependency.getFile(), request.getIncludePatterns(), dependency, true);
if (request.getMavenApiVersion() == null
&& dependency.getGroupId().equals("org.apache.maven")
&& (dependency.getArtifactId().equals("maven-plugin-api")
|| dependency.getArtifactId().equals("maven-api-core"))) {
request.setMavenApiVersion(dependency.getVersion());
String version = dependency.getVersion();
if (mavenApiVersion != null && !Objects.equals(version, mavenApiVersion)) {
throw new UnsupportedOperationException("Mixing Maven 3 and Maven 4 plugins is not supported."
+ " Fix your dependencies so that you depend either on maven-plugin-api for a Maven 3 plugin,"
+ " or maven-api-core for a Maven 4 plugin.");
}
mavenApiVersion = version;
}
}
request.setMavenApiVersion(mavenApiVersion);

for (File classDirectory : request.getClassesDirectories()) {
scan(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public class ParametersWithGenericsMojo extends AbstractMojo {
@Parameter
private Collection<Integer[]> integerArrayCollection;

@Parameter
private Map<String, List<String>> stringListStringMap;

@Override
public void execute() throws MojoExecutionException, MojoFailureException {}

Expand Down
Loading

0 comments on commit a0c4c74

Please sign in to comment.