Browse Source

add tempfile deleteOnExit. PR# 39842. Submitted by Patrick Martin (then slightly modified).

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@415695 13f79535-47bb-0310-9956-ffa450edef68
master
Matthew Jason Benson 19 years ago
parent
commit
ac92e4e6bd
5 changed files with 69 additions and 3 deletions
  1. +1
    -0
      CONTRIBUTORS
  2. +2
    -0
      WHATSNEW
  3. +14
    -2
      docs/manual/CoreTasks/tempfile.html
  4. +21
    -1
      src/main/org/apache/tools/ant/taskdefs/TempFile.java
  5. +31
    -0
      src/main/org/apache/tools/ant/util/FileUtils.java

+ 1
- 0
CONTRIBUTORS View File

@@ -178,6 +178,7 @@ Oystein Gisnas
Patrick C. Beard
Patrick Chanezon
Patrick G. Heck (Gus Heck)
Patrick Martin
Paul Austin
Paul Christmann
Paul Galbraith


+ 2
- 0
WHATSNEW View File

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

* Minor performance updates. Bugzilla report 39565.

* New deleteonexit attribute for the <tempfile> task. Bugzilla report 39842.

Changes from Ant 1.6.4 to Ant 1.6.5
===================================



+ 14
- 2
docs/manual/CoreTasks/tempfile.html View File

@@ -128,7 +128,7 @@
<td bgcolor="#eeeeee" valign="top" align="left">
<font color="#000000" size="-1" face="arial,helvetica,sanserif">File</font>
</td>
<td bgcolor="#eeeeee" valign="top" align="left" rowspan="3">
<td bgcolor="#eeeeee" valign="top" align="left" rowspan="4">
<font color="#000000" size="-1" face="arial,helvetica,sanserif">Optional</font>
</td>
</tr>
@@ -156,6 +156,18 @@
<font color="#000000" size="-1" face="arial,helvetica,sanserif">String</font>
</td>
</tr>
<!-- Attribute -->
<tr>
<td bgcolor="#eeeeee" valign="top" align="left">
<font color="#000000" size="-1" face="arial,helvetica,sanserif">deleteonexit</font>
</td>
<td bgcolor="#eeeeee" valign="top" align="left">
<font color="#000000" size="-1" face="arial,helvetica,sanserif">Whether the temp file will be marked for deletion on normal exit of the Java Virtual Machine (even though the file may never be created); default <em>false</em>. <strong>Since Ant 1.7</strong></font>
</td>
<td bgcolor="#eeeeee" valign="top" align="left">
<font color="#000000" size="-1" face="arial,helvetica,sanserif">String</font>
</td>
</tr>


</table>
@@ -197,7 +209,7 @@
<tr>
<td>
<div align="center"><font color="#525D76" size="-1"><em>
Copyright &copy; 2000-2004, The Apache Software Foundation. All Rights Reserved.
Copyright &copy; 2000-2004, 2006, The Apache Software Foundation. All Rights Reserved.
</em></font></div>
</td>
</tr>


+ 21
- 1
src/main/org/apache/tools/ant/taskdefs/TempFile.java View File

@@ -62,6 +62,8 @@ public class TempFile extends Task {
*/
private String suffix = "";

/** deleteOnExit flag */
private boolean deleteOnExit;

/**
* Sets the property you wish to assign the temporary file to.
@@ -104,6 +106,22 @@ public class TempFile extends Task {
this.suffix = suffix;
}

/**
* Set whether the tempfile created by this task should be set
* for deletion on normal VM exit.
* @param deleteOnExit boolean flag.
*/
public void setDeleteOnExit(boolean deleteOnExit) {
this.deleteOnExit = deleteOnExit;
}

/**
* Learn whether deleteOnExit is set for this tempfile task.
* @return boolean deleteOnExit flag.
*/
public boolean isDeleteOnExit() {
return deleteOnExit;
}

/**
* Creates the temporary file.
@@ -117,7 +135,9 @@ public class TempFile extends Task {
if (destDir == null) {
destDir = FILE_UTILS.resolveFile(getProject().getBaseDir(),".");
}
File tfile = FILE_UTILS.createTempFile(prefix, suffix, destDir);
File tfile = FILE_UTILS.createTempFile(
prefix, suffix, destDir, deleteOnExit);

getProject().setNewProperty(property, tfile.toString());
}
}

+ 31
- 0
src/main/org/apache/tools/ant/util/FileUtils.java View File

@@ -817,6 +817,34 @@ public class FileUtils {
* @since Ant 1.5
*/
public File createTempFile(String prefix, String suffix, File parentDir) {
return createTempFile(prefix, suffix, parentDir, false);
}

/**
* Create a temporary file in a given directory.
*
* <p>The file denoted by the returned abstract pathname did not
* exist before this method was invoked, any subsequent invocation
* of this method will yield a different file name.</p>
* <p>
* The filename is prefixNNNNNsuffix where NNNN is a random number.
* </p>
* <p>This method is different from File.createTempFile() of JDK 1.2
* as it doesn't create the file itself. It uses the location pointed
* to by java.io.tmpdir when the parentDir attribute is null.</p>
*
* @param prefix prefix before the random number.
* @param suffix file extension; include the '.'.
* @param parentDir Directory to create the temporary file in;
* @param deleteOnExit whether to set the tempfile for deletion on
* normal VM exit.
* java.io.tmpdir used if not specified.
*
* @return a File reference to the new temporary file.
* @since Ant 1.7
*/
public File createTempFile(String prefix, String suffix, File parentDir,
boolean deleteOnExit) {
File result = null;
String parent = (parentDir == null)
? System.getProperty("java.io.tmpdir")
@@ -830,6 +858,9 @@ public class FileUtils {
+ suffix);
} while (result.exists());
}
if (deleteOnExit) {
result.deleteOnExit();
}
return result;
}



Loading…
Cancel
Save