Skip to content

Commit fbe2481

Browse files
[MINVOKER-294] Allow override mavenExecutable in invoker.properties
1 parent e13fec8 commit fbe2481

File tree

12 files changed

+286
-15
lines changed

12 files changed

+286
-15
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
Licensed to the Apache Software Foundation (ASF) under one
5+
or more contributor license agreements. See the NOTICE file
6+
distributed with this work for additional information
7+
regarding copyright ownership. The ASF licenses this file
8+
to you under the Apache License, Version 2.0 (the
9+
"License"); you may not use this file except in compliance
10+
with the License. You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing,
15+
software distributed under the License is distributed on an
16+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
KIND, either express or implied. See the License for the
18+
specific language governing permissions and limitations
19+
under the License.
20+
-->
21+
22+
<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">
23+
<modelVersion>4.0.0</modelVersion>
24+
25+
<groupId>org.apache.maven.plugins.invoker.its</groupId>
26+
<artifactId>minvoker-294</artifactId>
27+
<version>1.0-SNAPSHOT</version>
28+
<packaging>pom</packaging>
29+
30+
<description>
31+
Test to check for usage of mavenExecutable in invoker.properties.
32+
</description>
33+
34+
<properties>
35+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
36+
</properties>
37+
38+
<build>
39+
<plugins>
40+
<plugin>
41+
<groupId>org.apache.maven.plugins</groupId>
42+
<artifactId>maven-invoker-plugin</artifactId>
43+
<version>@project.version@</version>
44+
<executions>
45+
<execution>
46+
<id>integration-test</id>
47+
<phase>initialize</phase>
48+
<goals>
49+
<goal>run</goal>
50+
</goals>
51+
</execution>
52+
</executions>
53+
</plugin>
54+
</plugins>
55+
</build>
56+
57+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
invoker.mavenExecutable.1 = mvn1
19+
invoker.mavenExecutable.2 = mvn2
20+
invoker.mavenExecutable.3 = mvn
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/sh
2+
# ----------------------------------------------------------------------------
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
# ----------------------------------------------------------------------------
20+
21+
echo "maven 1 execute"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@REM ----------------------------------------------------------------------------
2+
@REM Licensed to the Apache Software Foundation (ASF) under one
3+
@REM or more contributor license agreements. See the NOTICE file
4+
@REM distributed with this work for additional information
5+
@REM regarding copyright ownership. The ASF licenses this file
6+
@REM to you under the Apache License, Version 2.0 (the
7+
@REM "License"); you may not use this file except in compliance
8+
@REM with the License. You may obtain a copy of the License at
9+
@REM
10+
@REM http://www.apache.org/licenses/LICENSE-2.0
11+
@REM
12+
@REM Unless required by applicable law or agreed to in writing,
13+
@REM software distributed under the License is distributed on an
14+
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
@REM KIND, either express or implied. See the License for the
16+
@REM specific language governing permissions and limitations
17+
@REM under the License.
18+
@REM ----------------------------------------------------------------------------
19+
@ECHO off
20+
21+
echo maven 1 execute
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/sh
2+
# ----------------------------------------------------------------------------
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
# ----------------------------------------------------------------------------
20+
21+
echo "maven 2 execute"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@REM ----------------------------------------------------------------------------
2+
@REM Licensed to the Apache Software Foundation (ASF) under one
3+
@REM or more contributor license agreements. See the NOTICE file
4+
@REM distributed with this work for additional information
5+
@REM regarding copyright ownership. The ASF licenses this file
6+
@REM to you under the Apache License, Version 2.0 (the
7+
@REM "License"); you may not use this file except in compliance
8+
@REM with the License. You may obtain a copy of the License at
9+
@REM
10+
@REM http://www.apache.org/licenses/LICENSE-2.0
11+
@REM
12+
@REM Unless required by applicable law or agreed to in writing,
13+
@REM software distributed under the License is distributed on an
14+
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
@REM KIND, either express or implied. See the License for the
16+
@REM specific language governing permissions and limitations
17+
@REM under the License.
18+
@REM ----------------------------------------------------------------------------
19+
@ECHO off
20+
21+
echo maven 2 execute
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
Licensed to the Apache Software Foundation (ASF) under one
5+
or more contributor license agreements. See the NOTICE file
6+
distributed with this work for additional information
7+
regarding copyright ownership. The ASF licenses this file
8+
to you under the Apache License, Version 2.0 (the
9+
"License"); you may not use this file except in compliance
10+
with the License. You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing,
15+
software distributed under the License is distributed on an
16+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
KIND, either express or implied. See the License for the
18+
specific language governing permissions and limitations
19+
under the License.
20+
-->
21+
22+
<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">
23+
<modelVersion>4.0.0</modelVersion>
24+
<groupId>org.apache.maven.plugins.invoker.its</groupId>
25+
<artifactId>minvoker-294</artifactId>
26+
<version>0.1-SNAPSHOT</version>
27+
<packaging>pom</packaging>
28+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
def buildLog = new File( basedir, "build.log" ).text
21+
22+
assert buildLog.contains( "maven 1 execute" )
23+
assert buildLog.contains( "maven 2 execute" )
24+
assert buildLog.contains( "[INFO] BUILD SUCCESS" )
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
// workaround for executable flags, eg during build from source-release.zip
21+
new File( basedir, "mvn1" ).setExecutable( true )
22+
new File( basedir, "mvn2" ).setExecutable( true )

src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java

+11-12
Original file line numberDiff line numberDiff line change
@@ -415,13 +415,13 @@ public abstract class AbstractInvokerMojo
415415
private File mavenHome;
416416

417417
/**
418-
* mavenExecutable can either be a file relative to <code>${maven.home}/bin/</code> or an absolute file.
418+
* mavenExecutable can either be a file relative to <code>${maven.home}/bin/</code>, test project workspace
419+
* or an absolute file.
419420
*
420421
* @since 1.8
421-
* @see Invoker#setMavenExecutable(File)
422422
*/
423423
@Parameter( property = "invoker.mavenExecutable" )
424-
private String mavenExecutable;
424+
private File mavenExecutable;
425425

426426
/**
427427
* 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
501501
* # can be indexed
502502
* invoker.project = sub-module
503503
*
504+
* # The maven executable can either be a file relative to <code>${maven.home}/bin/</code>, test project workspace
505+
* # or an absolute file.
506+
* # Since plugin version 3.3.0
507+
* # can be indexed
508+
* invoker.mavenExecutable = mvnw
509+
*
504510
* # The value for the environment variable MAVEN_OPTS
505511
* # can be indexed
506512
* invoker.mavenOpts = -Dfile.encoding=UTF-16 -Xms32m -Xmx256m
@@ -2007,14 +2013,6 @@ private boolean runBuild( File basedir, File pomFile, File settingsFile, File ac
20072013
throw new RunFailureException( BuildJob.Result.FAILURE_PRE_HOOK, e );
20082014
}
20092015

2010-
// TODO - move to request
2011-
invoker.setMavenHome( mavenHome );
2012-
2013-
if ( mavenExecutable != null )
2014-
{
2015-
invoker.setMavenExecutable( new File( mavenExecutable ) );
2016-
}
2017-
20182016
for ( int invocationIndex = 1;; invocationIndex++ )
20192017
{
20202018
if ( invocationIndex > 1 && !invokerProperties.isInvocationDefined( invocationIndex ) )
@@ -2031,7 +2029,7 @@ private boolean runBuild( File basedir, File pomFile, File settingsFile, File ac
20312029
request.setShowErrors( showErrors );
20322030
request.setShowVersion( showVersion );
20332031
request.setJavaHome( actualJavaHome );
2034-
2032+
request.setMavenHome( mavenHome );
20352033
setupLoggerForBuildJob( logger, request );
20362034

20372035
request.setBaseDirectory( basedir );
@@ -2639,6 +2637,7 @@ private InvokerProperties getInvokerProperties( final File projectDirectory, Pro
26392637
invokerProperties.setDefaultDebug( debug );
26402638
invokerProperties.setDefaultGoals( goals );
26412639
invokerProperties.setDefaultProfiles( profiles );
2640+
invokerProperties.setDefaultMavenExecutable( mavenExecutable );
26422641
invokerProperties.setDefaultMavenOpts( mavenOpts );
26432642
invokerProperties.setDefaultTimeoutInSeconds( timeoutInSeconds );
26442643
invokerProperties.setDefaultEnvironmentVariables( environmentVariables );

src/main/java/org/apache/maven/plugins/invoker/InvokerProperties.java

+15
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,15 @@ class InvokerProperties
5454
private String defaultMavenOpts;
5555
private Integer defaultTimeoutInSeconds;
5656
private Map<String, String> defaultEnvironmentVariables;
57+
private File defaultMavenExecutable;
5758

5859
private enum InvocationProperty
5960
{
6061
PROJECT( "invoker.project" ),
6162
BUILD_RESULT( "invoker.buildResult" ),
6263
GOALS( "invoker.goals" ),
6364
PROFILES( "invoker.profiles" ),
65+
MAVEN_EXECUTABLE( "invoker.mavenExecutable" ),
6466
MAVEN_OPTS( "invoker.mavenOpts" ),
6567
FAILURE_BEHAVIOR( "invoker.failureBehavior" ),
6668
NON_RECURSIVE( "invoker.nonRecursive" ),
@@ -147,6 +149,15 @@ public void setDefaultProfiles( List<String> defaultProfiles )
147149
this.defaultProfiles = defaultProfiles;
148150
}
149151

152+
/**
153+
* Default value for mavenExecutable
154+
* @param defaultMavenExecutable a default value
155+
*/
156+
public void setDefaultMavenExecutable( File defaultMavenExecutable )
157+
{
158+
this.defaultMavenExecutable = defaultMavenExecutable;
159+
}
160+
150161
/**
151162
* Default value for mavenOpts
152163
* @param defaultMavenOpts a default value
@@ -423,6 +434,10 @@ public void configureInvocation( InvocationRequest request, int index )
423434
.filter( l -> !l.isEmpty() )
424435
.orElse( defaultProfiles ) );
425436

437+
setIfNotNull( request::setMavenExecutable, get( InvocationProperty.MAVEN_EXECUTABLE, index )
438+
.map( File::new )
439+
.orElse( defaultMavenExecutable ) );
440+
426441
setIfNotNull( request::setMavenOpts, get( InvocationProperty.MAVEN_OPTS, index ).orElse( defaultMavenOpts ) );
427442

428443
get( InvocationProperty.FAILURE_BEHAVIOR, index )

src/test/java/org/apache/maven/plugins/invoker/InvokerPropertiesTest.java

+25-3
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,35 @@ public void testConfigureRequestProject() throws Exception
223223
}
224224
}
225225

226+
@Test
227+
public void testConfigureRequestMavenExecutable()
228+
{
229+
Properties props = new Properties();
230+
231+
InvokerProperties facade = new InvokerProperties( props );
232+
File aDefExecutable = new File( "defExecutable" );
233+
facade.setDefaultMavenExecutable( aDefExecutable );
234+
235+
props.setProperty( "invoker.mavenExecutable", "aPropExecutable" );
236+
facade.configureInvocation( request, 0 );
237+
verify( request ).setMavenExecutable( new File( "aPropExecutable" ) );
238+
verifyNoMoreInteractions( request );
239+
clearInvocations( request );
240+
241+
props.clear();
242+
243+
facade.configureInvocation( request, 0 );
244+
verify( request ).setMavenExecutable( aDefExecutable );
245+
verifyNoMoreInteractions( request );
246+
}
247+
226248
@Test
227249
public void testConfigureRequestMavenOpts()
228250
{
229251
Properties props = new Properties();
252+
230253
InvokerProperties facade = new InvokerProperties( props );
254+
facade.setDefaultMavenOpts( "-XxxDef" );
231255

232256
props.setProperty( "invoker.mavenOpts", "-Xmx512m" );
233257
facade.configureInvocation( request, 0 );
@@ -237,11 +261,9 @@ public void testConfigureRequestMavenOpts()
237261

238262
props.clear();
239263

240-
facade.setDefaultMavenOpts( "-Xxx" );
241264
facade.configureInvocation( request, 0 );
242-
verify( request ).setMavenOpts( "-Xxx" );
265+
verify( request ).setMavenOpts( "-XxxDef" );
243266
verifyNoMoreInteractions( request );
244-
245267
}
246268

247269
@Test

0 commit comments

Comments
 (0)