ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r415695 - in /ant/core/trunk: CONTRIBUTORS WHATSNEW docs/manual/CoreTasks/tempfile.html src/main/org/apache/tools/ant/taskdefs/TempFile.java src/main/org/apache/tools/ant/util/FileUtils.java
Date Tue, 20 Jun 2006 15:09:20 GMT
Author: mbenson
Date: Tue Jun 20 08:09:20 2006
New Revision: 415695

URL: http://svn.apache.org/viewvc?rev=415695&view=rev
Log:
add tempfile deleteOnExit.  PR# 39842.  Submitted by Patrick Martin (then slightly modified).

Modified:
    ant/core/trunk/CONTRIBUTORS
    ant/core/trunk/WHATSNEW
    ant/core/trunk/docs/manual/CoreTasks/tempfile.html
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/TempFile.java
    ant/core/trunk/src/main/org/apache/tools/ant/util/FileUtils.java

Modified: ant/core/trunk/CONTRIBUTORS
URL: http://svn.apache.org/viewvc/ant/core/trunk/CONTRIBUTORS?rev=415695&r1=415694&r2=415695&view=diff
==============================================================================
Binary files - no diff available.

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=415695&r1=415694&r2=415695&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Tue Jun 20 08:09:20 2006
@@ -434,6 +434,8 @@
 
 * 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
 ===================================
 

Modified: ant/core/trunk/docs/manual/CoreTasks/tempfile.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTasks/tempfile.html?rev=415695&r1=415694&r2=415695&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTasks/tempfile.html (original)
+++ ant/core/trunk/docs/manual/CoreTasks/tempfile.html Tue Jun 20 08:09:20 2006
@@ -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>

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/TempFile.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/TempFile.java?rev=415695&r1=415694&r2=415695&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/TempFile.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/TempFile.java Tue Jun 20 08:09:20
2006
@@ -62,6 +62,8 @@
      */
     private String suffix = "";
 
+    /** deleteOnExit flag */
+    private boolean deleteOnExit;
 
     /**
      * Sets the property you wish to assign the temporary file to.
@@ -104,6 +106,22 @@
         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 @@
         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());
     }
 }

Modified: ant/core/trunk/src/main/org/apache/tools/ant/util/FileUtils.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/FileUtils.java?rev=415695&r1=415694&r2=415695&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/FileUtils.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/FileUtils.java Tue Jun 20 08:09:20 2006
@@ -817,6 +817,34 @@
      * @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")
@@ -829,6 +857,9 @@
                                   prefix + fmt.format(Math.abs(rand.nextInt()))
                                   + suffix);
             } while (result.exists());
+        }
+        if (deleteOnExit) {
+            result.deleteOnExit();
         }
         return result;
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message