[MNG-7891] IT for configuring extensions (#296)
Co-authored-by: Christoph Läubrich <christoph@laeubi-soft.de>
diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng7891ConfigurationForExtensionsTest.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng7891ConfigurationForExtensionsTest.java
new file mode 100644
index 0000000..a390cec
--- /dev/null
+++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng7891ConfigurationForExtensionsTest.java
@@ -0,0 +1,81 @@
+/*
+ * 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.it;
+
+import java.io.File;
+import java.util.List;
+
+import org.apache.maven.shared.verifier.Verifier;
+import org.apache.maven.shared.verifier.util.ResourceExtractor;
+import org.junit.jupiter.api.Test;
+
+class MavenITmng7891ConfigurationForExtensionsTest extends AbstractMavenIntegrationTestCase {
+
+ protected MavenITmng7891ConfigurationForExtensionsTest() {
+ super("(4.0.0-alpha-7,)");
+ }
+
+ @Test
+ void testConfigurationForCoreExtension() throws Exception {
+ File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-7891-extension-configuration");
+
+ Verifier verifier = newVerifier(new File(testDir, "extension").getAbsolutePath());
+ verifier.addCliArgument("install");
+ verifier.execute();
+ verifier.verifyErrorFreeLog();
+
+ verifier = newVerifier(new File(testDir, "core-extension").getAbsolutePath());
+ verifier.addCliArgument("install");
+ verifier.addCliArgument("-DuserValue=the-value");
+ verifier.execute();
+ verifier.verifyErrorFreeLog();
+
+ List<String> logFile = verifier.loadFile(verifier.getBasedir(), verifier.getLogFileName(), false);
+ String projects = logFile.stream()
+ .filter(s -> s.contains("All projects are read now"))
+ .findFirst()
+ .orElse(null);
+ assertNotNull(projects);
+ assertFalse(projects.contains("$"));
+ }
+
+ @Test
+ void testConfigurationForBuildExtension() throws Exception {
+ File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-7891-extension-configuration");
+
+ Verifier verifier = newVerifier(new File(testDir, "extension").getAbsolutePath());
+ verifier.addCliArgument("install");
+ verifier.execute();
+ verifier.verifyErrorFreeLog();
+
+ verifier = newVerifier(new File(testDir, "build-extension").getAbsolutePath());
+ verifier.addCliArgument("install");
+ verifier.addCliArgument("-DuserValue=the-value");
+ verifier.execute();
+ verifier.verifyErrorFreeLog();
+
+ List<String> logFile = verifier.loadFile(verifier.getBasedir(), verifier.getLogFileName(), false);
+ String projects = logFile.stream()
+ .filter(s -> s.contains("All projects are read now"))
+ .findFirst()
+ .orElse(null);
+ assertNotNull(projects);
+ assertFalse(projects.contains("$"));
+ }
+}
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 2b8c5e9..a039462 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
@@ -120,6 +120,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(MavenITmng7891ConfigurationForExtensionsTest.class);
suite.addTestSuite(MavenITmng6401ProxyPortInterpolationTest.class);
suite.addTestSuite(MavenITmng7228LeakyModelTest.class);
suite.addTestSuite(MavenITmng7819FileLockingWithSnapshotsTest.class);
diff --git a/core-it-suite/src/test/resources/mng-7891-extension-configuration/build-extension/pom.xml b/core-it-suite/src/test/resources/mng-7891-extension-configuration/build-extension/pom.xml
new file mode 100644
index 0000000..951402a
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-7891-extension-configuration/build-extension/pom.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.1.0" root="true">
+ <groupId>org.apache.maven.its.mng7891</groupId>
+ <artifactId>build-extension</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <build>
+ <extensions>
+ <extension>
+ <groupId>org.apache.maven.its.mng7891</groupId>
+ <artifactId>extension</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <configuration>
+ <messages>
+ <sessionStart>The session has just started at ${maven.build.timestamp}</sessionStart>
+ <projectsRead>All projects are read now! The build will start and the user has passed -DuserValue=${userValue} on the commandline</projectsRead>
+ </messages>
+ </configuration>
+ </extension>
+ </extensions>
+ </build>
+</project>
diff --git a/core-it-suite/src/test/resources/mng-7891-extension-configuration/core-extension/.mvn/extensions.xml b/core-it-suite/src/test/resources/mng-7891-extension-configuration/core-extension/.mvn/extensions.xml
new file mode 100644
index 0000000..b11a717
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-7891-extension-configuration/core-extension/.mvn/extensions.xml
@@ -0,0 +1,13 @@
+<extensions>
+ <extension>
+ <groupId>org.apache.maven.its.mng7891</groupId>
+ <artifactId>extension</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <configuration>
+ <messages>
+ <sessionStart>The session has just started at ${maven.build.timestamp}</sessionStart>
+ <projectsRead>All projects are read now! The build will start and the user has passed -DuserValue=${userValue} on the commandline</projectsRead>
+ </messages>
+ </configuration>
+ </extension>
+</extensions>
diff --git a/core-it-suite/src/test/resources/mng-7891-extension-configuration/core-extension/pom.xml b/core-it-suite/src/test/resources/mng-7891-extension-configuration/core-extension/pom.xml
new file mode 100644
index 0000000..248798e
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-7891-extension-configuration/core-extension/pom.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.1.0" root="true">
+ <groupId>org.apache.maven.its.mng7891</groupId>
+ <artifactId>core-extension</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+</project>
diff --git a/core-it-suite/src/test/resources/mng-7891-extension-configuration/extension/pom.xml b/core-it-suite/src/test/resources/mng-7891-extension-configuration/extension/pom.xml
new file mode 100644
index 0000000..d145a98
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-7891-extension-configuration/extension/pom.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.1.0" root="true">
+ <groupId>org.apache.maven.its.mng7891</groupId>
+ <artifactId>extension</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <properties>
+ <javaVersion>8</javaVersion>
+ <maven.compiler.source>${javaVersion}</maven.compiler.source>
+ <maven.compiler.target>${javaVersion}</maven.compiler.target>
+ <maven.version>3.8.6</maven.version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-core</artifactId>
+ <version>${maven.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.eclipse.sisu</groupId>
+ <artifactId>sisu-maven-plugin</artifactId>
+ <version>0.3.5</version>
+ <executions>
+ <execution>
+ <id>index-project</id>
+ <goals>
+ <goal>main-index</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/core-it-suite/src/test/resources/mng-7891-extension-configuration/extension/src/main/java/org/apache/maven/its/mng7891/MyLifecycleParticipant.java b/core-it-suite/src/test/resources/mng-7891-extension-configuration/extension/src/main/java/org/apache/maven/its/mng7891/MyLifecycleParticipant.java
new file mode 100644
index 0000000..21f5f67
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-7891-extension-configuration/extension/src/main/java/org/apache/maven/its/mng7891/MyLifecycleParticipant.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.its.mng7891;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.apache.maven.AbstractMavenLifecycleParticipant;
+import org.apache.maven.MavenExecutionException;
+import org.apache.maven.execution.MavenSession;
+import org.codehaus.plexus.configuration.PlexusConfiguration;
+import org.codehaus.plexus.logging.Logger;
+
+@Named
+@Singleton
+public class MyLifecycleParticipant extends AbstractMavenLifecycleParticipant {
+
+ private PlexusConfiguration configuration;
+ private Logger logger;
+
+ @Inject
+ public MyLifecycleParticipant(
+ @Named("org.apache.maven.its.mng7891:extension") PlexusConfiguration configuration, Logger logger) {
+ this.configuration = configuration;
+ this.logger = logger;
+ }
+
+ @Override
+ public void afterProjectsRead(MavenSession session) throws MavenExecutionException {
+ PlexusConfiguration messages = configuration.getChild("messages");
+ PlexusConfiguration sessionStart = messages.getChild("projectsRead");
+ logger.info(sessionStart.getValue("No session projects read message configured"));
+ }
+}