Browse Source

make failonerror work as expected when copying to a file instead of a directory

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@932241 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 15 years ago
parent
commit
c35f045b90
3 changed files with 86 additions and 3 deletions
  1. +4
    -0
      WHATSNEW
  2. +17
    -3
      src/main/org/apache/tools/ant/taskdefs/Copy.java
  3. +65
    -0
      src/tests/antunit/taskdefs/copy-test.xml

+ 4
- 0
WHATSNEW View File

@@ -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:
--------------



+ 17
- 3
src/main/org/apache/tools/ant/taskdefs/Copy.java View File

@@ -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);


+ 65
- 0
src/tests/antunit/taskdefs/copy-test.xml View File

@@ -188,4 +188,69 @@ public class NullByteStreamResource extends Resource {
</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>

Loading…
Cancel
Save