From 641eaf82319703a1f128a06a35b15052d28df07e Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Thu, 23 May 2024 09:43:39 +0200 Subject: [PATCH 1/3] Switch to version 4.0.0-SNAPSHOT --- maven-plugin-annotations/pom.xml | 2 +- maven-plugin-plugin/pom.xml | 2 +- maven-plugin-report-plugin/pom.xml | 2 +- maven-plugin-tools-annotations/pom.xml | 2 +- maven-plugin-tools-api/pom.xml | 2 +- maven-plugin-tools-generators/pom.xml | 2 +- maven-plugin-tools-java/pom.xml | 2 +- maven-script/maven-plugin-tools-ant/pom.xml | 2 +- maven-script/maven-plugin-tools-beanshell/pom.xml | 2 +- maven-script/maven-plugin-tools-model/pom.xml | 2 +- maven-script/maven-script-ant/pom.xml | 2 +- maven-script/maven-script-beanshell/pom.xml | 2 +- maven-script/pom.xml | 2 +- pom.xml | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/maven-plugin-annotations/pom.xml b/maven-plugin-annotations/pom.xml index e7bfb7dad..d009e6505 100644 --- a/maven-plugin-annotations/pom.xml +++ b/maven-plugin-annotations/pom.xml @@ -23,7 +23,7 @@ org.apache.maven.plugin-tools maven-plugin-tools - 3.13.1-SNAPSHOT + 4.0.0-SNAPSHOT maven-plugin-annotations diff --git a/maven-plugin-plugin/pom.xml b/maven-plugin-plugin/pom.xml index 465d41f22..327b0f5dc 100644 --- a/maven-plugin-plugin/pom.xml +++ b/maven-plugin-plugin/pom.xml @@ -23,7 +23,7 @@ org.apache.maven.plugin-tools maven-plugin-tools - 3.13.1-SNAPSHOT + 4.0.0-SNAPSHOT org.apache.maven.plugins diff --git a/maven-plugin-report-plugin/pom.xml b/maven-plugin-report-plugin/pom.xml index d023ad270..313417ede 100644 --- a/maven-plugin-report-plugin/pom.xml +++ b/maven-plugin-report-plugin/pom.xml @@ -23,7 +23,7 @@ org.apache.maven.plugin-tools maven-plugin-tools - 3.13.1-SNAPSHOT + 4.0.0-SNAPSHOT org.apache.maven.plugins diff --git a/maven-plugin-tools-annotations/pom.xml b/maven-plugin-tools-annotations/pom.xml index 9a66a25f8..2cf7ecfa7 100644 --- a/maven-plugin-tools-annotations/pom.xml +++ b/maven-plugin-tools-annotations/pom.xml @@ -22,7 +22,7 @@ org.apache.maven.plugin-tools maven-plugin-tools - 3.13.1-SNAPSHOT + 4.0.0-SNAPSHOT maven-plugin-tools-annotations diff --git a/maven-plugin-tools-api/pom.xml b/maven-plugin-tools-api/pom.xml index 21f4c209a..20573c7f8 100644 --- a/maven-plugin-tools-api/pom.xml +++ b/maven-plugin-tools-api/pom.xml @@ -23,7 +23,7 @@ org.apache.maven.plugin-tools maven-plugin-tools - 3.13.1-SNAPSHOT + 4.0.0-SNAPSHOT maven-plugin-tools-api diff --git a/maven-plugin-tools-generators/pom.xml b/maven-plugin-tools-generators/pom.xml index e2ca5627f..35cde987c 100644 --- a/maven-plugin-tools-generators/pom.xml +++ b/maven-plugin-tools-generators/pom.xml @@ -23,7 +23,7 @@ org.apache.maven.plugin-tools maven-plugin-tools - 3.13.1-SNAPSHOT + 4.0.0-SNAPSHOT maven-plugin-tools-generators diff --git a/maven-plugin-tools-java/pom.xml b/maven-plugin-tools-java/pom.xml index 7c0cc293e..eb194a2d3 100644 --- a/maven-plugin-tools-java/pom.xml +++ b/maven-plugin-tools-java/pom.xml @@ -23,7 +23,7 @@ org.apache.maven.plugin-tools maven-plugin-tools - 3.13.1-SNAPSHOT + 4.0.0-SNAPSHOT maven-plugin-tools-java diff --git a/maven-script/maven-plugin-tools-ant/pom.xml b/maven-script/maven-plugin-tools-ant/pom.xml index d69fc9ca7..61770630c 100644 --- a/maven-script/maven-plugin-tools-ant/pom.xml +++ b/maven-script/maven-plugin-tools-ant/pom.xml @@ -23,7 +23,7 @@ org.apache.maven.plugin-tools maven-script - 3.13.1-SNAPSHOT + 4.0.0-SNAPSHOT maven-plugin-tools-ant diff --git a/maven-script/maven-plugin-tools-beanshell/pom.xml b/maven-script/maven-plugin-tools-beanshell/pom.xml index 32c8d3cbe..4a1ac3ed2 100644 --- a/maven-script/maven-plugin-tools-beanshell/pom.xml +++ b/maven-script/maven-plugin-tools-beanshell/pom.xml @@ -23,7 +23,7 @@ org.apache.maven.plugin-tools maven-script - 3.13.1-SNAPSHOT + 4.0.0-SNAPSHOT maven-plugin-tools-beanshell diff --git a/maven-script/maven-plugin-tools-model/pom.xml b/maven-script/maven-plugin-tools-model/pom.xml index cb9b3c807..4a152a240 100644 --- a/maven-script/maven-plugin-tools-model/pom.xml +++ b/maven-script/maven-plugin-tools-model/pom.xml @@ -23,7 +23,7 @@ org.apache.maven.plugin-tools maven-script - 3.13.1-SNAPSHOT + 4.0.0-SNAPSHOT maven-plugin-tools-model diff --git a/maven-script/maven-script-ant/pom.xml b/maven-script/maven-script-ant/pom.xml index ae18622e7..e2bf4fae6 100644 --- a/maven-script/maven-script-ant/pom.xml +++ b/maven-script/maven-script-ant/pom.xml @@ -23,7 +23,7 @@ under the License. org.apache.maven.plugin-tools maven-script - 3.13.1-SNAPSHOT + 4.0.0-SNAPSHOT maven-script-ant diff --git a/maven-script/maven-script-beanshell/pom.xml b/maven-script/maven-script-beanshell/pom.xml index 564a60f39..269ddd49a 100644 --- a/maven-script/maven-script-beanshell/pom.xml +++ b/maven-script/maven-script-beanshell/pom.xml @@ -23,7 +23,7 @@ under the License. org.apache.maven.plugin-tools maven-script - 3.13.1-SNAPSHOT + 4.0.0-SNAPSHOT maven-script-beanshell diff --git a/maven-script/pom.xml b/maven-script/pom.xml index dd57a057b..21fb04b88 100644 --- a/maven-script/pom.xml +++ b/maven-script/pom.xml @@ -23,7 +23,7 @@ under the License. org.apache.maven.plugin-tools maven-plugin-tools - 3.13.1-SNAPSHOT + 4.0.0-SNAPSHOT maven-script diff --git a/pom.xml b/pom.xml index b07501221..815a1fdae 100644 --- a/pom.xml +++ b/pom.xml @@ -29,7 +29,7 @@ org.apache.maven.plugin-tools maven-plugin-tools - 3.13.1-SNAPSHOT + 4.0.0-SNAPSHOT pom Maven Plugin Tools From 46990912345ff9b8efed35ba5aad20c41b2fd69f Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Tue, 16 Jan 2024 09:27:26 +0100 Subject: [PATCH 2/3] Upgrade to 4.0.0-beta-3 --- .github/workflows/maven-verify.yml | 2 + maven-plugin-plugin/pom.xml | 39 +- maven-plugin-plugin/src/it/ant-basic/pom.xml | 1 + .../src/it/ant-reference-parameter/pom.xml | 1 + .../src/it/ant-simple-usage/plugin/pom.xml | 1 + .../src/it/ant-since-maven-plugin/pom.xml | 1 + .../src/it/beanshell-simple/pom.xml | 1 + .../org/apache/maven/its/v4api/FirstMojo.java | 29 +- .../src/it/v4api/verify.groovy | 53 +- .../plugin/DescriptorGeneratorMojo.java | 169 +++++- .../plugin/plugin/DiGeneratorMojoTest.java | 57 +++ .../report/PluginDescriptorBuilder.java | 484 ++++++++++++++++++ .../plugin/report/PluginOverviewRenderer.java | 6 +- .../plugin/plugin/report/PluginReport.java | 9 +- .../EnhancedPluginDescriptorBuilder.java | 138 ----- .../report/PluginDescriptorBuilderTest.java} | 34 +- maven-plugin-tools-annotations/pom.xml | 2 +- .../datamodel/ExecuteAnnotationContent.java | 15 + .../datamodel/MojoAnnotationContent.java | 21 +- .../DefaultMojoAnnotationsScanner.java | 17 +- .../ParametersWithGenericsMojo.java | 3 + .../DefaultMojoAnnotationsScannerTest.java | 6 + .../plugin/ExtendedPluginDescriptor.java | 25 +- maven-plugin-tools-generators/pom.xml | 9 + .../plugin/generator/GeneratorUtils.java | 27 +- .../PluginDescriptorFilesGenerator.java | 312 +++++++---- .../main/resources/help-class-source-v4.vm | 33 +- .../generator/AbstractGeneratorTestCase.java | 70 ++- .../plugin/generator/GeneratorUtilsTest.java | 12 +- .../PluginDescriptorFilesGeneratorTest.java | 42 +- maven-script/maven-plugin-tools-ant/pom.xml | 4 + maven-script/maven-script-ant/pom.xml | 10 +- pom.xml | 56 +- 33 files changed, 1288 insertions(+), 401 deletions(-) create mode 100644 maven-plugin-plugin/src/test/java/org/apache/maven/plugin/plugin/DiGeneratorMojoTest.java create mode 100644 maven-plugin-report-plugin/src/main/java/org/apache/maven/plugin/plugin/report/PluginDescriptorBuilder.java delete mode 100644 maven-plugin-report-plugin/src/main/java/org/apache/maven/plugins/plugin/descriptor/EnhancedPluginDescriptorBuilder.java rename maven-plugin-report-plugin/src/test/java/org/apache/maven/{plugins/plugin/descriptor/EnhancedPluginDescriptorBuilderTest.java => plugin/plugin/report/PluginDescriptorBuilderTest.java} (67%) diff --git a/.github/workflows/maven-verify.yml b/.github/workflows/maven-verify.yml index 932827cf9..c53cc8ea9 100644 --- a/.github/workflows/maven-verify.yml +++ b/.github/workflows/maven-verify.yml @@ -25,3 +25,5 @@ jobs: build: name: Verify uses: apache/maven-gh-actions-shared/.github/workflows/maven-verify.yml@v4 + with: + maven-matrix: '[ "3.6.3", "3.9.6", "4.0.0-alpha-13" ]' diff --git a/maven-plugin-plugin/pom.xml b/maven-plugin-plugin/pom.xml index 327b0f5dc..986bca5a2 100644 --- a/maven-plugin-plugin/pom.xml +++ b/maven-plugin-plugin/pom.xml @@ -44,11 +44,6 @@ - - org.apache.maven - maven-core - provided - org.apache.maven.plugin-tools maven-plugin-tools-api @@ -100,13 +95,17 @@ org.apache.maven - maven-model + maven-core provided org.apache.maven - maven-repository-metadata - ${maven3Version} + maven-compat + provided + + + org.apache.maven + maven-settings provided @@ -114,6 +113,17 @@ maven-artifact provided + + org.apache.maven + maven-model + provided + + + + org.apache.maven.resolver + maven-resolver-api + 2.0.0-alpha-7 + @@ -137,6 +147,12 @@ 0.0.7 + + javax.inject + javax.inject + 1 + + org.junit.jupiter @@ -163,6 +179,13 @@ test + + org.apache.maven + maven-di + ${maven4Version} + test + + diff --git a/maven-plugin-plugin/src/it/ant-basic/pom.xml b/maven-plugin-plugin/src/it/ant-basic/pom.xml index 86e0a1fe6..5839b4a14 100644 --- a/maven-plugin-plugin/src/it/ant-basic/pom.xml +++ b/maven-plugin-plugin/src/it/ant-basic/pom.xml @@ -54,6 +54,7 @@ maven-plugin-plugin ${pluginPluginVersion} + 3.6.3 antBasic diff --git a/maven-plugin-plugin/src/it/ant-reference-parameter/pom.xml b/maven-plugin-plugin/src/it/ant-reference-parameter/pom.xml index 0de107d67..387dd1893 100644 --- a/maven-plugin-plugin/src/it/ant-reference-parameter/pom.xml +++ b/maven-plugin-plugin/src/it/ant-reference-parameter/pom.xml @@ -50,6 +50,7 @@ maven-plugin-plugin @project.version@ + 3.6.3 antWithRefs diff --git a/maven-plugin-plugin/src/it/ant-simple-usage/plugin/pom.xml b/maven-plugin-plugin/src/it/ant-simple-usage/plugin/pom.xml index 315fa01e6..bb13a32fb 100644 --- a/maven-plugin-plugin/src/it/ant-simple-usage/plugin/pom.xml +++ b/maven-plugin-plugin/src/it/ant-simple-usage/plugin/pom.xml @@ -54,6 +54,7 @@ maven-plugin-plugin ${pluginPluginVersion} + 3.6.3 antSimpleUsage diff --git a/maven-plugin-plugin/src/it/ant-since-maven-plugin/pom.xml b/maven-plugin-plugin/src/it/ant-since-maven-plugin/pom.xml index 74669006a..d817bc864 100644 --- a/maven-plugin-plugin/src/it/ant-since-maven-plugin/pom.xml +++ b/maven-plugin-plugin/src/it/ant-since-maven-plugin/pom.xml @@ -43,6 +43,7 @@ + 3.6.3 prefix diff --git a/maven-plugin-plugin/src/it/beanshell-simple/pom.xml b/maven-plugin-plugin/src/it/beanshell-simple/pom.xml index 713f2ac2a..3dcb024da 100644 --- a/maven-plugin-plugin/src/it/beanshell-simple/pom.xml +++ b/maven-plugin-plugin/src/it/beanshell-simple/pom.xml @@ -53,6 +53,7 @@ maven-plugin-plugin ${pluginPluginVersion} + 3.6.3 beanshellBasic diff --git a/maven-plugin-plugin/src/it/v4api/src/main/java/org/apache/maven/its/v4api/FirstMojo.java b/maven-plugin-plugin/src/it/v4api/src/main/java/org/apache/maven/its/v4api/FirstMojo.java index 879f3cefa..abab3cee0 100644 --- a/maven-plugin-plugin/src/it/v4api/src/main/java/org/apache/maven/its/v4api/FirstMojo.java +++ b/maven-plugin-plugin/src/it/v4api/src/main/java/org/apache/maven/its/v4api/FirstMojo.java @@ -22,13 +22,12 @@ 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.di.Inject; +import org.apache.maven.api.di.Named; 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; import org.apache.maven.api.plugin.annotations.Parameter; import org.apache.maven.api.services.ArtifactInstaller; @@ -38,15 +37,12 @@ * Test mojo for the v4 api plugin descriptor generation. * This mojo is not actually runnable because: * - it's using a custom lifecycle which is not defined - * - it has a @Component dependency on ArtifactInstaller (hint=test) which does not exist + * - it has a @Inject dependency on ArtifactInstaller (hint=test) which does not exist * * @since 1.2 */ -@Mojo( - name = "first", - requiresDependencyResolution = ResolutionScope.TEST, - defaultPhase = LifecyclePhase.INTEGRATION_TEST) -@Execute(phase = LifecyclePhase.GENERATE_SOURCES, lifecycle = "cobertura") +@Mojo(name = "first", defaultPhase = "integration-test") +@Execute(phase = "generate-sources", lifecycle = "cobertura") public class FirstMojo implements org.apache.maven.api.plugin.Mojo { /** @@ -66,23 +62,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 {} } diff --git a/maven-plugin-plugin/src/it/v4api/verify.groovy b/maven-plugin-plugin/src/it/v4api/verify.groovy index 1405e2313..878ab95a3 100644 --- a/maven-plugin-plugin/src/it/v4api/verify.groovy +++ b/maven-plugin-plugin/src/it/v4api/verify.groovy @@ -24,8 +24,8 @@ 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.requiredJavaVersion.text() == '17' +assert pluginDescriptor.requiredMavenVersion.text() == '4.0.0-beta-3' def mojo = pluginDescriptor.mojos.mojo.findAll{ it.goal.text() == "first" }[0] @@ -33,51 +33,12 @@ 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.requirements.requirement.size() == 6 - -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.requirements.requirement[2].role.text() == 'org.apache.maven.api.MojoExecution' -assert mojo.requirements.requirement[2].'role-hint'.isEmpty() -assert mojo.requirements.requirement[2].'field-name'.text() == 'mojo' - -assert mojo.requirements.requirement[3].role.text() == 'org.apache.maven.api.Project' -assert mojo.requirements.requirement[3].'role-hint'.isEmpty() -assert mojo.requirements.requirement[3].'field-name'.text() == 'project' - -assert mojo.requirements.requirement[4].role.text() == 'org.apache.maven.api.Session' -assert mojo.requirements.requirement[4].'role-hint'.isEmpty() -assert mojo.requirements.requirement[4].'field-name'.text() == 'session' - -assert mojo.requirements.requirement[5].role.text() == 'org.apache.maven.api.settings.Settings' -assert mojo.requirements.requirement[5].'role-hint'.isEmpty() -assert mojo.requirements.requirement[5].'field-name'.text() == 'settings' assert mojo.parameters.parameter.size() == 3 @@ -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' @@ -100,6 +63,8 @@ assert parameter.deprecated.isEmpty() assert parameter.required.text() == 'true' assert parameter.editable.text() == 'true' 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' @@ -110,6 +75,8 @@ assert parameter.deprecated.text() == 'As of 0.2' assert parameter.required.text() == 'false' assert parameter.editable.text() == 'true' 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() diff --git a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/DescriptorGeneratorMojo.java b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/DescriptorGeneratorMojo.java index 862edeaec..527798596 100644 --- a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/DescriptorGeneratorMojo.java +++ b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/DescriptorGeneratorMojo.java @@ -19,12 +19,16 @@ package org.apache.maven.plugin.plugin; import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.net.URI; -import java.util.Arrays; -import java.util.Collections; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Set; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.resolver.filter.ArtifactFilter; @@ -32,6 +36,7 @@ import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException; +import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.LifecyclePhase; @@ -48,8 +53,14 @@ import org.apache.maven.tools.plugin.scanner.MojoScanner; import org.codehaus.plexus.component.repository.ComponentDependency; import org.codehaus.plexus.util.ReaderFactory; +import org.codehaus.plexus.util.io.CachingOutputStream; +import org.codehaus.plexus.util.io.CachingWriter; +import org.objectweb.asm.*; import org.sonatype.plexus.build.incremental.BuildContext; +import static org.objectweb.asm.Opcodes.*; +import static org.objectweb.asm.Opcodes.ACC_PUBLIC; + /** *

* Generate a plugin descriptor. @@ -78,6 +89,12 @@ public class DescriptorGeneratorMojo extends AbstractGeneratorMojo { @Parameter(defaultValue = "${project.build.outputDirectory}/META-INF/maven", readonly = true) private File outputDirectory; + /** + * The directory where the generated class files will be put. + */ + @Parameter(defaultValue = "${project.build.outputDirectory}", readonly = true) + private File classOutputDirectory; + /** * The file encoding of the source files. * @@ -269,7 +286,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") @@ -352,6 +368,12 @@ public void generate() throws MojoExecutionException { PluginDescriptorFilesGenerator pluginDescriptorGenerator = new PluginDescriptorFilesGenerator(); pluginDescriptorGenerator.execute(outputDirectory, request); + // Generate the additional factories for v4 mojos + generateFactories(request.getPluginDescriptor()); + + // Generate index for v4 beans + generateIndex(); + buildContext.refresh(outputDirectory); } catch (GeneratorException e) { throw new MojoExecutionException("Error writing plugin descriptor", e); @@ -367,6 +389,141 @@ public void generate() throws MojoExecutionException { } } + private void generateIndex() throws GeneratorException { + try { + Set diBeans = new TreeSet<>(); + try (Stream paths = Files.walk(classOutputDirectory.toPath())) { + List classes = paths.filter( + p -> p.getFileName().toString().endsWith(".class")) + .collect(Collectors.toList()); + for (Path classFile : classes) { + String fileString = classFile.toString(); + String className = fileString + .substring(0, fileString.length() - ".class".length()) + .replace('/', '.'); + try (InputStream is = Files.newInputStream(classFile)) { + ClassReader rdr = new ClassReader(is); + rdr.accept( + new ClassVisitor(Opcodes.ASM9) { + String className; + + @Override + public void visit( + int version, + int access, + String name, + String signature, + String superName, + String[] interfaces) { + super.visit(version, access, name, signature, superName, interfaces); + className = name; + } + + @Override + public AnnotationVisitor visitAnnotation(String descriptor, boolean visible) { + if ("Lorg/apache/maven/api/di/Named;".equals(descriptor)) { + diBeans.add(className.replace('/', '.')); + } + return null; + } + }, + ClassReader.SKIP_FRAMES | ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG); + } + + // Class clazz = project.getClassRealm().loadClass(className); + // boolean hasQualifier = Stream.of(clazz.getAnnotations()) + // .flatMap(ann -> Stream.of(ann.getClass().getAnnotations())) + // .anyMatch(ann -> "org.apache.maven.api.di.Qualifier" + // .equals(ann.annotationType().getName())); + // if (hasQualifier) { + // diBeans.add(className); + // } + } + } + Path path = outputDirectory.toPath().resolve("org.apache.maven.api.di.Inject"); + if (diBeans.isEmpty()) { + Files.deleteIfExists(path); + } else { + try (CachingWriter w = new CachingWriter(path, StandardCharsets.UTF_8)) { + String content = diBeans.stream().collect(Collectors.joining("\n", "", "\n")); + w.write(content); + } + } + } catch (Exception e) { + throw new GeneratorException("Unable to generate index for v4 beans", e); + } + } + + private void generateFactories(PluginDescriptor pd) throws GeneratorException { + try { + // Set diBeans = new TreeSet<>(); + for (MojoDescriptor md : pd.getMojos()) { + if (md.isV4Api()) { + // diBeans.add(md.getImplementation() + "Factory"); + generateFactory(md); + } + } + // if (!diBeans.isEmpty()) { + // Path path = outputDirectory.toPath().resolve("org.apache.maven.api.di.Inject"); + // if (Files.exists(path)) { + // try (Stream lines = Files.lines(path, StandardCharsets.UTF_8)) { + // lines.forEach(diBeans::add); + // } + // } + // try (CachingWriter w = new CachingWriter(path, StandardCharsets.UTF_8)) { + // String content = diBeans.stream().collect(Collectors.joining("\n", "", "\n")); + // w.write(content); + // } + // } + } catch (IOException e) { + throw new GeneratorException("Unable to generate factories for v4 mojos", e); + } + } + + private void generateFactory(MojoDescriptor md) throws IOException { + String mojoClassName = md.getImplementation(); + String packageName = mojoClassName.substring(0, mojoClassName.lastIndexOf('.')); + String generatorClassName = mojoClassName.substring(mojoClassName.lastIndexOf('.') + 1) + "Factory"; + String mojoName = md.getId(); + + getLog().debug("Generating v4 factory for " + mojoClassName); + + byte[] bin = computeGeneratorClassBytes(packageName, generatorClassName, mojoName, mojoClassName); + + try (OutputStream os = new CachingOutputStream(classOutputDirectory + .toPath() + .resolve(packageName.replace('.', '/') + "/" + generatorClassName + ".class"))) { + os.write(bin); + } + } + + static byte[] computeGeneratorClassBytes( + String packageName, String generatorClassName, String mojoName, String mojoClassName) { + String mojo = mojoClassName.replace('.', '/'); + ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); + cw.visitSource(generatorClassName + ".java", null); + AnnotationVisitor av = cw.visitAnnotation("Lorg/apache/maven/api/di/Named;", true); + av.visit("value", mojoName); + av.visitEnd(); + cw.visitAnnotation("Lorg/apache/maven/api/annotations/Generated;", true).visitEnd(); + cw.visit( + V1_8, + ACC_PUBLIC + ACC_SUPER + ACC_SYNTHETIC, + packageName.replace(".", "/") + "/" + generatorClassName, + null, + mojo, + null); + MethodVisitor mv = cw.visitMethod(ACC_PUBLIC + ACC_SYNTHETIC, "", "()V", null, null); + mv.visitCode(); + mv.visitVarInsn(Opcodes.ALOAD, 0); + mv.visitMethodInsn(Opcodes.INVOKESPECIAL, mojo, "", "()V", false); + mv.visitInsn(Opcodes.RETURN); + mv.visitMaxs(-1, -1); + mv.visitEnd(); + cw.visitEnd(); + return cw.toByteArray(); + } + private PluginDescriptor extendPluginDescriptor(PluginToolsRequest request) { ExtendedPluginDescriptor extendedPluginDescriptor = new ExtendedPluginDescriptor(request.getPluginDescriptor()); extendedPluginDescriptor.setRequiredJavaVersion(getRequiredJavaVersion(request)); diff --git a/maven-plugin-plugin/src/test/java/org/apache/maven/plugin/plugin/DiGeneratorMojoTest.java b/maven-plugin-plugin/src/test/java/org/apache/maven/plugin/plugin/DiGeneratorMojoTest.java new file mode 100644 index 000000000..def5971f1 --- /dev/null +++ b/maven-plugin-plugin/src/test/java/org/apache/maven/plugin/plugin/DiGeneratorMojoTest.java @@ -0,0 +1,57 @@ +/* + * 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.plugin.plugin; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +public class DiGeneratorMojoTest { + + @Test + void testMojoGenerator() throws Exception { + byte[] data = DescriptorGeneratorMojo.computeGeneratorClassBytes( + "org.foo", + "MojoGenerator", + "the-mojo-full-id", + MyMojo.class.getName().replace('.', '/')); + + CustomClassLoader cl = new CustomClassLoader(getClass().getClassLoader()); + Class generator = cl.loadClassFromBytes(data); + Object result = generator.getConstructor().newInstance(); + assertNotNull(result); + assertInstanceOf(MyMojo.class, result); + } + + static class CustomClassLoader extends ClassLoader { + public CustomClassLoader(ClassLoader parent) { + super(parent); + } + + public Class loadClassFromBytes(byte[] classBytes) { + return defineClass(null, classBytes, 0, classBytes.length); // Define the class + } + } + + public static class MyMojo implements org.apache.maven.api.plugin.Mojo { + @Override + public void execute() {} + } +} diff --git a/maven-plugin-report-plugin/src/main/java/org/apache/maven/plugin/plugin/report/PluginDescriptorBuilder.java b/maven-plugin-report-plugin/src/main/java/org/apache/maven/plugin/plugin/report/PluginDescriptorBuilder.java new file mode 100644 index 000000000..cb118fe34 --- /dev/null +++ b/maven-plugin-report-plugin/src/main/java/org/apache/maven/plugin/plugin/report/PluginDescriptorBuilder.java @@ -0,0 +1,484 @@ +/* + * 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.plugin.plugin.report; + +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import java.io.*; +import java.net.URI; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import com.ctc.wstx.stax.WstxInputFactory; +import org.apache.maven.api.xml.XmlNode; +import org.apache.maven.internal.xml.XmlNodeStaxBuilder; +import org.apache.maven.internal.xml.XmlPlexusConfiguration; +import org.apache.maven.plugin.descriptor.MojoDescriptor; +import org.apache.maven.plugin.descriptor.Parameter; +import org.apache.maven.plugin.descriptor.PluginDescriptor; +import org.apache.maven.plugin.descriptor.io.PluginDescriptorStaxReader; +import org.apache.maven.tools.plugin.EnhancedParameterWrapper; +import org.apache.maven.tools.plugin.ExtendedPluginDescriptor; +import org.codehaus.plexus.component.repository.ComponentDependency; +import org.codehaus.plexus.component.repository.ComponentRequirement; +import org.codehaus.plexus.configuration.PlexusConfiguration; +import org.codehaus.plexus.configuration.PlexusConfigurationException; + +/** + */ +public class PluginDescriptorBuilder { + + public static final String PLUGIN_2_0_0 = "http://maven.apache.org/PLUGIN/2.0.0"; + private static final int BUFFER_SIZE = 8192; + + public interface StreamSupplier { + InputStream open() throws IOException; + } + + public interface ReaderSupplier { + Reader open() throws IOException; + } + + /** + * @deprecated use {@link #build(ReaderSupplier)} + */ + @Deprecated + public ExtendedPluginDescriptor build(Reader reader) throws PlexusConfigurationException { + return build(reader, null); + } + + /** + * @deprecated use {@link #build(ReaderSupplier, String)} + */ + @Deprecated + public ExtendedPluginDescriptor build(Reader reader, String source) throws PlexusConfigurationException { + return build(() -> reader, source); + } + + public ExtendedPluginDescriptor build(ReaderSupplier readerSupplier) throws PlexusConfigurationException { + return build(readerSupplier, null); + } + + public ExtendedPluginDescriptor build(ReaderSupplier readerSupplier, String source) + throws PlexusConfigurationException { + try (BufferedReader br = new BufferedReader(readerSupplier.open(), BUFFER_SIZE)) { + br.mark(BUFFER_SIZE); + XMLStreamReader xsr = WstxInputFactory.newFactory().createXMLStreamReader(br); + xsr.nextTag(); + String nsUri = xsr.getNamespaceURI(); + try (BufferedReader br2 = reset(readerSupplier, br)) { + xsr = WstxInputFactory.newFactory().createXMLStreamReader(br2); + return build(source, nsUri, xsr); + } + } catch (XMLStreamException | IOException e) { + throw new PlexusConfigurationException(e.getMessage(), e); + } + } + + /** + * @deprecated use {@link #build(StreamSupplier, String)} + */ + @Deprecated + public ExtendedPluginDescriptor build(InputStream input, String source) throws PlexusConfigurationException { + return build(() -> input, source); + } + + public ExtendedPluginDescriptor build(StreamSupplier inputSupplier) throws PlexusConfigurationException { + return build(inputSupplier, null); + } + + public ExtendedPluginDescriptor build(StreamSupplier inputSupplier, String source) + throws PlexusConfigurationException { + try (BufferedInputStream bis = new BufferedInputStream(inputSupplier.open(), BUFFER_SIZE)) { + bis.mark(BUFFER_SIZE); + XMLStreamReader xsr = WstxInputFactory.newFactory().createXMLStreamReader(bis); + xsr.nextTag(); + String nsUri = xsr.getNamespaceURI(); + try (BufferedInputStream bis2 = reset(inputSupplier, bis)) { + xsr = WstxInputFactory.newFactory().createXMLStreamReader(bis2); + return build(source, nsUri, xsr); + } + } catch (XMLStreamException | IOException e) { + throw new PlexusConfigurationException(e.getMessage(), e); + } + } + + private static BufferedInputStream reset(StreamSupplier inputSupplier, BufferedInputStream bis) throws IOException { + try { + bis.reset(); + return bis; + } catch (IOException e) { + return new BufferedInputStream(inputSupplier.open(), BUFFER_SIZE); + } + } + + private static BufferedReader reset(ReaderSupplier readerSupplier, BufferedReader br) throws IOException { + try { + br.reset(); + return br; + } catch (IOException e) { + return new BufferedReader(readerSupplier.open(), BUFFER_SIZE); + } + } + + private ExtendedPluginDescriptor build(String source, String nsUri, XMLStreamReader xsr) + throws XMLStreamException, PlexusConfigurationException { + if (PLUGIN_2_0_0.equals(nsUri)) { + org.apache.maven.api.plugin.descriptor.PluginDescriptor pd = + new PluginDescriptorStaxReader().read(xsr, true); + return new ExtendedPluginDescriptor(new PluginDescriptor(pd)); + } else { + PlexusConfiguration cfg = buildConfiguration(xsr); + return build(source, cfg); + } + } + + protected PlexusConfiguration buildConfiguration(XMLStreamReader xsr) throws XMLStreamException { + XmlNode node = XmlNodeStaxBuilder.build(xsr, true, null); + PlexusConfiguration cfg = XmlPlexusConfiguration.toPlexusConfiguration(node); + return cfg; + } + + private ExtendedPluginDescriptor build(String source, PlexusConfiguration c) throws PlexusConfigurationException { + ExtendedPluginDescriptor pluginDescriptor = new ExtendedPluginDescriptor(new PluginDescriptor()); + + pluginDescriptor.setSource(source); + pluginDescriptor.setGroupId(extractGroupId(c)); + pluginDescriptor.setArtifactId(extractArtifactId(c)); + pluginDescriptor.setVersion(extractVersion(c)); + pluginDescriptor.setGoalPrefix(extractGoalPrefix(c)); + + pluginDescriptor.setName(extractName(c)); + pluginDescriptor.setDescription(extractDescription(c)); + + pluginDescriptor.setIsolatedRealm(extractIsolatedRealm(c)); + pluginDescriptor.setInheritedByDefault(extractInheritedByDefault(c)); + pluginDescriptor.setRequiredJavaVersion(extractRequiredJavaVersion(c).orElse(null)); + pluginDescriptor.setRequiredMavenVersion(extractRequiredMavenVersion(c).orElse(null)); + + pluginDescriptor.addMojos(extractMojos(c, pluginDescriptor)); + + pluginDescriptor.setDependencies(extractComponentDependencies(c)); + + return pluginDescriptor; + } + + private String extractGroupId(PlexusConfiguration c) { + return c.getChild("groupId").getValue(); + } + + private String extractArtifactId(PlexusConfiguration c) { + return c.getChild("artifactId").getValue(); + } + + private String extractVersion(PlexusConfiguration c) { + return c.getChild("version").getValue(); + } + + private String extractGoalPrefix(PlexusConfiguration c) { + return c.getChild("goalPrefix").getValue(); + } + + private String extractName(PlexusConfiguration c) { + return c.getChild("name").getValue(); + } + + private String extractDescription(PlexusConfiguration c) { + return c.getChild("description").getValue(); + } + + private List extractMojos(PlexusConfiguration c, ExtendedPluginDescriptor pluginDescriptor) + throws PlexusConfigurationException { + List mojos = new ArrayList<>(); + + PlexusConfiguration[] mojoConfigurations = c.getChild("mojos").getChildren("mojo"); + + for (PlexusConfiguration component : mojoConfigurations) { + mojos.add(buildComponentDescriptor(component, pluginDescriptor)); + } + return mojos; + } + + private boolean extractInheritedByDefault(PlexusConfiguration c) { + String inheritedByDefault = c.getChild("inheritedByDefault").getValue(); + + if (inheritedByDefault != null) { + return Boolean.parseBoolean(inheritedByDefault); + } + return false; + } + + private boolean extractIsolatedRealm(PlexusConfiguration c) { + String isolatedRealm = c.getChild("isolatedRealm").getValue(); + + if (isolatedRealm != null) { + return Boolean.parseBoolean(isolatedRealm); + } + return false; + } + + private Optional extractRequiredJavaVersion(PlexusConfiguration c) { + return Optional.ofNullable(c.getChild("requiredJavaVersion")).map(PlexusConfiguration::getValue); + } + + private Optional extractRequiredMavenVersion(PlexusConfiguration c) { + return Optional.ofNullable(c.getChild("requiredMavenVersion")).map(PlexusConfiguration::getValue); + } + + private List extractComponentDependencies(PlexusConfiguration c) { + + PlexusConfiguration[] dependencyConfigurations = + c.getChild("dependencies").getChildren("dependency"); + + List dependencies = new ArrayList<>(); + + for (PlexusConfiguration d : dependencyConfigurations) { + dependencies.add(extractComponentDependency(d)); + } + return dependencies; + } + + private ComponentDependency extractComponentDependency(PlexusConfiguration d) { + ComponentDependency cd = new ComponentDependency(); + + cd.setArtifactId(extractArtifactId(d)); + + cd.setGroupId(extractGroupId(d)); + + cd.setType(d.getChild("type").getValue()); + + cd.setVersion(extractVersion(d)); + return cd; + } + + @SuppressWarnings("checkstyle:methodlength") + public MojoDescriptor buildComponentDescriptor(PlexusConfiguration c, ExtendedPluginDescriptor pluginDescriptor) + throws PlexusConfigurationException { + MojoDescriptor mojo = new MojoDescriptor(); + mojo.setPluginDescriptor(pluginDescriptor); + + mojo.setGoal(c.getChild("goal").getValue()); + + mojo.setImplementation(c.getChild("implementation").getValue()); + + PlexusConfiguration langConfig = c.getChild("language"); + + if (langConfig != null) { + mojo.setLanguage(langConfig.getValue()); + } + + PlexusConfiguration configuratorConfig = c.getChild("configurator"); + + if (configuratorConfig != null) { + mojo.setComponentConfigurator(configuratorConfig.getValue()); + } + + PlexusConfiguration composerConfig = c.getChild("composer"); + + if (composerConfig != null) { + mojo.setComponentComposer(composerConfig.getValue()); + } + + String since = c.getChild("since").getValue(); + + if (since != null) { + mojo.setSince(since); + } + + PlexusConfiguration deprecated = c.getChild("deprecated", false); + + if (deprecated != null) { + mojo.setDeprecated(deprecated.getValue()); + } + + String phase = c.getChild("phase").getValue(); + + if (phase != null) { + mojo.setPhase(phase); + } + + String executePhase = c.getChild("executePhase").getValue(); + + if (executePhase != null) { + mojo.setExecutePhase(executePhase); + } + + String executeMojo = c.getChild("executeGoal").getValue(); + + if (executeMojo != null) { + mojo.setExecuteGoal(executeMojo); + } + + String executeLifecycle = c.getChild("executeLifecycle").getValue(); + + if (executeLifecycle != null) { + mojo.setExecuteLifecycle(executeLifecycle); + } + + mojo.setInstantiationStrategy(c.getChild("instantiationStrategy").getValue()); + + mojo.setDescription(extractDescription(c)); + + PlexusConfiguration dependencyResolution = c.getChild("requiresDependencyResolution", false); + + if (dependencyResolution != null) { + mojo.setDependencyResolutionRequired(dependencyResolution.getValue()); + } + + PlexusConfiguration dependencyCollection = c.getChild("requiresDependencyCollection", false); + + if (dependencyCollection != null) { + mojo.setDependencyCollectionRequired(dependencyCollection.getValue()); + } + + String directInvocationOnly = c.getChild("requiresDirectInvocation").getValue(); + + if (directInvocationOnly != null) { + mojo.setDirectInvocationOnly(Boolean.parseBoolean(directInvocationOnly)); + } + + String requiresProject = c.getChild("requiresProject").getValue(); + + if (requiresProject != null) { + mojo.setProjectRequired(Boolean.parseBoolean(requiresProject)); + } + + String requiresReports = c.getChild("requiresReports").getValue(); + + if (requiresReports != null) { + mojo.setRequiresReports(Boolean.parseBoolean(requiresReports)); + } + + String aggregator = c.getChild("aggregator").getValue(); + + if (aggregator != null) { + mojo.setAggregator(Boolean.parseBoolean(aggregator)); + } + + String requiresOnline = c.getChild("requiresOnline").getValue(); + + if (requiresOnline != null) { + mojo.setOnlineRequired(Boolean.parseBoolean(requiresOnline)); + } + + String inheritedByDefault = c.getChild("inheritedByDefault").getValue(); + + if (inheritedByDefault != null) { + mojo.setInheritedByDefault(Boolean.parseBoolean(inheritedByDefault)); + } + + String threadSafe = c.getChild("threadSafe").getValue(); + + if (threadSafe != null) { + mojo.setThreadSafe(Boolean.parseBoolean(threadSafe)); + } + + String v4Api = c.getChild("v4Api").getValue(); + + if (v4Api != null) { + mojo.setV4Api(Boolean.parseBoolean(v4Api)); + } + + // ---------------------------------------------------------------------- + // Configuration + // ---------------------------------------------------------------------- + + PlexusConfiguration mojoConfig = c.getChild("configuration"); + mojo.setMojoConfiguration(mojoConfig); + + // ---------------------------------------------------------------------- + // Parameters + // ---------------------------------------------------------------------- + + PlexusConfiguration[] parameterConfigurations = c.getChild("parameters").getChildren("parameter"); + + List parameters = new ArrayList<>(); + + for (PlexusConfiguration d : parameterConfigurations) { + EnhancedParameterWrapper parameter = new EnhancedParameterWrapper(new Parameter()); + + parameter.setName(extractName(d)); + + parameter.setAlias(d.getChild("alias").getValue()); + + parameter.setType(d.getChild("type").getValue()); + + String required = d.getChild("required").getValue(); + + parameter.setRequired(Boolean.parseBoolean(required)); + + PlexusConfiguration editableConfig = d.getChild("editable"); + + // we need the null check for pre-build legacy plugins... + if (editableConfig != null) { + String editable = d.getChild("editable").getValue(); + + parameter.setEditable(editable == null || Boolean.parseBoolean(editable)); + } + + parameter.setDescription(extractDescription(d)); + + parameter.setDeprecated(d.getChild("deprecated").getValue()); + + parameter.setImplementation(d.getChild("implementation").getValue()); + + parameter.setSince(d.getChild("since").getValue()); + + PlexusConfiguration paramConfig = mojoConfig.getChild(parameter.getName(), false); + if (paramConfig != null) { + parameter.setExpression(paramConfig.getValue(null)); + parameter.setDefaultValue(paramConfig.getAttribute("default-value")); + } + + PlexusConfiguration configTypeJavadocUrl = d.getChild("typeJavadocUrl", false); + if (configTypeJavadocUrl != null) { + String parameterTypeJavadocUrl = configTypeJavadocUrl.getValue(); + parameter.setTypeJavadocUrl(URI.create(parameterTypeJavadocUrl)); + } + + parameters.add(parameter); + } + + mojo.setParameters(parameters); + + // TODO this should not need to be handed off... + + // ---------------------------------------------------------------------- + // Requirements + // ---------------------------------------------------------------------- + + PlexusConfiguration[] requirements = c.getChild("requirements").getChildren("requirement"); + + for (PlexusConfiguration requirement : requirements) { + ComponentRequirement cr = new ComponentRequirement(); + + cr.setRole(requirement.getChild("role").getValue()); + + cr.setRoleHint(requirement.getChild("role-hint").getValue()); + + cr.setFieldName(requirement.getChild("field-name").getValue()); + + mojo.addRequirement(cr); + } + + return mojo; + } +} diff --git a/maven-plugin-report-plugin/src/main/java/org/apache/maven/plugin/plugin/report/PluginOverviewRenderer.java b/maven-plugin-report-plugin/src/main/java/org/apache/maven/plugin/plugin/report/PluginOverviewRenderer.java index d557ed7f6..d0211f96a 100644 --- a/maven-plugin-report-plugin/src/main/java/org/apache/maven/plugin/plugin/report/PluginOverviewRenderer.java +++ b/maven-plugin-report-plugin/src/main/java/org/apache/maven/plugin/plugin/report/PluginOverviewRenderer.java @@ -27,8 +27,8 @@ import org.apache.maven.doxia.sink.Sink; import org.apache.maven.doxia.sink.impl.SinkEventAttributeSet; import org.apache.maven.plugin.descriptor.MojoDescriptor; -import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.project.MavenProject; +import org.apache.maven.tools.plugin.ExtendedPluginDescriptor; import org.apache.maven.tools.plugin.util.PluginUtils; import org.codehaus.plexus.i18n.I18N; @@ -40,7 +40,7 @@ class PluginOverviewRenderer extends AbstractPluginReportRenderer { private final List requirementsHistories; - private final PluginDescriptor pluginDescriptor; + private final ExtendedPluginDescriptor pluginDescriptor; private final boolean hasExtensionsToLoad; @@ -58,7 +58,7 @@ class PluginOverviewRenderer extends AbstractPluginReportRenderer { Locale locale, MavenProject project, List requirementsHistories, - PluginDescriptor pluginDescriptor, + ExtendedPluginDescriptor pluginDescriptor, boolean hasExtensionsToLoad) { super(sink, locale, i18n, project); diff --git a/maven-plugin-report-plugin/src/main/java/org/apache/maven/plugin/plugin/report/PluginReport.java b/maven-plugin-report-plugin/src/main/java/org/apache/maven/plugin/plugin/report/PluginReport.java index 5979fe700..81fece5d8 100644 --- a/maven-plugin-report-plugin/src/main/java/org/apache/maven/plugin/plugin/report/PluginReport.java +++ b/maven-plugin-report-plugin/src/main/java/org/apache/maven/plugin/plugin/report/PluginReport.java @@ -35,13 +35,11 @@ import org.apache.maven.model.building.ModelBuildingRequest; import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptor; -import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder; import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Execute; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; -import org.apache.maven.plugins.plugin.descriptor.EnhancedPluginDescriptorBuilder; import org.apache.maven.project.DefaultProjectBuildingRequest; import org.apache.maven.project.MavenProject; import org.apache.maven.project.ProjectBuilder; @@ -50,6 +48,7 @@ import org.apache.maven.reporting.AbstractMavenReport; import org.apache.maven.reporting.MavenReportException; import org.apache.maven.rtinfo.RuntimeInformation; +import org.apache.maven.tools.plugin.ExtendedPluginDescriptor; import org.codehaus.plexus.configuration.PlexusConfigurationException; import org.codehaus.plexus.i18n.I18N; import org.codehaus.plexus.util.xml.XmlStreamReader; @@ -179,7 +178,7 @@ public boolean canGenerateReport() { */ @Override protected void executeReport(Locale locale) throws MavenReportException { - PluginDescriptor pluginDescriptor = extractPluginDescriptor(); + ExtendedPluginDescriptor pluginDescriptor = extractPluginDescriptor(); // Generate the mojos' documentation generateMojosDocumentation(pluginDescriptor, locale); @@ -220,8 +219,8 @@ protected void executeReport(Locale locale) throws MavenReportException { r.render(); } - private PluginDescriptor extractPluginDescriptor() throws MavenReportException { - PluginDescriptorBuilder builder = new EnhancedPluginDescriptorBuilder(rtInfo); + private ExtendedPluginDescriptor extractPluginDescriptor() throws MavenReportException { + PluginDescriptorBuilder builder = new PluginDescriptorBuilder(); try (Reader input = new XmlStreamReader(Files.newInputStream(enhancedPluginXmlFile.toPath()))) { return builder.build(input); diff --git a/maven-plugin-report-plugin/src/main/java/org/apache/maven/plugins/plugin/descriptor/EnhancedPluginDescriptorBuilder.java b/maven-plugin-report-plugin/src/main/java/org/apache/maven/plugins/plugin/descriptor/EnhancedPluginDescriptorBuilder.java deleted file mode 100644 index b14e94332..000000000 --- a/maven-plugin-report-plugin/src/main/java/org/apache/maven/plugins/plugin/descriptor/EnhancedPluginDescriptorBuilder.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * 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.plugins.plugin.descriptor; - -import java.io.Reader; -import java.net.URI; -import java.util.ArrayList; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; - -import org.apache.maven.plugin.descriptor.MojoDescriptor; -import org.apache.maven.plugin.descriptor.Parameter; -import org.apache.maven.plugin.descriptor.PluginDescriptor; -import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder; -import org.apache.maven.plugin.plugin.report.PluginReport; -import org.apache.maven.rtinfo.RuntimeInformation; -import org.apache.maven.tools.plugin.EnhancedParameterWrapper; -import org.apache.maven.tools.plugin.ExtendedPluginDescriptor; -import org.apache.maven.tools.plugin.generator.PluginDescriptorFilesGenerator; -import org.codehaus.plexus.configuration.PlexusConfiguration; -import org.codehaus.plexus.configuration.PlexusConfigurationException; - -/** - * Reads enhanced plugin.xml files as generated by - * {@link PluginDescriptorFilesGenerator} and used by {@link PluginReport}. - * Populates the slightly extended {@link Parameter} object {@link EnhancedParameterWrapper}. - * In addition populates all (optional) elements added after Maven Plugin API 3.2.5. - */ -public class EnhancedPluginDescriptorBuilder extends PluginDescriptorBuilder { - private final boolean requireAddingMissingParameterSinceField; - private PlexusConfiguration configuration; - - public EnhancedPluginDescriptorBuilder(RuntimeInformation rtInfo) { - this(rtInfo.isMavenVersion("[,3.3.9]")); - } - - EnhancedPluginDescriptorBuilder(boolean requireAddingMissingParameterSinceField) { - this.requireAddingMissingParameterSinceField = requireAddingMissingParameterSinceField; - } - - /** - * Cache the returned configuration for additional evaluation in {@link #build(Reader, String)}. - */ - @Override - public PlexusConfiguration buildConfiguration(Reader reader) throws PlexusConfigurationException { - configuration = super.buildConfiguration(reader); - return configuration; - } - - @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; - } - - @Override - public MojoDescriptor buildComponentDescriptor(PlexusConfiguration c, PluginDescriptor pluginDescriptor) - throws PlexusConfigurationException { - MojoDescriptor mojoDescriptor = super.buildComponentDescriptor(c, pluginDescriptor); - - // ---------------------------------------------------------------------- - // Parameters - // ---------------------------------------------------------------------- - - PlexusConfiguration[] parameterConfigurations = c.getChild("parameters").getChildren("parameter"); - - List parameters = new ArrayList<>( - Optional.ofNullable(mojoDescriptor.getParameters()).orElseGet(Collections::emptyList)); - Map parameterMap = new LinkedHashMap<>(mojoDescriptor.getParameterMap()); - - for (PlexusConfiguration d : parameterConfigurations) { - String parameterName = d.getChild("name").getValue(); - // don't call getParameterMap() to not populate - Parameter pd = parameterMap.get(parameterName); - if (requireAddingMissingParameterSinceField) { - addMissingParameterSinceField(pd, d); - } - PlexusConfiguration configTypeJavadocUrl = d.getChild("typeJavadocUrl", false); - if (configTypeJavadocUrl != null) { - String parameterTypeJavadocUrl = configTypeJavadocUrl.getValue(); - EnhancedParameterWrapper enhancedParameter = new EnhancedParameterWrapper(pd); - enhancedParameter.setTypeJavadocUrl(URI.create(parameterTypeJavadocUrl)); - parameters.set(mojoDescriptor.getParameters().indexOf(pd), enhancedParameter); - parameterMap.put(parameterName, enhancedParameter); - } - } - - // TODO This cruft has been resolved in Maven 3.8.9/3.9.7/4.0.0-alpha-1 with MNG-6776/MNG-7309 - if (mojoDescriptor.getParameters() != null) { - mojoDescriptor.getParameters().clear(); - } - // set parameters - mojoDescriptor.setParameters(parameters); - mojoDescriptor.getParameterMap().putAll(parameterMap); - - return mojoDescriptor; - } - - /** - * Reads the plugin descriptor and adds the fix for - * MNG-6109 when using Maven-3.3.9 and before. - * Method can be removed once Maven 3.5.0 is the prerequisite for this plugin. - * @throws PlexusConfigurationException - * - * @since 3.5.1 - * @see MNG-6109 - * @see MPLUGIN-319 - */ - void addMissingParameterSinceField(Parameter pd, PlexusConfiguration d) throws PlexusConfigurationException { - String parameterSince = d.getChild("since").getValue(); - pd.setSince(parameterSince); - } -} diff --git a/maven-plugin-report-plugin/src/test/java/org/apache/maven/plugins/plugin/descriptor/EnhancedPluginDescriptorBuilderTest.java b/maven-plugin-report-plugin/src/test/java/org/apache/maven/plugin/plugin/report/PluginDescriptorBuilderTest.java similarity index 67% rename from maven-plugin-report-plugin/src/test/java/org/apache/maven/plugins/plugin/descriptor/EnhancedPluginDescriptorBuilderTest.java rename to maven-plugin-report-plugin/src/test/java/org/apache/maven/plugin/plugin/report/PluginDescriptorBuilderTest.java index ca4ede9c7..a1bd2d981 100644 --- a/maven-plugin-report-plugin/src/test/java/org/apache/maven/plugins/plugin/descriptor/EnhancedPluginDescriptorBuilderTest.java +++ b/maven-plugin-report-plugin/src/test/java/org/apache/maven/plugin/plugin/report/PluginDescriptorBuilderTest.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.maven.plugins.plugin.descriptor; +package org.apache.maven.plugin.plugin.report; import java.io.IOException; import java.io.InputStream; @@ -33,46 +33,36 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -public class EnhancedPluginDescriptorBuilderTest { +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class PluginDescriptorBuilderTest { @Test void testTypeJavaDocUrlElement() throws PlexusConfigurationException, IOException { - EnhancedPluginDescriptorBuilder builder = new EnhancedPluginDescriptorBuilder(false); + PluginDescriptorBuilder builder = new PluginDescriptorBuilder(); try (InputStream input = Objects.requireNonNull(this.getClass().getResourceAsStream("/plugin-enhanced.xml")); Reader reader = new XmlStreamReader(input)) { PluginDescriptor descriptor = builder.build(reader); MojoDescriptor mojoDescriptor = descriptor.getMojo("format-xml"); - Assertions.assertNotNull(mojoDescriptor); - EnhancedParameterWrapper enhancedParameter = assertEnhancedParameter(mojoDescriptor, "excludes"); + assertNotNull(mojoDescriptor); + EnhancedParameterWrapper enhancedParameter = assertParameter(mojoDescriptor, "excludes"); Assertions.assertEquals(URI.create("apidocs/java/util/Set.html"), enhancedParameter.getTypeJavadocUrl()); assertParameter(mojoDescriptor, "enableForIncrementalBuild"); // primitive types don't have javadoc } } - EnhancedParameterWrapper assertEnhancedParameter(MojoDescriptor mojoDescriptor, String parameterName) { - return (EnhancedParameterWrapper) assertParameter(mojoDescriptor, parameterName, true); - } - - Parameter assertParameter(MojoDescriptor mojoDescriptor, String parameterName) { - return assertParameter(mojoDescriptor, parameterName, false); - } - - Parameter assertParameter(MojoDescriptor mojoDescriptor, String parameterName, boolean isEnhancedParameter) { + EnhancedParameterWrapper assertParameter(MojoDescriptor mojoDescriptor, String parameterName) { // test both getParameters() and getParameterMap() as both use independent objects Parameter parameter = mojoDescriptor.getParameters().stream() .filter(p -> p.getName().equals(parameterName)) .findFirst() .orElse(null); - assertParameter(parameter, isEnhancedParameter); + assertNotNull(parameter); + assertTrue(parameter instanceof EnhancedParameterWrapper); Parameter parameterFromMap = mojoDescriptor.getParameterMap().get(parameterName); - assertParameter(parameterFromMap, isEnhancedParameter); // check that both are equal Assertions.assertEquals(parameter, parameterFromMap); - return parameter; - } - - void assertParameter(Parameter parameter, boolean isEnhhancedParameter) { - Assertions.assertNotNull(parameter); - Assertions.assertEquals(isEnhhancedParameter, parameter instanceof EnhancedParameterWrapper); + return (EnhancedParameterWrapper) parameter; } } diff --git a/maven-plugin-tools-annotations/pom.xml b/maven-plugin-tools-annotations/pom.xml index 2cf7ecfa7..a4311ee93 100644 --- a/maven-plugin-tools-annotations/pom.xml +++ b/maven-plugin-tools-annotations/pom.xml @@ -38,7 +38,7 @@ org.apache.maven - maven-core + maven-compat org.apache.maven diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/datamodel/ExecuteAnnotationContent.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/datamodel/ExecuteAnnotationContent.java index c1e3c9302..a8e7af4e5 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/datamodel/ExecuteAnnotationContent.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/datamodel/ExecuteAnnotationContent.java @@ -19,6 +19,7 @@ package org.apache.maven.tools.plugin.extractor.annotations.datamodel; import java.lang.annotation.Annotation; +import java.util.Objects; import org.apache.maven.plugins.annotations.Execute; import org.apache.maven.plugins.annotations.LifecyclePhase; @@ -57,6 +58,20 @@ public String lifecycle() { } public void phase(String phase) { + if (phase != null && !phase.isEmpty()) { + for (LifecyclePhase p : LifecyclePhase.values()) { + if (Objects.equals(phase, p.id()) || Objects.equals(phase, p.name())) { + this.phase = p; + this.customPhase = null; + return; + } + } + this.phase = null; + this.customPhase = phase; + } else { + this.phase = null; + this.customPhase = null; + } this.phase = LifecyclePhase.valueOf(phase); } diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/datamodel/MojoAnnotationContent.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/datamodel/MojoAnnotationContent.java index a3b6f6e80..121969905 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/datamodel/MojoAnnotationContent.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/datamodel/MojoAnnotationContent.java @@ -19,6 +19,7 @@ package org.apache.maven.tools.plugin.extractor.annotations.datamodel; import java.lang.annotation.Annotation; +import java.util.Objects; import org.apache.maven.plugins.annotations.InstantiationStrategy; import org.apache.maven.plugins.annotations.LifecyclePhase; @@ -69,7 +70,17 @@ public LifecyclePhase defaultPhase() { } public void defaultPhase(String phase) { - this.defaultPhase = LifecyclePhase.valueOf(phase); + if (phase != null && !phase.isEmpty()) { + for (LifecyclePhase p : LifecyclePhase.values()) { + if (Objects.equals(phase, p.id()) || Objects.equals(phase, p.name())) { + this.defaultPhase = p; + return; + } + } + throw new IllegalArgumentException("Could not find a matching phase for " + phase); + } else { + this.defaultPhase = null; + } } @Override @@ -81,6 +92,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; @@ -117,6 +132,10 @@ public void requiresProject(boolean requiresProject) { this.requiresProject = requiresProject; } + public void projectRequired(boolean requiresProject) { + this.requiresProject = requiresProject; + } + @Override public boolean requiresReports() { return requiresReports; diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScanner.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScanner.java index a91aea24e..759890115 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScanner.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScanner.java @@ -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; @@ -70,7 +71,6 @@ public class DefaultMojoAnnotationsScanner extends AbstractLogEnabled implements public static final String MOJO_V4 = MVN4_API + "Mojo"; public static final String EXECUTE_V4 = MVN4_API + "Execute"; public static final String PARAMETER_V4 = MVN4_API + "Parameter"; - public static final String COMPONENT_V4 = MVN4_API + "Component"; public static final String MOJO_V3 = Mojo.class.getName(); public static final String EXECUTE_V3 = Execute.class.getName(); @@ -88,15 +88,23 @@ public Map scan(MojoAnnotationsScannerRequest reques Map 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( @@ -332,16 +340,13 @@ protected void analyzeVisitors(MojoClassVisitor mojoClassVisitor) throws Extract // @Component annotations List mojoFieldVisitors = - mojoClassVisitor.findFieldWithAnnotation(new HashSet<>(Arrays.asList(COMPONENT_V3, COMPONENT_V4))); + mojoClassVisitor.findFieldWithAnnotation(new HashSet<>(Arrays.asList(COMPONENT_V3))); for (MojoFieldVisitor mojoFieldVisitor : mojoFieldVisitors) { ComponentAnnotationContent componentAnnotationContent = new ComponentAnnotationContent(mojoFieldVisitor.getFieldName()); Map annotationVisitorMap = mojoFieldVisitor.getAnnotationVisitorMap(); MojoAnnotationVisitor annotationVisitor = annotationVisitorMap.get(COMPONENT_V3); - if (annotationVisitor == null) { - annotationVisitor = annotationVisitorMap.get(COMPONENT_V4); - } if (annotationVisitor != null) { for (Map.Entry entry : diff --git a/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/extractor/annotations/ParametersWithGenericsMojo.java b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/extractor/annotations/ParametersWithGenericsMojo.java index d5796ba5b..5de14478e 100644 --- a/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/extractor/annotations/ParametersWithGenericsMojo.java +++ b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/extractor/annotations/ParametersWithGenericsMojo.java @@ -46,6 +46,9 @@ public class ParametersWithGenericsMojo extends AbstractMojo { @Parameter private Collection integerArrayCollection; + @Parameter + private Map> stringListStringMap; + @Override public void execute() throws MojoExecutionException, MojoFailureException {} diff --git a/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScannerTest.java b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScannerTest.java index 83dd04c47..bc8c0723b 100644 --- a/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScannerTest.java +++ b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScannerTest.java @@ -132,6 +132,12 @@ void scanParametersWithGenerics() throws ExtractionException, IOException { assertNotNull(parameter); assertEquals("java.util.List", parameter.getClassName()); assertThat(parameter.getTypeParameters()).containsExactly("java.lang.Number"); + + parameter = annotatedClass.getParameters().get("stringListStringMap"); + assertNotNull(parameter); + assertEquals("java.util.Map", parameter.getClassName()); + assertThat(parameter.getTypeParameters()) + .containsExactly("java.lang.String", "java.util.List"); } @Test diff --git a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/ExtendedPluginDescriptor.java b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/ExtendedPluginDescriptor.java index bb3dc5c04..6af39217f 100644 --- a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/ExtendedPluginDescriptor.java +++ b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/ExtendedPluginDescriptor.java @@ -18,20 +18,21 @@ */ package org.apache.maven.tools.plugin; +import javax.xml.stream.XMLStreamException; + import java.io.IOException; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; +import org.apache.maven.api.plugin.descriptor.lifecycle.Lifecycle; import org.apache.maven.artifact.Artifact; import org.apache.maven.model.Plugin; import org.apache.maven.plugin.descriptor.DuplicateMojoDescriptorException; import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptor; -import org.apache.maven.plugin.lifecycle.Lifecycle; import org.codehaus.plexus.classworlds.realm.ClassRealm; -import org.codehaus.plexus.util.xml.pull.XmlPullParserException; /** * Extensions to {@link PluginDescriptor} not supported by Maven 3.2.5. @@ -51,11 +52,19 @@ public ExtendedPluginDescriptor(PluginDescriptor delegate) { } public void setRequiredJavaVersion(String requiredJavaVersion) { - this.requiredJavaVersion = requiredJavaVersion; + try { + delegate.setRequiredJavaVersion(requiredJavaVersion); + } catch (Throwable t) { + this.requiredJavaVersion = requiredJavaVersion; + } } public String getRequiredJavaVersion() { - return requiredJavaVersion; + try { + return delegate.getRequiredJavaVersion(); + } catch (Throwable t) { + return requiredJavaVersion; + } } @Override @@ -91,6 +100,12 @@ public void addMojo(MojoDescriptor mojoDescriptor) throws DuplicateMojoDescripto delegate.addMojo(mojoDescriptor); } + public void addMojos(List mojos) throws DuplicateMojoDescriptorException { + for (MojoDescriptor mojoDescriptor : mojos) { + addMojo(mojoDescriptor); + } + } + public String getGroupId() { return delegate.getGroupId(); } @@ -223,7 +238,7 @@ public void setPluginArtifact(Artifact pluginArtifact) { } @Override - public Lifecycle getLifecycleMapping(String lifecycleId) throws IOException, XmlPullParserException { + public Lifecycle getLifecycleMapping(String lifecycleId) throws IOException, XMLStreamException { return delegate.getLifecycleMapping(lifecycleId); } diff --git a/maven-plugin-tools-generators/pom.xml b/maven-plugin-tools-generators/pom.xml index 35cde987c..1365a3019 100644 --- a/maven-plugin-tools-generators/pom.xml +++ b/maven-plugin-tools-generators/pom.xml @@ -60,6 +60,15 @@ velocity + + com.fasterxml.woodstox + woodstox-core + + + org.apache.maven + maven-xml-impl + + org.ow2.asm asm diff --git a/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/GeneratorUtils.java b/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/GeneratorUtils.java index ff27c17e1..fbd9c1691 100644 --- a/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/GeneratorUtils.java +++ b/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/GeneratorUtils.java @@ -22,6 +22,8 @@ import javax.swing.text.html.HTML; import javax.swing.text.html.HTMLEditorKit; import javax.swing.text.html.parser.ParserDelegator; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -44,8 +46,6 @@ import org.apache.maven.project.MavenProject; import org.apache.maven.tools.plugin.util.PluginUtils; import org.codehaus.plexus.component.repository.ComponentDependency; -import org.codehaus.plexus.util.StringUtils; -import org.codehaus.plexus.util.xml.XMLWriter; import org.w3c.tidy.Tidy; /** @@ -62,12 +62,13 @@ private GeneratorUtils() { * @param w not null writer * @param pluginDescriptor not null */ - public static void writeDependencies(XMLWriter w, PluginDescriptor pluginDescriptor) { - w.startElement("dependencies"); + public static void writeDependencies(XMLStreamWriter w, PluginDescriptor pluginDescriptor) + throws XMLStreamException { + w.writeStartElement("dependencies"); List deps = pluginDescriptor.getDependencies(); for (ComponentDependency dep : deps) { - w.startElement("dependency"); + w.writeStartElement("dependency"); element(w, "groupId", dep.getGroupId()); @@ -77,10 +78,10 @@ public static void writeDependencies(XMLWriter w, PluginDescriptor pluginDescrip element(w, "version", dep.getVersion()); - w.endElement(); + w.writeEndElement(); } - w.endElement(); + w.writeEndElement(); } /** @@ -88,16 +89,16 @@ public static void writeDependencies(XMLWriter w, PluginDescriptor pluginDescrip * @param name not null * @param value could be null */ - public static void element(XMLWriter w, String name, String value) { - w.startElement(name); + public static void element(XMLStreamWriter w, String name, String value) throws XMLStreamException { + w.writeStartElement(name); if (value == null) { value = ""; } - w.writeText(value); + w.writeCharacters(value); - w.endElement(); + w.writeEndElement(); } /** @@ -198,12 +199,12 @@ static String decodeJavadocTags(String description) { if (text == null || text.isEmpty()) { text = ""; } - if (StringUtils.isNotEmpty(link.group(member))) { + if (link.group(member) != null && !link.group(member).isEmpty()) { if (text != null && !text.isEmpty()) { text += '.'; } text += link.group(member); - if (StringUtils.isNotEmpty(link.group(args))) { + if (link.group(args) != null && !link.group(args).isEmpty()) { text += "()"; } } diff --git a/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorFilesGenerator.java b/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorFilesGenerator.java index c6923de67..baa06dc55 100644 --- a/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorFilesGenerator.java +++ b/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorFilesGenerator.java @@ -18,6 +18,10 @@ */ package org.apache.maven.tools.plugin.generator; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; + import java.io.File; import java.io.IOException; import java.io.OutputStreamWriter; @@ -41,8 +45,7 @@ import org.apache.maven.tools.plugin.util.PluginUtils; import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.io.CachingOutputStream; -import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter; -import org.codehaus.plexus.util.xml.XMLWriter; +import org.codehaus.stax2.util.StreamWriterDelegate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -87,7 +90,7 @@ public void execute(File destinationDirectory, PluginToolsRequest request) throw // write enhanced plugin-enhanced.xml descriptor (containing some XHTML values) f = getEnhancedDescriptorFilePath(mavenProject); writeDescriptor(f, request, DescriptorType.XHTML); - } catch (IOException e) { + } catch (IOException | XMLStreamException e) { throw new GeneratorException(e.getMessage(), e); } } @@ -103,15 +106,25 @@ private String getVersion() { } public void writeDescriptor(File destinationFile, PluginToolsRequest request, DescriptorType type) - throws IOException { + throws IOException, XMLStreamException { PluginDescriptor pluginDescriptor = request.getPluginDescriptor(); + String apiVersion = request.getPluginDescriptor().getRequiredMavenVersion(); + boolean isV4 = apiVersion != null && apiVersion.startsWith("4."); + String namespace = isV4 ? "http://maven.apache.org/PLUGIN/2.0.0" : null; + String location = isV4 ? "https://maven.apache.org/xsd/plugin-2.0.0-alpha-10.xsd" : null; + if (!destinationFile.getParentFile().exists()) { destinationFile.getParentFile().mkdirs(); } try (Writer writer = new OutputStreamWriter(new CachingOutputStream(destinationFile), UTF_8)) { - XMLWriter w = new PrettyPrintXMLWriter(writer, UTF_8.name(), null); + XMLOutputFactory factory = new com.ctc.wstx.stax.WstxOutputFactory(); + factory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, false); + factory.setProperty(com.ctc.wstx.api.WstxOutputProperties.P_USE_DOUBLE_QUOTES_IN_XML_DECL, true); + factory.setProperty(com.ctc.wstx.api.WstxOutputProperties.P_ADD_SPACE_AFTER_EMPTY_ELEM, true); + XMLStreamWriter w = new IndentingXMLStreamWriter(factory.createXMLStreamWriter(writer)); + w.writeStartDocument(UTF_8.name(), null); final String additionalInfo; switch (type) { @@ -125,28 +138,33 @@ public void writeDescriptor(File destinationFile, PluginToolsRequest request, De additionalInfo = ""; break; } - w.writeMarkup("\n\n\n"); - - w.startElement("plugin"); - + w.writeCharacters("\n"); + w.writeComment(" Generated by maven-plugin-tools " + getVersion() + additionalInfo + " "); + + if (isV4) { + w.writeStartElement("", "plugin", namespace); + // xmlns="http://maven.apache.org/PLUGIN/2.0.0" + // xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + // xsi:schemaLocation="http://maven.apache.org/PLUGIN/2.0.0 + // https://maven.apache.org/xsd/plugin-2.0.0-alpha-9.xsd" + w.writeNamespace("", namespace); + w.writeNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); + w.writeAttribute( + "http://www.w3.org/2001/XMLSchema-instance", "schemaLocation", namespace + " " + location); + } else { + w.writeStartElement("plugin"); + } GeneratorUtils.element(w, "name", pluginDescriptor.getName()); - GeneratorUtils.element(w, "description", pluginDescriptor.getDescription()); - GeneratorUtils.element(w, "groupId", pluginDescriptor.getGroupId()); - GeneratorUtils.element(w, "artifactId", pluginDescriptor.getArtifactId()); - GeneratorUtils.element(w, "version", pluginDescriptor.getVersion()); - GeneratorUtils.element(w, "goalPrefix", pluginDescriptor.getGoalPrefix()); if (type != DescriptorType.LIMITED_FOR_HELP_MOJO) { GeneratorUtils.element(w, "isolatedRealm", String.valueOf(pluginDescriptor.isIsolatedRealm())); - GeneratorUtils.element( w, "inheritedByDefault", String.valueOf(pluginDescriptor.isInheritedByDefault())); - if (pluginDescriptor instanceof ExtendedPluginDescriptor) { ExtendedPluginDescriptor extPluginDescriptor = (ExtendedPluginDescriptor) pluginDescriptor; if (StringUtils.isNotBlank(extPluginDescriptor.getRequiredJavaVersion())) { @@ -158,7 +176,7 @@ public void writeDescriptor(File destinationFile, PluginToolsRequest request, De } } - w.startElement("mojos"); + w.writeStartElement("mojos"); final JavadocLinkGenerator javadocLinkGenerator; if (request.getInternalJavadocBaseUrl() != null @@ -174,22 +192,18 @@ public void writeDescriptor(File destinationFile, PluginToolsRequest request, De } if (pluginDescriptor.getMojos() != null) { List descriptors = pluginDescriptor.getMojos(); - PluginUtils.sortMojos(descriptors); - for (MojoDescriptor descriptor : descriptors) { - processMojoDescriptor(descriptor, w, type, javadocLinkGenerator); + processMojoDescriptor(descriptor, w, type, javadocLinkGenerator, isV4); } } - w.endElement(); - - if (type != DescriptorType.LIMITED_FOR_HELP_MOJO) { + w.writeEndElement(); + if (type != DescriptorType.LIMITED_FOR_HELP_MOJO && !isV4) { GeneratorUtils.writeDependencies(w, pluginDescriptor); } - - w.endElement(); - + w.writeEndElement(); + w.close(); writer.flush(); } } @@ -219,21 +233,23 @@ private static String getTextValue(DescriptorType type, boolean containsXhtmlVal @SuppressWarnings("deprecation") protected void processMojoDescriptor( MojoDescriptor mojoDescriptor, - XMLWriter w, + XMLStreamWriter w, DescriptorType type, - JavadocLinkGenerator javadocLinkGenerator) { + JavadocLinkGenerator javadocLinkGenerator, + boolean isV4) + throws XMLStreamException { boolean containsXhtmlTextValues = mojoDescriptor instanceof ExtendedMojoDescriptor && ((ExtendedMojoDescriptor) mojoDescriptor).containsXhtmlTextValues(); - w.startElement("mojo"); + w.writeStartElement("mojo"); // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- - w.startElement("goal"); - w.writeText(mojoDescriptor.getGoal()); - w.endElement(); + w.writeStartElement("goal"); + w.writeCharacters(mojoDescriptor.getGoal()); + w.writeEndElement(); // ---------------------------------------------------------------------- // @@ -242,9 +258,9 @@ protected void processMojoDescriptor( String description = mojoDescriptor.getDescription(); if (description != null && !description.isEmpty()) { - w.startElement("description"); - w.writeText(getTextValue(type, containsXhtmlTextValues, mojoDescriptor.getDescription())); - w.endElement(); + w.writeStartElement("description"); + w.writeCharacters(getTextValue(type, containsXhtmlTextValues, mojoDescriptor.getDescription())); + w.writeEndElement(); } // ---------------------------------------------------------------------- @@ -252,26 +268,34 @@ protected void processMojoDescriptor( // ---------------------------------------------------------------------- if (StringUtils.isNotEmpty(mojoDescriptor.isDependencyResolutionRequired())) { - GeneratorUtils.element(w, "requiresDependencyResolution", mojoDescriptor.isDependencyResolutionRequired()); + GeneratorUtils.element( + w, + isV4 ? "dependencyResolution" : "requiresDependencyResolution", + mojoDescriptor.isDependencyResolutionRequired()); } // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- - - GeneratorUtils.element(w, "requiresDirectInvocation", String.valueOf(mojoDescriptor.isDirectInvocationOnly())); + if (!isV4) { + GeneratorUtils.element( + w, "requiresDirectInvocation", String.valueOf(mojoDescriptor.isDirectInvocationOnly())); + } // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- - GeneratorUtils.element(w, "requiresProject", String.valueOf(mojoDescriptor.isProjectRequired())); + GeneratorUtils.element( + w, isV4 ? "projectRequired" : "requiresProject", String.valueOf(mojoDescriptor.isProjectRequired())); // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- - GeneratorUtils.element(w, "requiresReports", String.valueOf(mojoDescriptor.isRequiresReports())); + if (!isV4) { + GeneratorUtils.element(w, "requiresReports", String.valueOf(mojoDescriptor.isRequiresReports())); + } // ---------------------------------------------------------------------- // @@ -283,7 +307,8 @@ protected void processMojoDescriptor( // // ---------------------------------------------------------------------- - GeneratorUtils.element(w, "requiresOnline", String.valueOf(mojoDescriptor.isOnlineRequired())); + GeneratorUtils.element( + w, isV4 ? "onlineRequired" : "requiresOnline", String.valueOf(mojoDescriptor.isOnlineRequired())); // ---------------------------------------------------------------------- // @@ -319,26 +344,26 @@ protected void processMojoDescriptor( // // ---------------------------------------------------------------------- - w.startElement("implementation"); - w.writeText(mojoDescriptor.getImplementation()); - w.endElement(); + w.writeStartElement("implementation"); + w.writeCharacters(mojoDescriptor.getImplementation()); + w.writeEndElement(); // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- - w.startElement("language"); - w.writeText(mojoDescriptor.getLanguage()); - w.endElement(); + w.writeStartElement("language"); + w.writeCharacters(mojoDescriptor.getLanguage()); + w.writeEndElement(); // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- if (StringUtils.isNotEmpty(mojoDescriptor.getComponentConfigurator())) { - w.startElement("configurator"); - w.writeText(mojoDescriptor.getComponentConfigurator()); - w.endElement(); + w.writeStartElement("configurator"); + w.writeCharacters(mojoDescriptor.getComponentConfigurator()); + w.writeEndElement(); } // ---------------------------------------------------------------------- @@ -346,41 +371,45 @@ protected void processMojoDescriptor( // ---------------------------------------------------------------------- if (StringUtils.isNotEmpty(mojoDescriptor.getComponentComposer())) { - w.startElement("composer"); - w.writeText(mojoDescriptor.getComponentComposer()); - w.endElement(); + w.writeStartElement("composer"); + w.writeCharacters(mojoDescriptor.getComponentComposer()); + w.writeEndElement(); } // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- - w.startElement("instantiationStrategy"); - w.writeText(mojoDescriptor.getInstantiationStrategy()); - w.endElement(); + if (!isV4) { + w.writeStartElement("instantiationStrategy"); + w.writeCharacters(mojoDescriptor.getInstantiationStrategy()); + w.writeEndElement(); + } // ---------------------------------------------------------------------- // Strategy for handling repeated reference to mojo in // the calculated (decorated, resolved) execution stack // ---------------------------------------------------------------------- - w.startElement("executionStrategy"); - w.writeText(mojoDescriptor.getExecutionStrategy()); - w.endElement(); + if (!isV4) { + w.writeStartElement("executionStrategy"); + w.writeCharacters(mojoDescriptor.getExecutionStrategy()); + w.writeEndElement(); + } // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- if (mojoDescriptor.getSince() != null) { - w.startElement("since"); + w.writeStartElement("since"); if (StringUtils.isEmpty(mojoDescriptor.getSince())) { - w.writeText("No version given"); + w.writeCharacters("No version given"); } else { - w.writeText(mojoDescriptor.getSince()); + w.writeCharacters(mojoDescriptor.getSince()); } - w.endElement(); + w.writeEndElement(); } // ---------------------------------------------------------------------- @@ -388,15 +417,15 @@ protected void processMojoDescriptor( // ---------------------------------------------------------------------- if (mojoDescriptor.getDeprecated() != null) { - w.startElement("deprecated"); + w.writeStartElement("deprecated"); if (StringUtils.isEmpty(mojoDescriptor.getDeprecated())) { - w.writeText("No reason given"); + w.writeCharacters("No reason given"); } else { - w.writeText(getTextValue(type, containsXhtmlTextValues, mojoDescriptor.getDeprecated())); + w.writeCharacters(getTextValue(type, containsXhtmlTextValues, mojoDescriptor.getDeprecated())); } - w.endElement(); + w.writeEndElement(); } // ---------------------------------------------------------------------- @@ -407,14 +436,13 @@ protected void processMojoDescriptor( ExtendedMojoDescriptor extendedMojoDescriptor = (ExtendedMojoDescriptor) mojoDescriptor; if (extendedMojoDescriptor.getDependencyCollectionRequired() != null) { GeneratorUtils.element( - w, "requiresDependencyCollection", extendedMojoDescriptor.getDependencyCollectionRequired()); + w, + isV4 ? "dependencyCollection" : "requiresDependencyCollection", + extendedMojoDescriptor.getDependencyCollectionRequired()); } - GeneratorUtils.element(w, "threadSafe", String.valueOf(extendedMojoDescriptor.isThreadSafe())); - - boolean v4Api = extendedMojoDescriptor.isV4Api(); - if (v4Api) { - GeneratorUtils.element(w, "v4Api", String.valueOf(v4Api)); + if (!isV4) { + GeneratorUtils.element(w, "threadSafe", String.valueOf(extendedMojoDescriptor.isThreadSafe())); } } @@ -424,7 +452,7 @@ protected void processMojoDescriptor( List parameters = mojoDescriptor.getParameters(); - w.startElement("parameters"); + w.writeStartElement("parameters"); Map requirements = new LinkedHashMap<>(); @@ -462,7 +490,7 @@ protected void processMojoDescriptor( else if (type != DescriptorType.LIMITED_FOR_HELP_MOJO || parameter.isEditable()) { // treat it as a normal parameter. - w.startElement("parameter"); + w.writeStartElement("parameter"); GeneratorUtils.element(w, "name", parameter.getName()); @@ -470,18 +498,22 @@ else if (type != DescriptorType.LIMITED_FOR_HELP_MOJO || parameter.isEditable()) GeneratorUtils.element(w, "alias", parameter.getAlias()); } - writeParameterType(w, type, javadocLinkGenerator, parameter, mojoDescriptor.getGoal()); + if (isV4 && type == DescriptorType.STANDARD) { + GeneratorUtils.element(w, "type", parameter.getType()); + } else { + writeParameterType(w, type, javadocLinkGenerator, parameter, mojoDescriptor.getGoal()); + } if (parameter.getSince() != null) { - w.startElement("since"); + w.writeStartElement("since"); if (StringUtils.isEmpty(parameter.getSince())) { - w.writeText("No version given"); + w.writeCharacters("No version given"); } else { - w.writeText(parameter.getSince()); + w.writeCharacters(parameter.getSince()); } - w.endElement(); + w.writeEndElement(); } if (parameter.getDeprecated() != null) { @@ -495,7 +527,7 @@ else if (type != DescriptorType.LIMITED_FOR_HELP_MOJO || parameter.isEditable()) } } - if (parameter.getImplementation() != null) { + if (!isV4 && parameter.getImplementation() != null) { GeneratorUtils.element(w, "implementation", parameter.getImplementation()); } @@ -506,24 +538,31 @@ else if (type != DescriptorType.LIMITED_FOR_HELP_MOJO || parameter.isEditable()) GeneratorUtils.element( w, "description", getTextValue(type, containsXhtmlTextValues, parameter.getDescription())); - if (StringUtils.isNotEmpty(parameter.getDefaultValue()) + if (isV4) { + if (parameter.getDefaultValue() != null) { + GeneratorUtils.element(w, "defaultValue", parameter.getDefaultValue()); + } + if (StringUtils.isNotEmpty(parameter.getExpression())) { + GeneratorUtils.element(w, "expression", parameter.getExpression()); + } + } else if (StringUtils.isNotEmpty(parameter.getDefaultValue()) || StringUtils.isNotEmpty(parameter.getExpression())) { configuration.add(parameter); } - w.endElement(); + w.writeEndElement(); } } } - w.endElement(); + w.writeEndElement(); // ---------------------------------------------------------------------- // Configuration // ---------------------------------------------------------------------- - if (!configuration.isEmpty()) { - w.startElement("configuration"); + if (!isV4 && !configuration.isEmpty()) { + w.writeStartElement("configuration"); for (Parameter parameter : configuration) { if (type == DescriptorType.LIMITED_FOR_HELP_MOJO && !parameter.isEditable()) { @@ -531,40 +570,40 @@ else if (type != DescriptorType.LIMITED_FOR_HELP_MOJO || parameter.isEditable()) continue; } - w.startElement(parameter.getName()); + w.writeStartElement(parameter.getName()); // strip type by parameter type (generics) information String parameterType = StringUtils.chomp(parameter.getType(), "<"); if (parameterType != null && !parameterType.isEmpty()) { - w.addAttribute("implementation", parameterType); + w.writeAttribute("implementation", parameterType); } if (parameter.getDefaultValue() != null) { - w.addAttribute("default-value", parameter.getDefaultValue()); + w.writeAttribute("default-value", parameter.getDefaultValue()); } if (StringUtils.isNotEmpty(parameter.getExpression())) { - w.writeText(parameter.getExpression()); + w.writeCharacters(parameter.getExpression()); } - w.endElement(); + w.writeEndElement(); } - w.endElement(); + w.writeEndElement(); } // ---------------------------------------------------------------------- // Requirements // ---------------------------------------------------------------------- - if (!requirements.isEmpty() && type != DescriptorType.LIMITED_FOR_HELP_MOJO) { - w.startElement("requirements"); + if (!isV4 && !requirements.isEmpty() && type != DescriptorType.LIMITED_FOR_HELP_MOJO) { + w.writeStartElement("requirements"); for (Map.Entry entry : requirements.entrySet()) { String key = entry.getKey(); Requirement requirement = entry.getValue(); - w.startElement("requirement"); + w.writeStartElement("requirement"); GeneratorUtils.element(w, "role", requirement.getRole()); @@ -574,13 +613,13 @@ else if (type != DescriptorType.LIMITED_FOR_HELP_MOJO || parameter.isEditable()) GeneratorUtils.element(w, "field-name", key); - w.endElement(); + w.writeEndElement(); } - w.endElement(); + w.writeEndElement(); } - w.endElement(); + w.writeEndElement(); } /** @@ -592,11 +631,12 @@ else if (type != DescriptorType.LIMITED_FOR_HELP_MOJO || parameter.isEditable()) * @param goal */ protected void writeParameterType( - XMLWriter w, + XMLStreamWriter w, DescriptorType type, JavadocLinkGenerator javadocLinkGenerator, Parameter parameter, - String goal) { + String goal) + throws XMLStreamException { String parameterType = parameter.getType(); if (type == DescriptorType.STANDARD) { @@ -670,4 +710,76 @@ private String getExpression(Parameter parameter) { } return expression; } + + static class IndentingXMLStreamWriter extends StreamWriterDelegate { + + int depth = 0; + boolean hasChildren = false; + + IndentingXMLStreamWriter(XMLStreamWriter parent) { + super(parent); + } + + @Override + public void writeEmptyElement(String localName) throws XMLStreamException { + indent(); + super.writeEmptyElement(localName); + hasChildren = true; + } + + @Override + public void writeEmptyElement(String namespaceURI, String localName) throws XMLStreamException { + indent(); + super.writeEmptyElement(namespaceURI, localName); + hasChildren = true; + } + + @Override + public void writeEmptyElement(String prefix, String localName, String namespaceURI) throws XMLStreamException { + indent(); + super.writeEmptyElement(prefix, localName, namespaceURI); + hasChildren = true; + } + + @Override + public void writeStartElement(String localName) throws XMLStreamException { + indent(); + super.writeStartElement(localName); + depth++; + hasChildren = false; + } + + @Override + public void writeStartElement(String namespaceURI, String localName) throws XMLStreamException { + indent(); + super.writeStartElement(namespaceURI, localName); + depth++; + hasChildren = false; + } + + @Override + public void writeStartElement(String prefix, String localName, String namespaceURI) throws XMLStreamException { + indent(); + super.writeStartElement(prefix, localName, namespaceURI); + depth++; + hasChildren = false; + } + + @Override + public void writeEndElement() throws XMLStreamException { + depth--; + if (hasChildren) { + indent(); + } + super.writeEndElement(); + hasChildren = true; + } + + private void indent() throws XMLStreamException { + super.writeCharacters("\n"); + for (int i = 0; i < depth; i++) { + super.writeCharacters(" "); + } + } + } } diff --git a/maven-plugin-tools-generators/src/main/resources/help-class-source-v4.vm b/maven-plugin-tools-generators/src/main/resources/help-class-source-v4.vm index 0ac5b891a..008c52192 100644 --- a/maven-plugin-tools-generators/src/main/resources/help-class-source-v4.vm +++ b/maven-plugin-tools-generators/src/main/resources/help-class-source-v4.vm @@ -18,8 +18,8 @@ package ${helpPackageName}; #end +import org.apache.maven.api.di.Inject; import org.apache.maven.api.plugin.MojoException; -import org.apache.maven.api.plugin.annotations.Component; import org.apache.maven.api.plugin.annotations.Mojo; import org.apache.maven.api.plugin.annotations.Parameter; import org.apache.maven.api.plugin.Log; @@ -43,11 +43,11 @@ import java.util.List; * Call mvn ${goalPrefix}:help -Ddetail=true -Dgoal=<goal-name> to display parameter details. * @author maven-plugin-tools */ -@Mojo( name = "help", requiresProject = false ) +@Mojo( name = "help", projectRequired = false ) public class HelpMojo implements org.apache.maven.api.plugin.Mojo { - @Component + @Inject private Log logger; /** @@ -189,6 +189,21 @@ public class HelpMojo return getSingleChild( node, elementName ).getTextContent(); } + private static String getValueOr( Node node, String elementName, String def ) + throws MojoException + { + List namedChild = findNamedChild( node, elementName ); + if ( namedChild.isEmpty() ) + { + return def; + } + if ( namedChild.size() > 1 ) + { + throw new MojoException( "Multiple " + elementName + " in plugin-help.xml" ); + } + return namedChild.get( 0 ).getTextContent(); + } + private static Node getSingleChild( Node node, String elementName ) throws MojoException { @@ -286,10 +301,10 @@ public class HelpMojo fieldConfigurationElement = (Element) findSingleChild( configurationElement, parameterName ); } - String parameterDefaultValue = ""; - if ( fieldConfigurationElement != null && fieldConfigurationElement.hasAttribute( "default-value" ) ) + String parameterDefaultValue = getValueOr( parameter, "defaultValue", "" ); + if ( isNotEmpty( parameterDefaultValue ) ) { - parameterDefaultValue = " (Default: " + fieldConfigurationElement.getAttribute( "default-value" ) + ")"; + parameterDefaultValue = " (Default: " + parameterDefaultValue + ")"; } append( sb, parameterName + parameterDefaultValue, 2 ); Node deprecated = findSingleChild( parameter, "deprecated" ); @@ -305,9 +320,11 @@ public class HelpMojo { append( sb, "Required: Yes", 3 ); } - if ( ( fieldConfigurationElement != null ) && isNotEmpty( fieldConfigurationElement.getTextContent() ) ) + + String parameterExpression = getValueOr( parameter, "expression", "" ); + if ( isNotEmpty( parameterExpression ) ) { - String property = getPropertyFromExpression( fieldConfigurationElement.getTextContent() ); + String property = getPropertyFromExpression( parameterExpression ); append( sb, "User property: " + property, 3 ); } diff --git a/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/AbstractGeneratorTestCase.java b/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/AbstractGeneratorTestCase.java index f592b6319..650924e4a 100644 --- a/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/AbstractGeneratorTestCase.java +++ b/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/AbstractGeneratorTestCase.java @@ -105,7 +105,73 @@ public void testGenerator() throws Exception { extendPluginDescriptor(pluginDescriptor); generator.execute(destinationDirectory, new DefaultPluginToolsRequest(mavenProject, pluginDescriptor)); - validate(destinationDirectory); + validate(destinationDirectory, false); + + FileUtils.deleteDirectory(destinationDirectory); + } + + @Test + public void testGeneratorV4() throws Exception { + setupGenerator(); + + MojoDescriptor mojoDescriptor = new MojoDescriptor(); + mojoDescriptor.setGoal("testGoal"); + mojoDescriptor.setImplementation("org.apache.maven.tools.plugin.generator.TestMojo"); + mojoDescriptor.setDependencyResolutionRequired("compile"); + mojoDescriptor.setSince("mojoSince"); + + List params = new ArrayList<>(); + + Parameter param = new Parameter(); + param.setExpression("${project.build.directory}"); + param.setDefaultValue(""); + param.setName("dir"); + param.setRequired(true); + param.setType("java.lang.String"); + param.setDescription("Test parameter description"); + param.setAlias("some.alias"); + param.setSince("paramDirSince"); + params.add(param); + + param = new Parameter(); + param.setName("withoutSince"); + param.setType("java.lang.String"); + params.add(param); + + mojoDescriptor.setParameters(params); + + PluginDescriptor pluginDescriptor = new PluginDescriptor(); + mojoDescriptor.setPluginDescriptor(pluginDescriptor); + + pluginDescriptor.addMojo(mojoDescriptor); + + pluginDescriptor.setArtifactId("maven-unitTesting-plugin"); + pluginDescriptor.setGoalPrefix("test"); + + ComponentDependency dependency = new ComponentDependency(); + dependency.setGroupId("testGroup"); + dependency.setArtifactId("testArtifact"); + dependency.setVersion("0.0.0"); + + pluginDescriptor.setDependencies(Collections.singletonList(dependency)); + + File destinationDirectory = + Files.createTempDirectory("testGenerator-outDir").toFile(); + destinationDirectory.mkdir(); + + MavenProject mavenProject = new MavenProject(); + mavenProject.setGroupId("foo"); + mavenProject.setArtifactId("bar"); + Build build = new Build(); + build.setDirectory(basedir + "/target"); + build.setOutputDirectory(basedir + "/target"); + mavenProject.setBuild(build); + extendPluginDescriptor(pluginDescriptor); + DefaultPluginToolsRequest request = new DefaultPluginToolsRequest(mavenProject, pluginDescriptor); + pluginDescriptor.setRequiredMavenVersion("4.0.0"); + generator.execute(destinationDirectory, request); + + validate(destinationDirectory, true); FileUtils.deleteDirectory(destinationDirectory); } @@ -145,7 +211,7 @@ protected void setupGenerator() throws Exception { // // ---------------------------------------------------------------------- - protected void validate(File destinationDirectory) throws Exception { + protected void validate(File destinationDirectory, boolean isV4) throws Exception { // empty } } diff --git a/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/GeneratorUtilsTest.java b/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/GeneratorUtilsTest.java index d0e10c8e2..53adda692 100644 --- a/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/GeneratorUtilsTest.java +++ b/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/GeneratorUtilsTest.java @@ -18,6 +18,9 @@ */ package org.apache.maven.tools.plugin.generator; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamWriter; + import java.io.StringWriter; import java.util.Arrays; import java.util.Collections; @@ -27,8 +30,6 @@ import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.codehaus.plexus.component.repository.ComponentDependency; -import org.codehaus.plexus.util.xml.CompactXMLWriter; -import org.codehaus.plexus.util.xml.XMLWriter; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -49,9 +50,14 @@ void testShouldWriteDependencies() throws Exception { descriptor.setDependencies(Collections.singletonList(dependency)); StringWriter sWriter = new StringWriter(); - XMLWriter writer = new CompactXMLWriter(sWriter); + XMLOutputFactory factory = new com.ctc.wstx.stax.WstxOutputFactory(); + factory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, false); + factory.setProperty(com.ctc.wstx.api.WstxOutputProperties.P_USE_DOUBLE_QUOTES_IN_XML_DECL, true); + factory.setProperty(com.ctc.wstx.api.WstxOutputProperties.P_ADD_SPACE_AFTER_EMPTY_ELEM, true); + XMLStreamWriter writer = factory.createXMLStreamWriter(sWriter); GeneratorUtils.writeDependencies(writer, descriptor); + writer.close(); String output = sWriter.toString(); diff --git a/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/PluginDescriptorFilesGeneratorTest.java b/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/PluginDescriptorFilesGeneratorTest.java index eb35539e4..519b4a224 100644 --- a/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/PluginDescriptorFilesGeneratorTest.java +++ b/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/PluginDescriptorFilesGeneratorTest.java @@ -60,20 +60,22 @@ protected void extendPluginDescriptor(PluginDescriptor pluginDescriptor) throws } @Override - protected void validate(File destinationDirectory) throws Exception { + protected void validate(File destinationDirectory, boolean isV4) throws Exception { PluginDescriptorBuilder pdb = new PluginDescriptorBuilder(); File pluginDescriptorFile = new File(destinationDirectory, "plugin.xml"); String pd = readFile(pluginDescriptorFile); + System.err.println(pd); + PluginDescriptor pluginDescriptor = pdb.build(new StringReader(pd)); assertEquals(1, pluginDescriptor.getMojos().size()); MojoDescriptor mojoDescriptor = pluginDescriptor.getMojos().get(0); - checkMojo(mojoDescriptor); + checkMojo(mojoDescriptor, isV4); // ---------------------------------------------------------------------- // Dependencies @@ -81,14 +83,12 @@ protected void validate(File destinationDirectory) throws Exception { List dependencies = pluginDescriptor.getDependencies(); - checkDependency("testGroup", "testArtifact", "0.0.0", dependencies.get(0)); - - assertEquals(1, dependencies.size()); - - ComponentDependency dependency = dependencies.get(0); - assertEquals("testGroup", dependency.getGroupId()); - assertEquals("testArtifact", dependency.getArtifactId()); - assertEquals("0.0.0", dependency.getVersion()); + if (isV4) { + assertEquals(0, dependencies.size()); + } else { + assertEquals(1, dependencies.size()); + checkDependency("testGroup", "testArtifact", "0.0.0", dependencies.get(0)); + } } private String readFile(File pluginDescriptorFile) throws IOException { @@ -105,7 +105,7 @@ private String readFile(File pluginDescriptorFile) throws IOException { return sWriter.toString(); } - private void checkMojo(MojoDescriptor mojoDescriptor) { + private void checkMojo(MojoDescriptor mojoDescriptor, boolean isV4) { assertEquals("test:testGoal", mojoDescriptor.getFullGoalName()); assertEquals("org.apache.maven.tools.plugin.generator.TestMojo", mojoDescriptor.getImplementation()); @@ -122,14 +122,26 @@ private void checkMojo(MojoDescriptor mojoDescriptor) { Parameter parameterWithGenerics = mojoDescriptor.getParameters().get(2); assertNotNull(parameterWithGenerics); assertEquals("parameterWithGenerics", parameterWithGenerics.getName()); - assertEquals("java.util.Collection", parameterWithGenerics.getType()); + + if (isV4) { + assertEquals("java.util.Collection", parameterWithGenerics.getType()); + } else { + assertEquals("java.util.Collection", parameterWithGenerics.getType()); + } PlexusConfiguration configurations = mojoDescriptor.getMojoConfiguration(); assertNotNull(configurations); PlexusConfiguration configuration = configurations.getChild("parameterWithGenerics"); - assertEquals("java.util.Collection", configuration.getAttribute("implementation")); - assertEquals("a,b,c", configuration.getAttribute("default-value")); - assertEquals("${customParam}", configuration.getValue()); + if (isV4) { + assertEquals(0, configuration.getChildren().length); + assertEquals("a,b,c", parameterWithGenerics.getParameterV4().getDefaultValue()); + assertEquals( + "${customParam}", parameterWithGenerics.getParameterV4().getExpression()); + } else { + assertEquals("java.util.Collection", configuration.getAttribute("implementation")); + assertEquals("a,b,c", configuration.getAttribute("default-value")); + assertEquals("${customParam}", configuration.getValue()); + } } private void checkParameter(Parameter parameter) { diff --git a/maven-script/maven-plugin-tools-ant/pom.xml b/maven-script/maven-plugin-tools-ant/pom.xml index 61770630c..7f2b4322f 100644 --- a/maven-script/maven-plugin-tools-ant/pom.xml +++ b/maven-script/maven-plugin-tools-ant/pom.xml @@ -33,6 +33,10 @@ + + org.apache.maven + maven-compat + org.apache.maven.plugin-tools maven-plugin-tools-api diff --git a/maven-script/maven-script-ant/pom.xml b/maven-script/maven-script-ant/pom.xml index e2bf4fae6..fbd1a3a28 100644 --- a/maven-script/maven-script-ant/pom.xml +++ b/maven-script/maven-script-ant/pom.xml @@ -76,7 +76,15 @@ under the License. org.apache.maven - maven-core + maven-compat + + + com.fasterxml.woodstox + woodstox-core + + + org.apache.maven + maven-xml-impl org.codehaus.plexus diff --git a/pom.xml b/pom.xml index 815a1fdae..83d3efa29 100644 --- a/pom.xml +++ b/pom.xml @@ -92,9 +92,9 @@ 8 3.3.0 - 4.0.0-alpha-4 + 4.0.0-beta-3 3.9.6 - 1.7.36 + 2.0.11 1.10.14 plugin-tools-archives/plugin-tools-LATEST - - - org.apache.maven.plugin-tools - maven-plugin-tools-ant - runtime - true - - - org.apache.maven.plugin-tools - maven-plugin-tools-beanshell - runtime - true - @@ -166,19 +153,6 @@ - - org.apache.maven.plugin-tools - maven-script-beanshell - ${project.version} - test - - - org.apache.maven.plugin-tools - maven-script-ant - ${project.version} - test - - org.apache.maven maven-di @@ -311,8 +285,6 @@ org.apache.maven.plugin-tools:maven-plugin-tools-annotations:${project.version}:jar:test-sources org.apache.maven.plugin-tools:maven-plugin-tools-annotations:${project.version}:test-jar - org.apache.maven.plugin-tools:maven-script-ant:${project.version} - org.apache.maven.plugin-tools:maven-script-beanshell:${project.version} diff --git a/maven-plugin-plugin/src/it/ant-basic/invoker.properties b/maven-plugin-plugin/src/it/ant-basic/invoker.properties deleted file mode 100644 index 55875b64e..000000000 --- a/maven-plugin-plugin/src/it/ant-basic/invoker.properties +++ /dev/null @@ -1,20 +0,0 @@ -# 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. - -invoker.goals.1 = clean install -invoker.goals.2 = org.apache.maven.ant.it:maven-ant-it-basic:1.0-SNAPSHOT:touch -Dname=touch.txt - diff --git a/maven-plugin-plugin/src/it/ant-basic/pom.xml b/maven-plugin-plugin/src/it/ant-basic/pom.xml deleted file mode 100644 index 5839b4a14..000000000 --- a/maven-plugin-plugin/src/it/ant-basic/pom.xml +++ /dev/null @@ -1,70 +0,0 @@ - - - - - - 4.0.0 - - org.apache.maven.ant.it - maven-ant-it-basic - 1.0-SNAPSHOT - maven-plugin - - Basic Ant-Mojo Integration Test - Tests the simplest case of using an Ant script to drive a mojo. - - - @project.version@ - - - - - org.apache.ant - ant - @antVersion@ - - - org.apache.maven.plugin-tools - maven-script-ant - @project.version@ - - - - - - - org.apache.maven.plugins - maven-plugin-plugin - ${pluginPluginVersion} - - 3.6.3 - antBasic - - - - org.apache.maven.plugin-tools - maven-plugin-tools-ant - ${pluginPluginVersion} - - - - - - diff --git a/maven-plugin-plugin/src/it/ant-basic/src/main/scripts/touch.build.xml b/maven-plugin-plugin/src/it/ant-basic/src/main/scripts/touch.build.xml deleted file mode 100644 index dc163ecfb..000000000 --- a/maven-plugin-plugin/src/it/ant-basic/src/main/scripts/touch.build.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/maven-plugin-plugin/src/it/ant-basic/src/main/scripts/touch.mojos.xml b/maven-plugin-plugin/src/it/ant-basic/src/main/scripts/touch.mojos.xml deleted file mode 100644 index d904ca783..000000000 --- a/maven-plugin-plugin/src/it/ant-basic/src/main/scripts/touch.mojos.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - - - touch-file - - touch - - - name - ${name} - true - false - java.lang.String - - - - - - diff --git a/maven-plugin-plugin/src/it/ant-basic/verify.groovy b/maven-plugin-plugin/src/it/ant-basic/verify.groovy deleted file mode 100644 index 71ea7e143..000000000 --- a/maven-plugin-plugin/src/it/ant-basic/verify.groovy +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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. - */ - -File touchFile = new File( basedir, "target/touch.txt" ) -assert touchFile.isFile() - -File descriptorFile = new File( basedir, "target/classes/META-INF/maven/plugin.xml" ); -assert descriptorFile.isFile() - -File oldHelpClass = new File( basedir, "target/classes/HelpMojo.class" ); -assert !oldHelpClass.exists() - - -return true; diff --git a/maven-plugin-plugin/src/it/ant-reference-parameter/invoker.properties b/maven-plugin-plugin/src/it/ant-reference-parameter/invoker.properties deleted file mode 100644 index 96636d0b6..000000000 --- a/maven-plugin-plugin/src/it/ant-reference-parameter/invoker.properties +++ /dev/null @@ -1,20 +0,0 @@ -# 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. - -invoker.goals.1 = clean install -invoker.goals.2 = org.apache.maven.ant.it:maven-ant-it-referenceParameter:1.0-SNAPSHOT:test - diff --git a/maven-plugin-plugin/src/it/ant-reference-parameter/pom.xml b/maven-plugin-plugin/src/it/ant-reference-parameter/pom.xml deleted file mode 100644 index 387dd1893..000000000 --- a/maven-plugin-plugin/src/it/ant-reference-parameter/pom.xml +++ /dev/null @@ -1,66 +0,0 @@ - - - - - - 4.0.0 - - org.apache.maven.ant.it - maven-ant-it-referenceParameter - 1.0-SNAPSHOT - maven-plugin - - Ant-Mojo Integration Test with non-String parameter - Tests using an Ant script to drive a mojo where a parameter is not a String type. - - - - org.apache.ant - ant - @antVersion@ - - - org.apache.maven.plugin-tools - maven-script-ant - @project.version@ - - - - - - - org.apache.maven.plugins - maven-plugin-plugin - @project.version@ - - 3.6.3 - antWithRefs - - - - org.apache.maven.plugin-tools - maven-plugin-tools-ant - @project.version@ - - - - - - diff --git a/maven-plugin-plugin/src/it/ant-reference-parameter/src/main/java/org/apache/maven/plugins/antWithRefs/ArtifactsTask.java b/maven-plugin-plugin/src/it/ant-reference-parameter/src/main/java/org/apache/maven/plugins/antWithRefs/ArtifactsTask.java deleted file mode 100644 index 3098d66e2..000000000 --- a/maven-plugin-plugin/src/it/ant-reference-parameter/src/main/java/org/apache/maven/plugins/antWithRefs/ArtifactsTask.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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.plugins.antWithRefs; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Task; - -public class ArtifactsTask extends Task { - - public void execute() throws BuildException { - log(String.valueOf((Object) getProject().getReference("artifacts"))); - } -} diff --git a/maven-plugin-plugin/src/it/ant-reference-parameter/src/main/resources/org/apache/maven/plugins/antWithRefs/antlib.xml b/maven-plugin-plugin/src/it/ant-reference-parameter/src/main/resources/org/apache/maven/plugins/antWithRefs/antlib.xml deleted file mode 100644 index 2fb4b4f28..000000000 --- a/maven-plugin-plugin/src/it/ant-reference-parameter/src/main/resources/org/apache/maven/plugins/antWithRefs/antlib.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - diff --git a/maven-plugin-plugin/src/it/ant-reference-parameter/src/main/scripts/test.build.xml b/maven-plugin-plugin/src/it/ant-reference-parameter/src/main/scripts/test.build.xml deleted file mode 100644 index 72a61c96e..000000000 --- a/maven-plugin-plugin/src/it/ant-reference-parameter/src/main/scripts/test.build.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - Project artifacts: - - - diff --git a/maven-plugin-plugin/src/it/ant-reference-parameter/src/main/scripts/test.mojos.xml b/maven-plugin-plugin/src/it/ant-reference-parameter/src/main/scripts/test.mojos.xml deleted file mode 100644 index ef296d041..000000000 --- a/maven-plugin-plugin/src/it/ant-reference-parameter/src/main/scripts/test.mojos.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - test - test - compile - - - artifacts - ${project.artifacts} - true - true - java.util.List - - - - - diff --git a/maven-plugin-plugin/src/it/ant-simple-usage/invoker.properties b/maven-plugin-plugin/src/it/ant-simple-usage/invoker.properties deleted file mode 100644 index 3df4a4d69..000000000 --- a/maven-plugin-plugin/src/it/ant-simple-usage/invoker.properties +++ /dev/null @@ -1,20 +0,0 @@ -# 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. - -invoker.goals.1 = clean install -#invoker.goals.2 = org.apache.maven.ant.it:maven-ant-it-referenceParameter:1.0-SNAPSHOT:test - diff --git a/maven-plugin-plugin/src/it/ant-simple-usage/plugin/pom.xml b/maven-plugin-plugin/src/it/ant-simple-usage/plugin/pom.xml deleted file mode 100644 index bb13a32fb..000000000 --- a/maven-plugin-plugin/src/it/ant-simple-usage/plugin/pom.xml +++ /dev/null @@ -1,70 +0,0 @@ - - - - - - 4.0.0 - - org.apache.maven.ant.it - simpleUsage-root - 1.0-SNAPSHOT - - simpleUsage-plugin - Simple Ant-Mojo - maven-plugin - Tests the simplest case of using an Ant script to drive a mojo. - - - @project.version@ - - - - - org.apache.ant - ant - - - org.apache.maven.plugin-tools - maven-script-ant - @project.version@ - - - - - - - org.apache.maven.plugins - maven-plugin-plugin - ${pluginPluginVersion} - - 3.6.3 - antSimpleUsage - - - - org.apache.maven.plugin-tools - maven-plugin-tools-ant - @project.version@ - - - - - - diff --git a/maven-plugin-plugin/src/it/ant-simple-usage/plugin/src/main/scripts/test.build.xml b/maven-plugin-plugin/src/it/ant-simple-usage/plugin/src/main/scripts/test.build.xml deleted file mode 100644 index 8ba12c136..000000000 --- a/maven-plugin-plugin/src/it/ant-simple-usage/plugin/src/main/scripts/test.build.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - Hello, ${name}! - - \ No newline at end of file diff --git a/maven-plugin-plugin/src/it/ant-simple-usage/plugin/src/main/scripts/test.mojos.xml b/maven-plugin-plugin/src/it/ant-simple-usage/plugin/src/main/scripts/test.mojos.xml deleted file mode 100644 index 464d8aa6d..000000000 --- a/maven-plugin-plugin/src/it/ant-simple-usage/plugin/src/main/scripts/test.mojos.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - test - test - - - name - ${name} - true - false - java.lang.String - - - - - diff --git a/maven-plugin-plugin/src/it/ant-simple-usage/pom.xml b/maven-plugin-plugin/src/it/ant-simple-usage/pom.xml deleted file mode 100644 index 46eb6738b..000000000 --- a/maven-plugin-plugin/src/it/ant-simple-usage/pom.xml +++ /dev/null @@ -1,48 +0,0 @@ - - - - - - 4.0.0 - - org.apache.maven.ant.it - simpleUsage-root - 1.0-SNAPSHOT - pom - - Simple-Usage Ant-Mojo Integration Test - Root - Tests the simplest case of using an Ant script to drive a mojo. - - - - - org.apache.ant - ant - @antVersion@ - - - - - - plugin - usage - - - diff --git a/maven-plugin-plugin/src/it/ant-simple-usage/usage/pom.xml b/maven-plugin-plugin/src/it/ant-simple-usage/usage/pom.xml deleted file mode 100644 index 7339c8049..000000000 --- a/maven-plugin-plugin/src/it/ant-simple-usage/usage/pom.xml +++ /dev/null @@ -1,63 +0,0 @@ - - - - - - 4.0.0 - - org.apache.maven.ant.it - simpleUsage-root - 1.0-SNAPSHOT - - simpleUsage-usage - Simple Ant-Mojo Usage Case - Tests the simplest case of using an Ant script to drive a mojo. - - - - org.apache.ant - ant - - - - - - - org.apache.maven.ant.it - simpleUsage-plugin - 1.0-SNAPSHOT - - - Hani - - - - - test - package - - test - - - - - - - diff --git a/maven-plugin-plugin/src/it/ant-since-maven-plugin/pom.xml b/maven-plugin-plugin/src/it/ant-since-maven-plugin/pom.xml deleted file mode 100644 index d817bc864..000000000 --- a/maven-plugin-plugin/src/it/ant-since-maven-plugin/pom.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - - 4.0.0 - test - trivial-maven-plugin - maven-plugin - 1.0 - trivial-maven-plugin - Just a test project - http://nowere.test - 2012 - - - - - org.apache.maven.plugins - maven-plugin-plugin - @project.version@ - - - org.apache.maven.plugin-tools - maven-plugin-tools-ant - @project.version@ - - - - 3.6.3 - prefix - - - - - - diff --git a/maven-plugin-plugin/src/it/ant-since-maven-plugin/src/main/scripts/sample.build.xml b/maven-plugin-plugin/src/it/ant-since-maven-plugin/src/main/scripts/sample.build.xml deleted file mode 100644 index a2793dc40..000000000 --- a/maven-plugin-plugin/src/it/ant-since-maven-plugin/src/main/scripts/sample.build.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - - - - - - - diff --git a/maven-plugin-plugin/src/it/ant-since-maven-plugin/src/main/scripts/sample.mojos.xml b/maven-plugin-plugin/src/it/ant-since-maven-plugin/src/main/scripts/sample.mojos.xml deleted file mode 100644 index 988c04af5..000000000 --- a/maven-plugin-plugin/src/it/ant-since-maven-plugin/src/main/scripts/sample.mojos.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - sample - sample-task - Just a test - false - false - 1.0 - - - - message - java.lang.String - true - true - 1.0 - Test param - - - - - - diff --git a/maven-plugin-plugin/src/it/beanshell-simple/invoker.properties b/maven-plugin-plugin/src/it/beanshell-simple/invoker.properties deleted file mode 100644 index 88773cf4e..000000000 --- a/maven-plugin-plugin/src/it/beanshell-simple/invoker.properties +++ /dev/null @@ -1,20 +0,0 @@ -# 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. - -invoker.goals.1 = clean install -invoker.goals.2 = org.apache.maven.beanshell.it:maven-beanshell-it-basic:1.0-SNAPSHOT:touch -Dname=touch.txt - diff --git a/maven-plugin-plugin/src/it/beanshell-simple/pom.xml b/maven-plugin-plugin/src/it/beanshell-simple/pom.xml deleted file mode 100644 index 3dcb024da..000000000 --- a/maven-plugin-plugin/src/it/beanshell-simple/pom.xml +++ /dev/null @@ -1,69 +0,0 @@ - - - - - - 4.0.0 - - org.apache.maven.beanshell.it - maven-beanshell-it-basic - 1.0-SNAPSHOT - maven-plugin - - Basic Beanshell-Mojo Integration Test - - - @project.version@ - - - - - org.apache-extras.beanshell - bsh - 2.0b6 - - - org.apache.maven.plugin-tools - maven-script-beanshell - @project.version@ - - - - - - - org.apache.maven.plugins - maven-plugin-plugin - ${pluginPluginVersion} - - 3.6.3 - beanshellBasic - - - - org.apache.maven.plugin-tools - maven-plugin-tools-beanshell - ${pluginPluginVersion} - - - - - - diff --git a/maven-plugin-plugin/src/it/beanshell-simple/src/main/scripts/touch.bsh b/maven-plugin-plugin/src/it/beanshell-simple/src/main/scripts/touch.bsh deleted file mode 100644 index 99de7e4c5..000000000 --- a/maven-plugin-plugin/src/it/beanshell-simple/src/main/scripts/touch.bsh +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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. - */ - -// START SNIPPET: beanshell-mojo -/** - * Touches a test file. - * - * @goal touch - * @requiresDependencyResolution=test - * @deprecated Don't use! - * @since 1.2 - */ - -import org.apache.maven.plugin.Mojo; -import org.apache.maven.script.beanshell.BeanshellMojoAdapter; -import org.codehaus.plexus.util.FileUtils; - - - -execute() -{ - logger.info( "Executing beanshell mojo..." ); - FileUtils.fileWrite( outDir + "/" + name, "This is a Beanshell test" ); -} - -/** - * Output directory for files. - * - * @parameter expression="${project.build.directory}" - * @required - */ -setOutDir( file ) -{ - outDir = file; -} - -/** - * - * - * @parameter expression="${name}" - * @required - */ -setName( name ) -{ - name = name; -} - -return new BeanshellMojoAdapter( (Mojo) this, this.interpreter ); -// END SNIPPET: beanshell-mojo diff --git a/maven-plugin-plugin/src/it/beanshell-simple/verify.groovy b/maven-plugin-plugin/src/it/beanshell-simple/verify.groovy deleted file mode 100644 index c58c823e5..000000000 --- a/maven-plugin-plugin/src/it/beanshell-simple/verify.groovy +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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. - */ - -File touchFile = new File( basedir, "target/touch.txt" ) -assert touchFile.exists() -assert touchFile.isFile() -content = touchFile.text -assert content.contains('This is a Beanshell test'); - - -return true; diff --git a/maven-plugin-report-plugin/src/it/fix-maven-since-3.x/antsample-maven-plugin/pom.xml b/maven-plugin-report-plugin/src/it/fix-maven-since-3.x/antsample-maven-plugin/pom.xml deleted file mode 100644 index a529d616c..000000000 --- a/maven-plugin-report-plugin/src/it/fix-maven-since-3.x/antsample-maven-plugin/pom.xml +++ /dev/null @@ -1,78 +0,0 @@ - - - - 4.0.0 - - - test - maven-since-3.x - 1.0-SNAPSHOT - - - test - antsample-maven-plugin - maven-plugin - ANT Sample - Just a test project - http://nowere.test - 2012 - - - UTF-8 - - - - - org.apache.maven - maven-plugin-api - @maven3Version@ - provided - - - - - - - org.apache.maven.plugins - maven-plugin-plugin - @project.version@ - - - org.apache.maven.plugin-tools - maven-plugin-tools-ant - @project.version@ - - - - - - - - - - org.apache.maven.plugins - maven-plugin-report-plugin - @project.version@ - - - - - diff --git a/maven-plugin-report-plugin/src/it/fix-maven-since-3.x/antsample-maven-plugin/src/main/scripts/sample.build.xml b/maven-plugin-report-plugin/src/it/fix-maven-since-3.x/antsample-maven-plugin/src/main/scripts/sample.build.xml deleted file mode 100644 index 4e8e415ca..000000000 --- a/maven-plugin-report-plugin/src/it/fix-maven-since-3.x/antsample-maven-plugin/src/main/scripts/sample.build.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - - - - - - - diff --git a/maven-plugin-report-plugin/src/it/fix-maven-since-3.x/antsample-maven-plugin/src/main/scripts/sample.mojos.xml b/maven-plugin-report-plugin/src/it/fix-maven-since-3.x/antsample-maven-plugin/src/main/scripts/sample.mojos.xml deleted file mode 100644 index 1116b9075..000000000 --- a/maven-plugin-report-plugin/src/it/fix-maven-since-3.x/antsample-maven-plugin/src/main/scripts/sample.mojos.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - sample - sample-task - Just a test - false - false - 1.0 - - - - message - java.lang.String - true - false - 0.9 - Test param - - - - - - diff --git a/maven-plugin-report-plugin/src/it/fix-maven-since-3.x/antsample-maven-plugin/src/site/site.xml b/maven-plugin-report-plugin/src/it/fix-maven-since-3.x/antsample-maven-plugin/src/site/site.xml deleted file mode 100644 index e4ac0af49..000000000 --- a/maven-plugin-report-plugin/src/it/fix-maven-since-3.x/antsample-maven-plugin/src/site/site.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - org.apache.maven.skins - maven-fluido-skin - 1.11.1 - - - - - -

- - - - - - - - diff --git a/maven-plugin-report-plugin/src/it/fix-maven-since-3.x/pom.xml b/maven-plugin-report-plugin/src/it/fix-maven-since-3.x/pom.xml index b36696602..7e5a8fba9 100644 --- a/maven-plugin-report-plugin/src/it/fix-maven-since-3.x/pom.xml +++ b/maven-plugin-report-plugin/src/it/fix-maven-since-3.x/pom.xml @@ -30,7 +30,6 @@ 2012 - antsample-maven-plugin javasample-maven-plugin @@ -60,13 +59,6 @@ - - - org.apache.maven.plugin-tools - maven-plugin-tools-ant - @project.version@ - - org.apache.maven.plugins diff --git a/maven-plugin-report-plugin/src/it/fix-maven-since-3.x/verify.groovy b/maven-plugin-report-plugin/src/it/fix-maven-since-3.x/verify.groovy index 19e281a8d..62a67dbbb 100644 --- a/maven-plugin-report-plugin/src/it/fix-maven-since-3.x/verify.groovy +++ b/maven-plugin-report-plugin/src/it/fix-maven-since-3.x/verify.groovy @@ -17,7 +17,7 @@ * under the License. */ -File touchFile = new File( basedir, "antsample-maven-plugin/target/site/sample-mojo.html" ) +File touchFile = new File( basedir, "javasample-maven-plugin/target/site/touch-mojo.html" ) assert touchFile.exists() assert touchFile.isFile() content = touchFile.text diff --git a/maven-script/maven-plugin-tools-ant/pom.xml b/maven-script/maven-plugin-tools-ant/pom.xml deleted file mode 100644 index 7f2b4322f..000000000 --- a/maven-script/maven-plugin-tools-ant/pom.xml +++ /dev/null @@ -1,75 +0,0 @@ - - - - 4.0.0 - - - org.apache.maven.plugin-tools - maven-script - 4.0.0-SNAPSHOT - - - maven-plugin-tools-ant - - Maven Plugin Tool for Ant (deprecated) - Descriptor extractor for plugins written in Ant. - - - - - org.apache.maven - maven-compat - - - org.apache.maven.plugin-tools - maven-plugin-tools-api - - - org.apache.maven.plugin-tools - maven-plugin-tools-model - - - org.junit.jupiter - junit-jupiter-engine - test - - - - - org.codehaus.plexus - plexus-utils - - - org.eclipse.sisu - org.eclipse.sisu.plexus - compile - - - - - - - org.eclipse.sisu - sisu-maven-plugin - - - - - diff --git a/maven-script/maven-plugin-tools-ant/src/main/java/org/apache/maven/tools/plugin/extractor/ant/AntMojoDescriptorExtractor.java b/maven-script/maven-plugin-tools-ant/src/main/java/org/apache/maven/tools/plugin/extractor/ant/AntMojoDescriptorExtractor.java deleted file mode 100644 index 814e59576..000000000 --- a/maven-script/maven-plugin-tools-ant/src/main/java/org/apache/maven/tools/plugin/extractor/ant/AntMojoDescriptorExtractor.java +++ /dev/null @@ -1,236 +0,0 @@ -/* - * 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.tools.plugin.extractor.ant; - -import javax.inject.Named; -import javax.inject.Singleton; - -import java.io.File; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException; -import org.apache.maven.plugin.descriptor.MojoDescriptor; -import org.apache.maven.plugin.descriptor.Parameter; -import org.apache.maven.project.MavenProject; -import org.apache.maven.project.path.PathTranslator; -import org.apache.maven.tools.plugin.PluginToolsRequest; -import org.apache.maven.tools.plugin.extractor.AbstractScriptedMojoDescriptorExtractor; -import org.apache.maven.tools.plugin.extractor.ExtractionException; -import org.apache.maven.tools.plugin.extractor.GroupKey; -import org.apache.maven.tools.plugin.extractor.model.PluginMetadataParseException; -import org.apache.maven.tools.plugin.extractor.model.PluginMetadataParser; -import org.codehaus.plexus.component.repository.ComponentRequirement; - -/** - * Extracts Mojo descriptors from Ant sources. - * - * @deprecated Scripting support for mojos is deprecated and is planned tp be removed in maven 4.0 - */ -@Deprecated -@Named(AntMojoDescriptorExtractor.NAME) -@Singleton -public class AntMojoDescriptorExtractor extends AbstractScriptedMojoDescriptorExtractor { - public static final String NAME = "ant"; - - private static final GroupKey GROUP_KEY = new GroupKey("ant", 100); - - /** Default metadata file extension */ - private static final String METADATA_FILE_EXTENSION = ".mojos.xml"; - - /** Default Ant build file extension */ - private static final String SCRIPT_FILE_EXTENSION = ".build.xml"; - - @Override - public String getName() { - return NAME; - } - - @Override - public GroupKey getGroupKey() { - return GROUP_KEY; - } - - /** {@inheritDoc} */ - @Override - protected List extractMojoDescriptorsFromMetadata( - Map> metadataFilesKeyedByBasedir, PluginToolsRequest request) - throws ExtractionException, InvalidPluginDescriptorException { - List descriptors = new ArrayList<>(); - - PluginMetadataParser parser = new PluginMetadataParser(); - - for (Map.Entry> entry : metadataFilesKeyedByBasedir.entrySet()) { - String basedir = entry.getKey(); - Set metadataFiles = entry.getValue(); - - for (File metadataFile : metadataFiles) { - String basename = metadataFile.getName(); - basename = basename.substring(0, basename.length() - METADATA_FILE_EXTENSION.length()); - - File scriptFile = new File(metadataFile.getParentFile(), basename + SCRIPT_FILE_EXTENSION); - - if (!scriptFile.exists()) { - throw new InvalidPluginDescriptorException("Found orphaned plugin metadata file: " + metadataFile); - } - - String relativePath = - scriptFile.getPath().substring(basedir.length()).replace('\\', '/'); - - if (relativePath.startsWith("/")) { - relativePath = relativePath.substring(1); - } - - try { - Set mojoDescriptors = parser.parseMojoDescriptors(metadataFile); - - for (MojoDescriptor descriptor : mojoDescriptors) { - @SuppressWarnings("unchecked") - Map paramMap = descriptor.getParameterMap(); - - if (!paramMap.containsKey("basedir")) { - Parameter param = new Parameter(); - param.setName("basedir"); - param.setAlias("ant.basedir"); - param.setExpression("${antBasedir}"); - param.setDefaultValue("${basedir}"); - param.setType("java.io.File"); - param.setDescription("The base directory from which to execute the Ant script."); - param.setEditable(true); - param.setRequired(true); - - descriptor.addParameter(param); - } - - if (!paramMap.containsKey("antMessageLevel")) { - Parameter param = new Parameter(); - param.setName("messageLevel"); - param.setAlias("ant.messageLevel"); - param.setExpression("${antMessageLevel}"); - param.setDefaultValue("info"); - param.setType("java.lang.String"); - param.setDescription("The message-level used to tune the verbosity of Ant logging."); - param.setEditable(true); - param.setRequired(false); - - descriptor.addParameter(param); - } - - if (!paramMap.containsKey("project")) { - Parameter param = new Parameter(); - param.setName("project"); - param.setDefaultValue("${project}"); - param.setType(MavenProject.class.getName()); - param.setDescription( - "The current MavenProject instance, which contains classpath " + "elements."); - param.setEditable(false); - param.setRequired(true); - - descriptor.addParameter(param); - } - - if (!paramMap.containsKey("session")) { - Parameter param = new Parameter(); - param.setName("session"); - param.setDefaultValue("${session}"); - param.setType("org.apache.maven.execution.MavenSession"); - param.setDescription("The current MavenSession instance, which is used for " - + "plugin-style expression resolution."); - param.setEditable(false); - param.setRequired(true); - - descriptor.addParameter(param); - } - - if (!paramMap.containsKey("mojoExecution")) { - Parameter param = new Parameter(); - param.setName("mojoExecution"); - param.setDefaultValue("${mojoExecution}"); - param.setType("org.apache.maven.plugin.MojoExecution"); - param.setDescription("The current Maven MojoExecution instance, which contains " - + "information about the mojo currently executing."); - param.setEditable(false); - param.setRequired(true); - - descriptor.addParameter(param); - } - - @SuppressWarnings("unchecked") - List requirements = descriptor.getRequirements(); - Map reqMap = new HashMap<>(); - - if (requirements != null) { - for (ComponentRequirement req : requirements) { - reqMap.put(req.getRole(), req); - } - } - - if (!reqMap.containsKey(PathTranslator.class.getName())) { - ComponentRequirement req = new ComponentRequirement(); - req.setRole(PathTranslator.class.getName()); - - descriptor.addRequirement(req); - } - - String implementation = relativePath; - - String dImpl = descriptor.getImplementation(); - if (dImpl != null && !dImpl.isEmpty()) { - if (PluginMetadataParser.IMPL_BASE_PLACEHOLDER.equals(dImpl)) { - implementation = relativePath; - } else { - implementation = relativePath - + dImpl.substring(PluginMetadataParser.IMPL_BASE_PLACEHOLDER.length()); - } - } - - descriptor.setImplementation(implementation); - - descriptor.setLanguage("ant-mojo"); - descriptor.setComponentComposer("map-oriented"); - descriptor.setComponentConfigurator("map-oriented"); - - descriptor.setPluginDescriptor(request.getPluginDescriptor()); - - descriptors.add(descriptor); - } - } catch (PluginMetadataParseException e) { - throw new ExtractionException("Error extracting mojo descriptor from script: " + metadataFile, e); - } - } - } - - return descriptors; - } - - /** {@inheritDoc} */ - @Override - protected String getScriptFileExtension(PluginToolsRequest request) { - return SCRIPT_FILE_EXTENSION; - } - - /** {@inheritDoc} */ - @Override - protected String getMetadataFileExtension(PluginToolsRequest request) { - return METADATA_FILE_EXTENSION; - } -} diff --git a/maven-script/maven-plugin-tools-ant/src/site/apt/index.apt b/maven-script/maven-plugin-tools-ant/src/site/apt/index.apt deleted file mode 100644 index 7d4889825..000000000 --- a/maven-script/maven-plugin-tools-ant/src/site/apt/index.apt +++ /dev/null @@ -1,39 +0,0 @@ - ------ - Introduction - ------ - Vincent Siveton - ------ - 2008-07-15 - ------ - -~~ 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. - -~~ NOTE: For help with the syntax of this file, see: -~~ http://maven.apache.org/doxia/references/apt-format.html - -Maven Plugin Tool for Ant - - <> - - The Maven Plugin Tool for Ant is the <<>> implementation of - {{{../maven-plugin-tools-api/index.html}maven-plugin-tools-api}} to - extract descriptors for plugins written in Ant. - - An Ant Maven Plugin has to be written in a file ending in <<<.build.xml>>> in <<>>, - with {{{../maven-plugin-tools-model/plugin-metadata.html}plugin metadata}} in corresponding <<<.mojos.xml>>> file - to generate the plugin descriptor. diff --git a/maven-script/maven-plugin-tools-ant/src/site/site.xml b/maven-script/maven-plugin-tools-ant/src/site/site.xml deleted file mode 100644 index e39b127ee..000000000 --- a/maven-script/maven-plugin-tools-ant/src/site/site.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - - - diff --git a/maven-script/maven-plugin-tools-ant/src/test/java/org/apache/maven/tools/plugin/extractor/ant/AntMojoDescriptorExtractorTest.java b/maven-script/maven-plugin-tools-ant/src/test/java/org/apache/maven/tools/plugin/extractor/ant/AntMojoDescriptorExtractorTest.java deleted file mode 100644 index 5005105cf..000000000 --- a/maven-script/maven-plugin-tools-ant/src/test/java/org/apache/maven/tools/plugin/extractor/ant/AntMojoDescriptorExtractorTest.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * 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.tools.plugin.extractor.ant; - -import java.io.File; -import java.net.URISyntaxException; -import java.net.URL; -import java.nio.file.Paths; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException; -import org.apache.maven.plugin.descriptor.MojoDescriptor; -import org.apache.maven.plugin.descriptor.Parameter; -import org.apache.maven.plugin.descriptor.PluginDescriptor; -import org.apache.maven.project.MavenProject; -import org.apache.maven.project.path.PathTranslator; -import org.apache.maven.tools.plugin.DefaultPluginToolsRequest; -import org.apache.maven.tools.plugin.PluginToolsRequest; -import org.apache.maven.tools.plugin.extractor.ExtractionException; -import org.codehaus.plexus.component.repository.ComponentRequirement; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - -// at least one test class must be public for test-javadoc report -public class AntMojoDescriptorExtractorTest { - - @Test - void testBasicMojoExtraction_CheckInjectedParametersAndRequirements() - throws InvalidPluginDescriptorException, ExtractionException { - Map> scriptMap = buildTestMap("basic"); - - PluginDescriptor pd = new PluginDescriptor(); - - pd.setArtifactId("test-plugin"); - pd.setGroupId("org.mytest"); - pd.setVersion("1"); - pd.setGoalPrefix("mytest"); - - PluginToolsRequest request = new DefaultPluginToolsRequest(new MavenProject(), pd); - - List metadata = - new AntMojoDescriptorExtractor().extractMojoDescriptorsFromMetadata(scriptMap, request); - - assertEquals(2, metadata.size()); - - for (MojoDescriptor desc : metadata) { - if ("test".equals(desc.getGoal())) { - assertFalse(desc.getImplementation().contains(":")); - } else if ("test2".equals(desc.getGoal())) { - assertTrue(desc.getImplementation().endsWith(":test2")); - } - - List params = desc.getParameters(); - Map paramMap = new HashMap<>(); - for (Parameter param : params) { - paramMap.put(param.getName(), param); - } - - assertNotNull( - paramMap.get("basedir"), "Mojo descriptor: " + desc.getGoal() + " is missing 'basedir' parameter."); - assertNotNull( - paramMap.get("messageLevel"), - "Mojo descriptor: " + desc.getGoal() + " is missing 'messageLevel' parameter."); - assertNotNull( - paramMap.get("project"), "Mojo descriptor: " + desc.getGoal() + " is missing 'project' parameter."); - assertNotNull( - paramMap.get("session"), "Mojo descriptor: " + desc.getGoal() + " is missing 'session' parameter."); - assertNotNull( - paramMap.get("mojoExecution"), - "Mojo descriptor: " + desc.getGoal() + " is missing 'mojoExecution' parameter."); - - List components = desc.getRequirements(); - - assertNotNull(components); - assertEquals(1, components.size()); - - ComponentRequirement req = components.get(0); - assertEquals( - PathTranslator.class.getName(), - req.getRole(), - "Mojo descriptor: " + desc.getGoal() + " is missing 'PathTranslator' component requirement."); - } - } - - private Map> buildTestMap(String resourceDirName) { - try { - Map> result = new HashMap<>(); - ClassLoader cloader = Thread.currentThread().getContextClassLoader(); - URL mojosXmlUrl = cloader.getResource(resourceDirName + "/test.mojos.xml"); - - assertNotNull( - mojosXmlUrl, - "No classpath resource named: '" + resourceDirName + "/test.mojos.xml' could be found."); - - File mojosXml = Paths.get(mojosXmlUrl.toURI()).toFile(); - File dir = mojosXml.getParentFile(); - - Set scripts = new HashSet<>(); - String[] listing = dir.list(); - for (int i = 0; listing != null && i < listing.length; i++) { - if (listing[i].endsWith(".mojos.xml")) { - File f = new File(dir, listing[i]).getAbsoluteFile(); - - scripts.add(f); - } - } - - result.put(dir.getAbsolutePath(), scripts); - - return result; - } catch (final URISyntaxException e) { - throw new AssertionError(e); - } - } - - // TODO - -} diff --git a/maven-script/maven-plugin-tools-ant/src/test/resources/basic/test.build.xml b/maven-script/maven-plugin-tools-ant/src/test/resources/basic/test.build.xml deleted file mode 100644 index b0bd1fbff..000000000 --- a/maven-script/maven-plugin-tools-ant/src/test/resources/basic/test.build.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - ${testDir} - - - - Another test target - - \ No newline at end of file diff --git a/maven-script/maven-plugin-tools-ant/src/test/resources/basic/test.mojos.xml b/maven-script/maven-plugin-tools-ant/src/test/resources/basic/test.mojos.xml deleted file mode 100644 index f54c76586..000000000 --- a/maven-script/maven-plugin-tools-ant/src/test/resources/basic/test.mojos.xml +++ /dev/null @@ -1,74 +0,0 @@ - - - - - - - test - - - testDir - testDir - true - java.lang.String - Test directory location. - - - Runs the default ("test") goal of the build script. - - - test2 - test2 - - - org.apache.maven.project.path.PathTranslator - - - - - testDir - testDir - true - java.lang.String - Test directory location. - - - project - project - true - org.apache.maven.project.MavenProject - - - session - session - true - org.apache.maven.execution.MavenSession - - - mojoExecution - mojoExecution - true - org.apache.maven.plugin.MojoExecution - - - Runs the default ("test2") goal of the build script. - - - \ No newline at end of file diff --git a/maven-script/maven-plugin-tools-beanshell/pom.xml b/maven-script/maven-plugin-tools-beanshell/pom.xml deleted file mode 100644 index 4a1ac3ed2..000000000 --- a/maven-script/maven-plugin-tools-beanshell/pom.xml +++ /dev/null @@ -1,62 +0,0 @@ - - - - 4.0.0 - - - org.apache.maven.plugin-tools - maven-script - 4.0.0-SNAPSHOT - - - maven-plugin-tools-beanshell - - Maven Plugin Tool for Beanshell (deprecated) - Descriptor extractor for plugins written in Beanshell. - - - - - org.apache.maven.plugin-tools - maven-plugin-tools-api - - - org.apache.maven - maven-plugin-api - - - - - org.apache-extras.beanshell - bsh - 2.0b6 - - - - - - - org.eclipse.sisu - sisu-maven-plugin - - - - - diff --git a/maven-script/maven-plugin-tools-beanshell/src/main/java/org/apache/maven/tools/plugin/extractor/beanshell/BeanshellMojoDescriptorExtractor.java b/maven-script/maven-plugin-tools-beanshell/src/main/java/org/apache/maven/tools/plugin/extractor/beanshell/BeanshellMojoDescriptorExtractor.java deleted file mode 100644 index 1e2a6f48b..000000000 --- a/maven-script/maven-plugin-tools-beanshell/src/main/java/org/apache/maven/tools/plugin/extractor/beanshell/BeanshellMojoDescriptorExtractor.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * 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.tools.plugin.extractor.beanshell; - -import javax.inject.Named; -import javax.inject.Singleton; - -import java.io.File; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import bsh.EvalError; -import bsh.Interpreter; -import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException; -import org.apache.maven.plugin.descriptor.MojoDescriptor; -import org.apache.maven.tools.plugin.PluginToolsRequest; -import org.apache.maven.tools.plugin.extractor.AbstractScriptedMojoDescriptorExtractor; -import org.apache.maven.tools.plugin.extractor.ExtractionException; -import org.apache.maven.tools.plugin.extractor.GroupKey; - -import static java.nio.charset.StandardCharsets.UTF_8; - -/** - * Extracts Mojo descriptors from BeanShell sources. - * - * @deprecated Scripting support for mojos is deprecated and is planned tp be removed in maven 4.0 - */ -@Deprecated -@Named(BeanshellMojoDescriptorExtractor.NAME) -@Singleton -public class BeanshellMojoDescriptorExtractor extends AbstractScriptedMojoDescriptorExtractor { - public static final String NAME = "bsh"; - - private static final GroupKey GROUP_KEY = new GroupKey("bsh", 100); - - @Override - public String getName() { - return NAME; - } - - @Override - public GroupKey getGroupKey() { - return GROUP_KEY; - } - - /** - * {@inheritDoc} - */ - @Override - protected String getScriptFileExtension(PluginToolsRequest request) { - return ".bsh"; - } - - /** - * {@inheritDoc} - */ - @Override - protected List extractMojoDescriptors( - Map> scriptFilesKeyedByBasedir, PluginToolsRequest request) - throws ExtractionException, InvalidPluginDescriptorException { - List descriptors = new ArrayList<>(); - - for (Map.Entry> entry : scriptFilesKeyedByBasedir.entrySet()) { - String basedir = entry.getKey(); - Set metadataFiles = entry.getValue(); - - for (File scriptFile : metadataFiles) { - String relativePath = null; - - if (basedir.endsWith("/")) { - basedir = basedir.substring(0, basedir.length() - 2); - } - - relativePath = scriptFile.getPath().substring(basedir.length()); - - relativePath = relativePath.replace('\\', '/'); - - MojoDescriptor mojoDescriptor = createMojoDescriptor(basedir, relativePath, request); - descriptors.add(mojoDescriptor); - } - } - - return descriptors; - } - - /** - * @param basedir not null - * @param resource not null - * @param request not null - * @return a new Mojo descriptor instance - * @throws InvalidPluginDescriptorException - * if any - */ - private MojoDescriptor createMojoDescriptor(String basedir, String resource, PluginToolsRequest request) - throws InvalidPluginDescriptorException { - MojoDescriptor mojoDescriptor = new MojoDescriptor(); - mojoDescriptor.setPluginDescriptor(request.getPluginDescriptor()); - - mojoDescriptor.setLanguage("bsh"); - mojoDescriptor.setComponentConfigurator("bsh"); - - mojoDescriptor.setImplementation(resource); - - Interpreter interpreter = new Interpreter(); - - try { - interpreter.set("file", new File(basedir, resource)); - - interpreter.set("mojoDescriptor", mojoDescriptor); - - interpreter.set("encoding", "UTF-8"); - - interpreter.eval(new InputStreamReader(getClass().getResourceAsStream("/extractor.bsh"), UTF_8)); - } catch (EvalError evalError) { - throw new InvalidPluginDescriptorException("Error scanning beanshell script", evalError); - } - - // FIXME: convert javadocs - return mojoDescriptor; - } -} diff --git a/maven-script/maven-plugin-tools-beanshell/src/main/resources/extractor.bsh b/maven-script/maven-plugin-tools-beanshell/src/main/resources/extractor.bsh deleted file mode 100644 index d4b8947a0..000000000 --- a/maven-script/maven-plugin-tools-beanshell/src/main/resources/extractor.bsh +++ /dev/null @@ -1,242 +0,0 @@ -/* - * 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. - */ - -import bsh.*; -import java.util.regex.Pattern; -import java.io.FileInputStream; -import java.io.InputStreamReader; -import org.codehaus.plexus.util.StringUtils; -import org.apache.maven.plugin.descriptor.Parameter; -import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException; - -// only on start of line -this.tag = "\\r?\\n\\s*\\*?\\s*@(\\w+)"; -// zero width lookahead to next tag or end of comment -this.tagOrEndComment = "(?=" + tag + "|\\*/)"; -this.commentTextPattern = Pattern.compile( "(?s)/\\*\\*(.*?)" + tagOrEndComment ); -this.tagsPattern = Pattern.compile( "(?s)" + tag + "\\s*(.*?)" + tagOrEndComment ); -this.descriptionPattern = Pattern.compile( "(?s)\\r?\\n\\s*\\*" ); -this.typePattern = Pattern.compile( "type\\s*=\\s*\"(.*?)\"" ); -this.expressionPattern = Pattern.compile( "expression\\s*=\\s*\"(.*?)\"" ); -this.defaultValuePattern = Pattern.compile( "default-value\\s*=\\s*\"(.*?)\"" ); -this.phasePattern = Pattern.compile( "phase\\s*=\\s*\"(.*?)\"" ); -this.goalPattern = Pattern.compile( "goal\\s*=\\s*\"(.*?)\"" ); -this.lifecyclePattern = Pattern.compile( "lifecycle\\s*=\\s*\"(.*?)\"" ); -this.rolePattern = Pattern.compile( "role\\s*=\\s*\"(.*?)\"" ); -this.roleHintPattern = Pattern.compile( "roleHint\\s*=\\s*\"(.*?)\"" ); - -setAccessibility( true ); - -createParameter( text, method ) -{ - if ( method.startsWith( "set" ) ) - { - this.name = StringUtils.uncapitalise( method.substring( 3 ) ); - this.desc = getDescription( text ); - this.tags = getTags( text ); - - this.parameter = new Parameter(); - parameter.setName( name ); - parameter.setDescription( desc ); - parameter.setRequired( tags.containsKey( "required" ) ); - parameter.setEditable( !tags.containsKey( "readonly" ) ); - this.deprecation = tags.get( "deprecated" ); - if ( deprecation != null ) - { - parameter.setDeprecated( deprecation ); - } - this.alias = tags.get( "alias" ); - if ( alias != null ) - { - parameter.setAlias( alias ); - } - this.value = tags.get( "parameter" ); - if ( value != null ) - { - m = typePattern.matcher( value ); - if ( m.find() ) - { - parameter.setType( m.group( 1 ) ); - } - else - { - parameter.setType( "java.lang.Object" ); - } - m = expressionPattern.matcher( value ); - if ( m.find() ) - { - parameter.setExpression( m.group( 1 ) ); - } - m = defaultValuePattern.matcher( value ); - if ( m.find() ) - { - parameter.setDefaultValue( m.group( 1 ) ); - } - } - value = tags.get( "component" ); - if ( value != null ) - { - m = rolePattern.matcher( value ); - if ( m.find() ) - { - role = m.group( 1 ); - } - m = roleHintPattern.matcher( value ); - if ( m.find() ) - { - roleHint = m.group( 1 ); - } - else - { - roleHint = null; - } - parameter.setRequirement( new Requirement( role, roleHint ) ); - } - return parameter; - } - return null; -} - -getTags( text ) -{ - this.matcher = tagsPattern.matcher( text ); - this.tags = new HashMap(); - while ( matcher.find() ) - { - this.tagname = matcher.group( 1 ); - this.tagvalue = matcher.group( 2 ); - tags.put( tagname, tagvalue.trim() ); - } - return tags; -} - -getDescription( text ) -{ - this.matcher = commentTextPattern.matcher( text ); - if ( matcher.find() ) - { - this.input = matcher.group( 1 ); - return descriptionPattern.matcher( input ).replaceAll( "" ).trim(); - } - else - { - return ""; - } -} - -extract( file, encoding, mojoDescriptor ) -{ - this.parser = new Parser( new InputStreamReader( new FileInputStream( file ), encoding ) ); - parser.setRetainComments( true ); - - this.lastNode = null; - this.firstComment = null; - while ( !parser.Line() ) - { - this.node = parser.popNode(); - - if ( node instanceof BSHFormalComment && firstComment == null ) - { - firstComment = node; - } - - if ( node instanceof BSHMethodDeclaration ) - { - if ( lastNode instanceof BSHFormalComment ) - { - this.text = lastNode.text; - - this.method = node.name; - - this.parameter = createParameter( text, method ); - if ( parameter != null ) - { - if ( "${reports}".equals( parameter.getExpression() ) ) - { - mojoDescriptor.setRequiresReports( true ); - } - mojoDescriptor.addParameter( parameter ); - } - - if ( firstComment == lastNode ) - { - firstComment = null; - } - } - } - lastNode = node; - } - if ( firstComment != null ) - { - this.text = firstComment.text; - - mojoDescriptor.setDescription( getDescription( text ) ); - this.tags = getTags( text ); - mojoDescriptor.setGoal( tags.get( "goal" ) ); - mojoDescriptor.setPhase( tags.get( "phase" ) ); - this.value = tags.get( "requiresDependencyResolution" ); - // TODO: share with java extractor - if ( value == null || value.length() == 0 ) - { - value = "runtime"; - } - mojoDescriptor.setDependencyResolutionRequired( value ); - - mojoDescriptor.setProjectRequired( tags.containsKey( "requiresProject" ) ); - mojoDescriptor.setOnlineRequired( tags.containsKey( "requiresOnline" ) ); - - this.value = tags.get( "execute" ); - if ( value != null ) - { - m = phasePattern.matcher( value ); - if ( m.find() ) - { - mojoDescriptor.setExecutePhase( m.group( 1 ) ); - } - - m = goalPattern.matcher( value ); - if ( m.find() ) - { - mojoDescriptor.setExecuteGoal( m.group( 1 ) ); - } - - if ( mojoDescriptor.getExecutePhase() == null || mojoDescriptor.getExecuteGoal() == null ) - { - throw new InvalidPluginDescriptorException( "@execute must have a phase or goal" ); - } - - if ( mojoDescriptor.getExecutePhase() != null && mojoDescriptor.getExecuteGoal() != null ) - { - throw new InvalidPluginDescriptorException( "@execute must have only one of a phase or goal" ); - } - - m = lifecyclePattern.matcher( value ); - if ( m.find() ) - { - mojoDescriptor.setExecuteLifecycle( m.group( 1 ) ); - if ( mojoDescriptor.getExecuteGoal() != null ) - { - throw new InvalidPluginDescriptorException( "@execute lifecycle requires a phase instead of a goal" ); - } - } - } - } -} - -extract( file, encoding, mojoDescriptor ); diff --git a/maven-script/maven-plugin-tools-beanshell/src/site/apt/index.apt b/maven-script/maven-plugin-tools-beanshell/src/site/apt/index.apt deleted file mode 100644 index a079dbe15..000000000 --- a/maven-script/maven-plugin-tools-beanshell/src/site/apt/index.apt +++ /dev/null @@ -1,35 +0,0 @@ - ------ - Introduction - ------ - Vincent Siveton - ------ - 2008-07-15 - ------ - -~~ 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. - -~~ NOTE: For help with the syntax of this file, see: -~~ http://maven.apache.org/doxia/references/apt-format.html - -Maven Plugin Tool for Beanshell - - <> - - The Maven Plugin Tool for Beanshell is the <<>> implementation of - {{{../maven-plugin-tools-api/index.html}maven-plugin-tools-api}} - to extract descriptors for plugins written in Beanshell. diff --git a/maven-script/maven-plugin-tools-beanshell/src/site/site.xml b/maven-script/maven-plugin-tools-beanshell/src/site/site.xml deleted file mode 100644 index e39b127ee..000000000 --- a/maven-script/maven-plugin-tools-beanshell/src/site/site.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - - - diff --git a/maven-script/maven-plugin-tools-model/pom.xml b/maven-script/maven-plugin-tools-model/pom.xml deleted file mode 100644 index 4a152a240..000000000 --- a/maven-script/maven-plugin-tools-model/pom.xml +++ /dev/null @@ -1,99 +0,0 @@ - - - - 4.0.0 - - - org.apache.maven.plugin-tools - maven-script - 4.0.0-SNAPSHOT - - - maven-plugin-tools-model - - Maven Plugin Metadata Model (deprecated) - The Maven Plugin Metadata Model provides an API to play with the Metadata model. - - - - - org.apache.maven - maven-plugin-api - - - - org.codehaus.plexus - plexus-utils - - - org.codehaus.plexus - plexus-xml - - - org.junit.jupiter - junit-jupiter-engine - test - - - - - - - org.codehaus.modello - modello-maven-plugin - - - src/main/mdo/plugin-metadata.mdo - - 1.1.0 - 1.0.0 - - - - site-docs - - xdoc - - pre-site - - - xsd - - xsd - - pre-site - - ${project.reporting.outputDirectory} - - - - standard - - java - xpp3-reader - xpp3-writer - - - - - - - - diff --git a/maven-script/maven-plugin-tools-model/src/main/java/org/apache/maven/tools/plugin/extractor/model/PluginMetadataParseException.java b/maven-script/maven-plugin-tools-model/src/main/java/org/apache/maven/tools/plugin/extractor/model/PluginMetadataParseException.java deleted file mode 100644 index 6ca00bd5f..000000000 --- a/maven-script/maven-plugin-tools-model/src/main/java/org/apache/maven/tools/plugin/extractor/model/PluginMetadataParseException.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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.tools.plugin.extractor.model; - -import java.io.File; - -/** - * Exception when plugin metadata parsing occurred. - * - * @deprecated Scripting support for mojos is deprecated and is planned tp be removed in maven 4.0 - */ -@Deprecated -public class PluginMetadataParseException extends Exception { - /** serialVersionUID */ - static final long serialVersionUID = 4022348153707995574L; - - private final File metadataFile; - - private final String originalMessage; - - /** - * @param metadataFile could be null - * @param message could be null - * @param cause could be null - */ - public PluginMetadataParseException(File metadataFile, String message, Throwable cause) { - super("Error parsing file: " + metadataFile + ". Reason: " + message, cause); - - this.metadataFile = metadataFile; - this.originalMessage = message; - } - - /** - * @param metadataFile could be null - * @param message could be null - */ - public PluginMetadataParseException(File metadataFile, String message) { - super("Error parsing file: " + metadataFile + ". Reason: " + message); - - this.metadataFile = metadataFile; - this.originalMessage = message; - } - - /** - * @return the metadata file - */ - public File getMetadataFile() { - return metadataFile; - } - - /** - * @return the original message - */ - public String getOriginalMessage() { - return originalMessage; - } -} diff --git a/maven-script/maven-plugin-tools-model/src/main/java/org/apache/maven/tools/plugin/extractor/model/PluginMetadataParser.java b/maven-script/maven-plugin-tools-model/src/main/java/org/apache/maven/tools/plugin/extractor/model/PluginMetadataParser.java deleted file mode 100644 index 9d831b3a9..000000000 --- a/maven-script/maven-plugin-tools-model/src/main/java/org/apache/maven/tools/plugin/extractor/model/PluginMetadataParser.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * 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.tools.plugin.extractor.model; - -import java.io.File; -import java.io.IOException; -import java.io.Reader; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.apache.maven.plugin.descriptor.DuplicateParameterException; -import org.apache.maven.plugin.descriptor.MojoDescriptor; -import org.apache.maven.plugin.descriptor.Parameter; -import org.apache.maven.tools.plugin.extractor.model.io.xpp3.PluginMetadataXpp3Reader; -import org.codehaus.plexus.component.repository.ComponentRequirement; -import org.codehaus.plexus.util.ReaderFactory; -import org.codehaus.plexus.util.StringUtils; -import org.codehaus.plexus.util.xml.pull.XmlPullParserException; - -/** - * Parser for plugin metadata. - * - * @deprecated Scripting support for mojos is deprecated and is planned tp be removed in maven 4.0 - */ -@Deprecated -public class PluginMetadataParser { - /** - * Default implementation path which will be replaced in - * AbstractScriptedMojoDescriptorExtractor#extractMojoDescriptorsFromMetadata(Map, PluginDescriptor) - */ - public static final String IMPL_BASE_PLACEHOLDER = ""; - - /** - * @param metadataFile the metadata file to be parse - * @return a set of MojoDescriptor - * @throws PluginMetadataParseException if any - */ - public Set parseMojoDescriptors(File metadataFile) throws PluginMetadataParseException { - Set descriptors = new HashSet<>(); - - try (Reader reader = ReaderFactory.newXmlReader(metadataFile)) { - - PluginMetadataXpp3Reader metadataReader = new PluginMetadataXpp3Reader(); - - PluginMetadata pluginMetadata = metadataReader.read(reader); - - List mojos = pluginMetadata.getMojos(); - - if (mojos != null) { - for (Mojo mojo : mojos) { - MojoDescriptor descriptor = asDescriptor(metadataFile, mojo); - - descriptors.add(descriptor); - } - } - } catch (IOException | XmlPullParserException e) { - throw new PluginMetadataParseException(metadataFile, "Cannot parse plugin metadata from file.", e); - } - - return descriptors; - } - - /** - * @param metadataFile not null - * @param mojo not null - * @return a mojo descriptor instance - * @throws PluginMetadataParseException if any - */ - private MojoDescriptor asDescriptor(File metadataFile, Mojo mojo) throws PluginMetadataParseException { - MojoDescriptor descriptor = new MojoDescriptor(); - - if (mojo.getCall() != null) { - descriptor.setImplementation(IMPL_BASE_PLACEHOLDER + ":" + mojo.getCall()); - } else { - descriptor.setImplementation(IMPL_BASE_PLACEHOLDER); - } - - descriptor.setGoal(mojo.getGoal()); - descriptor.setPhase(mojo.getPhase()); - descriptor.setDependencyResolutionRequired(mojo.getRequiresDependencyResolution()); - descriptor.setAggregator(mojo.isAggregator()); - descriptor.setInheritedByDefault(mojo.isInheritByDefault()); - descriptor.setDirectInvocationOnly(mojo.isRequiresDirectInvocation()); - descriptor.setOnlineRequired(mojo.isRequiresOnline()); - descriptor.setProjectRequired(mojo.isRequiresProject()); - descriptor.setRequiresReports(mojo.isRequiresReports()); - descriptor.setDescription(mojo.getDescription()); - descriptor.setDeprecated(mojo.getDeprecation()); - descriptor.setSince(mojo.getSince()); - - LifecycleExecution le = mojo.getExecution(); - if (le != null) { - descriptor.setExecuteLifecycle(le.getLifecycle()); - descriptor.setExecutePhase(le.getPhase()); - descriptor.setExecuteGoal(le.getGoal()); - } - - List parameters = mojo.getParameters(); - - if (parameters != null && !parameters.isEmpty()) { - for (org.apache.maven.tools.plugin.extractor.model.Parameter param : parameters) { - Parameter dParam = new Parameter(); - dParam.setAlias(param.getAlias()); - dParam.setDeprecated(param.getDeprecation()); - dParam.setDescription(param.getDescription()); - dParam.setEditable(!param.isReadonly()); - dParam.setExpression(param.getExpression()); - dParam.setDefaultValue(param.getDefaultValue()); - dParam.setSince(param.getSince()); - - String property = param.getProperty(); - if (property != null && !property.isEmpty()) { - dParam.setName(property); - } else { - dParam.setName(param.getName()); - } - - if (StringUtils.isEmpty(dParam.getName())) { - throw new PluginMetadataParseException( - metadataFile, - "Mojo: \'" + mojo.getGoal() - + "\' has a parameter without either property or name attributes. Please specify one."); - } - - dParam.setRequired(param.isRequired()); - dParam.setType(param.getType()); - - try { - descriptor.addParameter(dParam); - } catch (DuplicateParameterException e) { - throw new PluginMetadataParseException( - metadataFile, "Duplicate parameters detected for mojo: " + mojo.getGoal(), e); - } - } - } - - List components = mojo.getComponents(); - - if (components != null && !components.isEmpty()) { - for (Component component : components) { - ComponentRequirement cr = new ComponentRequirement(); - cr.setRole(component.getRole()); - cr.setRoleHint(component.getHint()); - - descriptor.addRequirement(cr); - } - } - - return descriptor; - } -} diff --git a/maven-script/maven-plugin-tools-model/src/main/mdo/plugin-metadata.mdo b/maven-script/maven-plugin-tools-model/src/main/mdo/plugin-metadata.mdo deleted file mode 100644 index 804e50e55..000000000 --- a/maven-script/maven-plugin-tools-model/src/main/mdo/plugin-metadata.mdo +++ /dev/null @@ -1,357 +0,0 @@ - - - - - plugin-metadata - PluginMetadata - - - - package - org.apache.maven.tools.plugin.extractor.model - - - - - PluginMetadata - 1.0.0+ - Root element of a script-based mojo's plugin metadata bindings. - - - mojos - 1.0.0+ - true - The list of mojos contained in the accompanying script. - - Mojo - * - - - - - - Mojo - 1.0.0+ - Mojo descriptor definition. - - - 1.0.0+ - goal - String - true - The name of the goal used to invoke this mojo. - - - 1.0.0+ - phase - String - The phase to which this mojo should be bound by default. - - - 1.0.0+ - aggregator - boolean - Whether this mojo operates as an aggregator when the reactor is run. That is, only runs once. - - - - 1.0.0+ - requiresDependencyResolution - String - The scope of dependencies that this mojo requires to have resolved. - - - 1.0.0+ - requiresProject - boolean - Whether this mojo requires a project instance in order to execute. - - - 1.0.0+ - requiresReports - boolean - Whether this mojo requires a reports section in the POM. - - - 1.0.0+ - requiresOnline - boolean - Whether this mojo requires online mode to operate normally. - - - 1.0.0+ - inheritByDefault - boolean - Whether this mojo's configuration should propagate down the POM inheritance chain by default. - - - - 1.0.0+ - requiresDirectInvocation - boolean - If true, this mojo can only be directly invoked (eg. specified directly on the command line). - - - - 1.0.0+ - execution - Information about a sub-execution of the Maven lifecycle which should be processed. - - LifecycleExecution - - - - 1.0.0+ - components - List of plexus components required by this mojo. - - Component - * - - - - 1.0.0+ - parameters - List of parameters used by this mojo. - - Parameter - * - - - - description - 1.0.0+ - The description for this parameter. - String - - - deprecation - 1.0.0+ - A deprecation message for this mojo parameter. - String - - - 1.1.0+ - since - String - Version when the mojo was added to the API. - - - 1.0.0+ - call - String - The target/method within the script to call when this mojo executes. - - - - - LifecycleExecution - 1.0.0+ - - - - lifecycle - 1.0.0+ - String - The name of the overlay to apply to the sub-lifecycle before executing it. If specified, this - lifecycle overlay definition will be bundled with the plugin. - - - - phase - 1.0.0+ - The phase in the sub-lifecycle. - String - - - goal - 1.0.0+ - A goal, not attached to a lifecycle phase, which should be executed ahead of this mojo. - - String - - - - - Component - 1.0.0+ - - - - role - 1.0.0+ - The component role to lookup. - true - String - - - hint - 1.0.0+ - String - The role-hint to lookup. - - - - - Parameter - 1.0.0+ - - - - name - 1.0.0+ - The parameter name - true - String - - - alias - 1.0.0+ - String - An alternate name for the parameter. - - - property - 1.0.0+ - String - The JavaBeans property name to use to configure the mojo with this parameter. - - - required - 1.0.0+ - boolean - Whether this parameter is required. - - - readonly - 1.0.0+ - boolean - - - - expression - 1.0.0+ - String - - - - defaultValue - 1.0.0+ - String - - - - type - 1.0.0+ - String - true - - - - description - 1.0.0+ - The description for this parameter. - String - - - deprecation - 1.0.0+ - A deprecation message for this mojo parameter. - String - - - 1.1.0+ - since - String - Version when the parameter was added. - - - - - diff --git a/maven-script/maven-plugin-tools-model/src/site/apt/index.apt b/maven-script/maven-plugin-tools-model/src/site/apt/index.apt deleted file mode 100644 index 77d128c14..000000000 --- a/maven-script/maven-plugin-tools-model/src/site/apt/index.apt +++ /dev/null @@ -1,41 +0,0 @@ - ------ - Introduction - ------ - Vincent Siveton - ------ - 2008-07-15 - ------ - -~~ 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. - -~~ NOTE: For help with the syntax of this file, see: -~~ http://maven.apache.org/doxia/references/apt-format.html - -Maven Plugin Tool Model - - The Maven Plugin Tool Model is a model to extract descriptors information from plugins. - - The following are generated from this model: - - * {{{./apidocs/index.html}Java sources}} with Reader and Writers for the Xpp3 XML parser - - * A {{{./plugin-metadata.html}Descriptor Reference}} - - * An {{{./plugin-metadata-1.1.0.xsd}XSD}}. - - [] diff --git a/maven-script/maven-plugin-tools-model/src/site/site.xml b/maven-script/maven-plugin-tools-model/src/site/site.xml deleted file mode 100644 index 7b9a4c4d2..000000000 --- a/maven-script/maven-plugin-tools-model/src/site/site.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - - - diff --git a/maven-script/maven-plugin-tools-model/src/test/java/org/apache/maven/tools/plugin/extractor/model/PluginMetadataParserTest.java b/maven-script/maven-plugin-tools-model/src/test/java/org/apache/maven/tools/plugin/extractor/model/PluginMetadataParserTest.java deleted file mode 100644 index a2f5f70b6..000000000 --- a/maven-script/maven-plugin-tools-model/src/test/java/org/apache/maven/tools/plugin/extractor/model/PluginMetadataParserTest.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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.tools.plugin.extractor.model; - -import java.io.File; -import java.net.URISyntaxException; -import java.net.URL; -import java.nio.file.Paths; -import java.util.Set; - -import org.apache.maven.plugin.descriptor.MojoDescriptor; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - -// at least one test class must be public for test-javadoc report -public class PluginMetadataParserTest { - - @Test - void testBasicDeclarationWithoutCall() throws PluginMetadataParseException { - File metadataFile = getMetadataFile("test.mojos.xml"); - Set descriptors = new PluginMetadataParser().parseMojoDescriptors(metadataFile); - - assertEquals(1, descriptors.size()); - - MojoDescriptor desc = descriptors.iterator().next(); - assertFalse(desc.getImplementation().contains(":")); - assertEquals("test", desc.getGoal()); - } - - @Test - void testBasicDeclarationWithCall() throws PluginMetadataParseException { - File metadataFile = getMetadataFile("test2.mojos.xml"); - Set descriptors = new PluginMetadataParser().parseMojoDescriptors(metadataFile); - - assertEquals(1, descriptors.size()); - - MojoDescriptor desc = descriptors.iterator().next(); - assertTrue(desc.getImplementation().endsWith(":test2")); - assertEquals("test2", desc.getGoal()); - } - - private File getMetadataFile(String name) { - try { - URL resource = Thread.currentThread().getContextClassLoader().getResource(name); - assertNotNull(resource, "Cannot find classpath resource: '" + name + "'."); - return Paths.get(resource.toURI()).toFile(); - } catch (final URISyntaxException e) { - throw new AssertionError(e); - } - } -} diff --git a/maven-script/maven-plugin-tools-model/src/test/resources/test.mojos.xml b/maven-script/maven-plugin-tools-model/src/test/resources/test.mojos.xml deleted file mode 100644 index b7f819c32..000000000 --- a/maven-script/maven-plugin-tools-model/src/test/resources/test.mojos.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - test - - - testDir - testDir - true - java.lang.String - Test directory location. - - - Runs the default ("test") goal of the build script. - - - \ No newline at end of file diff --git a/maven-script/maven-plugin-tools-model/src/test/resources/test2.mojos.xml b/maven-script/maven-plugin-tools-model/src/test/resources/test2.mojos.xml deleted file mode 100644 index 8707a4cef..000000000 --- a/maven-script/maven-plugin-tools-model/src/test/resources/test2.mojos.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - test2 - test2 - - - testDir - testDir - true - java.lang.String - Test directory location. - - - Runs the default ("test2") goal of the build script. - - - \ No newline at end of file diff --git a/maven-script/maven-script-ant/pom.xml b/maven-script/maven-script-ant/pom.xml deleted file mode 100644 index fbd1a3a28..000000000 --- a/maven-script/maven-script-ant/pom.xml +++ /dev/null @@ -1,109 +0,0 @@ - - - - 4.0.0 - - - org.apache.maven.plugin-tools - maven-script - 4.0.0-SNAPSHOT - - - maven-script-ant - - Maven Ant Mojo Support (deprecated) - Maven Ant Mojo Support, ie write Maven plugins with Ant scripts. - - - - org.apache.ant - ant - ${antVersion} - - - com.sun - tools - - - - - org.apache.ant - ant-launcher - ${antVersion} - - - com.sun - tools - - - - - org.apache.maven - maven-plugin-api - - - org.codehaus.plexus - plexus-ant-factory - - 1.0-alpha-2.1 - - - org.codehaus.plexus - plexus-container-default - - - - - org.codehaus.plexus - plexus-archiver - - - org.apache.maven - maven-compat - - - com.fasterxml.woodstox - woodstox-core - - - org.apache.maven - maven-xml-impl - - - org.codehaus.plexus - plexus-xml - - - org.junit.jupiter - junit-jupiter-engine - test - - - org.hamcrest - hamcrest - test - - - org.mockito - mockito-core - test - - - diff --git a/maven-script/maven-script-ant/src/main/java/org/apache/maven/script/ant/AntMojoComponentFactory.java b/maven-script/maven-script-ant/src/main/java/org/apache/maven/script/ant/AntMojoComponentFactory.java deleted file mode 100644 index a81f2a1b6..000000000 --- a/maven-script/maven-script-ant/src/main/java/org/apache/maven/script/ant/AntMojoComponentFactory.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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.script.ant; - -import org.codehaus.classworlds.ClassRealm; -import org.codehaus.plexus.PlexusContainer; -import org.codehaus.plexus.component.factory.ComponentInstantiationException; -import org.codehaus.plexus.component.factory.ant.AntComponentFactory; -import org.codehaus.plexus.component.factory.ant.AntScriptInvoker; -import org.codehaus.plexus.component.repository.ComponentDescriptor; - -/** - * - * @deprecated Scripting support for mojos is deprecated and is planned tp be removed in maven 4.0 - */ -@Deprecated -public class AntMojoComponentFactory extends AntComponentFactory { - - public Object newInstance(ComponentDescriptor descriptor, ClassRealm realm, PlexusContainer container) - throws ComponentInstantiationException { - return new AntMojoWrapper((AntScriptInvoker) super.newInstance(descriptor, realm, container)); - } -} diff --git a/maven-script/maven-script-ant/src/main/java/org/apache/maven/script/ant/AntMojoWrapper.java b/maven-script/maven-script-ant/src/main/java/org/apache/maven/script/ant/AntMojoWrapper.java deleted file mode 100644 index 3b6e9096b..000000000 --- a/maven-script/maven-script-ant/src/main/java/org/apache/maven/script/ant/AntMojoWrapper.java +++ /dev/null @@ -1,324 +0,0 @@ -/* - * 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.script.ant; - -import java.io.File; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.DependencyResolutionRequiredException; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugin.ContextEnabled; -import org.apache.maven.plugin.MojoExecution; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.PluginParameterExpressionEvaluator; -import org.apache.maven.plugin.descriptor.PluginDescriptor; -import org.apache.maven.project.MavenProject; -import org.apache.maven.project.path.PathTranslator; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.PropertyHelper; -import org.apache.tools.ant.types.Path; -import org.codehaus.plexus.archiver.ArchiverException; -import org.codehaus.plexus.archiver.zip.ZipUnArchiver; -import org.codehaus.plexus.component.MapOrientedComponent; -import org.codehaus.plexus.component.configurator.ComponentConfigurationException; -import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; -import org.codehaus.plexus.component.factory.ant.AntComponentExecutionException; -import org.codehaus.plexus.component.factory.ant.AntScriptInvoker; -import org.codehaus.plexus.component.repository.ComponentRequirement; -import org.codehaus.plexus.logging.LogEnabled; -import org.codehaus.plexus.logging.Logger; -import org.codehaus.plexus.util.StringUtils; - -/** - * - * @deprecated Scripting support for mojos is deprecated and is planned tp be removed in maven 4.0 - */ -@Deprecated -public class AntMojoWrapper extends AbstractMojo implements ContextEnabled, MapOrientedComponent, LogEnabled { - - private Map pluginContext; - - private final AntScriptInvoker scriptInvoker; - - private Project antProject; - - private MavenProject mavenProject; - - private MojoExecution mojoExecution; - - private MavenSession session; - - private PathTranslator pathTranslator; - - private Logger logger; - - private transient List unconstructedParts = new ArrayList<>(); - - public AntMojoWrapper(AntScriptInvoker scriptInvoker) { - this.scriptInvoker = scriptInvoker; - } - - public void execute() throws MojoExecutionException { - if (antProject == null) { - antProject = scriptInvoker.getProject(); - } - - Map allConfig = new HashMap<>(); - if (pluginContext != null && !pluginContext.isEmpty()) { - allConfig.putAll(pluginContext); - } - - @SuppressWarnings("unchecked") - Map refs = scriptInvoker.getReferences(); - if (refs != null) { - allConfig.putAll(refs); - - for (Map.Entry entry : refs.entrySet()) { - if (entry.getKey().startsWith(PathTranslator.class.getName())) { - pathTranslator = entry.getValue(); - } - } - } - - mavenProject = (MavenProject) allConfig.get("project"); - - mojoExecution = (MojoExecution) allConfig.get("mojoExecution"); - - session = (MavenSession) allConfig.get("session"); - - unpackFileBasedResources(); - - addClasspathReferences(); - - if (logger.isDebugEnabled() && !unconstructedParts.isEmpty()) { - StringBuilder buffer = new StringBuilder(); - - buffer.append("The following standard Maven Ant-mojo support objects could not be created:\n\n"); - - for (String part : unconstructedParts) { - buffer.append("\n- ").append(part); - } - - buffer.append( - "\n\nMaven project, session, mojo-execution, or path-translation parameter " + "information is "); - buffer.append("\nmissing from this mojo's plugin descriptor."); - buffer.append("\n\nPerhaps this Ant-based mojo depends on maven-script-ant < 2.1.0, "); - buffer.append("or used maven-plugin-tools-ant < 2.2 during release?\n\n"); - - logger.debug(buffer.toString()); - } - - try { - scriptInvoker.invoke(); - } catch (AntComponentExecutionException e) { - throw new MojoExecutionException("Failed to execute: " + e.getMessage(), e); - } - - unconstructedParts.clear(); - } - - public void setPluginContext(Map pluginContext) { - this.pluginContext = pluginContext; - } - - public Map getPluginContext() { - return pluginContext; - } - - public void addComponentRequirement(ComponentRequirement requirementDescriptor, Object requirementValue) - throws ComponentConfigurationException { - scriptInvoker.addComponentRequirement(requirementDescriptor, requirementValue); - } - - public void setComponentConfiguration(Map componentConfiguration) throws ComponentConfigurationException { - scriptInvoker.setComponentConfiguration(componentConfiguration); - antProject = scriptInvoker.getProject(); - } - - private void unpackFileBasedResources() throws MojoExecutionException { - if (mojoExecution == null || mavenProject == null) { - unconstructedParts.add("Unpacked Ant build scripts (in Maven build directory)."); - - return; - } - - // What we need to write out any resources in the plugin to the target directory of the - // mavenProject using the Ant-based plugin: - // - // 1. Need a reference to the plugin JAR itself - // 2. Need a reference to the ${basedir} of the mavenProject - - PluginDescriptor pluginDescriptor = mojoExecution.getMojoDescriptor().getPluginDescriptor(); - - File pluginJar = pluginDescriptor.getPluginArtifact().getFile(); - - String resourcesPath = pluginDescriptor.getArtifactId(); - - File outputDirectory = new File(mavenProject.getBuild().getDirectory()); - - try { - ZipUnArchiver ua = new ZipUnArchiver(pluginJar); - - ua.extract(resourcesPath, outputDirectory); - } catch (ArchiverException e) { - throw new MojoExecutionException("Error extracting resources from your Ant-based plugin.", e); - } - } - - private void addClasspathReferences() throws MojoExecutionException { - try { - if (mavenProject != null && session != null && pathTranslator != null) { - ExpressionEvaluator exprEvaluator = new PluginParameterExpressionEvaluator(session, mojoExecution); - - PropertyHelper propertyHelper = PropertyHelper.getPropertyHelper(antProject); - propertyHelper.setNext(new AntPropertyHelper(exprEvaluator, mavenProject.getArtifacts(), getLog())); - } else { - unconstructedParts.add("Maven parameter expression evaluator for Ant properties."); - } - - @SuppressWarnings("unchecked") - Map references = scriptInvoker.getReferences(); - - if (mavenProject != null) { - - // Compile classpath - Path p = new Path(antProject); - - p.setPath(StringUtils.join( - mavenProject.getCompileClasspathElements().iterator(), File.pathSeparator)); - - /* maven.dependency.classpath it's deprecated as it's equal to maven.compile.classpath */ - references.put("maven.dependency.classpath", p); - antProject.addReference("maven.dependency.classpath", p); - - references.put("maven.compile.classpath", p); - antProject.addReference("maven.compile.classpath", p); - - // Runtime classpath - p = new Path(antProject); - - p.setPath(StringUtils.join( - mavenProject.getRuntimeClasspathElements().iterator(), File.pathSeparator)); - - references.put("maven.runtime.classpath", p); - antProject.addReference("maven.runtime.classpath", p); - - // Test classpath - p = new Path(antProject); - - p.setPath( - StringUtils.join(mavenProject.getTestClasspathElements().iterator(), File.pathSeparator)); - - references.put("maven.test.classpath", p); - antProject.addReference("maven.test.classpath", p); - - } else { - unconstructedParts.add("Maven standard project-based classpath references."); - } - - if (mojoExecution != null) { - // Plugin dependency classpath - Path p = getPathFromArtifacts( - mojoExecution.getMojoDescriptor().getPluginDescriptor().getArtifacts(), antProject); - - references.put("maven.plugin.classpath", p); - antProject.addReference("maven.plugin.classpath", p); - } else { - unconstructedParts.add("Maven standard plugin-based classpath references."); - } - } catch (DependencyResolutionRequiredException e) { - throw new MojoExecutionException("Error creating classpath references for Ant-based plugin scripts.", e); - } - } - - public Path getPathFromArtifacts(Collection artifacts, Project antProject) - throws DependencyResolutionRequiredException { - List list = new ArrayList<>(artifacts.size()); - - for (Artifact a : artifacts) { - File file = a.getFile(); - - if (file == null) { - throw new DependencyResolutionRequiredException(a); - } - - list.add(file.getPath()); - } - - Path p = new Path(antProject); - - p.setPath(StringUtils.join(list.iterator(), File.pathSeparator)); - - return p; - } - - public Project getAntProject() { - return antProject; - } - - public void setAntProject(Project antProject) { - this.antProject = antProject; - } - - public MavenProject getMavenProject() { - return mavenProject; - } - - public void setMavenProject(MavenProject mavenProject) { - this.mavenProject = mavenProject; - } - - public MojoExecution getMojoExecution() { - return mojoExecution; - } - - public void setMojoExecution(MojoExecution mojoExecution) { - this.mojoExecution = mojoExecution; - } - - public MavenSession getSession() { - return session; - } - - public void setSession(MavenSession session) { - this.session = session; - } - - public PathTranslator getPathTranslator() { - return pathTranslator; - } - - public void setPathTranslator(PathTranslator pathTranslator) { - this.pathTranslator = pathTranslator; - } - - public AntScriptInvoker getScriptInvoker() { - return scriptInvoker; - } - - public void enableLogging(Logger logger) { - this.logger = logger; - } -} diff --git a/maven-script/maven-script-ant/src/main/java/org/apache/maven/script/ant/AntPropertyHelper.java b/maven-script/maven-script-ant/src/main/java/org/apache/maven/script/ant/AntPropertyHelper.java deleted file mode 100644 index 7454072d9..000000000 --- a/maven-script/maven-script-ant/src/main/java/org/apache/maven/script/ant/AntPropertyHelper.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * 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.script.ant; - -import java.io.File; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.plugin.logging.Log; -import org.apache.maven.project.MavenProject; -import org.apache.tools.ant.PropertyHelper; -import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; -import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; -import org.codehaus.plexus.util.introspection.ReflectionValueExtractor; - -/** - * Makes the ${expressions} used in Maven available to Ant as properties. - * - * @author Kenney Westerhof - * @deprecated Scripting support for mojos is deprecated and is planned tp be removed in maven 4.0 - */ -@Deprecated -public class AntPropertyHelper extends PropertyHelper { - private static final String DEPENDENCY_PREFIX = "maven.dependency."; - private Log log; - private ExpressionEvaluator exprEvaluator; - private MavenProject mavenProject; - private Map artifactMap = new HashMap<>(); - - /** - * @deprecated use the other constructor - * @param project - * @param l - */ - public AntPropertyHelper(MavenProject project, Log l) { - mavenProject = project; - log = l; - } - - /** - * @deprecated use {@link #AntPropertyHelper(ExpressionEvaluator, Set, Log)} to resolve maven.dependency.* - * properties - * @param exprEvaluator - * @param l - */ - public AntPropertyHelper(ExpressionEvaluator exprEvaluator, Log l) { - this(exprEvaluator, Collections.emptySet(), l); - } - - /** - * @param exprEvaluator - * @param artifacts - * @param l - */ - public AntPropertyHelper(ExpressionEvaluator exprEvaluator, Set artifacts, Log l) { - this.mavenProject = null; - this.exprEvaluator = exprEvaluator; - this.log = l; - - for (Artifact artifact : artifacts) { - String key = DEPENDENCY_PREFIX + artifact.getGroupId() + "." + artifact.getArtifactId() - + (artifact.getClassifier() != null ? "." + artifact.getClassifier() : "") - + (artifact.getType() != null ? "." + artifact.getType() : "") + ".path"; - - log.debug("Storing: " + key + "=" + artifact.getFile().getPath()); - - artifactMap.put(key, artifact.getFile().getPath()); - } - } - - /** - * @see org.apache.tools.ant.PropertyHelper#getPropertyHook(java.lang.String, java.lang.String, boolean) - */ - public synchronized Object getPropertyHook(String ns, String name, boolean user) { - if (log.isDebugEnabled()) { - log.debug("getProperty(ns=" + ns + ", name=" + name + ", user=" + user + ")"); - } - - /* keep old behaviour */ - if (mavenProject != null) { - return getPropertyHook(ns, name, user, mavenProject); - } - - Object val = null; - - if (name.startsWith(DEPENDENCY_PREFIX)) { - val = artifactMap.get(name); - } - - if (val == null) { - try { - val = exprEvaluator.evaluate("${" + name + "}"); - } catch (ExpressionEvaluationException e) { - if (log.isErrorEnabled()) { - log.error("Failed to evaluate expression", e); - } - } - } - - if (val == null) { - val = super.getPropertyHook(ns, name, user); - - if (val == null) { - val = System.getProperty(name); - } - } - - return val; - } - - /** - * @deprecated added to keep backwards compatibility - * @param ns - * @param name - * @param user - * @param mavenProject - * @return The property value. - */ - private Object getPropertyHook(String ns, String name, boolean user, MavenProject mavenProject) { - Object val = null; - try { - if (name.startsWith(DEPENDENCY_PREFIX)) { - val = artifactMap.get(name); - } else if (name.startsWith("project.")) { - val = ReflectionValueExtractor.evaluate(name, mavenProject, true); - } else if (name.equals("basedir")) { - val = ReflectionValueExtractor.evaluate("basedir.path", mavenProject, false); - } - } catch (Exception e) { - if (log.isWarnEnabled()) { - log.warn("Error evaluating expression '" + name + "'", e); - } - } - - if (val == null) { - val = super.getPropertyHook(ns, name, user); - if (val == null) { - val = System.getProperty(name); - } - } - - if (val instanceof File) { - val = ((File) val).getAbsoluteFile(); - } - - return val; - } -} diff --git a/maven-script/maven-script-ant/src/main/resources/META-INF/plexus/components.xml b/maven-script/maven-script-ant/src/main/resources/META-INF/plexus/components.xml deleted file mode 100644 index cadddea95..000000000 --- a/maven-script/maven-script-ant/src/main/resources/META-INF/plexus/components.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - org.codehaus.plexus.component.factory.ComponentFactory - org.apache.maven.script.ant.AntMojoComponentFactory - ant-mojo - - - diff --git a/maven-script/maven-script-ant/src/site/site.xml b/maven-script/maven-script-ant/src/site/site.xml deleted file mode 100644 index 238b5340c..000000000 --- a/maven-script/maven-script-ant/src/site/site.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/maven-script/maven-script-ant/src/test/java/org/apache/maven/script/ant/AntMojoWrapperTest.java b/maven-script/maven-script-ant/src/test/java/org/apache/maven/script/ant/AntMojoWrapperTest.java deleted file mode 100644 index 55dfc8ee2..000000000 --- a/maven-script/maven-script-ant/src/test/java/org/apache/maven/script/ant/AntMojoWrapperTest.java +++ /dev/null @@ -1,224 +0,0 @@ -/* - * 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.script.ant; - -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.PrintStream; -import java.io.Reader; -import java.net.URISyntaxException; -import java.net.URL; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.model.Build; -import org.apache.maven.model.Model; -import org.apache.maven.plugin.MojoExecution; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.descriptor.MojoDescriptor; -import org.apache.maven.plugin.descriptor.PluginDescriptor; -import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder; -import org.apache.maven.project.MavenProject; -import org.apache.maven.project.path.PathTranslator; -import org.apache.tools.ant.BuildEvent; -import org.apache.tools.ant.BuildListener; -import org.codehaus.plexus.archiver.ArchiverException; -import org.codehaus.plexus.archiver.jar.JarArchiver; -import org.codehaus.plexus.component.configurator.ComponentConfigurationException; -import org.codehaus.plexus.component.factory.ComponentInstantiationException; -import org.codehaus.plexus.component.factory.ant.AntScriptInvoker; -import org.codehaus.plexus.component.repository.ComponentRequirement; -import org.codehaus.plexus.configuration.PlexusConfigurationException; -import org.codehaus.plexus.logging.Logger; -import org.codehaus.plexus.logging.console.ConsoleLogger; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.ArgumentCaptor; - -import static org.hamcrest.CoreMatchers.endsWith; -import static org.hamcrest.CoreMatchers.startsWith; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.Mockito.atLeastOnce; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -// at least one test class must be public for test-javadoc report -public class AntMojoWrapperTest { - - private BuildListener buildListener; - - @BeforeEach - public void setUp() { - buildListener = mock(BuildListener.class); - } - - @Test - void test2xStylePlugin() - throws PlexusConfigurationException, IOException, ComponentInstantiationException, MojoExecutionException, - ComponentConfigurationException, ArchiverException, URISyntaxException { - String pluginXml = "META-INF/maven/plugin-2.1.xml"; - - List messages = run(pluginXml); - - assertPresence(messages, "Unpacked Ant build scripts (in Maven build directory)."); - assertPresence(messages, "Maven parameter expression evaluator for Ant properties."); - assertPresence(messages, "Maven standard project-based classpath references."); - assertPresence(messages, "Maven standard plugin-based classpath references."); - assertPresence( - messages, "Maven project, session, mojo-execution, or path-translation parameter information is"); - assertPresence(messages, "maven-script-ant < 2.1.0, or used maven-plugin-tools-ant < 2.2 during release"); - - ArgumentCaptor buildEvent = ArgumentCaptor.forClass(BuildEvent.class); - verify(buildListener, atLeastOnce()).messageLogged(buildEvent.capture()); - - // last message - assertThat(buildEvent.getValue().getMessage(), startsWith("plugin classpath is: ")); - assertThat(buildEvent.getValue().getMessage(), endsWith(".test.jar")); - } - - private void assertPresence(List messages, String test) { - assertTrue( - messages.stream().noneMatch(s -> s.contains(test)), - "Test string: '" + test + "' was found in output, but SHOULD NOT BE THERE."); - } - - private List run(String pluginXml) - throws PlexusConfigurationException, IOException, ComponentInstantiationException, MojoExecutionException, - ComponentConfigurationException, ArchiverException, URISyntaxException { - StackTraceElement stack = new Throwable().getStackTrace()[1]; - System.out.println("\n\nRunning: " + stack.getMethodName() + "\n\n"); - - URL resource = Thread.currentThread().getContextClassLoader().getResource(pluginXml); - - assertNotNull(resource, "plugin descriptor not found: '" + pluginXml + "'."); - - PluginDescriptor pd; - try (Reader reader = new InputStreamReader(resource.openStream())) { - pd = new PluginDescriptorBuilder().build(reader, pluginXml); - } - - Map config = new HashMap<>(); - config.put("basedir", new File(".").getAbsoluteFile()); - config.put("messageLevel", "info"); - - MojoDescriptor md = pd.getMojo("test"); - - AntMojoWrapper wrapper = new AntMojoWrapper( - new AntScriptInvoker(md, Thread.currentThread().getContextClassLoader())); - - wrapper.enableLogging(new ConsoleLogger(Logger.LEVEL_DEBUG, "test")); - - Artifact artifact = mock(Artifact.class); - PathTranslator pt = mock(PathTranslator.class); - - File pluginXmlFile = Paths.get(resource.toURI()).toFile(); - - File jarFile = Files.createTempFile("AntMojoWrapperTest.", ".test.jar").toFile(); - jarFile.deleteOnExit(); - - JarArchiver archiver = new JarArchiver(); - archiver.setDestFile(jarFile); - archiver.addFile(pluginXmlFile, pluginXml); - archiver.createArchive(); - - when(artifact.getFile()).thenReturn(jarFile); - - Model model = new Model(); - - Build build = new Build(); - build.setDirectory("target"); - - model.setBuild(build); - - MavenProject project = new MavenProject(model); - project.setFile(new File("pom.xml").getAbsoluteFile()); - - pd.setPluginArtifact(artifact); - pd.setArtifacts(Collections.singletonList(artifact)); - - config.put("project", project); - config.put("session", new MavenSession(null, null, null, null, null, null, null, null, null, null)); - config.put("mojoExecution", new MojoExecution(md)); - - ComponentRequirement cr = new ComponentRequirement(); - cr.setRole(PathTranslator.class.getName()); - - wrapper.addComponentRequirement(cr, pt); - - wrapper.setComponentConfiguration(config); - - TestBuildListener tbl = new TestBuildListener(); - - wrapper.getAntProject().addBuildListener(buildListener); - - PrintStream oldOut = System.out; - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try { - System.setOut(new PrintStream(baos)); - - wrapper.execute(); - } finally { - System.setOut(oldOut); - } - - System.out.println("\n\n" + stack.getMethodName() + " executed; verifying...\n\n"); - - List messages = new ArrayList<>(); - if (!tbl.messages.isEmpty()) { - messages.addAll(tbl.messages); - } - - messages.add(baos.toString()); - - return messages; - } - - private static final class TestBuildListener implements BuildListener { - private final List messages = new ArrayList<>(); - - public void buildFinished(BuildEvent arg0) {} - - public void buildStarted(BuildEvent arg0) {} - - public void messageLogged(BuildEvent event) { - messages.add(event.getMessage()); - } - - public void targetFinished(BuildEvent arg0) {} - - public void targetStarted(BuildEvent arg0) {} - - public void taskFinished(BuildEvent arg0) {} - - public void taskStarted(BuildEvent arg0) {} - } -} diff --git a/maven-script/maven-script-ant/src/test/resources/META-INF/maven/plugin-2.1.xml b/maven-script/maven-script-ant/src/test/resources/META-INF/maven/plugin-2.1.xml deleted file mode 100644 index 2de9c5f54..000000000 --- a/maven-script/maven-script-ant/src/test/resources/META-INF/maven/plugin-2.1.xml +++ /dev/null @@ -1,89 +0,0 @@ - - - - - Test Plugin - org.myplugin - my-plugin - 1 - myplugin - false - true - - - test - Build a JAR from the current project. - false - false - false - false - false - true - test.build.xml:test - ant - per-lookup - once-per-session - - - basedir - true - false - java.io.File - - - messageLevel - true - false - java.lang.String - - - project - true - false - org.apache.maven.project.MavenProject - - - session - true - false - org.apache.maven.execution.MavenSession - - - mojoExecution - true - false - org.apache.maven.plugin.MojoExecution - - - - ${project} - ${session} - ${mojoExecution} - ${basedir} - ${messageLevel} - - - - org.apache.maven.project.path.PathTranslator - - - - - \ No newline at end of file diff --git a/maven-script/maven-script-ant/src/test/resources/test.build.xml b/maven-script/maven-script-ant/src/test/resources/test.build.xml deleted file mode 100644 index 6a07c7d32..000000000 --- a/maven-script/maven-script-ant/src/test/resources/test.build.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - - - - - plugin classpath is: ${cp} - - \ No newline at end of file diff --git a/maven-script/maven-script-beanshell/pom.xml b/maven-script/maven-script-beanshell/pom.xml deleted file mode 100644 index 269ddd49a..000000000 --- a/maven-script/maven-script-beanshell/pom.xml +++ /dev/null @@ -1,56 +0,0 @@ - - - - 4.0.0 - - - org.apache.maven.plugin-tools - maven-script - 4.0.0-SNAPSHOT - - - maven-script-beanshell - - Maven Beanshell Mojo Support (deprecated) - Maven Beanshell Mojo Support, ie write Maven plugins with Beanshell scripts. - - - - org.apache.maven - maven-plugin-api - - - org.codehaus.plexus - plexus-bsh-factory - 1.0-alpha-7 - - - org.codehaus.plexus - plexus-container-default - - - - - org.apache-extras.beanshell - bsh - 2.0b6 - - - diff --git a/maven-script/maven-script-beanshell/src/main/java/org/apache/maven/script/beanshell/BeanshellMojoAdapter.java b/maven-script/maven-script-beanshell/src/main/java/org/apache/maven/script/beanshell/BeanshellMojoAdapter.java deleted file mode 100644 index 4bee664f7..000000000 --- a/maven-script/maven-script-beanshell/src/main/java/org/apache/maven/script/beanshell/BeanshellMojoAdapter.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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.script.beanshell; - -import bsh.EvalError; -import bsh.Interpreter; -import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugin.Mojo; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; -import org.codehaus.plexus.component.factory.bsh.BshComponent; - -/** - * Mojo adapter for a Beanshell Mojo. - * - * @author Brett Porter - * @deprecated Scripting support for mojos is deprecated and is planned tp be removed in maven 4.0 - */ -@Deprecated -public class BeanshellMojoAdapter extends AbstractMojo implements BshComponent { - private Mojo mojo; - - private Interpreter interpreter; - - public BeanshellMojoAdapter(Mojo mojo, Interpreter interpreter) { - this.mojo = mojo; - this.interpreter = interpreter; - } - - public void execute() throws MojoExecutionException, MojoFailureException { - try { - interpreter.set("logger", getLog()); - - // TODO: set out, err to a print stream that will log at info, error respectively - } catch (EvalError evalError) { - throw new MojoExecutionException("Unable to establish mojo", evalError); - } - - mojo.execute(); - } - - public Interpreter getInterpreter() { - return interpreter; - } -} diff --git a/maven-script/maven-script-beanshell/src/site/site.xml b/maven-script/maven-script-beanshell/src/site/site.xml deleted file mode 100644 index 238b5340c..000000000 --- a/maven-script/maven-script-beanshell/src/site/site.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/maven-script/pom.xml b/maven-script/pom.xml deleted file mode 100644 index 21fb04b88..000000000 --- a/maven-script/pom.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - - 4.0.0 - - - org.apache.maven.plugin-tools - maven-plugin-tools - 4.0.0-SNAPSHOT - - - maven-script - pom - - Maven Script Mojo Support (deprecated) - Maven Script Mojo Support lets developer write Maven plugins/goals with scripting languages instead of compiled Java. Scripting support is deprecated, with Maven 4 only Java based Mojos will be supported. - - - maven-plugin-tools-ant - maven-script-ant - maven-plugin-tools-beanshell - maven-script-beanshell - maven-plugin-tools-model - - - diff --git a/maven-script/src/site/site.xml b/maven-script/src/site/site.xml deleted file mode 100644 index 72b9e7bd0..000000000 --- a/maven-script/src/site/site.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - diff --git a/pom.xml b/pom.xml index 83d3efa29..006a4faf5 100644 --- a/pom.xml +++ b/pom.xml @@ -62,7 +62,6 @@ maven-plugin-tools-java maven-plugin-tools-annotations maven-plugin-annotations - maven-script maven-plugin-plugin maven-plugin-report-plugin @@ -144,16 +143,6 @@ maven-plugin-annotations ${project.version} - - org.apache.maven.plugin-tools - maven-plugin-tools-ant - ${project.version} - - - org.apache.maven.plugin-tools - maven-plugin-tools-beanshell - ${project.version} - org.apache.maven.plugins maven-plugin-plugin @@ -402,6 +391,7 @@ ${surefire.version} false + true