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/06/07 09:46:55 UTC
[maven-invoker-plugin] branch MINVOKER-255 updated (2dbe51b ->
de9db33)
This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a change to branch MINVOKER-255
in repository https://gitbox.apache.org/repos/asf/maven-invoker-plugin.git.
discard 2dbe51b remove duplicate IT test
discard 279b283 [MINVOKER-255] support environmentVariable in invokerPropertiesFile
discard 3115d33 Fix checkstyle errors
discard 41d593c improve InvokerPropertiesTest
add e66e36a Test also with 15-ea
add 560123c [MINVOKER-254] Remove redundant profile - Java 7 is prerequisite now
add d63c7f0 Upgrade maven-reporting-impl from 2.4 to 3.0.0
add 326030d improve InvokerPropertiesTest
add 1bfaf26 Upgrade plugins
new de9db33 [MINVOKER-255] support environmentVariable in invokerPropertiesFile
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 (2dbe51b)
\
N -- N -- N refs/heads/MINVOKER-255 (de9db33)
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:
.github/workflows/maven.yml | 2 +-
pom.xml | 63 ++++------------------
src/it/invocation-environmentvariable/pom.xml | 1 +
.../src/it/minvoker-145}/verify.groovy | 44 ++++++++-------
.../src/it/minvoker-255}/verify.groovy | 44 ++++++++-------
.../invocation-environmentvariable/verify.groovy | 5 +-
.../plugins/invoker/InvokerPropertiesTest.java | 2 +
7 files changed, 65 insertions(+), 96 deletions(-)
copy src/it/{MINVOKER-196_junit_report_file/src/it/project_2 => invocation-environmentvariable/src/it/minvoker-145}/verify.groovy (77%)
copy src/it/{MINVOKER-196_junit_report_file/src/it/project_2 => invocation-environmentvariable/src/it/minvoker-255}/verify.groovy (77%)
copy Jenkinsfile => src/it/invocation-environmentvariable/verify.groovy (88%)
[maven-invoker-plugin] 01/01: [MINVOKER-255] support
environmentVariable in invokerPropertiesFile
Posted by sl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch MINVOKER-255
in repository https://gitbox.apache.org/repos/asf/maven-invoker-plugin.git
commit de9db335d7a9398af98dbcb2c9d8a2eab3b0d700
Author: Slawomir Jaranowski <s....@gmail.com>
AuthorDate: Mon Feb 17 18:38:20 2020 +0100
[MINVOKER-255] support environmentVariable in invokerPropertiesFile
---
pom.xml | 2 +-
src/it/invocation-environmentvariable/pom.xml | 2 +
.../src/it/minvoker-145/pom.xml | 1 +
.../src/it/minvoker-145/verify.groovy | 24 ++++
.../src/it/minvoker-255}/invoker.properties | 43 +++----
.../src/it/minvoker-255}/pom.xml | 123 ++++++++++-----------
.../src/it/minvoker-255/verify.groovy | 24 ++++
.../invocation-environmentvariable/verify.groovy | 21 ++++
src/it/multiEnvVar/pom.xml | 70 ------------
.../maven/plugins/invoker/AbstractInvokerMojo.java | 6 +
.../maven/plugins/invoker/InvokerProperties.java | 92 +++++++++++----
.../plugins/invoker/InvokerPropertiesTest.java | 40 +++++++
12 files changed, 272 insertions(+), 176 deletions(-)
diff --git a/pom.xml b/pom.xml
index c628664..60c4308 100644
--- a/pom.xml
+++ b/pom.xml
@@ -187,7 +187,7 @@ under the License.
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
- <version>2.5</version>
+ <version>2.6</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
diff --git a/src/it/invocation-environmentvariable/pom.xml b/src/it/invocation-environmentvariable/pom.xml
index f6646b7..fae28cf 100644
--- a/src/it/invocation-environmentvariable/pom.xml
+++ b/src/it/invocation-environmentvariable/pom.xml
@@ -41,11 +41,13 @@ under the License.
<version>@project.version@</version>
<configuration>
<debug>true</debug>
+ <postBuildHookScript>verify</postBuildHookScript>
<goals>
<goal>validate</goal>
</goals>
<environmentVariables>
<MINVOKER145>foobar</MINVOKER145>
+ <MINVOKER255_POM>minvoker255_pom</MINVOKER255_POM>
</environmentVariables>
</configuration>
<executions>
diff --git a/src/it/invocation-environmentvariable/src/it/minvoker-145/pom.xml b/src/it/invocation-environmentvariable/src/it/minvoker-145/pom.xml
index f3c3b04..340b0cb 100644
--- a/src/it/invocation-environmentvariable/src/it/minvoker-145/pom.xml
+++ b/src/it/invocation-environmentvariable/src/it/minvoker-145/pom.xml
@@ -25,6 +25,7 @@
<profiles>
<profile>
+ <id>envTest</id>
<activation>
<property>
<name>env.MINVOKER145</name>
diff --git a/src/it/invocation-environmentvariable/src/it/minvoker-145/verify.groovy b/src/it/invocation-environmentvariable/src/it/minvoker-145/verify.groovy
new file mode 100644
index 0000000..7cea0c1
--- /dev/null
+++ b/src/it/invocation-environmentvariable/src/it/minvoker-145/verify.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' )
+
+// on this level we try find some substring,
+// if not found it will be logged and cause parent verify script to find required text
+assert buildLog.text.contains('] BUILD SUCCESS')
+
diff --git a/src/it/multiEnvVar/src/it/project/invoker.properties b/src/it/invocation-environmentvariable/src/it/minvoker-255/invoker.properties
similarity index 77%
rename from src/it/multiEnvVar/src/it/project/invoker.properties
rename to src/it/invocation-environmentvariable/src/it/minvoker-255/invoker.properties
index 970ae39..2be833f 100644
--- a/src/it/multiEnvVar/src/it/project/invoker.properties
+++ b/src/it/invocation-environmentvariable/src/it/minvoker-255/invoker.properties
@@ -1,19 +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.
-
-invoker.name=Multiple env props
-invoker.goals=process-sources
+# 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.name = Test Environment variable
+
+# override value from plugin config
+invoker.environmentVariables.MINVOKER145 = minvoker_145
+
+# add next value
+invoker.environmentVariables.MINVOKER255_PROPERTIES = minvoker255_properties
diff --git a/src/it/multiEnvVar/src/it/project/pom.xml b/src/it/invocation-environmentvariable/src/it/minvoker-255/pom.xml
similarity index 66%
rename from src/it/multiEnvVar/src/it/project/pom.xml
rename to src/it/invocation-environmentvariable/src/it/minvoker-255/pom.xml
index f2455e9..9ab12be 100644
--- a/src/it/multiEnvVar/src/it/project/pom.xml
+++ b/src/it/invocation-environmentvariable/src/it/minvoker-255/pom.xml
@@ -1,62 +1,61 @@
-<?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.invoker.its.it</groupId>
- <artifactId>multEnvVar</artifactId>
- <version>0.1-SNAPSHOT</version>
- <packaging>pom</packaging>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-enforcer-plugin</artifactId>
- <version>1.2</version>
- <executions>
- <execution>
- <id>enforce-env-properties</id>
- <phase>process-sources</phase>
- <goals>
- <goal>enforce</goal>
- </goals>
- <configuration>
- <rules>
- <requireProperty>
- <property>env.A_PROP</property>
- <message>### Missing property 'A_PROP'</message>
- </requireProperty>
- <requireProperty>
- <property>env.Z_PROP</property>
- <message>### Missing property 'Z_PROP'</message>
- </requireProperty>
- </rules>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
-
-</project>
+<?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-145</artifactId>
+ <version>0.1-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-enforcer-plugin</artifactId>
+ <version>3.0.0-M3</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>enforce</goal>
+ </goals>
+ <configuration>
+ <rules>
+ <evaluateBeanshell>
+ <condition><![CDATA[
+ "${env.MINVOKER145}" == "minvoker_145" &&
+ "${env.MINVOKER255_POM}" == "minvoker255_pom" &&
+ "${env.MINVOKER255_PROPERTIES}" == "minvoker255_properties"
+ ]]></condition>
+ </evaluateBeanshell>
+ </rules>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/src/it/invocation-environmentvariable/src/it/minvoker-255/verify.groovy b/src/it/invocation-environmentvariable/src/it/minvoker-255/verify.groovy
new file mode 100644
index 0000000..7cea0c1
--- /dev/null
+++ b/src/it/invocation-environmentvariable/src/it/minvoker-255/verify.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' )
+
+// on this level we try find some substring,
+// if not found it will be logged and cause parent verify script to find required text
+assert buildLog.text.contains('] BUILD SUCCESS')
+
diff --git a/src/it/invocation-environmentvariable/verify.groovy b/src/it/invocation-environmentvariable/verify.groovy
new file mode 100644
index 0000000..0ef60fd
--- /dev/null
+++ b/src/it/invocation-environmentvariable/verify.groovy
@@ -0,0 +1,21 @@
+/*
+ * 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' )
+assert buildLog.text.contains('[INFO] BUILD SUCCESS')
+
diff --git a/src/it/multiEnvVar/pom.xml b/src/it/multiEnvVar/pom.xml
deleted file mode 100644
index b34d142..0000000
--- a/src/it/multiEnvVar/pom.xml
+++ /dev/null
@@ -1,70 +0,0 @@
-<?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.its</groupId>
- <artifactId>maven-env-test</artifactId>
- <version>0.1-SNAPSHOT</version>
- <name>Maven Environment Test</name>
- <description>Maven Invoker tests for environment variable setting</description>
-
- <url>https://issues.apache.org/jira/browse/MINVOKER-155</url>
-
- <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>
- <configuration>
- <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
- <postBuildHookScript>verify</postBuildHookScript>
- <properties>
- <!-- e.g. ensure that Java7 picks up TLSv1.2 when connecting with Central -->
- <https.protocols>${https.protocols}</https.protocols>
- </properties>
- </configuration>
- <executions>
- <execution>
- <phase>initialize</phase>
- <goals>
- <goal>install</goal>
- <goal>run</goal>
- </goals>
- <configuration>
- <environmentVariables>
- <A_PROP>white</A_PROP>
- <Z_PROP>blue</Z_PROP>
- </environmentVariables>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
-</project>
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 6a5c879..deec2cc 100644
--- a/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java
+++ b/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java
@@ -573,6 +573,12 @@ public abstract class AbstractInvokerMojo
* # Since plugin version 3.2.1
* invoker.ordinal = 3
* invoker.ordinal = 1
+ *
+ * # The additional value for the environment variable.
+ * # Since plugin version 3.2.2
+ * invoker.environmentVariables.<variableName> = variableValue
+ * invoker.environmentVariables.MY_ENV_NAME = myEnvValue
+ *
* </pre>
*
* @since 1.2
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 a3b8f3c..8dd7742 100644
--- a/src/main/java/org/apache/maven/plugins/invoker/InvokerProperties.java
+++ b/src/main/java/org/apache/maven/plugins/invoker/InvokerProperties.java
@@ -42,6 +42,9 @@ class InvokerProperties
{
private static final String SELECTOR_PREFIX = "selector.";
+ private static final Pattern ENVIRONMENT_VARIABLES_PATTERN =
+ Pattern.compile( "invoker\\.environmentVariables\\.([A-Za-z][^.]+)(\\.([0-9]+))?" );
+
private enum InvocationProperty
{
PROJECT( "invoker.project" ),
@@ -53,9 +56,9 @@ class InvokerProperties
OFFLINE( "invoker.offline" ),
SYSTEM_PROPERTIES_FILE( "invoker.systemPropertiesFile" ),
DEBUG( "invoker.debug" ),
- SETTINGS_FILE ( "invoker.settingsFile" ),
- TIMEOUT_IN_SECONDS ( "invoker.timeoutInSeconds" ),
- ORDINAL ( "invoker.ordinal" );
+ SETTINGS_FILE( "invoker.settingsFile" ),
+ TIMEOUT_IN_SECONDS( "invoker.timeoutInSeconds" ),
+ ORDINAL( "invoker.ordinal" );
private final String key;
@@ -70,20 +73,20 @@ class InvokerProperties
return key;
}
}
-
+
private enum SelectorProperty
{
JAVA_VERSION( ".java.version" ),
MAVEN_VERSION( ".maven.version" ),
OS_FAMLY( ".os.family" );
-
+
private final String suffix;
-
+
SelectorProperty( String suffix )
{
this.suffix = suffix;
}
-
+
@Override
public String toString()
{
@@ -139,6 +142,7 @@ class InvokerProperties
/**
* Get the corresponding ordinal value
+ *
* @return The ordinal value
*/
public int getOrdinal()
@@ -163,8 +167,8 @@ class InvokerProperties
*/
public String getJreVersion( int index )
{
- return this.properties.getProperty( SELECTOR_PREFIX + index + SelectorProperty.JAVA_VERSION.suffix,
- getJreVersion() );
+ return this.properties.getProperty( SELECTOR_PREFIX + index + SelectorProperty.JAVA_VERSION,
+ getJreVersion() );
}
/**
@@ -177,17 +181,16 @@ class InvokerProperties
{
return this.properties.getProperty( "invoker.maven.version", "" );
}
-
+
/**
- *
* @param index the selector index
* @return The specification of Maven versions on which this build job should be run.
* @since 3.0.0
*/
public String getMavenVersion( int index )
{
- return this.properties.getProperty( SELECTOR_PREFIX + index + SelectorProperty.MAVEN_VERSION.suffix,
- getMavenVersion() );
+ return this.properties.getProperty( SELECTOR_PREFIX + index + SelectorProperty.MAVEN_VERSION,
+ getMavenVersion() );
}
/**
@@ -199,7 +202,7 @@ class InvokerProperties
{
return this.properties.getProperty( "invoker.os.family", "" );
}
-
+
/**
* Gets the specification of OS families on which this build job should be run.
*
@@ -209,18 +212,17 @@ class InvokerProperties
*/
public String getOsFamily( int index )
{
- return this.properties.getProperty( SELECTOR_PREFIX + index + SelectorProperty.OS_FAMLY.suffix,
- getOsFamily() );
+ return this.properties.getProperty( SELECTOR_PREFIX + index + SelectorProperty.OS_FAMLY, getOsFamily() );
}
-
+
public Collection<InvokerToolchain> getToolchains()
{
- return getToolchains( Pattern.compile( "invoker\\.toolchain\\.([^\\.]+)\\.(.+)" ) );
+ return getToolchains( Pattern.compile( "invoker\\.toolchain\\.([^.]+)\\.(.+)" ) );
}
public Collection<InvokerToolchain> getToolchains( int index )
{
- return getToolchains( Pattern.compile( "selector\\." + index + "\\.invoker\\.toolchain\\.([^\\.]+)\\.(.+)" ) );
+ return getToolchains( Pattern.compile( "selector\\." + index + "\\.invoker\\.toolchain\\.([^.]+)\\.(.+)" ) );
}
private Collection<InvokerToolchain> getToolchains( Pattern p )
@@ -248,6 +250,43 @@ class InvokerProperties
}
/**
+ * Extract environment variable from properties for given index.
+ * Every environment variable without index is also returned.
+ *
+ * @param index index to lookup
+ * @return map of environment name and value
+ */
+
+ private Map<String, String> getEnvironmentVariables( int index )
+ {
+
+ Map<String, String> envItems = new HashMap<>();
+
+ for ( Map.Entry<Object, Object> entry : properties.entrySet() )
+ {
+ Matcher matcher = ENVIRONMENT_VARIABLES_PATTERN.matcher( entry.getKey().toString() );
+ if ( matcher.matches() )
+ {
+
+ if ( String.valueOf( index ).equals( matcher.group( 3 ) ) )
+ {
+ // variables with index has higher priority, so override
+ envItems.put( matcher.group( 1 ), entry.getValue().toString() );
+ }
+ else if ( matcher.group( 3 ) == null )
+ {
+ // variables without index has lower priority, so check if exist
+ if ( !envItems.containsKey( matcher.group( 1 ) ) )
+ {
+ envItems.put( matcher.group( 1 ), entry.getValue().toString() );
+ }
+ }
+ }
+ }
+ return envItems;
+ }
+
+ /**
* Determines whether these invoker properties contain a build definition for the specified invocation index.
*
* @param index The one-based index of the invocation to check for, must not be negative.
@@ -264,10 +303,10 @@ class InvokerProperties
}
return false;
}
-
+
/**
* Determines whether these invoker properties contain a build definition for the specified selector index.
- *
+ *
* @param index the index
* @return <code>true</code> if the selector with the specified index is defined, <code>false</code> otherwise.
* @since 3.0.0
@@ -341,19 +380,24 @@ class InvokerProperties
String nonRecursive = get( InvocationProperty.NON_RECURSIVE, index );
if ( nonRecursive != null )
{
- request.setRecursive( !Boolean.valueOf( nonRecursive ) );
+ request.setRecursive( !Boolean.parseBoolean( nonRecursive ) );
}
String offline = get( InvocationProperty.OFFLINE, index );
if ( offline != null )
{
- request.setOffline( Boolean.valueOf( offline ) );
+ request.setOffline( Boolean.parseBoolean( offline ) );
}
String debug = get( InvocationProperty.DEBUG, index );
if ( debug != null )
{
- request.setDebug( Boolean.valueOf( debug ) );
+ request.setDebug( Boolean.parseBoolean( debug ) );
+ }
+
+ for ( Map.Entry<String, String> envItem : getEnvironmentVariables( index ).entrySet() )
+ {
+ request.addShellEnvironment( envItem.getKey(), envItem.getValue() );
}
}
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 784a7f4..f4aebb0 100644
--- a/src/test/java/org/apache/maven/plugins/invoker/InvokerPropertiesTest.java
+++ b/src/test/java/org/apache/maven/plugins/invoker/InvokerPropertiesTest.java
@@ -309,6 +309,44 @@ public class InvokerPropertiesTest
}
@Test
+ public void testConfigureEnvironmentVariables() throws Exception
+ {
+ Properties props = new Properties();
+ InvokerProperties facade = new InvokerProperties( props );
+
+ props.setProperty( "invoker.abcdef", "abcdf" );
+ props.setProperty( "invoker.environmentVariables.KEY1.1", "value1.1" );
+ props.setProperty( "invoker.environmentVariables.KEY1", "value1" );
+ props.setProperty( "invoker.environmentVariables.KEY2", "value2" );
+ props.setProperty( "invoker.environmentVariables.KEY2.1", "value2.1" );
+ props.setProperty( "invoker.environmentVariables.KEY3", "value3" );
+ facade.configureInvocation( request, 0 );
+ verify( request ).addShellEnvironment( "KEY1", "value1" );
+ verify( request ).addShellEnvironment( "KEY2", "value2" );
+ verify( request ).addShellEnvironment( "KEY3", "value3" );
+ verifyNoMoreInteractions( request );
+ }
+
+ @Test
+ public void testConfigureEnvironmentVariablesWithIndex() throws Exception
+ {
+ Properties props = new Properties();
+ InvokerProperties facade = new InvokerProperties( props );
+
+ props.setProperty( "invoker.abcdef", "abcdf" );
+ props.setProperty( "invoker.environmentVariables.KEY1.1", "value1.1" );
+ props.setProperty( "invoker.environmentVariables.KEY1", "value1" );
+ props.setProperty( "invoker.environmentVariables.KEY2", "value2" );
+ props.setProperty( "invoker.environmentVariables.KEY2.1", "value2.1" );
+ props.setProperty( "invoker.environmentVariables.KEY3", "value3" );
+ facade.configureInvocation( request, 1 );
+ verify( request ).addShellEnvironment( "KEY1", "value1.1" );
+ verify( request ).addShellEnvironment( "KEY2", "value2.1" );
+ verify( request ).addShellEnvironment( "KEY3", "value3" );
+ verifyNoMoreInteractions( request );
+ }
+
+ @Test
public void testIsInvocationDefined() throws Exception
{
Properties props = new Properties();
@@ -373,6 +411,7 @@ public class InvokerPropertiesTest
@Test
public void testGetToolchains()
{
+
Properties props = new Properties();
props.put( "invoker.toolchain.jdk.version", "11" );
InvokerProperties facade = new InvokerProperties( props );
@@ -388,6 +427,7 @@ public class InvokerPropertiesTest
@Test
public void testGetToolchainsWithIndex()
{
+
Properties props = new Properties();
props.put( "selector.1.invoker.toolchain.jdk.version", "11" );
InvokerProperties facade = new InvokerProperties( props );