This is an automated email from the ASF dual-hosted git repository. slachiewicz pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/maven-plugin-tools.git
commit 8814a21b60da545a69cbf5a8785d472c79a4d287 Author: Sylwester Lachiewicz <[email protected]> AuthorDate: Wed Nov 4 19:53:59 2026 +0000 Move seven ITs to unit tests Nested-mojo and comment-only extraction run in the annotations extractor test; skip, packaging, provided-scope check and reproducible help mojo run as mojo tests, which adds maven-plugin-testing-harness to maven-plugin-plugin. --- maven-plugin-plugin/pom.xml | 5 + .../it/javaparser-nested-mojo/invoker.properties | 18 -- .../src/it/javaparser-nested-mojo/pom.xml | 77 --------- .../src/it/javaparser-nested-mojo/verify.groovy | 34 ---- .../invoker.properties | 19 --- .../src/it/mplugin-363_help-reproducible/pom.xml | 108 ------------ .../src/main/java/test/MyMojo.java | 62 ------- .../it/mplugin-363_help-reproducible/verify.groovy | 23 --- .../invoker.properties | 18 -- .../it/mplugin-370-maven-deps-scope-bad/pom.xml | 95 ----------- .../org/apache/maven/plugin/coreit/FirstMojo.java | 49 ------ .../mplugin-370-maven-deps-scope-bad/verify.groovy | 22 --- .../invoker.properties | 18 -- .../it/mplugin-370-maven-deps-scope-good/pom.xml | 101 ------------ .../org/apache/maven/plugin/coreit/FirstMojo.java | 49 ------ .../verify.groovy | 22 --- .../src/it/mplugin-421/invoker.properties | 18 -- maven-plugin-plugin/src/it/mplugin-421/pom.xml | 77 --------- .../src/it/mplugin-421/verify.groovy | 32 ---- .../src/it/packaging-jar/invoker.properties | 18 -- maven-plugin-plugin/src/it/packaging-jar/pom.xml | 94 ----------- .../org/apache/maven/plugin/coreit/FirstMojo.java | 32 ---- .../src/it/packaging-jar/verify.groovy | 33 ---- maven-plugin-plugin/src/it/skip/invoker.properties | 19 --- maven-plugin-plugin/src/it/skip/pom.xml | 65 -------- .../org/apache/maven/plugin/coreit/FirstMojo.java | 32 ---- maven-plugin-plugin/src/it/skip/verify.groovy | 23 --- .../plugin/DescriptorGeneratorMojoExecuteTest.java | 181 +++++++++++++++++++++ .../plugin/HelpGeneratorMojoExecuteTest.java | 73 +++++++++ .../descriptor-packaging-jar/plugin-config.xml | 41 +++++ .../unit/descriptor-scope/plugin-config.xml | 38 +++++ .../unit/descriptor-skip/plugin-config.xml | 39 +++++ .../plugin-config.xml | 38 +++++ .../unit/help-reproducible/plugin-config.xml | 33 ++++ ...JavaAnnotationsMojoDescriptorExtractorTest.java | 84 ++++++++++ .../apache/maven/plugin/coreit/CommentOnly.java | 0 .../org/apache/maven/plugin/coreit/HelloMojo.java | 0 .../apache/maven/plugin/coreit/NestedMojos.java | 0 pom.xml | 2 +- 39 files changed, 533 insertions(+), 1159 deletions(-) diff --git a/maven-plugin-plugin/pom.xml b/maven-plugin-plugin/pom.xml index 70c877fa..8213bb35 100644 --- a/maven-plugin-plugin/pom.xml +++ b/maven-plugin-plugin/pom.xml @@ -151,6 +151,11 @@ <artifactId>junit-jupiter-params</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>org.apache.maven.plugin-testing</groupId> + <artifactId>maven-plugin-testing-harness</artifactId> + <scope>test</scope> + </dependency> </dependencies> <build> diff --git a/maven-plugin-plugin/src/it/javaparser-nested-mojo/invoker.properties b/maven-plugin-plugin/src/it/javaparser-nested-mojo/invoker.properties deleted file mode 100644 index a5ed592b..00000000 --- a/maven-plugin-plugin/src/it/javaparser-nested-mojo/invoker.properties +++ /dev/null @@ -1,18 +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 = clean verify diff --git a/maven-plugin-plugin/src/it/javaparser-nested-mojo/pom.xml b/maven-plugin-plugin/src/it/javaparser-nested-mojo/pom.xml deleted file mode 100644 index 9f1e2568..00000000 --- a/maven-plugin-plugin/src/it/javaparser-nested-mojo/pom.xml +++ /dev/null @@ -1,77 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<!-- -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. ---> - -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <groupId>org.apache.maven.its.javaparser-nested-mojo</groupId> - <artifactId>javaparser-nested-mojo</artifactId> - <version>1.0-SNAPSHOT</version> - <packaging>maven-plugin</packaging> - - <name>Maven Integration Test :: javaparser-nested-mojo</name> - <description>Checks that nested Mojo classes retain their Javadoc metadata.</description> - - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - </properties> - - <dependencies> - <dependency> - <groupId>org.apache.maven</groupId> - <artifactId>maven-plugin-api</artifactId> - <version>@maven3Version@</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.apache.maven.plugin-tools</groupId> - <artifactId>maven-plugin-annotations</artifactId> - <version>@project.version@</version> - <scope>provided</scope> - </dependency> - </dependencies> - - <build> - <pluginManagement> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <version>@version.maven-compiler-plugin@</version> - <configuration> - <source>1.8</source> - <target>1.8</target> - </configuration> - </plugin> - </plugins> - </pluginManagement> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-plugin-plugin</artifactId> - <version>@project.version@</version> - <configuration> - <goalPrefix>nested</goalPrefix> - </configuration> - </plugin> - </plugins> - </build> -</project> diff --git a/maven-plugin-plugin/src/it/javaparser-nested-mojo/verify.groovy b/maven-plugin-plugin/src/it/javaparser-nested-mojo/verify.groovy deleted file mode 100644 index c2e29df7..00000000 --- a/maven-plugin-plugin/src/it/javaparser-nested-mojo/verify.groovy +++ /dev/null @@ -1,34 +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 groovy.xml.XmlParser - -File descriptorFile = new File(basedir, "target/classes/META-INF/maven/plugin.xml") -assert descriptorFile.isFile() - -def pluginDescriptor = new XmlParser().parse(descriptorFile) -def mojo = pluginDescriptor.mojos.mojo.find { it.goal.text() == "nested" } - -assert mojo != null -assert mojo.implementation.text() == "org.apache.maven.plugin.coreit.NestedMojos\$NestedMojo" -assert mojo.description.text() == "Runs the nested goal." -assert mojo.since.text() == "1.2" -assert mojo.deprecated.text() == "Use a top-level Mojo instead." - -return true diff --git a/maven-plugin-plugin/src/it/mplugin-363_help-reproducible/invoker.properties b/maven-plugin-plugin/src/it/mplugin-363_help-reproducible/invoker.properties deleted file mode 100644 index a56062ae..00000000 --- a/maven-plugin-plugin/src/it/mplugin-363_help-reproducible/invoker.properties +++ /dev/null @@ -1,19 +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 package -invoker.goals.2 = process-classes diff --git a/maven-plugin-plugin/src/it/mplugin-363_help-reproducible/pom.xml b/maven-plugin-plugin/src/it/mplugin-363_help-reproducible/pom.xml deleted file mode 100644 index 11659ba4..00000000 --- a/maven-plugin-plugin/src/it/mplugin-363_help-reproducible/pom.xml +++ /dev/null @@ -1,108 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<!-- -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. ---> - -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <groupId>org.apache.maven.its.plugin</groupId> - <artifactId>help</artifactId> - <version>1.0-SNAPSHOT</version> - <packaging>maven-plugin</packaging> - - <description> - Tests generation and compilation of the help mojo. - </description> - - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - </properties> - - <dependencies> - <dependency> - <groupId>org.apache.maven</groupId> - <artifactId>maven-plugin-api</artifactId> - <version>@maven3Version@</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.apache.maven.plugin-tools</groupId> - <artifactId>maven-plugin-annotations</artifactId> - <version>@project.version@</version> - <scope>provided</scope> - </dependency> - </dependencies> - - <build> - <pluginManagement> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <version>@version.maven-compiler-plugin@</version> - </plugin> - </plugins> - </pluginManagement> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-plugin-plugin</artifactId> - <version>@project.version@</version> - <configuration> - <goalPrefix>prefix</goalPrefix> - </configuration> - <executions> - <execution> - <id>help-goal</id> - <goals> - <goal>helpmojo</goal> - </goals> - </execution> - <execution> - <id>default-descriptor</id> - <phase>process-classes</phase> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-resources-plugin</artifactId> - <version>3.3.1</version> - <executions> - <execution> - <id>copy</id> - <phase>prepare-package</phase> - <goals> - <goal>copy-resources</goal> - </goals> - <configuration> - <resources> - <resource> - <directory>target/generated-sources</directory> - </resource> - </resources> - <outputDirectory>target/generated-sources-run1</outputDirectory> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> -</project> diff --git a/maven-plugin-plugin/src/it/mplugin-363_help-reproducible/src/main/java/test/MyMojo.java b/maven-plugin-plugin/src/it/mplugin-363_help-reproducible/src/main/java/test/MyMojo.java deleted file mode 100644 index 480fdbc7..00000000 --- a/maven-plugin-plugin/src/it/mplugin-363_help-reproducible/src/main/java/test/MyMojo.java +++ /dev/null @@ -1,62 +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 test; - -import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; - -/** - * MOJO-DESCRIPTION. Some "quotation" marks and backslashes '\\', some <strong>important</strong> javadoc<br> and an - * inline link to {@link test.AnotherMojo}. - * - * @deprecated As of 1.0, use the "quoted" goal instead. - * @since 2.1 - */ -@Mojo(name = "test") -public class MyMojo extends AbstractMojo { - - /** - * This parameter uses "quotation" marks and backslashes '\\' in its description. Those characters <em>must</em> be - * escaped in Java string literals. - * - * @since 2.0 - */ - @Parameter(defaultValue = "escape\\backslash") - private String defaultParam; - - /** - * This parameter is deprecated. - * - * @deprecated As of version 1.0, use the {@link #defaultParam} instead. - */ - @Parameter - private String deprecatedParam; - - @Parameter(property = "test.undocumented", required = true) - private String undocumentedParam; - - /** - * Readonly parameter: should not be proposed for configuration. - */ - @Parameter(defaultValue = "not for configuration", readonly = true) - private String readonly; - - public void execute() {} -} diff --git a/maven-plugin-plugin/src/it/mplugin-363_help-reproducible/verify.groovy b/maven-plugin-plugin/src/it/mplugin-363_help-reproducible/verify.groovy deleted file mode 100644 index b47f8a9d..00000000 --- a/maven-plugin-plugin/src/it/mplugin-363_help-reproducible/verify.groovy +++ /dev/null @@ -1,23 +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. - */ - -firstRun = new File( basedir, "target/generated-sources-run1/plugin/org/apache/maven/its/plugin/help/HelpMojo.java" ).text; -secondRun = new File( basedir, "target/generated-sources/plugin/org/apache/maven/its/plugin/help/HelpMojo.java" ).text; - -assert firstRun == secondRun; diff --git a/maven-plugin-plugin/src/it/mplugin-370-maven-deps-scope-bad/invoker.properties b/maven-plugin-plugin/src/it/mplugin-370-maven-deps-scope-bad/invoker.properties deleted file mode 100644 index c959b536..00000000 --- a/maven-plugin-plugin/src/it/mplugin-370-maven-deps-scope-bad/invoker.properties +++ /dev/null @@ -1,18 +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 = process-classes diff --git a/maven-plugin-plugin/src/it/mplugin-370-maven-deps-scope-bad/pom.xml b/maven-plugin-plugin/src/it/mplugin-370-maven-deps-scope-bad/pom.xml deleted file mode 100644 index 49cf632f..00000000 --- a/maven-plugin-plugin/src/it/mplugin-370-maven-deps-scope-bad/pom.xml +++ /dev/null @@ -1,95 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<!-- -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. ---> - -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <groupId>org.apache.maven.its.maven-deps-scope-bad</groupId> - <artifactId>maven-deps-scope-bad</artifactId> - <version>1.0-SNAPSHOT</version> - <packaging>maven-plugin</packaging> - - <name>Maven Integration Test :: maven-deps-scope-bad</name> - <description> - Test plugin-plugin, which does not sets maven dependencies - to provided scope. - </description> - - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - </properties> - - <dependencies> - <dependency> - <groupId>org.apache.maven</groupId> - <artifactId>maven-plugin-api</artifactId> - <version>@maven3Version@</version> - <scope>compile</scope> - </dependency> - <dependency> - <groupId>org.apache.maven.plugin-tools</groupId> - <artifactId>maven-plugin-annotations</artifactId> - <version>@project.version@</version> - <scope>compile</scope> - </dependency> - </dependencies> - - <build> - <pluginManagement> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <version>@version.maven-compiler-plugin@</version> - <configuration> - <source>1.8</source> - <target>1.8</target> - </configuration> - </plugin> - </plugins> - </pluginManagement> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-plugin-plugin</artifactId> - <version>@project.version@</version> - <configuration> - <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound> - <goalPrefix>prefix</goalPrefix> - </configuration> - <executions> - <execution> - <id>mojo-descriptor</id> - <goals> - <goal>descriptor</goal> - </goals> - </execution> - <execution> - <id>help-goal</id> - <goals> - <goal>helpmojo</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - </build> -</project> diff --git a/maven-plugin-plugin/src/it/mplugin-370-maven-deps-scope-bad/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java b/maven-plugin-plugin/src/it/mplugin-370-maven-deps-scope-bad/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java deleted file mode 100644 index 2968e8af..00000000 --- a/maven-plugin-plugin/src/it/mplugin-370-maven-deps-scope-bad/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java +++ /dev/null @@ -1,49 +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.plugin.coreit; - -import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugin.MojoExecutionException; -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.annotations.ResolutionScope; - -/** - * Touches a test file. - * - * @since 1.2 - */ -@Mojo( - name = "first", - requiresDependencyResolution = ResolutionScope.TEST, - defaultPhase = LifecyclePhase.INTEGRATION_TEST) -public class FirstMojo extends AbstractMojo { - - /** - * @since 0.1 - * @deprecated As of 0.2 - */ - @Parameter(alias = "alias") - private String aliasedParam; - - public void execute() throws MojoExecutionException { - // nothing - } -} diff --git a/maven-plugin-plugin/src/it/mplugin-370-maven-deps-scope-bad/verify.groovy b/maven-plugin-plugin/src/it/mplugin-370-maven-deps-scope-bad/verify.groovy deleted file mode 100644 index e40bc0be..00000000 --- a/maven-plugin-plugin/src/it/mplugin-370-maven-deps-scope-bad/verify.groovy +++ /dev/null @@ -1,22 +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 buildLog = new File( basedir, "build.log" ); -assert buildLog.isFile() -assert buildLog.text.contains( "Some dependencies of Maven Plugins are expected to be in provided scope." ) \ No newline at end of file diff --git a/maven-plugin-plugin/src/it/mplugin-370-maven-deps-scope-good/invoker.properties b/maven-plugin-plugin/src/it/mplugin-370-maven-deps-scope-good/invoker.properties deleted file mode 100644 index c959b536..00000000 --- a/maven-plugin-plugin/src/it/mplugin-370-maven-deps-scope-good/invoker.properties +++ /dev/null @@ -1,18 +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 = process-classes diff --git a/maven-plugin-plugin/src/it/mplugin-370-maven-deps-scope-good/pom.xml b/maven-plugin-plugin/src/it/mplugin-370-maven-deps-scope-good/pom.xml deleted file mode 100644 index ed5bd0f6..00000000 --- a/maven-plugin-plugin/src/it/mplugin-370-maven-deps-scope-good/pom.xml +++ /dev/null @@ -1,101 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<!-- -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. ---> - -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <groupId>org.apache.maven.its.maven-deps-scope-good</groupId> - <artifactId>maven-deps-scope-good</artifactId> - <version>1.0-SNAPSHOT</version> - <packaging>maven-plugin</packaging> - - <name>Maven Integration Test :: maven-deps-scope-good</name> - <description> - Test plugin-plugin, which does sets maven dependencies - to provided scope. - </description> - - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - </properties> - - <dependencies> - <dependency> - <groupId>org.apache.maven</groupId> - <artifactId>maven-jxr</artifactId> - <version>3.3.0</version> - <scope>compile</scope> - </dependency> - <dependency> - <groupId>org.apache.maven</groupId> - <artifactId>maven-plugin-api</artifactId> - <version>@maven3Version@</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.apache.maven.plugin-tools</groupId> - <artifactId>maven-plugin-annotations</artifactId> - <version>@project.version@</version> - <scope>compile</scope> - </dependency> - </dependencies> - - <build> - <pluginManagement> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <version>@version.maven-compiler-plugin@</version> - <configuration> - <source>1.8</source> - <target>1.8</target> - </configuration> - </plugin> - </plugins> - </pluginManagement> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-plugin-plugin</artifactId> - <version>@project.version@</version> - <configuration> - <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound> - <goalPrefix>prefix</goalPrefix> - </configuration> - <executions> - <execution> - <id>mojo-descriptor</id> - <goals> - <goal>descriptor</goal> - </goals> - </execution> - <execution> - <id>help-goal</id> - <goals> - <goal>helpmojo</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - </build> -</project> diff --git a/maven-plugin-plugin/src/it/mplugin-370-maven-deps-scope-good/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java b/maven-plugin-plugin/src/it/mplugin-370-maven-deps-scope-good/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java deleted file mode 100644 index 2968e8af..00000000 --- a/maven-plugin-plugin/src/it/mplugin-370-maven-deps-scope-good/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java +++ /dev/null @@ -1,49 +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.plugin.coreit; - -import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugin.MojoExecutionException; -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.annotations.ResolutionScope; - -/** - * Touches a test file. - * - * @since 1.2 - */ -@Mojo( - name = "first", - requiresDependencyResolution = ResolutionScope.TEST, - defaultPhase = LifecyclePhase.INTEGRATION_TEST) -public class FirstMojo extends AbstractMojo { - - /** - * @since 0.1 - * @deprecated As of 0.2 - */ - @Parameter(alias = "alias") - private String aliasedParam; - - public void execute() throws MojoExecutionException { - // nothing - } -} diff --git a/maven-plugin-plugin/src/it/mplugin-370-maven-deps-scope-good/verify.groovy b/maven-plugin-plugin/src/it/mplugin-370-maven-deps-scope-good/verify.groovy deleted file mode 100644 index 6a58c348..00000000 --- a/maven-plugin-plugin/src/it/mplugin-370-maven-deps-scope-good/verify.groovy +++ /dev/null @@ -1,22 +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 buildLog = new File( basedir, "build.log" ); -assert buildLog.isFile() -assert !buildLog.text.contains( "Some dependencies of Maven Plugins are expected to be in provided scope." ) \ No newline at end of file diff --git a/maven-plugin-plugin/src/it/mplugin-421/invoker.properties b/maven-plugin-plugin/src/it/mplugin-421/invoker.properties deleted file mode 100644 index a5ed592b..00000000 --- a/maven-plugin-plugin/src/it/mplugin-421/invoker.properties +++ /dev/null @@ -1,18 +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 = clean verify diff --git a/maven-plugin-plugin/src/it/mplugin-421/pom.xml b/maven-plugin-plugin/src/it/mplugin-421/pom.xml deleted file mode 100644 index 2321a47f..00000000 --- a/maven-plugin-plugin/src/it/mplugin-421/pom.xml +++ /dev/null @@ -1,77 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<!-- -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. ---> - -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <groupId>org.apache.maven.its.mplugin-421</groupId> - <artifactId>mplugin-421</artifactId> - <version>1.0-SNAPSHOT</version> - <packaging>maven-plugin</packaging> - - <name>Maven Integration Test :: mplugin-421</name> - <description>Checks that comment-only Java sources do not prevent plugin descriptor generation.</description> - - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - </properties> - - <dependencies> - <dependency> - <groupId>org.apache.maven</groupId> - <artifactId>maven-plugin-api</artifactId> - <version>@maven3Version@</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.apache.maven.plugin-tools</groupId> - <artifactId>maven-plugin-annotations</artifactId> - <version>@project.version@</version> - <scope>provided</scope> - </dependency> - </dependencies> - - <build> - <pluginManagement> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <version>@version.maven-compiler-plugin@</version> - <configuration> - <source>1.8</source> - <target>1.8</target> - </configuration> - </plugin> - </plugins> - </pluginManagement> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-plugin-plugin</artifactId> - <version>@project.version@</version> - <configuration> - <goalPrefix>mplugin421</goalPrefix> - </configuration> - </plugin> - </plugins> - </build> -</project> diff --git a/maven-plugin-plugin/src/it/mplugin-421/verify.groovy b/maven-plugin-plugin/src/it/mplugin-421/verify.groovy deleted file mode 100644 index df29f2e1..00000000 --- a/maven-plugin-plugin/src/it/mplugin-421/verify.groovy +++ /dev/null @@ -1,32 +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 groovy.xml.XmlParser - -File descriptorFile = new File( basedir, "target/classes/META-INF/maven/plugin.xml" ) -assert descriptorFile.isFile() - -def pluginDescriptor = new XmlParser().parse( descriptorFile ) -def mojo = pluginDescriptor.mojos.mojo.find { it.goal.text() == "hello" } - -assert mojo != null -assert mojo.implementation.text() == "org.apache.maven.plugin.coreit.HelloMojo" -assert mojo.description.text() == "Says hello." - -return true diff --git a/maven-plugin-plugin/src/it/packaging-jar/invoker.properties b/maven-plugin-plugin/src/it/packaging-jar/invoker.properties deleted file mode 100644 index 43be5b1d..00000000 --- a/maven-plugin-plugin/src/it/packaging-jar/invoker.properties +++ /dev/null @@ -1,18 +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 diff --git a/maven-plugin-plugin/src/it/packaging-jar/pom.xml b/maven-plugin-plugin/src/it/packaging-jar/pom.xml deleted file mode 100644 index 9521be6b..00000000 --- a/maven-plugin-plugin/src/it/packaging-jar/pom.xml +++ /dev/null @@ -1,94 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<!-- -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. ---> - -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <groupId>org.apache.maven.its.packaging-jar</groupId> - <artifactId>packaging-jar</artifactId> - <version>1.0-SNAPSHOT</version> - <packaging>jar</packaging> - - <name>Maven Integration Test :: packaging-jar</name> - <description> - Test plugin-plugin can be enabled for projects with alternative packaging types, - "jar" in this particular case. - </description> - - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - </properties> - - <dependencies> - <dependency> - <groupId>org.apache.maven</groupId> - <artifactId>maven-plugin-api</artifactId> - <version>@maven3Version@</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.apache.maven.plugin-tools</groupId> - <artifactId>maven-plugin-annotations</artifactId> - <version>@project.version@</version> - <scope>provided</scope> - </dependency> - </dependencies> - - <build> - <pluginManagement> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <version>@version.maven-compiler-plugin@</version> - </plugin> - </plugins> - </pluginManagement> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-plugin-plugin</artifactId> - <version>@project.version@</version> - <configuration> - <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound> - <packagingTypes> - <packaging>jar</packaging> - </packagingTypes> - <goalPrefix>prefix</goalPrefix> - </configuration> - <executions> - <execution> - <id>mojo-descriptor</id> - <goals> - <goal>descriptor</goal> - </goals> - </execution> - <execution> - <id>help-goal</id> - <goals> - <goal>helpmojo</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - </build> -</project> diff --git a/maven-plugin-plugin/src/it/packaging-jar/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java b/maven-plugin-plugin/src/it/packaging-jar/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java deleted file mode 100644 index a9a098ef..00000000 --- a/maven-plugin-plugin/src/it/packaging-jar/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java +++ /dev/null @@ -1,32 +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.plugin.coreit; - -import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugins.annotations.Mojo; - -/** - * @deprecated Don't use! - */ -@Mojo(name = "first") -public class FirstMojo extends AbstractMojo { - - public void execute() throws MojoExecutionException {} -} diff --git a/maven-plugin-plugin/src/it/packaging-jar/verify.groovy b/maven-plugin-plugin/src/it/packaging-jar/verify.groovy deleted file mode 100644 index cdf45e37..00000000 --- a/maven-plugin-plugin/src/it/packaging-jar/verify.groovy +++ /dev/null @@ -1,33 +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 groovy.xml.XmlParser - -File descriptorFile = new File( basedir, "target/classes/META-INF/maven/plugin.xml" ); -assert descriptorFile.isFile() - -def pluginDescriptor = new XmlParser().parse( descriptorFile ); - -def mojo = pluginDescriptor.mojos.mojo.findAll{ it.goal.text() == "first" }[0] - -assert mojo.goal.text() == 'first' -assert mojo.implementation.text() == 'org.apache.maven.plugin.coreit.FirstMojo' -assert mojo.language.text() == 'java' - -return true; diff --git a/maven-plugin-plugin/src/it/skip/invoker.properties b/maven-plugin-plugin/src/it/skip/invoker.properties deleted file mode 100644 index b1922736..00000000 --- a/maven-plugin-plugin/src/it/skip/invoker.properties +++ /dev/null @@ -1,19 +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 = install -invoker.mavenOpts = -Dmaven.plugin.skip=true diff --git a/maven-plugin-plugin/src/it/skip/pom.xml b/maven-plugin-plugin/src/it/skip/pom.xml deleted file mode 100644 index b5ec3666..00000000 --- a/maven-plugin-plugin/src/it/skip/pom.xml +++ /dev/null @@ -1,65 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<!-- -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. ---> - -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <groupId>org.apache.maven.its.it0013</groupId> - <artifactId>mplugin-174</artifactId> - <version>1.0-SNAPSHOT</version> - <packaging>maven-plugin</packaging> - - <name>MPLUGIN-174</name> - <description> - Test the skip property - </description> - - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - </properties> - - <dependencies> - <dependency> - <groupId>org.apache.maven</groupId> - <artifactId>maven-plugin-api</artifactId> - <version>@maven3Version@</version> - </dependency> - <dependency> - <groupId>org.apache.maven.plugin-tools</groupId> - <artifactId>maven-plugin-annotations</artifactId> - <version>@project.version@</version> - <scope>compile</scope> - </dependency> - </dependencies> - - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-plugin-plugin</artifactId> - <version>@project.version@</version> - <configuration> - <goalPrefix>prefix</goalPrefix> - </configuration> - </plugin> - </plugins> - </build> -</project> diff --git a/maven-plugin-plugin/src/it/skip/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java b/maven-plugin-plugin/src/it/skip/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java deleted file mode 100644 index e7a15341..00000000 --- a/maven-plugin-plugin/src/it/skip/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java +++ /dev/null @@ -1,32 +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.plugin.coreit; - -import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugins.annotations.Mojo; - -/** - * Touches a test file. - */ -@Mojo(name = "test") -public class FirstMojo extends AbstractMojo { - - public void execute() throws MojoExecutionException {} -} diff --git a/maven-plugin-plugin/src/it/skip/verify.groovy b/maven-plugin-plugin/src/it/skip/verify.groovy deleted file mode 100644 index e386564f..00000000 --- a/maven-plugin-plugin/src/it/skip/verify.groovy +++ /dev/null @@ -1,23 +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 descriptorFile = new File( basedir, "target/classes/META-INF/maven/plugin.xml" ); -assert !descriptorFile.isFile() - -return true; diff --git a/maven-plugin-plugin/src/test/java/org/apache/maven/plugin/plugin/DescriptorGeneratorMojoExecuteTest.java b/maven-plugin-plugin/src/test/java/org/apache/maven/plugin/plugin/DescriptorGeneratorMojoExecuteTest.java new file mode 100644 index 00000000..c55187b1 --- /dev/null +++ b/maven-plugin-plugin/src/test/java/org/apache/maven/plugin/plugin/DescriptorGeneratorMojoExecuteTest.java @@ -0,0 +1,181 @@ +/* + * 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 javax.inject.Inject; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.apache.maven.api.plugin.testing.Basedir; +import org.apache.maven.api.plugin.testing.InjectMojo; +import org.apache.maven.api.plugin.testing.MojoTest; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.DefaultArtifact; +import org.apache.maven.artifact.handler.DefaultArtifactHandler; +import org.apache.maven.plugin.logging.SystemStreamLog; +import org.apache.maven.project.MavenProject; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +import static org.apache.maven.api.plugin.testing.MojoExtension.setVariableValueToObject; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * Runs {@link DescriptorGeneratorMojo#execute()} against an empty class output directory. Execution that is not + * stopped early still writes a {@code plugin.xml}, which is how the tests tell a skipped run from a real one. + */ +@MojoTest +class DescriptorGeneratorMojoExecuteTest { + + private static final String SCOPE_WARNING = + "Some dependencies of Maven Plugins are expected to be in provided scope."; + + @TempDir + private Path outputDirectory; + + @Inject + private MavenProject project; + + private final RecordingLog log = new RecordingLog(); + + @Test + @InjectMojo(goal = "descriptor", pom = "plugin-config.xml") + @Basedir("/unit/descriptor-skip") + void skipParameterSuppressesDescriptorGeneration(DescriptorGeneratorMojo mojo) throws Exception { + prepare(mojo, "maven-plugin"); + + mojo.execute(); + + assertTrue(log.contains("Execution skipped"), log.toString()); + assertFalse(Files.exists(descriptor()), "plugin.xml must not be written"); + } + + @Test + @InjectMojo(goal = "descriptor", pom = "plugin-config.xml") + @Basedir("/unit/descriptor-unsupported-packaging") + void unsupportedPackagingIsSkipped(DescriptorGeneratorMojo mojo) throws Exception { + prepare(mojo, "jar"); + + mojo.execute(); + + assertTrue(log.contains("Unsupported packaging type jar, execution skipped"), log.toString()); + assertFalse(Files.exists(descriptor()), "plugin.xml must not be written"); + } + + @Test + @InjectMojo(goal = "descriptor", pom = "plugin-config.xml") + @Basedir("/unit/descriptor-packaging-jar") + void configuredPackagingTypeIsExecuted(DescriptorGeneratorMojo mojo) throws Exception { + prepare(mojo, "jar"); + + mojo.execute(); + + assertFalse(log.contains("Unsupported packaging type"), log.toString()); + assertTrue(Files.isRegularFile(descriptor()), "plugin.xml must be written for packagingTypes=jar"); + } + + @Test + @InjectMojo(goal = "descriptor", pom = "plugin-config.xml") + @Basedir("/unit/descriptor-scope") + void mavenDependencyOutsideProvidedScopeIsReported(DescriptorGeneratorMojo mojo) throws Exception { + prepare(mojo, "maven-plugin"); + project.setArtifacts(artifacts( + artifact("org.apache.maven", "maven-plugin-api", Artifact.SCOPE_COMPILE), + artifact("org.apache.maven.plugin-tools", "maven-plugin-annotations", Artifact.SCOPE_COMPILE))); + + mojo.execute(); + + assertTrue(log.contains(SCOPE_WARNING), log.toString()); + assertTrue(log.contains(" * org.apache.maven:maven-plugin-api:jar:1.0:compile"), log.toString()); + assertFalse(log.contains("maven-plugin-annotations:jar"), log.toString()); + } + + @Test + @InjectMojo(goal = "descriptor", pom = "plugin-config.xml") + @Basedir("/unit/descriptor-scope") + void providedAndExcludedDependenciesAreNotReported(DescriptorGeneratorMojo mojo) throws Exception { + prepare(mojo, "maven-plugin"); + project.setArtifacts(artifacts( + artifact("org.apache.maven", "maven-plugin-api", Artifact.SCOPE_PROVIDED), + // maven-jxr is on the default exclusion list + artifact("org.apache.maven", "maven-jxr", Artifact.SCOPE_COMPILE), + artifact("org.apache.maven.plugin-tools", "maven-plugin-annotations", Artifact.SCOPE_COMPILE))); + + mojo.execute(); + + assertFalse(log.contains(SCOPE_WARNING), log.toString()); + assertTrue(Files.isRegularFile(descriptor()), "the run must get past the scope check"); + } + + private void prepare(DescriptorGeneratorMojo mojo, String packaging) throws Exception { + project.setGroupId("org.apache.maven.its"); + project.setArtifactId("descriptor-execute"); + project.setVersion("1.0-SNAPSHOT"); + project.setPackaging(packaging); + Path classes = Files.createDirectories(outputDirectory.resolve("classes")); + project.getBuild().setOutputDirectory(classes.toString()); + setVariableValueToObject(mojo, "classesOutputDirectory", classes.toFile()); + setVariableValueToObject( + mojo, "outputDirectory", descriptor().getParent().toFile()); + mojo.setLog(log); + } + + private Path descriptor() { + return outputDirectory.resolve("META-INF/maven/plugin.xml"); + } + + private static Artifact artifact(String groupId, String artifactId, String scope) { + return new DefaultArtifact(groupId, artifactId, "1.0", scope, "jar", null, new DefaultArtifactHandler("jar")); + } + + private static Set<Artifact> artifacts(Artifact... artifacts) { + return new HashSet<>(Arrays.asList(artifacts)); + } + + /** Collects what the mojo logs at info and warn level. */ + static final class RecordingLog extends SystemStreamLog { + private final List<String> messages = new ArrayList<>(); + + boolean contains(String text) { + return messages.stream().anyMatch(message -> message.contains(text)); + } + + @Override + public void info(CharSequence content) { + messages.add(content.toString()); + } + + @Override + public void warn(CharSequence content) { + messages.add(content.toString()); + } + + @Override + public String toString() { + return messages.toString(); + } + } +} diff --git a/maven-plugin-plugin/src/test/java/org/apache/maven/plugin/plugin/HelpGeneratorMojoExecuteTest.java b/maven-plugin-plugin/src/test/java/org/apache/maven/plugin/plugin/HelpGeneratorMojoExecuteTest.java new file mode 100644 index 00000000..bc82f9dc --- /dev/null +++ b/maven-plugin-plugin/src/test/java/org/apache/maven/plugin/plugin/HelpGeneratorMojoExecuteTest.java @@ -0,0 +1,73 @@ +/* + * 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 javax.inject.Inject; + +import java.io.File; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; + +import org.apache.maven.api.plugin.testing.Basedir; +import org.apache.maven.api.plugin.testing.InjectMojo; +import org.apache.maven.api.plugin.testing.MojoTest; +import org.apache.maven.project.MavenProject; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +import static org.apache.maven.api.plugin.testing.MojoExtension.setVariableValueToObject; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +@MojoTest +class HelpGeneratorMojoExecuteTest { + + @TempDir + private Path tempDir; + + @Inject + private MavenProject project; + + /** MPLUGIN-363: generating the help mojo again must not change a single byte of it. */ + @Test + @InjectMojo(goal = "helpmojo", pom = "plugin-config.xml") + @Basedir("/unit/help-reproducible") + void helpMojoSourceIsReproducible(HelpGeneratorMojo mojo) throws Exception { + project.setGroupId("org.apache.maven.its.plugin"); + project.setArtifactId("help"); + project.setVersion("1.0-SNAPSHOT"); + project.setPackaging("maven-plugin"); + + Path first = generate(mojo, "run1"); + Path second = generate(mojo, "run2"); + + String firstSource = new String(Files.readAllBytes(first), StandardCharsets.UTF_8); + assertTrue(firstSource.contains("package org.apache.maven.its.plugin.help;"), firstSource); + assertTrue(firstSource.contains("prefix"), firstSource); + assertEquals(firstSource, new String(Files.readAllBytes(second), StandardCharsets.UTF_8)); + } + + private Path generate(HelpGeneratorMojo mojo, String directoryName) throws Exception { + File outputDirectory = tempDir.resolve(directoryName).toFile(); + setVariableValueToObject(mojo, "outputDirectory", outputDirectory); + mojo.execute(); + return outputDirectory.toPath().resolve("org/apache/maven/its/plugin/help/HelpMojo.java"); + } +} diff --git a/maven-plugin-plugin/src/test/resources/unit/descriptor-packaging-jar/plugin-config.xml b/maven-plugin-plugin/src/test/resources/unit/descriptor-packaging-jar/plugin-config.xml new file mode 100644 index 00000000..0bc4b2c7 --- /dev/null +++ b/maven-plugin-plugin/src/test/resources/unit/descriptor-packaging-jar/plugin-config.xml @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- +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. +--> + +<project> + <build> + <plugins> + <plugin> + <artifactId>maven-plugin-plugin</artifactId> + <configuration> + <goalPrefix>prefix</goalPrefix> + <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound> + <!-- no extractors: the test only needs the descriptor file to be written --> + <extractors> + <extractor/> + </extractors> + <packagingTypes> + <packaging>jar</packaging> + </packagingTypes> + </configuration> + </plugin> + </plugins> + </build> +</project> diff --git a/maven-plugin-plugin/src/test/resources/unit/descriptor-scope/plugin-config.xml b/maven-plugin-plugin/src/test/resources/unit/descriptor-scope/plugin-config.xml new file mode 100644 index 00000000..655c6038 --- /dev/null +++ b/maven-plugin-plugin/src/test/resources/unit/descriptor-scope/plugin-config.xml @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- +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. +--> + +<project> + <build> + <plugins> + <plugin> + <artifactId>maven-plugin-plugin</artifactId> + <configuration> + <goalPrefix>prefix</goalPrefix> + <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound> + <!-- no extractors: the test only needs the descriptor file to be written --> + <extractors> + <extractor/> + </extractors> + </configuration> + </plugin> + </plugins> + </build> +</project> diff --git a/maven-plugin-plugin/src/test/resources/unit/descriptor-skip/plugin-config.xml b/maven-plugin-plugin/src/test/resources/unit/descriptor-skip/plugin-config.xml new file mode 100644 index 00000000..6b895049 --- /dev/null +++ b/maven-plugin-plugin/src/test/resources/unit/descriptor-skip/plugin-config.xml @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- +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. +--> + +<project> + <build> + <plugins> + <plugin> + <artifactId>maven-plugin-plugin</artifactId> + <configuration> + <goalPrefix>prefix</goalPrefix> + <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound> + <!-- no extractors: a run that is not skipped just writes an empty plugin.xml --> + <extractors> + <extractor/> + </extractors> + <skip>true</skip> + </configuration> + </plugin> + </plugins> + </build> +</project> diff --git a/maven-plugin-plugin/src/test/resources/unit/descriptor-unsupported-packaging/plugin-config.xml b/maven-plugin-plugin/src/test/resources/unit/descriptor-unsupported-packaging/plugin-config.xml new file mode 100644 index 00000000..be8678e1 --- /dev/null +++ b/maven-plugin-plugin/src/test/resources/unit/descriptor-unsupported-packaging/plugin-config.xml @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- +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. +--> + +<project> + <build> + <plugins> + <plugin> + <artifactId>maven-plugin-plugin</artifactId> + <configuration> + <goalPrefix>prefix</goalPrefix> + <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound> + <!-- no extractors: a run that is not skipped just writes an empty plugin.xml --> + <extractors> + <extractor/> + </extractors> + </configuration> + </plugin> + </plugins> + </build> +</project> diff --git a/maven-plugin-plugin/src/test/resources/unit/help-reproducible/plugin-config.xml b/maven-plugin-plugin/src/test/resources/unit/help-reproducible/plugin-config.xml new file mode 100644 index 00000000..dae7a81b --- /dev/null +++ b/maven-plugin-plugin/src/test/resources/unit/help-reproducible/plugin-config.xml @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- +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. +--> + +<project> + <build> + <plugins> + <plugin> + <artifactId>maven-plugin-plugin</artifactId> + <configuration> + <goalPrefix>prefix</goalPrefix> + </configuration> + </plugin> + </plugins> + </build> +</project> diff --git a/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/extractor/annotations/JavaAnnotationsMojoDescriptorExtractorTest.java b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/extractor/annotations/JavaAnnotationsMojoDescriptorExtractorTest.java index 54b53d92..5cea9d38 100644 --- a/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/extractor/annotations/JavaAnnotationsMojoDescriptorExtractorTest.java +++ b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/extractor/annotations/JavaAnnotationsMojoDescriptorExtractorTest.java @@ -18,12 +18,19 @@ */ package org.apache.maven.tools.plugin.extractor.annotations; +import javax.tools.JavaCompiler; +import javax.tools.ToolProvider; + import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.Field; import java.net.URISyntaxException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -37,11 +44,14 @@ import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.project.MavenProject; import org.apache.maven.tools.plugin.DefaultPluginToolsRequest; import org.apache.maven.tools.plugin.extractor.ExtractionException; +import org.apache.maven.tools.plugin.extractor.annotations.converter.JavadocBlockTagsToXhtmlConverter; +import org.apache.maven.tools.plugin.extractor.annotations.converter.JavadocInlineTagsToXhtmlConverter; import org.apache.maven.tools.plugin.extractor.annotations.scanner.DefaultMojoAnnotationsScanner; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -116,4 +126,78 @@ class JavaAnnotationsMojoDescriptorExtractorTest { // two conflicting phase ids set assertThrows(InvalidPluginDescriptorException.class, () -> extractDescriptorFromMojoClass(Execute2Mojo.class)); } + + @Test + void nestedMojoKeepsItsJavadocMetadata() throws Exception { + MojoDescriptor mojoDescriptor = extractDescriptorFromSources("NestedMojos.java"); + + assertEquals("nested", mojoDescriptor.getGoal()); + assertEquals("org.apache.maven.plugin.coreit.NestedMojos$NestedMojo", mojoDescriptor.getImplementation()); + assertEquals("Runs the nested goal.", mojoDescriptor.getDescription()); + assertEquals("1.2", mojoDescriptor.getSince()); + assertEquals("Use a top-level Mojo instead.", mojoDescriptor.getDeprecated()); + } + + @Test + void commentOnlySourceDoesNotPreventExtraction() throws Exception { + MojoDescriptor mojoDescriptor = extractDescriptorFromSources("HelloMojo.java", "CommentOnly.java"); + + assertEquals("hello", mojoDescriptor.getGoal()); + assertEquals("org.apache.maven.plugin.coreit.HelloMojo", mojoDescriptor.getImplementation()); + assertEquals("Says hello.", mojoDescriptor.getDescription()); + } + + /** + * Compiles the named sources of {@code src/test/resources/mojo-sources} and extracts the single mojo they + * contain, with the sources registered as compile source root so that the Javadoc is read. + */ + private MojoDescriptor extractDescriptorFromSources(String... fileNames) throws Exception { + Path sourceRoot = targetDir.resolve("sources"); + Path classesDirectory = targetDir.resolve("classes"); + Files.createDirectories(classesDirectory); + + List<String> arguments = new ArrayList<>(); + arguments.add("-d"); + arguments.add(classesDirectory.toString()); + arguments.add("-classpath"); + arguments.add(System.getProperty("java.class.path")); + for (String fileName : fileNames) { + Path source = sourceRoot.resolve("org/apache/maven/plugin/coreit").resolve(fileName); + Files.createDirectories(source.getParent()); + try (InputStream in = + getClass().getResourceAsStream("/mojo-sources/org/apache/maven/plugin/coreit/" + fileName)) { + assertNotNull(in, fileName); + Files.copy(in, source); + } + arguments.add(source.toString()); + } + JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); + assertNotNull(compiler); + assertEquals(0, compiler.run(null, null, null, arguments.toArray(new String[0]))); + + MavenProject mavenProject = new MavenProject(); + mavenProject.setArtifact( + new DefaultArtifact("groupId", "artifactId", "1.0.0", null, "jar", "classifier", null)); + mavenProject.getBuild().setOutputDirectory(classesDirectory.toString()); + mavenProject.addCompileSourceRoot(sourceRoot.toString()); + + JavaAnnotationsMojoDescriptorExtractor extractor = new JavaAnnotationsMojoDescriptorExtractor(); + extractor.mojoAnnotationsScanner = new DefaultMojoAnnotationsScanner(); + JavadocInlineTagsToXhtmlConverter inlineConverter = new JavadocInlineTagsToXhtmlConverter(new HashMap<>()); + inject(extractor, "javadocInlineTagsToHtmlConverter", inlineConverter); + inject( + extractor, + "javadocBlockTagsToHtmlConverter", + new JavadocBlockTagsToXhtmlConverter(inlineConverter, new HashMap<>())); + List<MojoDescriptor> mojoDescriptors = + extractor.execute(new DefaultPluginToolsRequest(mavenProject, new PluginDescriptor())); + assertEquals(1, mojoDescriptors.size()); + return mojoDescriptors.get(0); + } + + private static void inject(Object target, String fieldName, Object value) throws ReflectiveOperationException { + Field field = target.getClass().getDeclaredField(fieldName); + field.setAccessible(true); + field.set(target, value); + } } diff --git a/maven-plugin-plugin/src/it/mplugin-421/src/main/java/org/apache/maven/plugin/coreit/CommentOnly.java b/maven-plugin-tools-annotations/src/test/resources/mojo-sources/org/apache/maven/plugin/coreit/CommentOnly.java similarity index 100% rename from maven-plugin-plugin/src/it/mplugin-421/src/main/java/org/apache/maven/plugin/coreit/CommentOnly.java rename to maven-plugin-tools-annotations/src/test/resources/mojo-sources/org/apache/maven/plugin/coreit/CommentOnly.java diff --git a/maven-plugin-plugin/src/it/mplugin-421/src/main/java/org/apache/maven/plugin/coreit/HelloMojo.java b/maven-plugin-tools-annotations/src/test/resources/mojo-sources/org/apache/maven/plugin/coreit/HelloMojo.java similarity index 100% rename from maven-plugin-plugin/src/it/mplugin-421/src/main/java/org/apache/maven/plugin/coreit/HelloMojo.java rename to maven-plugin-tools-annotations/src/test/resources/mojo-sources/org/apache/maven/plugin/coreit/HelloMojo.java diff --git a/maven-plugin-plugin/src/it/javaparser-nested-mojo/src/main/java/org/apache/maven/plugin/coreit/NestedMojos.java b/maven-plugin-tools-annotations/src/test/resources/mojo-sources/org/apache/maven/plugin/coreit/NestedMojos.java similarity index 100% rename from maven-plugin-plugin/src/it/javaparser-nested-mojo/src/main/java/org/apache/maven/plugin/coreit/NestedMojos.java rename to maven-plugin-tools-annotations/src/test/resources/mojo-sources/org/apache/maven/plugin/coreit/NestedMojos.java diff --git a/pom.xml b/pom.xml index 7fd5fd87..e0cdd681 100644 --- a/pom.xml +++ b/pom.xml @@ -359,7 +359,7 @@ <excludes> <exclude>**/it/source-encoding/</exclude> <!-- Intentionally contains no type declaration (MPLUGIN-421). --> - <exclude>**/it/mplugin-421/**/CommentOnly.java</exclude> + <exclude>**/mojo-sources/**/CommentOnly.java</exclude> </excludes> </java> </configuration>
