diff --git a/WHATSNEW b/WHATSNEW index 5d124e2e5..6058a3daa 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -215,6 +215,8 @@ Other changes: * Add implicit nested element to . Bugzilla Report 25633. +* Add deleteonexit attribute to . + Changes from Ant 1.6.0 to Ant 1.6.1 ============================================= diff --git a/docs/manual/CoreTasks/delete.html b/docs/manual/CoreTasks/delete.html index 25c1fe3f3..9b7591b95 100644 --- a/docs/manual/CoreTasks/delete.html +++ b/docs/manual/CoreTasks/delete.html @@ -130,6 +130,16 @@ in Directory-based Tasks, and see the Default excludes are used when omitted. No + + deleteonexit + + Indicates whether to use File#deleteOnExit() if there is a + failure to delete a file, this causes the jvm to attempt + to delete the file when the jvm process is terminating. + The default is false. + Since Ant 1.6.2 + No +

Examples

  <delete file="/lib/ant.jar"/>
diff --git a/src/main/org/apache/tools/ant/taskdefs/Delete.java b/src/main/org/apache/tools/ant/taskdefs/Delete.java index 9bfe997de..bd8022f90 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Delete.java +++ b/src/main/org/apache/tools/ant/taskdefs/Delete.java @@ -69,6 +69,7 @@ public class Delete extends MatchingTask { private int verbosity = Project.MSG_VERBOSE; private boolean quiet = false; private boolean failonerror = true; + private boolean deleteOnExit = false; /** * Set the name of a single file to be removed. @@ -126,6 +127,16 @@ public class Delete extends MatchingTask { this.failonerror = failonerror; } + /** + * If true, on failure to delete, note the error and set + * the deleteonexit flag, and continue + * + * @param deleteOnExit true or false + */ + public void setDeleteOnExit(boolean deleteOnExit) { + this.deleteOnExit = deleteOnExit; + } + /** * If true, delete empty directories. @@ -540,9 +551,17 @@ public class Delete extends MatchingTask { } try { Thread.sleep(DELETE_RETRY_SLEEP_MILLIS); - return f.delete(); } catch (InterruptedException ex) { - return f.delete(); + // Ignore Exception + } + if (!f.delete()) { + if (deleteOnExit) { + int level = quiet ? Project.MSG_VERBOSE : Project.MSG_INFO; + log("Failed to delete " + f + ", calling deleteOnExit" + f, level); + f.deleteOnExit(); + return true; + } + return false; } } return true;