From 194f9cafed2b7c71664756a14fa71cc6307c0a39 Mon Sep 17 00:00:00 2001
From: Stefan Bodewig
Date: Mon, 19 May 2003 15:37:31 +0000
Subject: [PATCH] Make 's failonerror attribute swallow exception while
copying as well. PR: 12999
git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274594 13f79535-47bb-0310-9956-ffa450edef68
---
WHATSNEW | 4 +
docs/manual/CoreTasks/copy.html | 3 +-
docs/manual/CoreTasks/move.html | 3 +-
.../org/apache/tools/ant/taskdefs/Copy.java | 104 ++++++++++--------
4 files changed, 64 insertions(+), 50 deletions(-)
diff --git a/WHATSNEW b/WHATSNEW
index 33130dd29..225b508ab 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -358,6 +358,10 @@ Other changes:
* and will display a summary if you set the new
verbose attribute to true. Bugzilla Report 19883.
+* /'s failonerror attribute can now also be used to
+ continue the build if an I/O error caused a problem. Bugzilla
+ Report 12999.
+
Changes from Ant 1.5.2 to Ant 1.5.3
===================================
diff --git a/docs/manual/CoreTasks/copy.html b/docs/manual/CoreTasks/copy.html
index 7a288c3e8..93f6ee428 100644
--- a/docs/manual/CoreTasks/copy.html
+++ b/docs/manual/CoreTasks/copy.html
@@ -95,7 +95,8 @@ operation as filtersets
failonerror |
Log a warning message, but do not stop the
build, when the file to copy does not exist or one of the nested
- filesets points to a directory that doesn't exist.
+ filesets points to a directory that doesn't exist or an error occurs
+ while copying.
|
No; defaults to true. |
diff --git a/docs/manual/CoreTasks/move.html b/docs/manual/CoreTasks/move.html
index 2af559294..b05000513 100644
--- a/docs/manual/CoreTasks/move.html
+++ b/docs/manual/CoreTasks/move.html
@@ -80,7 +80,8 @@ to move to the todir directory.
failonerror |
Log a warning message, but do not stop the
build, when the file to copy does not exist or one of the nested
- filesets points to a directory that doesn't exist.
+ filesets points to a directory that doesn't exist or an error occurs
+ while moving.
|
No; defaults to true. |
diff --git a/src/main/org/apache/tools/ant/taskdefs/Copy.java b/src/main/org/apache/tools/ant/taskdefs/Copy.java
index de1c146f8..f5d558ee2 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Copy.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Copy.java
@@ -401,7 +401,15 @@ public class Copy extends Task {
}
// do all the copy operations now...
- doFileOperations();
+ try {
+ doFileOperations();
+ } catch (BuildException e) {
+ if (!failonerror) {
+ log("Warning: " + e.getMessage(), Project.MSG_ERR);
+ } else {
+ throw e;
+ }
+ }
} finally {
// clean up again, so this instance can be used a second
// time
@@ -418,66 +426,66 @@ public class Copy extends Task {
}
}
-//************************************************************************
-// protected and private methods
-//************************************************************************
-
- /**
- * Ensure we have a consistent and legal set of attributes, and set
- * any internal flags necessary based on different combinations
- * of attributes.
- */
- protected void validateAttributes() throws BuildException {
- if (file == null && filesets.size() == 0) {
- throw new BuildException("Specify at least one source "
- + "- a file or a fileset.");
- }
-
- if (destFile != null && destDir != null) {
- throw new BuildException("Only one of tofile and todir "
- + "may be set.");
- }
+ //************************************************************************
+ // protected and private methods
+ //************************************************************************
+
+ /**
+ * Ensure we have a consistent and legal set of attributes, and set
+ * any internal flags necessary based on different combinations
+ * of attributes.
+ */
+ protected void validateAttributes() throws BuildException {
+ if (file == null && filesets.size() == 0) {
+ throw new BuildException("Specify at least one source "
+ + "- a file or a fileset.");
+ }
- if (destFile == null && destDir == null) {
- throw new BuildException("One of tofile or todir must be set.");
- }
+ if (destFile != null && destDir != null) {
+ throw new BuildException("Only one of tofile and todir "
+ + "may be set.");
+ }
- if (file != null && file.exists() && file.isDirectory()) {
- throw new BuildException("Use a fileset to copy directories.");
- }
+ if (destFile == null && destDir == null) {
+ throw new BuildException("One of tofile or todir must be set.");
+ }
- if (destFile != null && filesets.size() > 0) {
- if (filesets.size() > 1) {
- throw new BuildException(
- "Cannot concatenate multiple files into a single file.");
- } else {
- FileSet fs = (FileSet) filesets.elementAt(0);
- DirectoryScanner ds = fs.getDirectoryScanner(getProject());
- String[] srcFiles = ds.getIncludedFiles();
+ if (file != null && file.exists() && file.isDirectory()) {
+ throw new BuildException("Use a fileset to copy directories.");
+ }
- if (srcFiles.length == 0) {
+ if (destFile != null && filesets.size() > 0) {
+ if (filesets.size() > 1) {
throw new BuildException(
- "Cannot perform operation from directory to file.");
- } else if (srcFiles.length == 1) {
- if (file == null) {
- file = new File(ds.getBasedir(), srcFiles[0]);
- filesets.removeElementAt(0);
+ "Cannot concatenate multiple files into a single file.");
+ } else {
+ FileSet fs = (FileSet) filesets.elementAt(0);
+ DirectoryScanner ds = fs.getDirectoryScanner(getProject());
+ String[] srcFiles = ds.getIncludedFiles();
+
+ if (srcFiles.length == 0) {
+ throw new BuildException(
+ "Cannot perform operation from directory to file.");
+ } else if (srcFiles.length == 1) {
+ if (file == null) {
+ file = new File(ds.getBasedir(), srcFiles[0]);
+ filesets.removeElementAt(0);
+ } else {
+ throw new BuildException("Cannot concatenate multiple "
+ + "files into a single file.");
+ }
} else {
throw new BuildException("Cannot concatenate multiple "
+ "files into a single file.");
}
- } else {
- throw new BuildException("Cannot concatenate multiple "
- + "files into a single file.");
}
}
- }
- if (destFile != null) {
- destDir = fileUtils.getParentFile(destFile);
- }
+ if (destFile != null) {
+ destDir = fileUtils.getParentFile(destFile);
+ }
- }
+ }
/**
* Compares source files to destination files to see if they should be