diff --git a/WHATSNEW b/WHATSNEW index 36454f296..c9848cd17 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -71,6 +71,10 @@ Fixed bugs: * 's sourcebase attribute was broken. Bugzilla Report 48970 + * 's failonerror didn't work as expected when copying a single + element resource collection to a file. + Bugzilla Report 49070 + Other changes: -------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/Copy.java b/src/main/org/apache/tools/ant/taskdefs/Copy.java index 28add025f..ca45d9b06 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Copy.java +++ b/src/main/org/apache/tools/ant/taskdefs/Copy.java @@ -66,6 +66,9 @@ import org.apache.tools.ant.util.FlatFileNameMapper; * @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); diff --git a/src/tests/antunit/taskdefs/copy-test.xml b/src/tests/antunit/taskdefs/copy-test.xml index 6ca8cecda..612a0a1bc 100644 --- a/src/tests/antunit/taskdefs/copy-test.xml +++ b/src/tests/antunit/taskdefs/copy-test.xml @@ -188,4 +188,69 @@ public class NullByteStreamResource extends Resource { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +