[MNG-7390] Allow selecting modules outside the cwd into the reactor using --projects
This closes #138
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 2c3e744..6c9bd8f 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
@@ -106,6 +106,7 @@
// Tests that don't run stable and need to be fixed
// -------------------------------------------------------------------------------------------------------------
// suite.addTestSuite( MavenIT0108SnapshotUpdateTest.class ); -- MNG-3137
+ suite.addTestSuite( MavenITmng7390SelectModuleOutsideCwdTest.class );
suite.addTestSuite( MavenITmng7244IgnorePomPrefixInExpressions.class );
suite.addTestSuite( MavenITmng7349RelocationWarningTest.class );
suite.addTestSuite( MavenITmng6326CoreExtensionsNotFoundTest.class );
diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng7390SelectModuleOutsideCwdTest.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng7390SelectModuleOutsideCwdTest.java
new file mode 100644
index 0000000..ffba5d9
--- /dev/null
+++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng7390SelectModuleOutsideCwdTest.java
@@ -0,0 +1,131 @@
+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;
+
+/**
+ * This test suite tests whether other modules in the same multi module project can be selected when invoking Maven from a submodule.
+ * Related JIRA issue: <a href="https://issues.apache.org/jira/browse/MNG-7390">MNG-7390</a>.
+ *
+ * @author Martin Kanters
+ */
+public class MavenITmng7390SelectModuleOutsideCwdTest extends AbstractMavenIntegrationTestCase
+{
+
+ private File moduleADir;
+
+ public MavenITmng7390SelectModuleOutsideCwdTest()
+ {
+ super( "[4.0.0-alpha-1,)" );
+ }
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ moduleADir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-7390-pl-outside-cwd/module-a" );
+
+ // Clean up target files from earlier runs (verifier.setAutoClean does not work, as we are reducing the reactor)
+ final Verifier verifier = newVerifier( moduleADir.getAbsolutePath() );
+ verifier.addCliOption( "-f" );
+ verifier.addCliOption( ".." );
+ verifier.executeGoal( "clean" );
+ }
+
+ public void testSelectModuleByCoordinate() throws Exception
+ {
+ final Verifier verifier = newVerifier( moduleADir.getAbsolutePath() );
+
+ verifier.addCliOption( "-pl" );
+ verifier.addCliOption( ":module-b" );
+ verifier.setLogFileName( "log-module-by-coordinate.txt" );
+ verifier.executeGoal( "validate" );
+ verifier.assertFileNotPresent( "target/touch.txt" );
+ verifier.assertFileNotPresent( "../target/touch.txt" );
+ verifier.assertFilePresent( "../module-b/target/touch.txt" );
+ }
+
+ public void testSelectMultipleModulesByCoordinate() throws Exception
+ {
+ final Verifier verifier = newVerifier( moduleADir.getAbsolutePath() );
+
+ verifier.addCliOption( "-pl" );
+ verifier.addCliOption( ":module-b,:module-a" );
+ verifier.setLogFileName( "log-modules-by-coordinate.txt" );
+ verifier.executeGoal( "validate" );
+ verifier.assertFilePresent( "target/touch.txt" );
+ verifier.assertFileNotPresent( "../target/touch.txt" );
+ verifier.assertFilePresent( "../module-b/target/touch.txt" );
+ }
+
+ public void testSelectModuleByRelativePath() throws Exception
+ {
+ final Verifier verifier = newVerifier( moduleADir.getAbsolutePath() );
+
+ verifier.addCliOption( "-pl" );
+ verifier.addCliOption( "../module-b" );
+ verifier.setLogFileName( "log-module-by-relative-path.txt" );
+ verifier.executeGoal( "validate" );
+ verifier.assertFileNotPresent( "target/touch.txt" );
+ verifier.assertFileNotPresent( "../target/touch.txt" );
+ verifier.assertFilePresent( "../module-b/target/touch.txt" );
+ }
+
+ public void testSelectModulesByRelativePath() throws Exception
+ {
+ final Verifier verifier = newVerifier( moduleADir.getAbsolutePath() );
+
+ verifier.addCliOption( "-pl" );
+ verifier.addCliOption( "../module-b,." );
+ verifier.setLogFileName( "log-modules-by-relative-path.txt" );
+ verifier.executeGoal( "validate" );
+ verifier.assertFilePresent( "target/touch.txt" );
+ verifier.assertFileNotPresent( "../target/touch.txt" );
+ verifier.assertFilePresent( "../module-b/target/touch.txt" );
+ }
+
+ /**
+ Maven determines whether the target module is in a multi module project based on the presence of a .mvn directory in root.
+ This test verifies that when that directory is missing, the module cannot be found.
+ */
+ public void testSelectModulesOutsideCwdDoesNotWorkWhenDotMvnIsNotPresent() throws Exception
+ {
+ final String noDotMvnPath = "/mng-7390-pl-outside-cwd-no-dotmvn/module-a";
+ final File noDotMvnDir = ResourceExtractor.simpleExtractResources( getClass(), noDotMvnPath );
+ final Verifier verifier = newVerifier( noDotMvnDir.getAbsolutePath() );
+
+ verifier.addCliOption( "-pl" );
+ verifier.addCliOption( "../module-b" );
+ verifier.setLogFileName( "log-modules-by-relative-path-no-dotmvn.txt" );
+ try
+ {
+ verifier.executeGoal( "validate" );
+ fail( "Expected goal to fail" );
+ }
+ catch ( VerificationException e )
+ {
+ verifier.assertFileNotPresent( "target/touch.txt" );
+ verifier.assertFileNotPresent( "../target/touch.txt" );
+ verifier.assertFileNotPresent( "../module-b/target/touch.txt" );
+ }
+ }
+}
diff --git a/core-it-suite/src/test/resources/mng-7390-pl-outside-cwd-no-dotmvn/module-a/pom.xml b/core-it-suite/src/test/resources/mng-7390-pl-outside-cwd-no-dotmvn/module-a/pom.xml
new file mode 100644
index 0000000..ae48d0a
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-7390-pl-outside-cwd-no-dotmvn/module-a/pom.xml
@@ -0,0 +1,34 @@
+<?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">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>module-a</artifactId>
+
+ <parent>
+ <groupId>org.apache.maven.its.mng7390</groupId>
+ <artifactId>parent</artifactId>
+ <version>1.0</version>
+ </parent>
+
+</project>
diff --git a/core-it-suite/src/test/resources/mng-7390-pl-outside-cwd-no-dotmvn/module-b/pom.xml b/core-it-suite/src/test/resources/mng-7390-pl-outside-cwd-no-dotmvn/module-b/pom.xml
new file mode 100644
index 0000000..f91ebc2
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-7390-pl-outside-cwd-no-dotmvn/module-b/pom.xml
@@ -0,0 +1,34 @@
+<?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">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>module-b</artifactId>
+
+ <parent>
+ <groupId>org.apache.maven.its.mng7390</groupId>
+ <artifactId>parent</artifactId>
+ <version>1.0</version>
+ </parent>
+
+</project>
diff --git a/core-it-suite/src/test/resources/mng-7390-pl-outside-cwd-no-dotmvn/pom.xml b/core-it-suite/src/test/resources/mng-7390-pl-outside-cwd-no-dotmvn/pom.xml
new file mode 100644
index 0000000..c8de709
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-7390-pl-outside-cwd-no-dotmvn/pom.xml
@@ -0,0 +1,70 @@
+<?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">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.its.mng7390</groupId>
+ <artifactId>parent</artifactId>
+ <version>1.0</version>
+
+ <packaging>pom</packaging>
+
+ <name>Maven Integration Test :: MNG-7390</name>
+ <description>
+ This test suite verifies that other modules in the same multi module project cannot be selected when invoking Maven
+ from a submodule, when the .mvn directory in the root is missing.
+ </description>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <maven.compiler.source>1.7</maven.compiler.source>
+ <maven.compiler.target>1.7</maven.compiler.target>
+ </properties>
+
+ <modules>
+ <module>module-a</module>
+ <module>module-b</module>
+ </modules>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.its.plugins</groupId>
+ <artifactId>maven-it-plugin-log-file</artifactId>
+ <version>2.1-SNAPSHOT</version>
+ <configuration>
+ <logFile>target/touch.txt</logFile>
+ </configuration>
+ <executions>
+ <execution>
+ <id>test</id>
+ <phase>validate</phase>
+ <goals>
+ <goal>reset</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/core-it-suite/src/test/resources/mng-7390-pl-outside-cwd/.mvn/.gitkeep b/core-it-suite/src/test/resources/mng-7390-pl-outside-cwd/.mvn/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-7390-pl-outside-cwd/.mvn/.gitkeep
diff --git a/core-it-suite/src/test/resources/mng-7390-pl-outside-cwd/module-a/pom.xml b/core-it-suite/src/test/resources/mng-7390-pl-outside-cwd/module-a/pom.xml
new file mode 100644
index 0000000..ae48d0a
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-7390-pl-outside-cwd/module-a/pom.xml
@@ -0,0 +1,34 @@
+<?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">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>module-a</artifactId>
+
+ <parent>
+ <groupId>org.apache.maven.its.mng7390</groupId>
+ <artifactId>parent</artifactId>
+ <version>1.0</version>
+ </parent>
+
+</project>
diff --git a/core-it-suite/src/test/resources/mng-7390-pl-outside-cwd/module-b/pom.xml b/core-it-suite/src/test/resources/mng-7390-pl-outside-cwd/module-b/pom.xml
new file mode 100644
index 0000000..f91ebc2
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-7390-pl-outside-cwd/module-b/pom.xml
@@ -0,0 +1,34 @@
+<?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">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>module-b</artifactId>
+
+ <parent>
+ <groupId>org.apache.maven.its.mng7390</groupId>
+ <artifactId>parent</artifactId>
+ <version>1.0</version>
+ </parent>
+
+</project>
diff --git a/core-it-suite/src/test/resources/mng-7390-pl-outside-cwd/pom.xml b/core-it-suite/src/test/resources/mng-7390-pl-outside-cwd/pom.xml
new file mode 100644
index 0000000..6c47209
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-7390-pl-outside-cwd/pom.xml
@@ -0,0 +1,70 @@
+<?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">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.its.mng7390</groupId>
+ <artifactId>parent</artifactId>
+ <version>1.0</version>
+
+ <packaging>pom</packaging>
+
+ <name>Maven Integration Test :: MNG-7390</name>
+ <description>
+ This test suite tests whether other modules in the same multi module project can be selected when invoking Maven
+ from a submodule.
+ </description>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <maven.compiler.source>1.7</maven.compiler.source>
+ <maven.compiler.target>1.7</maven.compiler.target>
+ </properties>
+
+ <modules>
+ <module>module-a</module>
+ <module>module-b</module>
+ </modules>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.its.plugins</groupId>
+ <artifactId>maven-it-plugin-log-file</artifactId>
+ <version>2.1-SNAPSHOT</version>
+ <configuration>
+ <logFile>target/touch.txt</logFile>
+ </configuration>
+ <executions>
+ <execution>
+ <id>test</id>
+ <phase>validate</phase>
+ <goals>
+ <goal>reset</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>