Author: gboue
Date: Wed May 31 21:15:31 2017
New Revision: 1797111

URL: http://svn.apache.org/viewvc?rev=1797111&view=rev
Log:
[MANTRUN-178] Ignore precedence of mvn command line over property defined in 
<properties> section

Only properties declared in the POM are passed to Ant invocations, and their 
value should be overridable from a user property.

Added:
    maven/plugins/trunk/maven-antrun-plugin/src/it/MANTRUN-178/
    maven/plugins/trunk/maven-antrun-plugin/src/it/MANTRUN-178/build.xml   
(with props)
    
maven/plugins/trunk/maven-antrun-plugin/src/it/MANTRUN-178/invoker.properties   
(with props)
    maven/plugins/trunk/maven-antrun-plugin/src/it/MANTRUN-178/pom.xml   (with 
props)
Modified:
    
maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugins/antrun/AntRunMojo.java

Added: maven/plugins/trunk/maven-antrun-plugin/src/it/MANTRUN-178/build.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antrun-plugin/src/it/MANTRUN-178/build.xml?rev=1797111&view=auto
==============================================================================
--- maven/plugins/trunk/maven-antrun-plugin/src/it/MANTRUN-178/build.xml (added)
+++ maven/plugins/trunk/maven-antrun-plugin/src/it/MANTRUN-178/build.xml Wed 
May 31 21:15:31 2017
@@ -0,0 +1,44 @@
+<?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 name="MANTRUN-178" default="main">
+  <condition property="isProp1Ok">
+    <equals arg1="${prop1}" arg2="val1-pom" />
+  </condition>
+  <condition property="isProp2Ok">
+    <equals arg1="${prop2}" arg2="val2-cli" />
+  </condition>
+  <condition property="isProp3Ok">
+    <not><isset property="${prop3}" /></not>
+  </condition>
+       
+  <target name="-prop1" unless="isProp1Ok">
+       <fail>prop1=${prop1} is not equal to val1-pom</fail>
+  </target>
+  <target name="-prop2" unless="isProp2Ok">
+       <fail>prop2=${prop2} is not equal to val2-cli</fail>
+  </target>
+  <target name="-prop3" unless="isProp3Ok">
+       <fail>prop3=${prop3} was set</fail>
+  </target>
+
+  <target name="main" depends="-prop1,-prop2,-prop3" />
+</project>
\ No newline at end of file

Propchange: maven/plugins/trunk/maven-antrun-plugin/src/it/MANTRUN-178/build.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-antrun-plugin/src/it/MANTRUN-178/build.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
maven/plugins/trunk/maven-antrun-plugin/src/it/MANTRUN-178/invoker.properties
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antrun-plugin/src/it/MANTRUN-178/invoker.properties?rev=1797111&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-antrun-plugin/src/it/MANTRUN-178/invoker.properties 
(added)
+++ 
maven/plugins/trunk/maven-antrun-plugin/src/it/MANTRUN-178/invoker.properties 
Wed May 31 21:15:31 2017
@@ -0,0 +1,18 @@
+# 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.goals = clean validate -Dprop2=val2-cli -Dprop3=val3-cli

Propchange: 
maven/plugins/trunk/maven-antrun-plugin/src/it/MANTRUN-178/invoker.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/plugins/trunk/maven-antrun-plugin/src/it/MANTRUN-178/invoker.properties
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/plugins/trunk/maven-antrun-plugin/src/it/MANTRUN-178/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antrun-plugin/src/it/MANTRUN-178/pom.xml?rev=1797111&view=auto
==============================================================================
--- maven/plugins/trunk/maven-antrun-plugin/src/it/MANTRUN-178/pom.xml (added)
+++ maven/plugins/trunk/maven-antrun-plugin/src/it/MANTRUN-178/pom.xml Wed May 
31 21:15:31 2017
@@ -0,0 +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/maven-v4_0_0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.maven.plugins.antrun</groupId>
+  <artifactId>MANTRUN-178</artifactId>
+  <packaging>pom</packaging>
+  <version>1.0</version>
+  <url>https://issues.apache.org/jira/browse/MANTRUN-178</url>
+  <description>
+    Checks that only POM properties are passed to Ant invocation, and that 
their values can be overriden by a user
+    property.
+  </description>
+  <properties>
+    <prop1>val1-pom</prop1> <!-- not a user property -->
+    <prop2>val2-pom</prop2> <!-- value should to be overriden by user property 
-->
+    <!-- prop3 is only set as a user property and should not be passed to the 
Ant invocation -->
+  </properties>
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-antrun-plugin</artifactId>
+        <version>@pom.version@</version>
+        <executions>
+          <execution>
+            <phase>validate</phase>
+            <goals>
+              <goal>run</goal>
+            </goals>
+            <configuration>
+              <target>
+                <ant antfile="build.xml" />
+              </target>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Propchange: maven/plugins/trunk/maven-antrun-plugin/src/it/MANTRUN-178/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-antrun-plugin/src/it/MANTRUN-178/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: 
maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugins/antrun/AntRunMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugins/antrun/AntRunMojo.java?rev=1797111&r1=1797110&r2=1797111&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugins/antrun/AntRunMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugins/antrun/AntRunMojo.java
 Wed May 31 21:15:31 2017
@@ -33,6 +33,7 @@ import java.util.Set;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.DependencyResolutionRequiredException;
 import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.execution.MavenSession;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
@@ -128,6 +129,12 @@ public class AntRunMojo
     private MavenProject project;
 
     /**
+     * The Maven session object
+     */
+    @Parameter( defaultValue = "${session}", readonly = true, required = true )
+    private MavenSession session;
+
+    /**
      * The Maven project helper object
      */
     @Component
@@ -421,9 +428,11 @@ public class AntRunMojo
     public void copyProperties( MavenProject mavenProject, Project antProject )
     {
         Properties mavenProps = mavenProject.getProperties();
-        for ( Map.Entry<?, ?> entry : mavenProps.entrySet() )
+        Properties userProps = session.getUserProperties();
+        for ( String key : mavenProps.stringPropertyNames() )
         {
-            antProject.setProperty( (String) entry.getKey(), (String) 
entry.getValue() );
+            String value = userProps.getProperty( key, mavenProps.getProperty( 
key ) );
+            antProject.setProperty( key, value );
         }
 
         // Set the POM file as the ant.file for the tasks run directly in 
Maven.


Reply via email to