Browse Source

Add deleteonexit attribute to <delete>

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@276546 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Reilly 21 years ago
parent
commit
9aa711ca63
3 changed files with 33 additions and 2 deletions
  1. +2
    -0
      WHATSNEW
  2. +10
    -0
      docs/manual/CoreTasks/delete.html
  3. +21
    -2
      src/main/org/apache/tools/ant/taskdefs/Delete.java

+ 2
- 0
WHATSNEW View File

@@ -215,6 +215,8 @@ Other changes:

* Add implicit nested element to <macrodef>. Bugzilla Report 25633.

* Add deleteonexit attribute to <delete>.

Changes from Ant 1.6.0 to Ant 1.6.1
=============================================



+ 10
- 0
docs/manual/CoreTasks/delete.html View File

@@ -130,6 +130,16 @@ in <strong>Directory-based Tasks</strong>, and see the
Default excludes are used when omitted.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">deleteonexit</td>
<td valign="top">
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.
<em>Since Ant 1.6.2</em>
<td valign="top" align="center">No</td>
</tr>
</table>
<h3>Examples</h3>
<pre> &lt;delete file=&quot;/lib/ant.jar&quot;/&gt;</pre>


+ 21
- 2
src/main/org/apache/tools/ant/taskdefs/Delete.java View File

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


Loading…
Cancel
Save