git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@415695 13f79535-47bb-0310-9956-ffa450edef68master
@@ -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 | ||||
@@ -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 | ||||
=================================== | =================================== | ||||
@@ -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 © 2000-2004, The Apache Software Foundation. All Rights Reserved. | |||||
Copyright © 2000-2004, 2006, The Apache Software Foundation. All Rights Reserved. | |||||
</em></font></div> | </em></font></div> | ||||
</td> | </td> | ||||
</tr> | </tr> | ||||
@@ -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()); | ||||
} | } | ||||
} | } |
@@ -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; | ||||
} | } | ||||