You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ol...@apache.org on 2018/03/28 04:59:52 UTC

[maven-invoker-plugin] 01/01: [MINVOKER-191] only install direct references project

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

olamy pushed a commit to branch bugfix/MINVOKER-191
in repository https://gitbox.apache.org/repos/asf/maven-invoker-plugin.git

commit 372f25e09d257c0528f185e3a109137ebbaaf61a
Author: olivier lamy <ol...@apache.org>
AuthorDate: Wed Mar 28 14:59:36 2018 +1000

    [MINVOKER-191] only install direct references project
    
    Signed-off-by: olivier lamy <ol...@apache.org>
---
 src/it/MINVOKER-191/invoker.properties             | 18 +++++
 src/it/MINVOKER-191/module-a/pom.xml               | 40 +++++++++++
 .../java/org/apache/maven/plugins/foo/Hello.java   | 28 ++++++++
 .../org/apache/maven/plugins/foo/HelloTest.java    | 32 +++++++++
 src/it/MINVOKER-191/module-b/pom.xml               | 40 +++++++++++
 .../java/org/apache/maven/plugins/foo/Hello.java   | 28 ++++++++
 .../org/apache/maven/plugins/foo/HelloTest.java    | 32 +++++++++
 src/it/MINVOKER-191/plugin/pom.xml                 | 62 +++++++++++++++++
 src/it/MINVOKER-191/plugin/src/it/basic/pom.xml    | 47 +++++++++++++
 .../org/apache/maven/it/plugins/dummy/MyMojo.java  | 78 ++++++++++++++++++++++
 src/it/MINVOKER-191/pom.xml                        | 72 ++++++++++++++++++++
 .../apache/maven/plugins/invoker/InstallMojo.java  | 22 +++++-
 12 files changed, 496 insertions(+), 3 deletions(-)

diff --git a/src/it/MINVOKER-191/invoker.properties b/src/it/MINVOKER-191/invoker.properties
new file mode 100644
index 0000000..332fb68
--- /dev/null
+++ b/src/it/MINVOKER-191/invoker.properties
@@ -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 install -T3
diff --git a/src/it/MINVOKER-191/module-a/pom.xml b/src/it/MINVOKER-191/module-a/pom.xml
new file mode 100644
index 0000000..942b5b3
--- /dev/null
+++ b/src/it/MINVOKER-191/module-a/pom.xml
@@ -0,0 +1,40 @@
+<?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>MINVOKER-191-parent</artifactId>
+    <version>1.0-SNAPSHOT</version>
+  </parent>
+  <artifactId>MINVOKER-191-java-a</artifactId>
+
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.12</version>
+    </dependency>
+  </dependencies>
+
+</project>
diff --git a/src/it/MINVOKER-191/module-a/src/main/java/org/apache/maven/plugins/foo/Hello.java b/src/it/MINVOKER-191/module-a/src/main/java/org/apache/maven/plugins/foo/Hello.java
new file mode 100644
index 0000000..b235be8
--- /dev/null
+++ b/src/it/MINVOKER-191/module-a/src/main/java/org/apache/maven/plugins/foo/Hello.java
@@ -0,0 +1,28 @@
+package org.apache.maven.plugins.foo;
+
+/*
+ * 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 Hello {
+
+    public static String sayHello(String who) throws Exception {
+        return "Hello " + who;
+    }
+
+}
\ No newline at end of file
diff --git a/src/it/MINVOKER-191/module-a/src/test/java/org/apache/maven/plugins/foo/HelloTest.java b/src/it/MINVOKER-191/module-a/src/test/java/org/apache/maven/plugins/foo/HelloTest.java
new file mode 100644
index 0000000..ea1e4ff
--- /dev/null
+++ b/src/it/MINVOKER-191/module-a/src/test/java/org/apache/maven/plugins/foo/HelloTest.java
@@ -0,0 +1,32 @@
+package org.apache.maven.plugins.foo;
+
+/*
+ * 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.junit.Test;
+
+public class HelloTest {
+
+    @Test
+    public void say_hello_test() throws Exception {
+        Hello.sayHello("foo");
+        Thread.sleep(4000);
+    }
+
+}
\ No newline at end of file
diff --git a/src/it/MINVOKER-191/module-b/pom.xml b/src/it/MINVOKER-191/module-b/pom.xml
new file mode 100644
index 0000000..46cfd92
--- /dev/null
+++ b/src/it/MINVOKER-191/module-b/pom.xml
@@ -0,0 +1,40 @@
+<?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>MINVOKER-191-parent</artifactId>
+    <version>1.0-SNAPSHOT</version>
+  </parent>
+  <artifactId>MINVOKER-191-java-b</artifactId>
+
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.12</version>
+    </dependency>
+  </dependencies>
+
+</project>
diff --git a/src/it/MINVOKER-191/module-b/src/main/java/org/apache/maven/plugins/foo/Hello.java b/src/it/MINVOKER-191/module-b/src/main/java/org/apache/maven/plugins/foo/Hello.java
new file mode 100644
index 0000000..b235be8
--- /dev/null
+++ b/src/it/MINVOKER-191/module-b/src/main/java/org/apache/maven/plugins/foo/Hello.java
@@ -0,0 +1,28 @@
+package org.apache.maven.plugins.foo;
+
+/*
+ * 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 Hello {
+
+    public static String sayHello(String who) throws Exception {
+        return "Hello " + who;
+    }
+
+}
\ No newline at end of file
diff --git a/src/it/MINVOKER-191/module-b/src/test/java/org/apache/maven/plugins/foo/HelloTest.java b/src/it/MINVOKER-191/module-b/src/test/java/org/apache/maven/plugins/foo/HelloTest.java
new file mode 100644
index 0000000..f6c26db
--- /dev/null
+++ b/src/it/MINVOKER-191/module-b/src/test/java/org/apache/maven/plugins/foo/HelloTest.java
@@ -0,0 +1,32 @@
+package org.apache.maven.plugins.foo;
+
+/*
+ * 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.junit.Test;
+
+public class HelloTest {
+
+    @Test
+    public void say_hello_test() throws Exception {
+        Hello.sayHello("foo");
+        Thread.sleep(2000);
+    }
+
+}
\ No newline at end of file
diff --git a/src/it/MINVOKER-191/plugin/pom.xml b/src/it/MINVOKER-191/plugin/pom.xml
new file mode 100644
index 0000000..cf5b9fc
--- /dev/null
+++ b/src/it/MINVOKER-191/plugin/pom.xml
@@ -0,0 +1,62 @@
+<?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>MINVOKER-191-parent</artifactId>
+    <version>1.0-SNAPSHOT</version>
+  </parent>
+  <artifactId>MINVOKER-191-plugin</artifactId>
+  <packaging>maven-plugin</packaging>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-plugin-api</artifactId>
+      <version>2.0</version>
+    </dependency>
+  </dependencies>
+
+  <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>
+              <goal>run</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git a/src/it/MINVOKER-191/plugin/src/it/basic/pom.xml b/src/it/MINVOKER-191/plugin/src/it/basic/pom.xml
new file mode 100644
index 0000000..6d3c05a
--- /dev/null
+++ b/src/it/MINVOKER-191/plugin/src/it/basic/pom.xml
@@ -0,0 +1,47 @@
+<?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>
+  <groupId>foo.it</groupId>
+  <artifactId>basic</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>pom</packaging>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins.invoker</groupId>
+        <artifactId>MINVOKER-191-plugin</artifactId>
+        <version>1.0-SNAPSHOT</version>
+        <executions>
+          <execution>
+            <id>touch</id>
+            <goals>
+              <goal>touch</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git a/src/it/MINVOKER-191/plugin/src/main/java/org/apache/maven/it/plugins/dummy/MyMojo.java b/src/it/MINVOKER-191/plugin/src/main/java/org/apache/maven/it/plugins/dummy/MyMojo.java
new file mode 100644
index 0000000..c225e4b
--- /dev/null
+++ b/src/it/MINVOKER-191/plugin/src/main/java/org/apache/maven/it/plugins/dummy/MyMojo.java
@@ -0,0 +1,78 @@
+package org.apache.maven.it.plugins.dummy;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed 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.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+
+/**
+ * @goal touch
+ * @phase process-sources
+ */
+public class MyMojo
+    extends AbstractMojo
+{
+    /**
+     * Location of the file.
+     * @parameter expression="${project.build.directory}"
+     * @required
+     */
+    private File outputDirectory;
+
+    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/src/it/MINVOKER-191/pom.xml b/src/it/MINVOKER-191/pom.xml
new file mode 100644
index 0000000..fc24aa5
--- /dev/null
+++ b/src/it/MINVOKER-191/pom.xml
@@ -0,0 +1,72 @@
+<?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>MINVOKER-191-parent</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>pom</packaging>
+
+  <description>
+    Test of reported issue MINVOKER-191: install plugins try to install all reactors projects
+    even non dependendant projects which cause build using multi thread builds
+  </description>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <modules>
+    <module>module-a</module>
+    <module>plugin</module>
+    <module>module-b</module>
+  </modules>
+
+  <build>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-compiler-plugin</artifactId>
+          <version>2.5.1</version>
+        </plugin>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-plugin-plugin</artifactId>
+          <version>2.9</version>
+        </plugin>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-resources-plugin</artifactId>
+          <version>2.6</version>
+        </plugin>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-invoker-plugin</artifactId>
+          <version>@pom.version@</version>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+  </build>
+</project>
diff --git a/src/main/java/org/apache/maven/plugins/invoker/InstallMojo.java b/src/main/java/org/apache/maven/plugins/invoker/InstallMojo.java
index b0a0c21..c07c86a 100644
--- a/src/main/java/org/apache/maven/plugins/invoker/InstallMojo.java
+++ b/src/main/java/org/apache/maven/plugins/invoker/InstallMojo.java
@@ -28,6 +28,7 @@ import java.util.HashSet;
 import java.util.LinkedHashSet;
 import java.util.Map;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.repository.ArtifactRepository;
@@ -427,9 +428,8 @@ public class InstallMojo
 
             projects.put( projectId, reactorProject );
 
-            // only add projects of reactor build previous to this mvnProject
-            foundCurrent |= ( mvnProject.equals( reactorProject ) );
-            if ( !foundCurrent )
+            // only add projects used by the current project
+            if ( isInProjectReferences( project.getProjectReferences().values(), reactorProject ) )
             {
                 dependencyProjects.add( projectId );
             }
@@ -477,6 +477,22 @@ public class InstallMojo
         }
     }
 
+    protected boolean isInProjectReferences( Collection<MavenProject> references, MavenProject project )
+    {
+        if ( references == null || references.isEmpty() )
+        {
+            return false;
+        }
+        for ( MavenProject mavenProject : references )
+        {
+            if ( StringUtils.equals( mavenProject.getId(), project.getId() ) )
+            {
+                return true;
+            }
+        }
+        return false;
+    }
+
     private void copyArtifact( Artifact artifact )
         throws MojoExecutionException
     {

-- 
To stop receiving notification emails like this one, please contact
olamy@apache.org.