You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by vs...@apache.org on 2010/10/20 15:30:03 UTC

svn commit: r1025558 - /maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AntRunMojo.java

Author: vsiveton
Date: Wed Oct 20 13:30:03 2010
New Revision: 1025558

URL: http://svn.apache.org/viewvc?rev=1025558&view=rev
Log:
MANTRUN-158: Add a new parameter to export Ant properties to Maven properties

o added exportAntProperties and copy Ant properties to Maven properties

Modified:
    maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AntRunMojo.java

Modified: maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AntRunMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AntRunMojo.java?rev=1025558&r1=1025557&r2=1025558&view=diff
==============================================================================
--- maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AntRunMojo.java (original)
+++ maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AntRunMojo.java Wed Oct 20 13:30:03 2010
@@ -24,6 +24,7 @@ import java.io.IOException;
 import java.io.StringWriter;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Properties;
@@ -49,7 +50,7 @@ import org.codehaus.plexus.util.StringUt
 
 /**
  * Maven AntRun Mojo.
- *
+ * <br/>
  * This plugin provides the capability of calling Ant tasks
  * from a POM by running the nested ant tasks inside the &lt;tasks/&gt;
  * parameter. It is encouraged to move the actual tasks to
@@ -204,6 +205,14 @@ public class AntRunMojo
     private boolean skip;
 
     /**
+     * Specifies whether the Ant properties should be propagated to the Maven properties.
+     *
+     * @parameter default-value="false"
+     * @since 1.7
+     */
+    private boolean exportAntProperties;
+
+    /**
      * @see org.apache.maven.plugin.Mojo#execute()
      */
     public void execute()
@@ -287,6 +296,8 @@ public class AntRunMojo
             {
                 getLog().info( "Executed tasks" );
             }
+
+            copyProperties( antProject, mavenProject );
         }
         catch ( DependencyResolutionRequiredException e )
         {
@@ -419,6 +430,38 @@ public class AntRunMojo
     }
 
     /**
+     * Copy properties from the ant project to the maven project.
+     *
+     * @param antProject not null
+     * @param mavenProject not null
+     * @since 1.7
+     */
+    public void copyProperties( Project antProject, MavenProject mavenProject )
+    {
+        if ( !exportAntProperties )
+        {
+            return;
+        }
+
+        getLog().debug( "Propagated Ant properties to Maven properties" );
+        Hashtable antProps = antProject.getProperties();
+        Iterator iter = antProps.keySet().iterator();
+        while ( iter.hasNext() )
+        {
+            String key = (String) iter.next();
+
+            Properties mavenProperties = mavenProject.getProperties();
+            if ( mavenProperties.getProperty( key ) != null )
+            {
+                getLog().debug( "Ant property '" + key +"=" +mavenProperties.getProperty( key )
+                                   + "' clashs with an existing Maven property, SKIPPING this Ant property propagation." );
+                continue;
+            }
+            mavenProperties.setProperty( key, antProps.get( key ).toString() );
+        }
+    }
+
+    /**
      * Prefix for legacy property format.
      * @deprecated This should only be used for generating the old property format.
      */