[MNG-7587] Add an IT for jsr330 components (#264)
diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng7587Jsr330.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng7587Jsr330.java
new file mode 100644
index 0000000..869dc59
--- /dev/null
+++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng7587Jsr330.java
@@ -0,0 +1,73 @@
+package org.apache.maven.it;
+
+/*
+ * 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 org.apache.maven.shared.verifier.Verifier;
+import org.apache.maven.shared.verifier.util.ResourceExtractor;
+import org.codehaus.plexus.util.Os;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledOnJre;
+import org.junit.jupiter.api.condition.JRE;
+
+import java.io.File;
+
+/**
+ * This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-7587">MNG-7587</a>.
+ * Simply verifies that plexus component using JSR330 and compiled with JDK 17 bytecode can
+ * work on maven.
+ */
+class MavenITmng7587Jsr330
+ extends AbstractMavenIntegrationTestCase
+{
+
+ public MavenITmng7587Jsr330()
+ {
+ // affected Maven versions: 3.9.2 and 4.0.0-alpha-5
+ super( "(3.9.2,3.999),(4.0.0-alpha-5,)" );
+ }
+
+ /**
+ * Verify components can be written using JSR330 on JDK 17.
+ *
+ * @throws Exception in case of failure
+ */
+ @Test
+ @EnabledOnJre(JRE.JAVA_17)
+ void testJdk17() throws Exception
+ {
+ File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-7587-jsr330").getAbsoluteFile();
+
+ final Verifier pluginVerifier = newVerifier( new File( testDir, "plugin" ).getPath() );
+ pluginVerifier.addCliArgument( "clean" );
+ pluginVerifier.addCliArgument( "install" );
+ pluginVerifier.addCliArgument( "-V" );
+ pluginVerifier.execute();
+ pluginVerifier.verifyErrorFreeLog();
+
+ final Verifier consumerVerifier = newVerifier( new File( testDir, "consumer" ).getPath() );
+ consumerVerifier.addCliArgument( "clean" );
+ consumerVerifier.addCliArgument( "verify" );
+ consumerVerifier.addCliArgument( "-V" );
+ consumerVerifier.execute();
+ consumerVerifier.verifyErrorFreeLog();
+ }
+
+}
diff --git a/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java b/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java
index f776804..5c755a9 100644
--- a/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java
+++ b/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java
@@ -111,6 +111,7 @@
* the tests are to finishing. Newer tests are also more likely to fail, so this is
* a fail fast technique as well.
*/
+ suite.addTestSuite( MavenITmng7587Jsr330.class );
suite.addTestSuite( MavenITmng7038RootdirTest.class );
suite.addTestSuite( MavenITmng7697PomWithEmojiTest.class );
suite.addTestSuite( MavenITmng7737ProfileActivationTest.class );
diff --git a/core-it-suite/src/test/resources-filtered/bootstrap.txt b/core-it-suite/src/test/resources-filtered/bootstrap.txt
index 1b702ef..8fdae04 100644
--- a/core-it-suite/src/test/resources-filtered/bootstrap.txt
+++ b/core-it-suite/src/test/resources-filtered/bootstrap.txt
@@ -96,6 +96,7 @@
org.apache.maven.plugins:maven-plugin-plugin:3.2
org.apache.maven.plugins:maven-plugin-plugin:3.3
org.apache.maven.plugins:maven-plugin-plugin:3.6.0
+org.apache.maven.plugins:maven-plugin-plugin:3.9.0
org.apache.maven.plugins:maven-rar-plugin:${stubPluginVersion}
org.apache.maven.plugins:maven-release-plugin:3.0.0-M5
org.apache.maven.plugins:maven-resources-plugin:${stubPluginVersion}
@@ -135,6 +136,7 @@
org.apache.maven:maven-script-ant:2.1.0
org.apache.maven:maven-settings-builder:3.1.1
org.apache.maven:maven-settings:3.1.1
+org.apache.maven.plugin-testing:maven-plugin-testing-harness:3.3.0
org.codehaus.gmavenplus:gmavenplus-plugin:1.11.0
org.codehaus.mojo:build-helper-maven-plugin:3.2.0
org.codehaus.mojo:flatten-maven-plugin:1.0.0
diff --git a/core-it-suite/src/test/resources/mng-7587-jsr330/consumer/pom.xml b/core-it-suite/src/test/resources/mng-7587-jsr330/consumer/pom.xml
new file mode 100644
index 0000000..8e2d2c3
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-7587-jsr330/consumer/pom.xml
@@ -0,0 +1,53 @@
+<?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.mng7587</groupId>
+ <artifactId>consumer</artifactId>
+ <version>1.0-SNAPSHOT</version>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.its.mng7587</groupId>
+ <artifactId>plugin</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <executions>
+ <execution>
+ <id>touch</id>
+ <goals>
+ <goal>touch</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <maven.compiler.source>1.8</maven.compiler.source>
+ <maven.compiler.target>1.8</maven.compiler.target>
+ </properties>
+
+</project>
diff --git a/core-it-suite/src/test/resources/mng-7587-jsr330/plugin/pom.xml b/core-it-suite/src/test/resources/mng-7587-jsr330/plugin/pom.xml
new file mode 100644
index 0000000..3b1d530
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-7587-jsr330/plugin/pom.xml
@@ -0,0 +1,92 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+
+<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.mng7587</groupId>
+ <artifactId>plugin</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>maven-plugin</packaging>
+
+ <name>hello-maven-plugin Maven Plugin</name>
+
+ <prerequisites>
+ <maven>${maven.version}</maven>
+ </prerequisites>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <maven.version>3.8.6</maven.version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>${maven.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-core</artifactId>
+ <version>${maven.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-annotations</artifactId>
+ <version>3.6.0</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <artifactId>maven-clean-plugin</artifactId>
+ <version>3.2.0</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-resources-plugin</artifactId>
+ <version>3.3.0</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.10.1</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-plugin-plugin</artifactId>
+ <version>3.9.0</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>3.3.0</version>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <release>17</release>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-plugin-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>mojo-descriptor</id>
+ <goals>
+ <goal>descriptor</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/core-it-suite/src/test/resources/mng-7587-jsr330/plugin/src/main/java/sample/plugin/MyComponent.java b/core-it-suite/src/test/resources/mng-7587-jsr330/plugin/src/main/java/sample/plugin/MyComponent.java
new file mode 100644
index 0000000..41c4b26
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-7587-jsr330/plugin/src/main/java/sample/plugin/MyComponent.java
@@ -0,0 +1,8 @@
+package sample.plugin;
+
+import javax.inject.Named;
+
+@Named
+public class MyComponent implements MyService {
+
+}
diff --git a/core-it-suite/src/test/resources/mng-7587-jsr330/plugin/src/main/java/sample/plugin/MyMojo.java b/core-it-suite/src/test/resources/mng-7587-jsr330/plugin/src/main/java/sample/plugin/MyMojo.java
new file mode 100644
index 0000000..319ad2a
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-7587-jsr330/plugin/src/main/java/sample/plugin/MyMojo.java
@@ -0,0 +1,70 @@
+package sample.plugin;
+
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugins.annotations.Component;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+
+/**
+ * Goal which touches a timestamp file.
+ */
+@Mojo( name = "touch", defaultPhase = LifecyclePhase.PROCESS_SOURCES )
+public class MyMojo
+ extends AbstractMojo
+{
+ /**
+ * Location of the file.
+ */
+ @Parameter( defaultValue = "${project.build.directory}", property = "outputDir", required = true )
+ private File outputDirectory;
+
+ @Component
+ private MyService myService;
+
+ @Override
+ public void execute()
+ throws MojoExecutionException
+ {
+ File f = outputDirectory;
+
+ if ( !f.exists() )
+ {
+ f.mkdirs();
+ }
+
+ File touch = new File( f, "touch.txt" );
+
+ FileWriter w = null;
+ try
+ {
+ w = new FileWriter( touch );
+
+ w.write( "touch.txt" );
+ }
+ catch ( IOException e )
+ {
+ throw new MojoExecutionException( "Error creating file " + touch, e );
+ }
+ finally
+ {
+ if ( w != null )
+ {
+ try
+ {
+ w.close();
+ }
+ catch ( IOException e )
+ {
+ // ignore
+ }
+ }
+ }
+ }
+}
diff --git a/core-it-suite/src/test/resources/mng-7587-jsr330/plugin/src/main/java/sample/plugin/MyService.java b/core-it-suite/src/test/resources/mng-7587-jsr330/plugin/src/main/java/sample/plugin/MyService.java
new file mode 100644
index 0000000..30d92e6
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-7587-jsr330/plugin/src/main/java/sample/plugin/MyService.java
@@ -0,0 +1,5 @@
+package sample.plugin;
+
+public interface MyService {
+
+}
diff --git a/core-it-suite/src/test/resources/mng-7587-jsr330/plugin/src/test/MyMojoTest.java b/core-it-suite/src/test/resources/mng-7587-jsr330/plugin/src/test/MyMojoTest.java
new file mode 100644
index 0000000..07172ca
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-7587-jsr330/plugin/src/test/MyMojoTest.java
@@ -0,0 +1,61 @@
+package sample.plugin;
+
+
+import org.apache.maven.plugin.testing.MojoRule;
+import org.apache.maven.plugin.testing.WithoutMojo;
+
+import org.junit.Rule;
+import static org.junit.Assert.*;
+import org.junit.Test;
+import java.io.File;
+
+public class MyMojoTest
+{
+ @Rule
+ public MojoRule rule = new MojoRule()
+ {
+ @Override
+ protected void before() throws Throwable
+ {
+ }
+
+ @Override
+ protected void after()
+ {
+ }
+ };
+
+ /**
+ * @throws Exception if any
+ */
+ @Test
+ public void testSomething()
+ throws Exception
+ {
+ File pom = new File( "target/test-classes/project-to-test/" );
+ assertNotNull( pom );
+ assertTrue( pom.exists() );
+
+ MyMojo myMojo = ( MyMojo ) rule.lookupConfiguredMojo( pom, "touch" );
+ assertNotNull( myMojo );
+ myMojo.execute();
+
+ File outputDirectory = ( File ) rule.getVariableValueFromObject( myMojo, "outputDirectory" );
+ assertNotNull( outputDirectory );
+ assertTrue( outputDirectory.exists() );
+
+ File touch = new File( outputDirectory, "touch.txt" );
+ assertTrue( touch.exists() );
+
+ }
+
+ /** Do not need the MojoRule. */
+ @WithoutMojo
+ @Test
+ public void testSomethingWhichDoesNotNeedTheMojoAndProbablyShouldBeExtractedIntoANewClassOfItsOwn()
+ {
+ assertTrue( true );
+ }
+
+}
+
diff --git a/core-it-suite/src/test/resources/mng-7587-jsr330/plugin/src/test/resources/project-to-test/pom.xml b/core-it-suite/src/test/resources/mng-7587-jsr330/plugin/src/test/resources/project-to-test/pom.xml
new file mode 100644
index 0000000..6224deb
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-7587-jsr330/plugin/src/test/resources/project-to-test/pom.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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>sample.plugin</groupId>
+ <artifactId>hello-maven-plugin</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+ <name>Test MyMojo</name>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-my-plugin</artifactId>
+ <configuration>
+ <!-- Specify the MyMojo parameter -->
+ <outputDirectory>target/test-harness/project-to-test</outputDirectory>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>