You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ma...@apache.org on 2020/10/18 18:35:48 UTC

[maven-integration-testing] branch master updated: [MNG-6118] Test various scenarios of invoking Maven in a sub-module.

This is an automated email from the ASF dual-hosted git repository.

martinkanters pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-integration-testing.git


The following commit(s) were added to refs/heads/master by this push:
     new abad210  [MNG-6118] Test various scenarios of invoking Maven in a sub-module.
abad210 is described below

commit abad210a351ac4d898e17507732349558bbf2330
Author: Maarten Mulders <ma...@infosupport.com>
AuthorDate: Wed Jul 1 16:15:51 2020 +0200

    [MNG-6118] Test various scenarios of invoking Maven in a sub-module.
    
    This closes #68
---
 .../org/apache/maven/it/IntegrationTestSuite.java  |   1 +
 .../it/MavenITmng6118SubmoduleInvocation.java      | 114 +++++++++++++++++++++
 .../.mvn/.gitkeep                                  |   0
 .../app/pom.xml                                    |  45 ++++++++
 .../src/main/java/org/apache/its/mng6118/App.java  |  29 ++++++
 .../test/java/org/apache/its/mng6118/AppTest.java  |  33 ++++++
 .../lib/pom.xml                                    |  41 ++++++++
 .../main/java/org/apache/its/mng6118/Helper.java   |  28 +++++
 .../java/org/apache/its/mng6118/HelperTest.java    |  37 +++++++
 .../pom.xml                                        |  82 +++++++++++++++
 .../mng-6991-local-repo-from-settings/settings.xml |  24 +++++
 11 files changed, 434 insertions(+)

diff --git a/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java b/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java
index c717aca..ed6554f 100644
--- a/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java
+++ b/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java
@@ -128,6 +128,7 @@ public class IntegrationTestSuite
         suite.addTestSuite( MavenITmng6173GetProjectsAndDependencyGraphTest.class );
         suite.addTestSuite( MavenITmng6173GetAllProjectsInReactorTest.class );
         suite.addTestSuite( MavenITmng6127PluginExecutionConfigurationInterferenceTest.class );
+        suite.addTestSuite( MavenITmng6118SubmoduleInvocation.class );
         suite.addTestSuite( MavenITmng6090CIFriendlyTest.class );
         suite.addTestSuite( MavenITmng6084Jsr250PluginTest.class );
         suite.addTestSuite( MavenITmng6071GetResourceWithCustomPom.class );
diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6118SubmoduleInvocation.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6118SubmoduleInvocation.java
new file mode 100644
index 0000000..6726056
--- /dev/null
+++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6118SubmoduleInvocation.java
@@ -0,0 +1,114 @@
+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.it.util.ResourceExtractor;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * This is a collection of test cases for <a href="https://issues.apache.org/jira/browse/MNG-6118">MNG-6118</a>,
+ * invoking Maven in a submodule of a multi-module project.
+ *
+ * The test uses a multi-module project with two modules:
+ * <ul>
+ *     <li>app</li> (depends on lib)
+ *     <li>lib</li>
+ * </ul>
+ *
+ * @author Maarten Mulders
+ * @author Martin Kanters
+ */
+public class MavenITmng6118SubmoduleInvocation extends AbstractMavenIntegrationTestCase
+{
+    private static final String RESOURCE_PATH = "/mng-6118-submodule-invocation-full-reactor";
+    private final File testDir;
+    private final Map<String, String> envVars = new HashMap<>();
+
+    public MavenITmng6118SubmoduleInvocation() throws IOException
+    {
+        super( "[3.7.0,)" );
+        testDir = ResourceExtractor.simpleExtractResources( getClass(), RESOURCE_PATH );
+        // It seems MAVEN_BASEDIR isn't always properly set, so make sure to have the right value here
+        // as it is determined by the mvn script.
+        envVars.put( "MAVEN_BASEDIR", testDir.getAbsolutePath() );
+    }
+
+    /**
+     * Performs a <code>cd app && mvn compile</code> invocation. Verifies that inter-module dependencies are resolved.
+     */
+    public void testInSubModule() throws IOException, VerificationException
+    {
+        // Compile the whole project first.
+        Verifier verifier = newVerifier( testDir.getAbsolutePath() );
+        verifier.executeGoal( "compile", envVars );
+
+        final File submoduleDirectory = new File( testDir, "app" );
+        verifier = newVerifier( submoduleDirectory.getAbsolutePath() );
+        verifier.setAutoclean( false );
+        verifier.setLogFileName( "log-insubmodule.txt" );
+        verifier.executeGoal( "compile", envVars );
+    }
+
+    /**
+     * Performs a <code>mvn -f app/pom.xml compile</code> invocation. Verifies that inter-module dependencies are resolved.
+     */
+    public void testWithFile() throws IOException, VerificationException
+    {
+        // Compile the whole project first.
+        Verifier verifier = newVerifier( testDir.getAbsolutePath() );
+        verifier.executeGoal( "compile" );
+
+        verifier = newVerifier( testDir.getAbsolutePath() );
+        verifier.setAutoclean( false );
+        verifier.setLogFileName( "log-withfile.txt" );
+        verifier.addCliOption( "-f app/pom.xml" );
+        verifier.executeGoal( "compile", envVars );
+    }
+
+    /**
+     * Performs a <code>mvn -f app/pom.xml -am compile</code> invocation. Verifies that dependent modules are also built.
+     */
+    public void testWithFileAndAlsoMake() throws IOException, VerificationException
+    {
+        Verifier verifier = newVerifier( testDir.getAbsolutePath() );
+        verifier.addCliOption( "-am" );
+        verifier.addCliOption( "-f app/pom.xml" );
+        verifier.setLogFileName( "log-withfilealsomake.txt" );
+        verifier.executeGoal( "compile", envVars );
+        verifier.verifyTextInLog( "Building Maven Integration Test :: MNG-6118 :: Library 1.0" );
+    }
+
+    /**
+     * Performs a <code>cd app && mvn compile -am</code> invocation. Verifies that dependent modules are also built.
+     */
+    public void testInSubModuleWithAlsoMake() throws IOException, VerificationException
+    {
+        File submoduleDirectory = new File( testDir, "app" );
+        Verifier verifier = newVerifier( submoduleDirectory.getAbsolutePath() );
+        verifier.addCliOption( "-am" );
+        verifier.setLogFileName( "log-insubmodulealsomake.txt" );
+        verifier.executeGoal( "compile", envVars );
+        verifier.verifyTextInLog( "Building Maven Integration Test :: MNG-6118 :: Library 1.0" );
+    }
+}
diff --git a/core-it-suite/src/test/resources/mng-6118-submodule-invocation-full-reactor/.mvn/.gitkeep b/core-it-suite/src/test/resources/mng-6118-submodule-invocation-full-reactor/.mvn/.gitkeep
new file mode 100644
index 0000000..e69de29
diff --git a/core-it-suite/src/test/resources/mng-6118-submodule-invocation-full-reactor/app/pom.xml b/core-it-suite/src/test/resources/mng-6118-submodule-invocation-full-reactor/app/pom.xml
new file mode 100644
index 0000000..88a6635
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-6118-submodule-invocation-full-reactor/app/pom.xml
@@ -0,0 +1,45 @@
+<?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/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <artifactId>parent</artifactId>
+    <groupId>org.apache.its.mng6118</groupId>
+    <version>1.0</version>
+  </parent>
+
+  <artifactId>app</artifactId>
+  <name>Maven Integration Test :: MNG-6118 :: Application</name>
+
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.its.mng6118</groupId>
+      <artifactId>lib</artifactId>
+    </dependency>
+  </dependencies>
+</project>
diff --git a/core-it-suite/src/test/resources/mng-6118-submodule-invocation-full-reactor/app/src/main/java/org/apache/its/mng6118/App.java b/core-it-suite/src/test/resources/mng-6118-submodule-invocation-full-reactor/app/src/main/java/org/apache/its/mng6118/App.java
new file mode 100644
index 0000000..b23c6a9
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-6118-submodule-invocation-full-reactor/app/src/main/java/org/apache/its/mng6118/App.java
@@ -0,0 +1,29 @@
+package org.apache.its.mng6118;
+
+/*
+ * 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.
+ */
+
+public class App 
+{
+    public static void main( String[] args )
+    {
+        new Helper().generateObject();
+        System.out.println( "Hello World!" );
+    }
+}
diff --git a/core-it-suite/src/test/resources/mng-6118-submodule-invocation-full-reactor/app/src/test/java/org/apache/its/mng6118/AppTest.java b/core-it-suite/src/test/resources/mng-6118-submodule-invocation-full-reactor/app/src/test/java/org/apache/its/mng6118/AppTest.java
new file mode 100644
index 0000000..cea86af
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-6118-submodule-invocation-full-reactor/app/src/test/java/org/apache/its/mng6118/AppTest.java
@@ -0,0 +1,33 @@
+package org.apache.its.mng6118;
+
+/*
+ * 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 static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+public class AppTest
+{
+    @Test
+    public void shouldAnswerWithTrue()
+    {
+        assertTrue( true );
+    }
+}
diff --git a/core-it-suite/src/test/resources/mng-6118-submodule-invocation-full-reactor/lib/pom.xml b/core-it-suite/src/test/resources/mng-6118-submodule-invocation-full-reactor/lib/pom.xml
new file mode 100644
index 0000000..5f1a103
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-6118-submodule-invocation-full-reactor/lib/pom.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 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/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <artifactId>parent</artifactId>
+    <groupId>org.apache.its.mng6118</groupId>
+    <version>1.0</version>
+  </parent>
+
+  <artifactId>lib</artifactId>
+  <name>Maven Integration Test :: MNG-6118 :: Library</name>
+
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+    </dependency>
+  </dependencies>
+</project>
diff --git a/core-it-suite/src/test/resources/mng-6118-submodule-invocation-full-reactor/lib/src/main/java/org/apache/its/mng6118/Helper.java b/core-it-suite/src/test/resources/mng-6118-submodule-invocation-full-reactor/lib/src/main/java/org/apache/its/mng6118/Helper.java
new file mode 100644
index 0000000..bb8ad0c
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-6118-submodule-invocation-full-reactor/lib/src/main/java/org/apache/its/mng6118/Helper.java
@@ -0,0 +1,28 @@
+package org.apache.its.mng6118;
+
+/*
+ * 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.
+ */
+
+public class Helper
+{
+    public Object generateObject()
+    {
+        return new Object();
+    }
+}
diff --git a/core-it-suite/src/test/resources/mng-6118-submodule-invocation-full-reactor/lib/src/test/java/org/apache/its/mng6118/HelperTest.java b/core-it-suite/src/test/resources/mng-6118-submodule-invocation-full-reactor/lib/src/test/java/org/apache/its/mng6118/HelperTest.java
new file mode 100644
index 0000000..8ed8133
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-6118-submodule-invocation-full-reactor/lib/src/test/java/org/apache/its/mng6118/HelperTest.java
@@ -0,0 +1,37 @@
+package org.apache.its.mng6118;
+
+/*
+ * 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 static org.junit.Assert.assertThat;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+
+import org.junit.Test;
+
+public class HelperTest
+{
+    private final Helper helper = new Helper();
+
+    @Test
+    public void shouldAnswerWithTrue()
+    {
+        assertThat( helper.generateObject(), is( notNullValue() ) );
+    }
+}
diff --git a/core-it-suite/src/test/resources/mng-6118-submodule-invocation-full-reactor/pom.xml b/core-it-suite/src/test/resources/mng-6118-submodule-invocation-full-reactor/pom.xml
new file mode 100644
index 0000000..0e3f101
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-6118-submodule-invocation-full-reactor/pom.xml
@@ -0,0 +1,82 @@
+<?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/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.its.mng6118</groupId>
+  <artifactId>parent</artifactId>
+  <version>1.0</version>
+
+  <packaging>pom</packaging>
+
+  <name>Maven Integration Test :: MNG-6118</name>
+  <description>
+    Tests for invoking Maven in a submodule while having access to the full reactor.
+  </description>
+
+  <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>
+
+  <modules>
+    <module>lib</module>
+    <module>app</module>
+  </modules>
+
+  <build>
+    <pluginManagement>
+      <!-- maven-resources-plugin, maven-compiler-plugin -->
+      <plugins>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-resources-plugin</artifactId>
+          <version>2.7</version>
+        </plugin>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-compiler-plugin</artifactId>
+          <version>2.0.2</version>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+  </build>
+
+  <dependencyManagement>
+    <dependencies>
+      <dependency>
+        <groupId>org.apache.its.mng6118</groupId>
+        <artifactId>lib</artifactId>
+        <version>${project.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>junit</groupId>
+        <artifactId>junit</artifactId>
+        <version>4.12</version>
+        <scope>test</scope>
+      </dependency>
+    </dependencies>
+  </dependencyManagement>
+</project>
diff --git a/core-it-suite/src/test/resources/mng-6991-local-repo-from-settings/settings.xml b/core-it-suite/src/test/resources/mng-6991-local-repo-from-settings/settings.xml
new file mode 100644
index 0000000..434bae4
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-6991-local-repo-from-settings/settings.xml
@@ -0,0 +1,24 @@
+<?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.
+-->
+
+<settings>
+    <localRepository>./custom-local-repo</localRepository>
+</settings>
\ No newline at end of file