You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2012/11/13 18:43:26 UTC

svn commit: r1408853 - in /maven/plugins/trunk/maven-invoker-plugin/src: it/invocation-environmentvariable/ it/invocation-environmentvariable/src/ it/invocation-environmentvariable/src/it/ it/invocation-environmentvariable/src/it/minvoker-145/ main/jav...

Author: rfscholte
Date: Tue Nov 13 17:43:25 2012
New Revision: 1408853

URL: http://svn.apache.org/viewvc?rev=1408853&view=rev
Log:
[MINVOKER-145] Add option to set environment variables 

Added:
    maven/plugins/trunk/maven-invoker-plugin/src/it/invocation-environmentvariable/
    maven/plugins/trunk/maven-invoker-plugin/src/it/invocation-environmentvariable/pom.xml
    maven/plugins/trunk/maven-invoker-plugin/src/it/invocation-environmentvariable/src/
    maven/plugins/trunk/maven-invoker-plugin/src/it/invocation-environmentvariable/src/it/
    maven/plugins/trunk/maven-invoker-plugin/src/it/invocation-environmentvariable/src/it/minvoker-145/
    maven/plugins/trunk/maven-invoker-plugin/src/it/invocation-environmentvariable/src/it/minvoker-145/pom.xml
Modified:
    maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/AbstractInvokerMojo.java

Added: maven/plugins/trunk/maven-invoker-plugin/src/it/invocation-environmentvariable/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/invocation-environmentvariable/pom.xml?rev=1408853&view=auto
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/it/invocation-environmentvariable/pom.xml (added)
+++ maven/plugins/trunk/maven-invoker-plugin/src/it/invocation-environmentvariable/pom.xml Tue Nov 13 17:43:25 2012
@@ -0,0 +1,64 @@
+<?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>invocation-environmentvariable</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>pom</packaging>
+
+  <description>Test if the environmentvariable is applied</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>
+        <configuration>
+          <debug>true</debug>
+          <goals>
+            <goal>validate</goal>
+          </goals>
+          <environmentVariables>
+            <MINVOKER145>foobar</MINVOKER145>
+          </environmentVariables>
+        </configuration>
+        <executions>
+          <execution>
+            <id>integration-test</id>
+            <phase>initialize</phase>
+            <goals>
+              <goal>run</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>

Added: maven/plugins/trunk/maven-invoker-plugin/src/it/invocation-environmentvariable/src/it/minvoker-145/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/invocation-environmentvariable/src/it/minvoker-145/pom.xml?rev=1408853&view=auto
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/it/invocation-environmentvariable/src/it/minvoker-145/pom.xml (added)
+++ maven/plugins/trunk/maven-invoker-plugin/src/it/invocation-environmentvariable/src/it/minvoker-145/pom.xml Tue Nov 13 17:43:25 2012
@@ -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-145</artifactId>
+  <version>0.1-SNAPSHOT</version>
+  <packaging>pom</packaging>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <profiles>
+    <profile>
+      <activation>
+        <property>
+          <name>env.MINVOKER145</name>
+          <value>!foobar</value>
+        </property>
+      </activation>
+      <build>
+        <plugins>
+          <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-enforcer-plugin</artifactId>
+            <version>1.1.1</version>
+            <executions>
+              <execution>
+                <goals>
+                  <goal>enforce</goal>
+                </goals>
+                <configuration>
+                  <rules>
+                    <AlwaysFail />
+                  </rules>
+                </configuration>
+              </execution>
+            </executions>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+  </profiles>
+</project>

Modified: maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/AbstractInvokerMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/AbstractInvokerMojo.java?rev=1408853&r1=1408852&r2=1408853&view=diff
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/AbstractInvokerMojo.java (original)
+++ maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/AbstractInvokerMojo.java Tue Nov 13 17:43:25 2012
@@ -565,6 +565,12 @@ public abstract class AbstractInvokerMoj
     private boolean mergeUserSettings;
 
     /**
+     * Additional environment variables to set on the command line.
+     * @since 1.8
+     */
+    @Parameter
+    private Map<String, String> environmentVariables;  
+    /**
      * The scripter runner that is responsible to execute hook scripts.
      */
     private ScriptRunner scriptRunner;
@@ -1511,7 +1517,7 @@ public abstract class AbstractInvokerMoj
             request.setDebug( debug );
 
             request.setShowVersion( showVersion );
-
+            
             if ( logger != null )
             {
                 request.setErrorHandler( logger );
@@ -1529,6 +1535,14 @@ public abstract class AbstractInvokerMoj
             {
                 request.setJavaHome( javaHome );
             }
+            
+            if ( environmentVariables != null )
+            {
+                for( Map.Entry<String, String> variable : environmentVariables.entrySet() )
+                {
+                    request.addShellEnvironment( variable.getKey(), variable.getValue() );
+                }
+            }
 
             for ( int invocationIndex = 1; ; invocationIndex++ )
             {