You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sj...@apache.org on 2022/05/14 21:10:05 UTC

[maven-invoker-plugin] branch MINVOKER-294 updated (5c2213f -> 0b67f1c)

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

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


 discard 5c2213f  [MINVOKER-294] Allow override mavenExecutable in invoker.properties
     new 0b67f1c  [MINVOKER-294] Allow override mavenExecutable in invoker.properties

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (5c2213f)
            \
             N -- N -- N   refs/heads/MINVOKER-294 (0b67f1c)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 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.


Summary of changes:
 .../src/it/project/postbuild.groovy                                    | 3 ---
 .../java/org/apache/maven/plugins/invoker/InvokerPropertiesTest.java   | 2 +-
 2 files changed, 1 insertion(+), 4 deletions(-)


[maven-invoker-plugin] 01/01: [MINVOKER-294] Allow override mavenExecutable in invoker.properties

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

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

commit 0b67f1c2ce44718c039fb1d451dae96834fb32d4
Author: Slawomir Jaranowski <s....@gmail.com>
AuthorDate: Sat May 14 22:48:34 2022 +0200

    [MINVOKER-294] Allow override mavenExecutable in invoker.properties
---
 .../pom.xml                                        | 57 ++++++++++++++++++++++
 .../src/it/project/invoker.properties              | 20 ++++++++
 .../src/it/project/mvn1                            | 21 ++++++++
 .../src/it/project/mvn1.cmd                        | 21 ++++++++
 .../src/it/project/mvn2                            | 21 ++++++++
 .../src/it/project/mvn2.cmd                        | 21 ++++++++
 .../src/it/project/pom.xml                         | 28 +++++++++++
 .../src/it/project/postbuild.groovy                | 24 +++++++++
 .../src/it/project/prebuild.groovy                 | 22 +++++++++
 .../maven/plugins/invoker/AbstractInvokerMojo.java | 23 +++++----
 .../maven/plugins/invoker/InvokerProperties.java   | 15 ++++++
 .../plugins/invoker/InvokerPropertiesTest.java     | 28 +++++++++--
 12 files changed, 286 insertions(+), 15 deletions(-)

diff --git a/src/it/MINVOKER-294-mavenExacutable-in-properties/pom.xml b/src/it/MINVOKER-294-mavenExacutable-in-properties/pom.xml
new file mode 100644
index 0000000..7bb91d8
--- /dev/null
+++ b/src/it/MINVOKER-294-mavenExacutable-in-properties/pom.xml
@@ -0,0 +1,57 @@
+<?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.its</groupId>
+  <artifactId>minvoker-294</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>pom</packaging>
+
+  <description>
+    Test to check for usage of mavenExecutable in invoker.properties.
+  </description>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-invoker-plugin</artifactId>
+        <version>@project.version@</version>
+        <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/MINVOKER-294-mavenExacutable-in-properties/src/it/project/invoker.properties b/src/it/MINVOKER-294-mavenExacutable-in-properties/src/it/project/invoker.properties
new file mode 100644
index 0000000..9cf046a
--- /dev/null
+++ b/src/it/MINVOKER-294-mavenExacutable-in-properties/src/it/project/invoker.properties
@@ -0,0 +1,20 @@
+# 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.mavenExecutable.1 = mvn1
+invoker.mavenExecutable.2 = mvn2
+invoker.mavenExecutable.3 = mvn
diff --git a/src/it/MINVOKER-294-mavenExacutable-in-properties/src/it/project/mvn1 b/src/it/MINVOKER-294-mavenExacutable-in-properties/src/it/project/mvn1
new file mode 100644
index 0000000..2a9ca7e
--- /dev/null
+++ b/src/it/MINVOKER-294-mavenExacutable-in-properties/src/it/project/mvn1
@@ -0,0 +1,21 @@
+#!/bin/sh
+# ----------------------------------------------------------------------------
+# 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.
+# ----------------------------------------------------------------------------
+
+echo "maven 1 execute"
diff --git a/src/it/MINVOKER-294-mavenExacutable-in-properties/src/it/project/mvn1.cmd b/src/it/MINVOKER-294-mavenExacutable-in-properties/src/it/project/mvn1.cmd
new file mode 100644
index 0000000..a2615a3
--- /dev/null
+++ b/src/it/MINVOKER-294-mavenExacutable-in-properties/src/it/project/mvn1.cmd
@@ -0,0 +1,21 @@
+@REM ----------------------------------------------------------------------------
+@REM Licensed to the Apache Software Foundation (ASF) under one
+@REM or more contributor license agreements.  See the NOTICE file
+@REM distributed with this work for additional information
+@REM regarding copyright ownership.  The ASF licenses this file
+@REM to you under the Apache License, Version 2.0 (the
+@REM "License"); you may not use this file except in compliance
+@REM with the License.  You may obtain a copy of the License at
+@REM
+@REM    http://www.apache.org/licenses/LICENSE-2.0
+@REM
+@REM Unless required by applicable law or agreed to in writing,
+@REM software distributed under the License is distributed on an
+@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+@REM KIND, either express or implied.  See the License for the
+@REM specific language governing permissions and limitations
+@REM under the License.
+@REM ----------------------------------------------------------------------------
+@ECHO off
+
+echo maven 1 execute
diff --git a/src/it/MINVOKER-294-mavenExacutable-in-properties/src/it/project/mvn2 b/src/it/MINVOKER-294-mavenExacutable-in-properties/src/it/project/mvn2
new file mode 100644
index 0000000..3fad820
--- /dev/null
+++ b/src/it/MINVOKER-294-mavenExacutable-in-properties/src/it/project/mvn2
@@ -0,0 +1,21 @@
+#!/bin/sh
+# ----------------------------------------------------------------------------
+# 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.
+# ----------------------------------------------------------------------------
+
+echo "maven 2 execute"
diff --git a/src/it/MINVOKER-294-mavenExacutable-in-properties/src/it/project/mvn2.cmd b/src/it/MINVOKER-294-mavenExacutable-in-properties/src/it/project/mvn2.cmd
new file mode 100644
index 0000000..7fb138c
--- /dev/null
+++ b/src/it/MINVOKER-294-mavenExacutable-in-properties/src/it/project/mvn2.cmd
@@ -0,0 +1,21 @@
+@REM ----------------------------------------------------------------------------
+@REM Licensed to the Apache Software Foundation (ASF) under one
+@REM or more contributor license agreements.  See the NOTICE file
+@REM distributed with this work for additional information
+@REM regarding copyright ownership.  The ASF licenses this file
+@REM to you under the Apache License, Version 2.0 (the
+@REM "License"); you may not use this file except in compliance
+@REM with the License.  You may obtain a copy of the License at
+@REM
+@REM    http://www.apache.org/licenses/LICENSE-2.0
+@REM
+@REM Unless required by applicable law or agreed to in writing,
+@REM software distributed under the License is distributed on an
+@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+@REM KIND, either express or implied.  See the License for the
+@REM specific language governing permissions and limitations
+@REM under the License.
+@REM ----------------------------------------------------------------------------
+@ECHO off
+
+echo maven 2 execute
diff --git a/src/it/MINVOKER-294-mavenExacutable-in-properties/src/it/project/pom.xml b/src/it/MINVOKER-294-mavenExacutable-in-properties/src/it/project/pom.xml
new file mode 100644
index 0000000..2ec8902
--- /dev/null
+++ b/src/it/MINVOKER-294-mavenExacutable-in-properties/src/it/project/pom.xml
@@ -0,0 +1,28 @@
+<?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.its</groupId>
+  <artifactId>minvoker-294</artifactId>
+  <version>0.1-SNAPSHOT</version>
+  <packaging>pom</packaging>
+</project>
diff --git a/src/it/MINVOKER-294-mavenExacutable-in-properties/src/it/project/postbuild.groovy b/src/it/MINVOKER-294-mavenExacutable-in-properties/src/it/project/postbuild.groovy
new file mode 100644
index 0000000..2cde89b
--- /dev/null
+++ b/src/it/MINVOKER-294-mavenExacutable-in-properties/src/it/project/postbuild.groovy
@@ -0,0 +1,24 @@
+/*
+ * 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 buildLog = new File( basedir, "build.log" ).text
+
+assert buildLog.contains( "maven 1 execute" )
+assert buildLog.contains( "maven 2 execute" )
+assert buildLog.contains( "[INFO] BUILD SUCCESS" )
diff --git a/src/it/MINVOKER-294-mavenExacutable-in-properties/src/it/project/prebuild.groovy b/src/it/MINVOKER-294-mavenExacutable-in-properties/src/it/project/prebuild.groovy
new file mode 100644
index 0000000..0ac20bb
--- /dev/null
+++ b/src/it/MINVOKER-294-mavenExacutable-in-properties/src/it/project/prebuild.groovy
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ */
+
+// workaround for executable flags, eg during build from source-release.zip
+new File( basedir, "mvn1" ).setExecutable( true )
+new File( basedir, "mvn2" ).setExecutable( 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 4ec0de1..74220aa 100644
--- a/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java
+++ b/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java
@@ -415,13 +415,13 @@ public abstract class AbstractInvokerMojo
     private File mavenHome;
 
     /**
-     * mavenExecutable can either be a file relative to <code>${maven.home}/bin/</code> or an absolute file.
+     * mavenExecutable can either be a file relative to <code>${maven.home}/bin/</code>, test project workspace
+     * or an absolute file.
      *
      * @since 1.8
-     * @see Invoker#setMavenExecutable(File)
      */
     @Parameter( property = "invoker.mavenExecutable" )
-    private String mavenExecutable;
+    private File mavenExecutable;
 
     /**
      * The <code>JAVA_HOME</code> environment variable to use for forked Maven invocations. Defaults to the current Java
@@ -501,6 +501,12 @@ public abstract class AbstractInvokerMojo
      * # can be indexed
      * invoker.project = sub-module
      *
+     * # The maven executable can either be a file relative to <code>${maven.home}/bin/</code>, test project workspace
+     * # or an absolute file.
+     * # Since plugin version 3.3.0
+     * # can be indexed
+     * invoker.mavenExecutable = mvnw
+     *
      * # The value for the environment variable MAVEN_OPTS
      * # can be indexed
      * invoker.mavenOpts = -Dfile.encoding=UTF-16 -Xms32m -Xmx256m
@@ -2007,14 +2013,6 @@ public abstract class AbstractInvokerMojo
                 throw new RunFailureException( BuildJob.Result.FAILURE_PRE_HOOK, e );
             }
 
-            // TODO - move to request
-            invoker.setMavenHome( mavenHome );
-
-            if ( mavenExecutable != null )
-            {
-                invoker.setMavenExecutable( new File( mavenExecutable ) );
-            }
-
             for ( int invocationIndex = 1;; invocationIndex++ )
             {
                 if ( invocationIndex > 1 && !invokerProperties.isInvocationDefined( invocationIndex ) )
@@ -2031,7 +2029,7 @@ public abstract class AbstractInvokerMojo
                 request.setShowErrors( showErrors );
                 request.setShowVersion( showVersion );
                 request.setJavaHome( actualJavaHome );
-
+                request.setMavenHome( mavenHome );
                 setupLoggerForBuildJob( logger, request );
 
                 request.setBaseDirectory( basedir );
@@ -2639,6 +2637,7 @@ public abstract class AbstractInvokerMojo
         invokerProperties.setDefaultDebug( debug );
         invokerProperties.setDefaultGoals( goals );
         invokerProperties.setDefaultProfiles( profiles );
+        invokerProperties.setDefaultMavenExecutable( mavenExecutable );
         invokerProperties.setDefaultMavenOpts( mavenOpts );
         invokerProperties.setDefaultTimeoutInSeconds( timeoutInSeconds );
         invokerProperties.setDefaultEnvironmentVariables( environmentVariables );
diff --git a/src/main/java/org/apache/maven/plugins/invoker/InvokerProperties.java b/src/main/java/org/apache/maven/plugins/invoker/InvokerProperties.java
index a057f8c..ecebdcd 100644
--- a/src/main/java/org/apache/maven/plugins/invoker/InvokerProperties.java
+++ b/src/main/java/org/apache/maven/plugins/invoker/InvokerProperties.java
@@ -54,6 +54,7 @@ class InvokerProperties
     private String defaultMavenOpts;
     private Integer defaultTimeoutInSeconds;
     private Map<String, String> defaultEnvironmentVariables;
+    private File defaultMavenExecutable;
 
     private enum InvocationProperty
     {
@@ -61,6 +62,7 @@ class InvokerProperties
         BUILD_RESULT( "invoker.buildResult" ),
         GOALS( "invoker.goals" ),
         PROFILES( "invoker.profiles" ),
+        MAVEN_EXECUTABLE( "invoker.mavenExecutable" ),
         MAVEN_OPTS( "invoker.mavenOpts" ),
         FAILURE_BEHAVIOR( "invoker.failureBehavior" ),
         NON_RECURSIVE( "invoker.nonRecursive" ),
@@ -147,6 +149,15 @@ class InvokerProperties
         this.defaultProfiles =  defaultProfiles;
     }
 
+    /**
+     * Default value for mavenExecutable
+     * @param defaultMavenExecutable a default value
+     */
+    public void setDefaultMavenExecutable( File defaultMavenExecutable )
+    {
+        this.defaultMavenExecutable = defaultMavenExecutable;
+    }
+
     /**
      * Default value for mavenOpts
      * @param defaultMavenOpts a default value
@@ -423,6 +434,10 @@ class InvokerProperties
             .filter( l -> !l.isEmpty() )
             .orElse( defaultProfiles ) );
 
+        setIfNotNull( request::setMavenExecutable, get( InvocationProperty.MAVEN_EXECUTABLE, index )
+            .map( File::new )
+            .orElse( defaultMavenExecutable ) );
+
         setIfNotNull( request::setMavenOpts, get( InvocationProperty.MAVEN_OPTS, index ).orElse( defaultMavenOpts ) );
 
         get( InvocationProperty.FAILURE_BEHAVIOR, index )
diff --git a/src/test/java/org/apache/maven/plugins/invoker/InvokerPropertiesTest.java b/src/test/java/org/apache/maven/plugins/invoker/InvokerPropertiesTest.java
index c380e20..1deeb11 100644
--- a/src/test/java/org/apache/maven/plugins/invoker/InvokerPropertiesTest.java
+++ b/src/test/java/org/apache/maven/plugins/invoker/InvokerPropertiesTest.java
@@ -223,11 +223,35 @@ public class InvokerPropertiesTest
         }
     }
 
+    @Test
+    public void testConfigureRequestMavenExecutable()
+    {
+        Properties props = new Properties();
+
+        InvokerProperties facade = new InvokerProperties( props );
+        File aDefExecutable = new File( "defExecutable" );
+        facade.setDefaultMavenExecutable( aDefExecutable );
+
+        props.setProperty( "invoker.mavenExecutable", "aPropExecutable" );
+        facade.configureInvocation( request, 0 );
+        verify( request ).setMavenExecutable( new File( "aPropExecutable" ) );
+        verifyNoMoreInteractions( request );
+        clearInvocations( request );
+
+        props.clear();
+
+        facade.configureInvocation( request, 0 );
+        verify( request ).setMavenExecutable( aDefExecutable );
+        verifyNoMoreInteractions( request );
+    }
+
     @Test
     public void testConfigureRequestMavenOpts()
     {
         Properties props = new Properties();
+
         InvokerProperties facade = new InvokerProperties( props );
+        facade.setDefaultMavenOpts( "-XxxDef" );
 
         props.setProperty( "invoker.mavenOpts", "-Xmx512m" );
         facade.configureInvocation( request, 0 );
@@ -237,11 +261,9 @@ public class InvokerPropertiesTest
 
         props.clear();
 
-        facade.setDefaultMavenOpts( "-Xxx" );
         facade.configureInvocation( request, 0 );
-        verify( request ).setMavenOpts( "-Xxx" );
+        verify( request ).setMavenOpts( "-XxxDef" );
         verifyNoMoreInteractions( request );
-
     }
 
     @Test