ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r574339 - in /ant/core/trunk: WHATSNEW docs/manual/CoreTasks/tempfile.html src/main/org/apache/tools/ant/taskdefs/TempFile.java src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java src/main/org/apache/tools/ant/util/FileUtils.java
Date Mon, 10 Sep 2007 19:15:27 GMT
Author: jkf
Date: Mon Sep 10 12:15:27 2007
New Revision: 574339

URL: http://svn.apache.org/viewvc?rev=574339&view=rev
Log:
pr33969: tempfile task / FileUtils.createTempFile now actually creates the file.

Modified:
    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/taskdefs/optional/net/FTP.java
    ant/core/trunk/src/main/org/apache/tools/ant/util/FileUtils.java

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=574339&r1=574338&r2=574339&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Mon Sep 10 12:15:27 2007
@@ -28,6 +28,11 @@
 * Remove fall-back mechanism for references that are not resolved
   during normal runtime execution.
 
+* FileUtils.createTempFile now actually creates the file.
+  The TempFile task still does not create the file by default, can be instructed
+  to do so however using a new parameter.
+  Bugzilla report 33969.
+  
 Fixed bugs:
 -----------
 

Modified: ant/core/trunk/docs/manual/CoreTasks/tempfile.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTasks/tempfile.html?rev=574339&r1=574338&r2=574339&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTasks/tempfile.html (original)
+++ ant/core/trunk/docs/manual/CoreTasks/tempfile.html Mon Sep 10 12:15:27 2007
@@ -144,7 +144,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="4">
+        <td bgcolor="#eeeeee" valign="top" align="left" rowspan="5">
           <font color="#000000" size="-1" face="arial,helvetica,sanserif">Optional</font>
         </td>
     </tr>
@@ -181,10 +181,21 @@
           <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>
+          <font color="#000000" size="-1" face="arial,helvetica,sanserif">boolean</font>
+        </td>
+    </tr>
+    <!-- Attribute -->
+    <tr>
+        <td bgcolor="#eeeeee" valign="top" align="left">
+          <font color="#000000" size="-1" face="arial,helvetica,sanserif">createfile</font>
+        </td>
+        <td bgcolor="#eeeeee" valign="top" align="left">
+          <font color="#000000" size="-1" face="arial,helvetica,sanserif">Whether the
temp file should be created by this task.<strong>Since Ant 1.8</strong></font>
+        </td>
+        <td bgcolor="#eeeeee" valign="top" align="left">
+          <font color="#000000" size="-1" face="arial,helvetica,sanserif">boolean</font>
         </td>
     </tr>
-
 
         </table>
       </blockquote></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=574339&r1=574338&r2=574339&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 Mon Sep 10 12:15:27
2007
@@ -65,6 +65,9 @@
 
     /** deleteOnExit flag */
     private boolean deleteOnExit;
+    
+    /** createFile flag */
+    private boolean createFile;
 
     /**
      * Sets the property you wish to assign the temporary file to.
@@ -123,6 +126,22 @@
     public boolean isDeleteOnExit() {
         return deleteOnExit;
     }
+    
+    /**
+     * If set the file is actually created, if not just a name is created.
+     * @param createFile boolean flag.
+     */
+    public void setCreateFile(boolean createFile) {
+        this.createFile = deleteOnExit;
+    }
+
+    /**
+     * Learn whether createFile flag is set for this tempfile task.
+     * @return the createFile flag.
+     */
+    public boolean isCreateFile() {
+        return createFile;
+    }
 
     /**
      * Creates the temporary file.
@@ -136,8 +155,14 @@
         if (destDir == null) {
             destDir = getProject().resolveFile(".");
         }
-        File tfile = FILE_UTILS.createTempFile(
-                prefix, suffix, destDir, deleteOnExit);
+        File tfile;
+        if (createFile) {
+            tfile = FILE_UTILS.createTempFile(prefix, suffix, destDir,
+                    deleteOnExit);
+        } else {
+            tfile = FILE_UTILS.createTempFileName(prefix, suffix, destDir,
+                    deleteOnExit);
+        }
 
         getProject().setNewProperty(property, tfile.toString());
     }

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java?rev=574339&r1=574338&r2=574339&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java Mon Sep 10
12:15:27 2007
@@ -1824,8 +1824,8 @@
         FTPFile [] theFiles = null;
         final int maxIterations = 1000;
         for (int counter = 1; counter < maxIterations; counter++) {
-            File localFile = FILE_UTILS.createTempFile("ant" + Integer.toString(counter),
".tmp",
-                null);
+            File localFile = FILE_UTILS.createTempFileName("ant" + Integer.toString(counter),
".tmp",
+                null, false);
             String fileName = localFile.getName();
             boolean found = false;
             try {

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=574339&r1=574338&r2=574339&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 Mon Sep 10 12:15:27 2007
@@ -786,12 +786,8 @@
      * <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>
+     *
+     * <p>As of ant 1.8 the file is actually created.</p>
      *
      * @param prefix prefix before the random number.
      * @param suffix file extension; include the '.'.
@@ -811,19 +807,15 @@
      * <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>
+     *
+     * <p>As of ant 1.8 the file is actually created.</p>
      *
      * @param prefix prefix before the random number.
      * @param suffix file extension; include the '.'.
      * @param parentDir Directory to create the temporary file in;
+     * java.io.tmpdir used if not specified.
      * @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
@@ -834,11 +826,51 @@
         String parent = (parentDir == null)
                 ? System.getProperty("java.io.tmpdir")
                 : parentDir.getPath();
+        
+        try {
+            result = File.createTempFile(prefix, suffix, new File(parent));
+        } catch (IOException e) {
+            throw new BuildException("Could not create tempfile in " + parent, e);
+        }
+        
+        if (deleteOnExit) {
+            result.deleteOnExit();
+        }
+        return result;
+    }
+    
+    /**
+     * Create a File object for a temporary file in a given directory. Without
+     * actually creating the file.
+     *
+     * <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>
+     *
+     * @param prefix prefix before the random number.
+     * @param suffix file extension; include the '.'.
+     * @param parentDir Directory to create the temporary file in;
+     * java.io.tmpdir used if not specified.
+     * @param deleteOnExit whether to set the tempfile for deletion on
+     *        normal VM exit.
+     *
+     * @return a File reference to the new, nonexistent temporary file.
+     * @since Ant 1.8
+     */
+    public File createTempFileName(String prefix, String suffix,
+            File parentDir, boolean deleteOnExit) {
+        File result = null;
+        String parent = (parentDir == null) ? System
+                .getProperty("java.io.tmpdir") : parentDir.getPath();
 
         DecimalFormat fmt = new DecimalFormat("#####");
         synchronized (rand) {
             do {
-                result = new File(parent, prefix + fmt.format(Math.abs(rand.nextInt())) +
suffix);
+                result = new File(parent, prefix
+                        + fmt.format(Math.abs(rand.nextInt())) + suffix);
             } while (result.exists());
         }
         if (deleteOnExit) {
@@ -846,6 +878,8 @@
         }
         return result;
     }
+    
+    
 
     /**
      * Compares the contents of two files.



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


Mime
View raw message