ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r986290 - in /ant/core/trunk: WHATSNEW docs/manual/Tasks/copy.html src/main/org/apache/tools/ant/taskdefs/Copy.java src/tests/antunit/taskdefs/copy-test.xml
Date Tue, 17 Aug 2010 12:22:07 GMT
Author: bodewig
Date: Tue Aug 17 12:22:07 2010
New Revision: 986290

URL: http://svn.apache.org/viewvc?rev=986290&view=rev
Log:
allow copy/@tofile to be used with non-file resources.  PR 49756

Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/docs/manual/Tasks/copy.html
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Copy.java
    ant/core/trunk/src/tests/antunit/taskdefs/copy-test.xml

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=986290&r1=986289&r2=986290&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Tue Aug 17 12:22:07 2010
@@ -166,6 +166,9 @@ Other changes:
    the imported resource. This means that several kinds of different build
    files can import each other.
 
+ * <copy tofile=""> now also works for non-filesystem resources.
+   Bugzilla Report 49756.
+
 Changes from Ant 1.8.0 TO Ant 1.8.1 
 ===================================
 

Modified: ant/core/trunk/docs/manual/Tasks/copy.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/Tasks/copy.html?rev=986290&r1=986289&r2=986290&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/Tasks/copy.html (original)
+++ ant/core/trunk/docs/manual/Tasks/copy.html Tue Aug 17 12:22:07 2010
@@ -73,12 +73,15 @@ operation as <a href="../Types/filterset
     <td valign="top">The file to copy to.</td>
     <td valign="top" align="center" rowspan="2">With the <code>file</code>
       attribute, either <code>tofile</code> or <code>todir</code>
can be used.<br/>
-      With nested resource collection elements, if the collection
-      contains non-filesystem resources, the number of included files
+
+      With nested resource collection elements, if the number of
+      included resources
       is greater than 1, or if only the <code>dir</code> attribute is
       specified in the <code>&lt;fileset&gt;</code>, or if the
       <code>file</code> attribute is also specified, then only
-      <code>todir</code> is allowed.</td>
+      <code>todir</code> is allowed.<br/>
+      <em>Prior to Ant 1.8.2</em> the <code>tofile</code> attribute
+      only supported filesystem resources top copy from.</td>
   </tr>
   <tr>
     <td valign="top">todir</td>

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Copy.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Copy.java?rev=986290&r1=986289&r2=986290&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Copy.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Copy.java Tue Aug 17 12:22:07 2010
@@ -102,6 +102,10 @@ public class Copy extends Task {
     private long granularity = 0;
     private boolean force = false;
 
+    // used to store the single non-file resource to copy when the
+    // tofile attribute has been used
+    private Resource singleResource = null;
+
     /**
      * Copy task constructor.
      */
@@ -550,11 +554,15 @@ public class Copy extends Task {
                 }
             }
 
-            if (nonFileResources.size() > 0) {
+            if (nonFileResources.size() > 0 || singleResource != null) {
                 Resource[] nonFiles =
                     (Resource[]) nonFileResources.toArray(new Resource[nonFileResources.size()]);
                 // restrict to out-of-date resources
                 Map map = scan(nonFiles, destDir);
+                if (singleResource != null) {
+                    map.put(singleResource,
+                            new String[] { destFile.getAbsolutePath() });
+                }
                 try {
                     doResourceOperations(map);
                 } catch (BuildException e) {
@@ -568,6 +576,7 @@ public class Copy extends Task {
         } finally {
             // clean up again, so this instance can be used a second
             // time
+            singleResource = null;
             file = savedFile;
             destFile = savedDestFile;
             destDir = savedDestDir;
@@ -661,10 +670,9 @@ public class Copy extends Task {
                     "Cannot concatenate multiple files into a single file.");
             } else {
                 ResourceCollection rc = (ResourceCollection) rcs.elementAt(0);
-                if (!rc.isFilesystemOnly()) {
+                if (!rc.isFilesystemOnly() && !supportsNonFileResources()) {
                     throw new BuildException("Only FileSystem resources are"
-                                             + " supported when concatenating"
-                                             + " files.");
+                                             + " supported.");
                 }
                 if (rc.size() == 0) {
                     throw new BuildException(MSG_WHEN_COPYING_EMPTY_RC_TO_FILE);
@@ -672,7 +680,11 @@ public class Copy extends Task {
                     Resource res = (Resource) rc.iterator().next();
                     FileProvider r = (FileProvider) res.as(FileProvider.class);
                     if (file == null) {
-                        file = r.getFile();
+                        if (r != null) {
+                            file = r.getFile();
+                        } else {
+                            singleResource = res;
+                        }
                         rcs.removeElementAt(0);
                     } else {
                         throw new BuildException(

Modified: ant/core/trunk/src/tests/antunit/taskdefs/copy-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/copy-test.xml?rev=986290&r1=986289&r2=986290&view=diff
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/copy-test.xml (original)
+++ ant/core/trunk/src/tests/antunit/taskdefs/copy-test.xml Tue Aug 17 12:22:07 2010
@@ -403,4 +403,40 @@ public class NullByteStreamResource exte
     </copy>
   </target>
 
+  <target name="testCopyWithResourceAndFile"
+          description="https://issues.apache.org/bugzilla/show_bug.cgi?id=49756"
+          >
+    <mkdir dir="${input}"/>
+    <au:assertFileDoesntExist file="${input}/somefile"/>
+    <copy tofile="${input}/somefile">
+      <first>
+        <union>
+          <restrict>
+            <exists/>
+            <fileset file="${input}/somefile"/>
+          </restrict>
+          <string value="default contents"/>
+        </union>
+      </first>
+    </copy>
+    <au:assertFileExists file="${input}/somefile"/>
+    <au:assertResourceContains resource="${input}/somefile"
+                               value="default contents"/>
+    <delete file="${input}/somefile"/>
+    <touch file="${input}/somefile"/>
+    <copy tofile="${input}/somefile">
+      <first>
+        <union>
+          <restrict>
+            <exists/>
+            <fileset file="${input}/somefile"/>
+          </restrict>
+          <string value="default contents"/>
+        </union>
+      </first>
+    </copy>
+    <au:assertFileExists file="${input}/somefile"/>
+    <au:assertResourceDoesntContain resource="${input}/somefile"
+                                    value="default contents"/>
+  </target>
 </project>



Mime
View raw message