[MINVOKER-243] invoker:install doesn't copy transitive dependencies from reactor
authorrfscholte <rfscholte@apache.org>
Fri, 11 Jan 2019 13:02:18 +0000 (14:02 +0100)
committerrfscholte <rfscholte@apache.org>
Fri, 11 Jan 2019 13:02:18 +0000 (14:02 +0100)
src/it/MINVOKER-243_install-reactor/invoker.properties [new file with mode: 0644]
src/it/MINVOKER-243_install-reactor/module-a/pom.xml [new file with mode: 0644]
src/it/MINVOKER-243_install-reactor/module-b/pom.xml [new file with mode: 0644]
src/it/MINVOKER-243_install-reactor/plugin/pom.xml [new file with mode: 0644]
src/it/MINVOKER-243_install-reactor/pom.xml [new file with mode: 0644]
src/it/MINVOKER-243_install-reactor/verify.groovy [new file with mode: 0644]
src/main/java/org/apache/maven/plugins/invoker/InstallMojo.java

diff --git a/src/it/MINVOKER-243_install-reactor/invoker.properties b/src/it/MINVOKER-243_install-reactor/invoker.properties
new file mode 100644 (file)
index 0000000..e71f103
--- /dev/null
@@ -0,0 +1,18 @@
+# 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/src/it/MINVOKER-243_install-reactor/module-a/pom.xml b/src/it/MINVOKER-243_install-reactor/module-a/pom.xml
new file mode 100644 (file)
index 0000000..6fbab1e
--- /dev/null
@@ -0,0 +1,32 @@
+<?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 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+  xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.maven.plugins.invoker</groupId>
+    <artifactId>minvoker251-parent</artifactId>
+    <version>1.0-SNAPSHOT</version>
+  </parent>
+  <artifactId>minvoker251-a</artifactId>
+
+</project>
diff --git a/src/it/MINVOKER-243_install-reactor/module-b/pom.xml b/src/it/MINVOKER-243_install-reactor/module-b/pom.xml
new file mode 100644 (file)
index 0000000..5eb478b
--- /dev/null
@@ -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 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+  xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.maven.plugins.invoker</groupId>
+    <artifactId>minvoker251-parent</artifactId>
+    <version>1.0-SNAPSHOT</version>
+  </parent>
+  <artifactId>minvoker251-b</artifactId>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven.plugins.invoker</groupId>
+      <artifactId>minvoker251-a</artifactId>
+    </dependency>
+  </dependencies>
+
+</project>
diff --git a/src/it/MINVOKER-243_install-reactor/plugin/pom.xml b/src/it/MINVOKER-243_install-reactor/plugin/pom.xml
new file mode 100644 (file)
index 0000000..66a42f3
--- /dev/null
@@ -0,0 +1,59 @@
+<?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 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+  xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.maven.plugins.invoker</groupId>
+    <artifactId>minvoker251-parent</artifactId>
+    <version>1.0-SNAPSHOT</version>
+  </parent>
+  <artifactId>minvoker251-plugin</artifactId>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-invoker-plugin</artifactId>
+        <configuration>
+          <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
+          <localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
+        </configuration>
+        <executions>
+          <execution>
+            <id>itests</id>
+            <goals>
+              <goal>install</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven.plugins.invoker</groupId>
+      <artifactId>minvoker251-b</artifactId>
+    </dependency>
+  </dependencies>
+</project>
diff --git a/src/it/MINVOKER-243_install-reactor/pom.xml b/src/it/MINVOKER-243_install-reactor/pom.xml
new file mode 100644 (file)
index 0000000..21881e3
--- /dev/null
@@ -0,0 +1,80 @@
+<?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.plugins.invoker</groupId>
+  <artifactId>minvoker251-parent</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>pom</packaging>
+
+  <url>https://issues.apache.org/jira/browse/MINVOKER-243</url>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+  
+  <dependencyManagement>
+    <dependencies>
+      <dependency>
+        <groupId>org.apache.maven.plugins.invoker</groupId>
+        <artifactId>minvoker251-a</artifactId>
+        <version>${project.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.maven.plugins.invoker</groupId>
+        <artifactId>minvoker251-b</artifactId>
+        <version>${project.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.maven.plugins.invoker</groupId>
+        <artifactId>minvoker251-plugin</artifactId>
+        <version>${project.version}</version>
+      </dependency>
+    </dependencies>
+  </dependencyManagement>
+
+  <build>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-invoker-plugin</artifactId>
+          <version>@project.version@</version>
+          <configuration>
+            <properties>
+              <!-- e.g. ensure that Java7 picks up TLSv1.2 when connecting with Central -->
+              <https.protocols>${https.protocols}</https.protocols>
+            </properties>
+          </configuration>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+  </build>
+  
+  <modules>
+    <module>module-a</module>
+    <module>module-b</module>
+    <module>plugin</module>
+  </modules>
+</project>
diff --git a/src/it/MINVOKER-243_install-reactor/verify.groovy b/src/it/MINVOKER-243_install-reactor/verify.groovy
new file mode 100644 (file)
index 0000000..3f06315
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+
+def localRepo = new File(basedir,'plugin/target/local-repo')
+
+assert new File(localRepo, 'org/apache/maven/plugins/invoker/minvoker251-a/1.0-SNAPSHOT/minvoker251-a-1.0-SNAPSHOT.pom').exists()
+assert new File(localRepo, 'org/apache/maven/plugins/invoker/minvoker251-a/1.0-SNAPSHOT/minvoker251-a-1.0-SNAPSHOT.jar').exists()
+assert new File(localRepo, 'org/apache/maven/plugins/invoker/minvoker251-b/1.0-SNAPSHOT/minvoker251-b-1.0-SNAPSHOT.pom').exists()
+assert new File(localRepo, 'org/apache/maven/plugins/invoker/minvoker251-b/1.0-SNAPSHOT/minvoker251-b-1.0-SNAPSHOT.jar').exists()
+assert new File(localRepo, 'org/apache/maven/plugins/invoker/minvoker251-parent/1.0-SNAPSHOT/minvoker251-parent-1.0-SNAPSHOT.pom').exists()
+assert new File(localRepo, 'org/apache/maven/plugins/invoker/minvoker251-plugin/1.0-SNAPSHOT/minvoker251-plugin-1.0-SNAPSHOT.pom').exists()
+assert new File(localRepo, 'org/apache/maven/plugins/invoker/minvoker251-plugin/1.0-SNAPSHOT/minvoker251-plugin-1.0-SNAPSHOT.jar').exists()
+
index 79ace5a..e00fa6b 100644 (file)
@@ -413,11 +413,9 @@ public class InstallMojo
     private void installProjectDependencies( MavenProject mvnProject, Collection<MavenProject> reactorProjects )\r
         throws MojoExecutionException\r
     {\r
-        // keep track if we have passed mvnProject in reactorProjects\r
-        boolean foundCurrent = false;\r
-\r
         // ... into dependencies that were resolved from reactor projects ...\r
         Collection<String> dependencyProjects = new LinkedHashSet<String>();\r
+        collectAllProjectReferences( mvnProject, dependencyProjects );\r
 \r
         // index available reactor projects\r
         Map<String, MavenProject> projects = new HashMap<String, MavenProject>( reactorProjects.size() );\r
@@ -427,12 +425,6 @@ public class InstallMojo
                 reactorProject.getGroupId() + ':' + reactorProject.getArtifactId() + ':' + reactorProject.getVersion();\r
 \r
             projects.put( projectId, reactorProject );\r
-\r
-            // only add projects used by the current project\r
-            if ( isInProjectReferences( project.getProjectReferences().values(), reactorProject ) )\r
-            {\r
-                dependencyProjects.add( projectId );\r
-            }\r
         }\r
 \r
         // group transitive dependencies (even those that don't contribute to the class path like POMs) ...\r
@@ -476,6 +468,19 @@ public class InstallMojo
             throw new MojoExecutionException( "Failed to install project dependencies: " + mvnProject, e );\r
         }\r
     }\r
+    \r
+    protected void collectAllProjectReferences( MavenProject project, Collection<String> dependencyProjects )\r
+    {\r
+        for ( MavenProject reactorProject : project.getProjectReferences().values() )\r
+        {\r
+            String projectId =\r
+                reactorProject.getGroupId() + ':' + reactorProject.getArtifactId() + ':' + reactorProject.getVersion();\r
+            if ( dependencyProjects.add( projectId ) )\r
+            {\r
+                collectAllProjectReferences( reactorProject, dependencyProjects );\r
+            }\r
+        }\r
+    }\r
 \r
     protected boolean isInProjectReferences( Collection<MavenProject> references, MavenProject project )\r
     {\r