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 2010/04/09 06:43:38 UTC

svn commit: r932241 - in /ant/core/trunk: WHATSNEW src/main/org/apache/tools/ant/taskdefs/Copy.java src/tests/antunit/taskdefs/copy-test.xml

Author: bodewig
Date: Fri Apr  9 04:43:38 2010
New Revision: 932241

URL: http://svn.apache.org/viewvc?rev=932241&view=rev
Log:
make failonerror work as expected when copying to a file instead of a directory

Modified:
    ant/core/trunk/WHATSNEW
    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=932241&r1=932240&r2=932241&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Fri Apr  9 04:43:38 2010
@@ -71,6 +71,10 @@ Fixed bugs:
  * <rmic>'s sourcebase attribute was broken.
    Bugzilla Report 48970
 
+ * <copy>'s failonerror didn't work as expected when copying a single
+   element resource collection to a file.
+   Bugzilla Report 49070
+
 Other changes:
 --------------
 

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=932241&r1=932240&r2=932241&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 Fri Apr  9 04:43:38 2010
@@ -66,6 +66,9 @@ import org.apache.tools.ant.util.FlatFil
  * @ant.task category="filesystem"
  */
 public class Copy extends Task {
+    private static final String MSG_WHEN_COPYING_EMPTY_RC_TO_FILE =
+        "Cannot perform operation from directory to file.";
+
     static final File NULL_FILE_PLACEHOLDER = new File("/NULL_FILE");
     static final String LINE_SEPARATOR = System.getProperty("line.separator");
     // CheckStyle:VisibilityModifier OFF - bc
@@ -395,10 +398,22 @@ public class Copy extends Task {
             // will be removed in validateAttributes
             savedRc = (ResourceCollection) rcs.elementAt(0);
         }
+
+        try {
         // make sure we don't have an illegal set of options
+            try {
         validateAttributes();
+            } catch (BuildException e) {
+                if (failonerror
+                    || !getMessage(e)
+                    .equals(MSG_WHEN_COPYING_EMPTY_RC_TO_FILE)) {
+                    throw e;
+                } else {
+                    log("Warning: " + getMessage(e), Project.MSG_ERR);
+                    return;
+                }
+            }
 
-        try {
             // deal with the single file
             copySingleFile();
 
@@ -631,8 +646,7 @@ public class Copy extends Task {
                                              + " files.");
                 }
                 if (rc.size() == 0) {
-                    throw new BuildException(
-                        "Cannot perform operation from directory to file.");
+                    throw new BuildException(MSG_WHEN_COPYING_EMPTY_RC_TO_FILE);
                 } else if (rc.size() == 1) {
                     Resource res = (Resource) rc.iterator().next();
                     FileProvider r = (FileProvider) res.as(FileProvider.class);

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=932241&r1=932240&r2=932241&view=diff
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/copy-test.xml (original)
+++ ant/core/trunk/src/tests/antunit/taskdefs/copy-test.xml Fri Apr  9 04:43:38 2010
@@ -188,4 +188,69 @@ public class NullByteStreamResource exte
     </copy>
     <au:assertFileExists file="${output}/foo.jpg"/>
   </target>
+
+  <target name="testMissingFileUsingFileAttribute">
+    <mkdir dir="${output}"/>
+    <mkdir dir="${input}"/>
+    <au:expectfailure expectedMessage="Could not find file">
+      <copy file="${input}/not-there.txt" todir="${output}"/>
+    </au:expectfailure>
+    <copy file="${input}/not-there.txt" todir="${output}"
+          failonerror="false"/>
+  </target>
+
+  <target name="testMissingFilesetRoot">
+    <mkdir dir="${output}"/>
+    <au:expectfailure expectedMessage="does not exist">
+      <copy todir="${output}">
+        <fileset dir="${input}">
+          <include name="not-there.txt"/>
+        </fileset>
+      </copy>
+    </au:expectfailure>
+    <copy todir="${output}" failonerror="false">
+      <fileset dir="${input}">
+        <include name="not-there.txt"/>
+      </fileset>
+    </copy>
+  </target>
+
+  <target name="testMissingFileUsingFilesetInclude"
+          description="https://issues.apache.org/bugzilla/show_bug.cgi?id=49070">
+    <mkdir dir="${output}"/>
+    <mkdir dir="${input}"/>
+    <au:expectfailure
+       expectedMessage="Cannot perform operation from directory to file.">
+      <copy tofile="${output}/foo.txt">
+        <fileset dir="${input}">
+          <include name="not-there.txt"/>
+        </fileset>
+      </copy>
+    </au:expectfailure>
+    <copy tofile="${output}/foo.txt" failonerror="false">
+      <fileset dir="${input}">
+        <include name="not-there.txt"/>
+      </fileset>
+    </copy>
+  </target>
+
+  <target name="testMissingFileUsingFilesetFilename"
+          description="https://issues.apache.org/bugzilla/show_bug.cgi?id=49070">
+    <mkdir dir="${output}"/>
+    <mkdir dir="${input}"/>
+    <au:expectfailure
+       expectedMessage="Cannot perform operation from directory to file.">
+      <copy tofile="${output}/foo.txt">
+        <fileset dir="${input}">
+          <filename name="not-there.txt"/>
+        </fileset>
+      </copy>
+    </au:expectfailure>
+    <copy  tofile="${output}/foo.txt" failonerror="false">
+      <fileset dir="${input}">
+        <filename name="not-there.txt"/>
+      </fileset>
+    </copy>
+  </target>
+
 </project>