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 C. Beard
Patrick Chanezon Patrick Chanezon
Patrick G. Heck (Gus Heck) Patrick G. Heck (Gus Heck)
Patrick Martin
Paul Austin Paul Austin
Paul Christmann Paul Christmann
Paul Galbraith Paul Galbraith


+ 2
- 0
WHATSNEW View File

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


* Minor performance updates. Bugzilla report 39565. * 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 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"> <td bgcolor="#eeeeee" valign="top" align="left">
<font color="#000000" size="-1" face="arial,helvetica,sanserif">File</font> <font color="#000000" size="-1" face="arial,helvetica,sanserif">File</font>
</td> </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> <font color="#000000" size="-1" face="arial,helvetica,sanserif">Optional</font>
</td> </td>
</tr> </tr>
@@ -156,6 +156,18 @@
<font color="#000000" size="-1" face="arial,helvetica,sanserif">String</font> <font color="#000000" size="-1" face="arial,helvetica,sanserif">String</font>
</td> </td>
</tr> </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> </table>
@@ -197,7 +209,7 @@
<tr> <tr>
<td> <td>
<div align="center"><font color="#525D76" size="-1"><em> <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> </em></font></div>
</td> </td>
</tr> </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 = ""; private String suffix = "";


/** deleteOnExit flag */
private boolean deleteOnExit;


/** /**
* Sets the property you wish to assign the temporary file to. * Sets the property you wish to assign the temporary file to.
@@ -104,6 +106,22 @@ public class TempFile extends Task {
this.suffix = suffix; 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. * Creates the temporary file.
@@ -117,7 +135,9 @@ public class TempFile extends Task {
if (destDir == null) { if (destDir == null) {
destDir = FILE_UTILS.resolveFile(getProject().getBaseDir(),"."); 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()); 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 * @since Ant 1.5
*/ */
public File createTempFile(String prefix, String suffix, File parentDir) { 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; File result = null;
String parent = (parentDir == null) String parent = (parentDir == null)
? System.getProperty("java.io.tmpdir") ? System.getProperty("java.io.tmpdir")
@@ -830,6 +858,9 @@ public class FileUtils {
+ suffix); + suffix);
} while (result.exists()); } while (result.exists());
} }
if (deleteOnExit) {
result.deleteOnExit();
}
return result; return result;
} }




Loading…
Cancel
Save