You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2009/06/29 11:41:37 UTC

svn commit: r789271 - in /ant/core/trunk: WHATSNEW docs/manual/CoreTasks/apply.html src/main/org/apache/tools/ant/taskdefs/ExecuteOn.java src/main/org/apache/tools/ant/types/Commandline.java src/tests/antunit/taskdefs/exec/apply-test.xml

Author: bodewig
Date: Mon Jun 29 09:41:37 2009
New Revision: 789271

URL: http://svn.apache.org/viewvc?rev=789271&view=rev
Log:
add prefix and suffix attributes to apply's srcfile and targetfile elements.  PR 45625

Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/docs/manual/CoreTasks/apply.html
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ExecuteOn.java
    ant/core/trunk/src/main/org/apache/tools/ant/types/Commandline.java
    ant/core/trunk/src/tests/antunit/taskdefs/exec/apply-test.xml

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=789271&r1=789270&r2=789271&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Mon Jun 29 09:41:37 2009
@@ -741,6 +741,10 @@
    optional prefix and suffix attributes.
    Bugzilla Report 47365
 
+ * <apply>'s srcfile and targetfile child elements can now have
+   optional prefix and suffix attributes.
+   Bugzilla Report 45625
+
 Changes from Ant 1.7.0 TO Ant 1.7.1
 =============================================
 

Modified: ant/core/trunk/docs/manual/CoreTasks/apply.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTasks/apply.html?rev=789271&r1=789270&r2=789271&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTasks/apply.html (original)
+++ ant/core/trunk/docs/manual/CoreTasks/apply.html Mon Jun 29 09:41:37 2009
@@ -333,12 +333,50 @@
 <code>false</code>). If you need to place it somewhere different,
 use a nested <code>&lt;srcfile&gt;</code> element between your
 <code>&lt;arg&gt;</code> elements to mark the insertion point.</p>
+<table border="1" cellpadding="2" cellspacing="0">
+  <tr>
+    <td valign="top"><b>Attribute</b></td>
+    <td valign="top"><b>Description</b></td>
+    <td align="center" valign="top"><b>Required</b></td>
+  </tr>
+  <tr>
+    <td valign="top">prefix</td>
+    <td valign="top">a prefix to place in front of the file name when
+    building the command line argument.  <em>Since Ant 1.8.0</em></td>
+    <td align="center" valign="top">No.</td>
+  </tr>
+  <tr>
+    <td valign="top">suffix</td>
+    <td valign="top">a suffix to append to the file name when
+    building the command line argument.  <em>Since Ant 1.8.0</em></td>
+    <td align="center" valign="top">No.</td>
+  </tr>
+</table>
 <h4>targetfile</h4>
 <p><code>&lt;targetfile&gt;</code> is similar to
 <code>&lt;srcfile&gt;</code> and marks the position of the target
 filename on the command line. If omitted, the target filenames will
 not be added to the command line at all. This element can only be
 specified if you also define a nested mapper.</p>
+<table border="1" cellpadding="2" cellspacing="0">
+  <tr>
+    <td valign="top"><b>Attribute</b></td>
+    <td valign="top"><b>Description</b></td>
+    <td align="center" valign="top"><b>Required</b></td>
+  </tr>
+  <tr>
+    <td valign="top">prefix</td>
+    <td valign="top">a prefix to place in front of the file name when
+    building the command line argument.  <em>Since Ant 1.8.0</em></td>
+    <td align="center" valign="top">No.</td>
+  </tr>
+  <tr>
+    <td valign="top">suffix</td>
+    <td valign="top">a suffix to append to the file name when
+    building the command line argument.  <em>Since Ant 1.8.0</em></td>
+    <td align="center" valign="top">No.</td>
+  </tr>
+</table>
 <h4>env</h4>
 <p>It is possible to specify environment variables to pass to the
 system command via nested <code>&lt;env&gt;</code> elements. See the

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ExecuteOn.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ExecuteOn.java?rev=789271&r1=789270&r2=789271&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ExecuteOn.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ExecuteOn.java Mon Jun 29 09:41:37 2009
@@ -576,10 +576,10 @@
                                  srcIndex + srcFiles.length,
                                  targetIndex - srcIndex);
 
-                // targets are already absolute file names
-                System.arraycopy(targetFiles, 0, result,
-                                 targetIndex + srcFiles.length,
-                                 targetFiles.length);
+                insertTargetFiles(targetFiles, result,
+                                  targetIndex + srcFiles.length,
+                                  targetFilePos.getPrefix(),
+                                  targetFilePos.getSuffix());
 
                 // targetIndex --> end
                 System.arraycopy(orig, targetIndex, result,
@@ -589,10 +589,9 @@
                 // 0 --> targetIndex
                 System.arraycopy(orig, 0, result, 0, targetIndex);
 
-                // targets are already absolute file names
-                System.arraycopy(targetFiles, 0, result,
-                                 targetIndex,
-                                 targetFiles.length);
+                insertTargetFiles(targetFiles, result, targetIndex,
+                                  targetFilePos.getPrefix(),
+                                  targetFilePos.getSuffix());
 
                 // targetIndex --> srcIndex
                 System.arraycopy(orig, targetIndex, result,
@@ -626,6 +625,11 @@
             if (forwardSlash && fileSeparator != '/') {
                 src = src.replace(fileSeparator, '/');
             }
+            if (srcFilePos != null &&
+                (srcFilePos.getPrefix().length() > 0
+                 || srcFilePos.getSuffix().length() > 0)) {
+                src = srcFilePos.getPrefix() + src + srcFilePos.getSuffix();
+            }
             result[srcIndex + i] = src;
         }
         return result;
@@ -736,6 +740,26 @@
     }
 
     /**
+     * Inserts target file names (which are already absolute paths)
+     * into the list of arguments, taking prefix and postfix into
+     * account.
+     */
+    private static void insertTargetFiles(String[] targetFiles,
+                                          String[] arguments,
+                                          int insertPosition,
+                                          String prefix, String suffix) {
+        if (prefix.length() == 0 && suffix.length() == 0) {
+            System.arraycopy(targetFiles, 0, arguments, insertPosition,
+                             targetFiles.length);
+        } else {
+            for (int i = 0; i < targetFiles.length; i++) {
+                arguments[insertPosition + i] =
+                    prefix + targetFiles[i] + suffix;
+            }
+        }
+    }
+
+    /**
      * Enumerated attribute with the values "file", "dir" and "both"
      * for the type attribute.
      */

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/Commandline.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/Commandline.java?rev=789271&r1=789270&r2=789271&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/Commandline.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/Commandline.java Mon Jun 29 09:41:37 2009
@@ -202,14 +202,16 @@
 
     /**
      * Class to keep track of the position of an Argument.
-     <p>This class is there to support the srcfile and targetfile
-     elements of &lt;execon&gt; and &lt;transform&gt; - don't know
-     whether there might be additional use cases.</p> --SB
+     *
+     * <p>This class is there to support the srcfile and targetfile
+     * elements of &lt;apply&gt;.</p>
      */
     public class Marker {
 
         private int position;
         private int realPos = -1;
+        private String prefix = "";
+        private String suffix = "";
 
         /**
          * Construct a marker for the specified position.
@@ -236,6 +238,45 @@
             }
             return realPos;
         }
+
+        /**
+         * Set the prefix to be placed in front of the inserted argument.
+         *
+         * @param prefix fixed prefix string.
+         * @since Ant 1.8.0
+         */
+        public void setPrefix(String prefix) {
+            this.prefix = prefix != null ? prefix : "";
+        }
+
+        /**
+         * Get the prefix to be placed in front of the inserted argument.
+         *
+         * @since Ant 1.8.0
+         */
+        public String getPrefix() {
+            return prefix;
+        }
+
+        /**
+         * Set the suffix to be placed at the end of the inserted argument.
+         *
+         * @param suffix fixed suffix string.
+         * @since Ant 1.8.0
+         */
+        public void setSuffix(String suffix) {
+            this.suffix = suffix != null ? suffix : "";
+        }
+
+        /**
+         * Get the suffix to be placed at the end of the inserted argument.
+         *
+         * @since Ant 1.8.0
+         */
+        public String getSuffix() {
+            return suffix;
+        }
+
     }
 
     /**

Modified: ant/core/trunk/src/tests/antunit/taskdefs/exec/apply-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/exec/apply-test.xml?rev=789271&r1=789270&r2=789271&view=diff
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/exec/apply-test.xml (original)
+++ ant/core/trunk/src/tests/antunit/taskdefs/exec/apply-test.xml Mon Jun 29 09:41:37 2009
@@ -731,6 +731,29 @@
     </au:assertTrue>
   </target>
 
+  <target name="testSrcfilePrefix" if="test.can.run" depends="xyz">
+    <apply executable="sh" force="true">
+      <arg value="parrot.sh" />
+      <srcfile prefix="-Dfoo="/>
+      <fileset refid="xyz" />
+    </apply>
+    <au:assertLogContains text="-Dfoo=${x} out" />
+    <au:assertLogContains text="-Dfoo=${y} out" />
+    <au:assertLogContains text="-Dfoo=${z} out" />
+  </target>
+
+  <target name="testTargetfileSuffix" if="test.can.run" depends="xyz">
+    <apply executable="sh" addsourcefile="false" dest="${basedir}">
+      <arg value="parrot.sh" />
+      <targetfile suffix=",x"/>
+      <fileset refid="xyz" />
+      <globmapper from="*" to="*.bar"/>
+    </apply>
+    <au:assertLogContains text="${x}.bar,x out" />
+    <au:assertLogContains text="${y}.bar,x out" />
+    <au:assertLogContains text="${z}.bar,x out" />
+  </target>
+
   <target name="tearDown">
     <delete>
       <fileset refid="xyz" />