git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@932241 13f79535-47bb-0310-9956-ffa450edef68master
@@ -71,6 +71,10 @@ Fixed bugs: | |||||
* <rmic>'s sourcebase attribute was broken. | * <rmic>'s sourcebase attribute was broken. | ||||
Bugzilla Report 48970 | 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: | Other changes: | ||||
-------------- | -------------- | ||||
@@ -66,6 +66,9 @@ import org.apache.tools.ant.util.FlatFileNameMapper; | |||||
* @ant.task category="filesystem" | * @ant.task category="filesystem" | ||||
*/ | */ | ||||
public class Copy extends Task { | 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 File NULL_FILE_PLACEHOLDER = new File("/NULL_FILE"); | ||||
static final String LINE_SEPARATOR = System.getProperty("line.separator"); | static final String LINE_SEPARATOR = System.getProperty("line.separator"); | ||||
// CheckStyle:VisibilityModifier OFF - bc | // CheckStyle:VisibilityModifier OFF - bc | ||||
@@ -395,10 +398,22 @@ public class Copy extends Task { | |||||
// will be removed in validateAttributes | // will be removed in validateAttributes | ||||
savedRc = (ResourceCollection) rcs.elementAt(0); | savedRc = (ResourceCollection) rcs.elementAt(0); | ||||
} | } | ||||
try { | |||||
// make sure we don't have an illegal set of options | // make sure we don't have an illegal set of options | ||||
try { | |||||
validateAttributes(); | 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 | // deal with the single file | ||||
copySingleFile(); | copySingleFile(); | ||||
@@ -631,8 +646,7 @@ public class Copy extends Task { | |||||
+ " files."); | + " files."); | ||||
} | } | ||||
if (rc.size() == 0) { | 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) { | } else if (rc.size() == 1) { | ||||
Resource res = (Resource) rc.iterator().next(); | Resource res = (Resource) rc.iterator().next(); | ||||
FileProvider r = (FileProvider) res.as(FileProvider.class); | FileProvider r = (FileProvider) res.as(FileProvider.class); | ||||
@@ -188,4 +188,69 @@ public class NullByteStreamResource extends Resource { | |||||
</copy> | </copy> | ||||
<au:assertFileExists file="${output}/foo.jpg"/> | <au:assertFileExists file="${output}/foo.jpg"/> | ||||
</target> | </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> | </project> |