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/16 17:18:43 UTC

[maven-invoker-plugin] branch master updated: [MINVOKER-294] Allow override mavenExecutable in invoker.properties

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

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


The following commit(s) were added to refs/heads/master by this push:
     new fbe2481  [MINVOKER-294] Allow override mavenExecutable in invoker.properties
fbe2481 is described below

commit fbe24819a8b914d470da0c26ba6f3b741b2556d0
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