From be29c38722c008d0b87e7b97114da552fef2ee37 Mon Sep 17 00:00:00 2001
From: Jon Scott Stevens
Date: Tue, 5 Dec 2000 03:53:15 +0000
Subject: [PATCH] added setQuiet option to emulate a rm -f
i can't actually test this code since i can't even get Ant to compile.
maybe someone else would like to test it for me?
git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268296 13f79535-47bb-0310-9956-ffa450edef68
---
.../org/apache/tools/ant/taskdefs/Delete.java | 25 +++++++++++++++----
1 file changed, 20 insertions(+), 5 deletions(-)
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