You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2020/08/16 21:06:37 UTC

[maven-invoker-plugin] branch MINVOKER-268 created (now eed9d70)

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

slachiewicz pushed a change to branch MINVOKER-268
in repository https://gitbox.apache.org/repos/asf/maven-invoker-plugin.git.


      at eed9d70  [MINVOKER-268] - Introduce updateOnly parameter to AbstractInvokerMojo

This branch includes the following new commits:

     new d96fed6  [MINVOKER-268] - Refactor to avoid duplicate calls to cloneProjects()
     new eed9d70  [MINVOKER-268] - Introduce updateOnly parameter to AbstractInvokerMojo

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[maven-invoker-plugin] 01/02: [MINVOKER-268] - Refactor to avoid duplicate calls to cloneProjects()

Posted by sl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit d96fed63258eaf9fe7cf0eb9983d0708f02ddf55
Author: Rob Oxspring <ro...@imapmail.org>
AuthorDate: Wed Aug 12 21:04:55 2020 +0100

    [MINVOKER-268] - Refactor to avoid duplicate calls to cloneProjects()
---
 .../org/apache/maven/plugins/invoker/AbstractInvokerMojo.java    | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java b/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java
index deec2cc..1761639 100644
--- a/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java
+++ b/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java
@@ -754,14 +754,13 @@ public abstract class AbstractInvokerMojo
 
         File projectsDir = projectsDirectory;
 
-        if ( cloneProjectsTo != null )
+        if ( cloneProjectsTo == null && "maven-plugin".equals( project.getPackaging() ) )
         {
-            cloneProjects( collectedProjects );
-            projectsDir = cloneProjectsTo;
+            cloneProjectsTo = new File( project.getBuild().getDirectory(), "its" );
         }
-        else if ( cloneProjectsTo == null && "maven-plugin".equals( project.getPackaging() ) )
+
+        if ( cloneProjectsTo != null )
         {
-            cloneProjectsTo = new File( project.getBuild().getDirectory(), "its" );
             cloneProjects( collectedProjects );
             projectsDir = cloneProjectsTo;
         }


[maven-invoker-plugin] 02/02: [MINVOKER-268] - Introduce updateOnly parameter to AbstractInvokerMojo

Posted by sl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit eed9d704ff06925508cde59895e6e7b48ec248fa
Author: Rob Oxspring <ro...@imapmail.org>
AuthorDate: Tue Aug 11 00:55:15 2020 +0100

    [MINVOKER-268] - Introduce updateOnly parameter to AbstractInvokerMojo
---
 src/it/updateOnly/pom.xml                          | 90 ++++++++++++++++++++++
 src/it/updateOnly/src/it/project/pom.xml           | 30 ++++++++
 src/it/updateOnly/verify.bsh                       | 34 ++++++++
 .../maven/plugins/invoker/AbstractInvokerMojo.java | 50 ++++++++++++
 4 files changed, 204 insertions(+)

diff --git a/src/it/updateOnly/pom.xml b/src/it/updateOnly/pom.xml
new file mode 100644
index 0000000..e388df9
--- /dev/null
+++ b/src/it/updateOnly/pom.xml
@@ -0,0 +1,90 @@
+<?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.maven.plugins.invoker</groupId>
+  <artifactId>updateOnly</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>pom</packaging>
+
+  <description>
+    Test to check that invocations can use a different POM than the one that was selected via the pomInclude
+    parameter. This allows fine-grained control over the build of a multi-module project where the modules are
+    (intentionally) not collectively build by the reactor.
+  </description>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-antrun-plugin</artifactId>
+        <version>3.0.0</version>
+        <executions>
+          <execution>
+            <phase>initialize</phase>
+            <goals>
+              <goal>run</goal>
+            </goals>
+            <configuration>
+              <target>
+                <!-- simulate recently modified file in target directory -->
+                <touch file="${project.build.directory}/it/project/target/marker.txt" mkdirs="true" />
+              </target>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-invoker-plugin</artifactId>
+        <version>@project.version@</version>
+        <configuration>
+          <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
+          <pomIncludes>
+            <pomInclude>project/pom.xml</pomInclude>
+          </pomIncludes>
+          <postBuildHookScript>verify</postBuildHookScript>
+          <goals>
+            <goal>package</goal>
+          </goals>
+          <!-- turn on the feature-under-test -->
+          <updateOnly>true</updateOnly>
+        </configuration>
+        <executions>
+          <execution>
+            <id>integration-test</id>
+            <phase>initialize</phase>
+            <goals>
+              <goal>run</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
diff --git a/src/it/updateOnly/src/it/project/pom.xml b/src/it/updateOnly/src/it/project/pom.xml
new file mode 100644
index 0000000..3d88840
--- /dev/null
+++ b/src/it/updateOnly/src/it/project/pom.xml
@@ -0,0 +1,30 @@
+<?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>
+  <packaging>jar</packaging>
+
+  <groupId>test</groupId>
+  <artifactId>project</artifactId>
+  <version>0.1-SNAPSHOT</version>
+
+</project>
diff --git a/src/it/updateOnly/verify.bsh b/src/it/updateOnly/verify.bsh
new file mode 100644
index 0000000..18922e7
--- /dev/null
+++ b/src/it/updateOnly/verify.bsh
@@ -0,0 +1,34 @@
+/*
+ * 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 java.io.*;
+
+File marker = new File( basedir, "target/it/project/target/marker.txt" );
+if ( !marker.exists() )
+{
+  throw new IOException( "Marker file should have been created in setup: " + marker );
+}
+
+File archive = new File( basedir, "target/it/project/target/project-0.1-SNAPSHOT.jar" );
+if ( archive.exists() )
+{
+  throw new IOException( "Target file creation should have been skipped: " + archive );
+}
+
+return true;
diff --git a/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java b/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java
index 1761639..f6e3586 100644
--- a/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java
+++ b/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java
@@ -659,6 +659,15 @@ public abstract class AbstractInvokerMojo
     private String junitPackageName = "maven.invoker.it";
 
     /**
+     * Only invoke maven projects if their sources have been modified since
+     * they were last built. Only works in conjunction with <code>cloneProjectsTo</code>.
+
+     * @since 3.2.2
+     */
+    @Parameter( defaultValue = "false", property = "invoker.updateOnly" )
+    private boolean updateOnly = false;
+
+    /**
      * The scripter runner that is responsible to execute hook scripts.
      */
     private ScriptRunner scriptRunner;
@@ -759,6 +768,24 @@ public abstract class AbstractInvokerMojo
             cloneProjectsTo = new File( project.getBuild().getDirectory(), "its" );
         }
 
+        if ( updateOnly )
+        {
+            if ( cloneProjectsTo == null )
+            {
+                getLog().warn( "updateOnly functionality is not supported without cloning the projects" );
+            }
+            else if ( lastModifiedRecursive( projectsDirectory ) <= lastModifiedRecursive( cloneProjectsTo ) )
+            {
+                getLog().debug( "Skipping invocation as cloned projects are up-to-date"
+                        + "and updateOnly parameter is set to true." );
+                return;
+            }
+            else
+            {
+                getLog().debug( "Cloned projects are out of date" );
+            }
+        }
+
         if ( cloneProjectsTo != null )
         {
             cloneProjects( collectedProjects );
@@ -806,6 +833,29 @@ public abstract class AbstractInvokerMojo
     }
 
     /**
+     * Find the latest lastModified recursively within a directory structure.
+     *
+     * @param file the root file to check.
+     * @return the latest lastModified time found.
+     */
+    private long lastModifiedRecursive( File file )
+    {
+        long lastModified = file.lastModified();
+
+        final File[] entries = file.listFiles();
+
+        if ( entries != null )
+        {
+            for ( File entry : entries )
+            {
+                lastModified = Math.max( lastModified, lastModifiedRecursive( entry ) );
+            }
+        }
+
+        return lastModified;
+    }
+
+    /**
      * This will create the necessary folders for the reports.
      * 
      * @throws MojoExecutionException in case of failure during creation of the reports folder.