diff --git a/src/main/org/apache/tools/ant/taskdefs/Delete.java b/src/main/org/apache/tools/ant/taskdefs/Delete.java index 5af6365b6..40c4a086a 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Delete.java +++ b/src/main/org/apache/tools/ant/taskdefs/Delete.java @@ -68,9 +68,10 @@ import java.util.*; * to provide backwards compatibility for a release. The future position * is to use nested filesets exclusively.

* - * @author stefano@apache.org + * @author Stefano Mazzocchi stefano@apache.org * @author Tom Dimock tad1@cornell.edu * @author Glenn McAllister glennm@ca.ibm.com + * @author Jon S. Stevens jon@latchkey.com */ public class Delete extends MatchingTask { protected File file = null; @@ -79,6 +80,7 @@ public class Delete extends MatchingTask { protected boolean usedMatchingTask = false; private int verbosity = Project.MSG_VERBOSE; + private boolean quiet = false; /** * Set the name of a single file to be removed. @@ -111,6 +113,19 @@ public class Delete extends MatchingTask { } } + /** + * If the file does not exist, do not display a diagnostic + * message or modify the exit status to reflect an error. + * This means that if a file or directory cannot be deleted, + * then no error is reported. This setting emulates the + * -f option to the Unix "rm" command. + * Default is false meaning things are "noisy" + * @param quiet "true" or "on" + */ + public void setQuiet(boolean quiet) { + this.quiet = quiet; + } + /** * Adds a set of files (nested fileset attribute). */ @@ -218,7 +233,7 @@ public class Delete extends MatchingTask { } else { log("Deleting: " + file.getAbsolutePath()); - if (!file.delete()) { + if (!quiet && !file.delete()) { throw new BuildException("Unable to delete file " + file.getAbsolutePath()); } } @@ -262,13 +277,13 @@ public class Delete extends MatchingTask { removeDir(f); } else { log("Deleting " + f.getAbsolutePath(), verbosity); - if (!f.delete()) { + if (!quiet && !f.delete()) { throw new BuildException("Unable to delete file " + f.getAbsolutePath()); } } } log("Deleting directory " + d.getAbsolutePath(), verbosity); - if (!d.delete()) { + if (!quiet && !d.delete()) { throw new BuildException("Unable to delete directory " + dir.getAbsolutePath()); } } @@ -279,7 +294,7 @@ public class Delete extends MatchingTask { for (int j=0; j