ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r608939 - in /ant/core/trunk/src: main/org/apache/tools/ant/taskdefs/ main/org/apache/tools/ant/taskdefs/compilers/ main/org/apache/tools/ant/taskdefs/cvslib/ main/org/apache/tools/ant/taskdefs/optional/ main/org/apache/tools/ant/taskdefs/o...
Date Fri, 04 Jan 2008 17:45:15 GMT
Author: jkf
Date: Fri Jan  4 09:45:12 2008
New Revision: 608939

URL: http://svn.apache.org/viewvc?rev=608939&view=rev
Log:
request from cactus team, backward incompatible change in FileUtils made backward compatible

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Execute.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Javadoc.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Replace.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/TempFile.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Zip.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/Cab.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/NetCommand.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java
    ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/modifiedselector/ModifiedSelector.java
    ant/core/trunk/src/main/org/apache/tools/ant/util/FileUtils.java
    ant/core/trunk/src/main/org/apache/tools/ant/util/JavaEnvUtils.java
    ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/ExecTaskTest.java
    ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/JavaTest.java
    ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java
    ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Execute.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Execute.java?rev=608939&r1=608938&r2=608939&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Execute.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Execute.java Fri Jan  4 09:45:12
2008
@@ -1190,8 +1190,7 @@
          */
         private File createCommandFile(String[] cmd, String[] env)
             throws IOException {
-            File script = FILE_UTILS.createTempFile("ANT", ".COM", null);
-            script.deleteOnExit();
+            File script = FILE_UTILS.createTempFile("ANT", ".COM", null, true, true);
             PrintWriter out = null;
             try {
                 out = new PrintWriter(new FileWriter(script));

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java?rev=608939&r1=608938&r2=608939&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java Fri Jan  4 09:45:12
2008
@@ -343,7 +343,7 @@
             fcv = new Vector(1);
             fcv.add(fc);
         }
-        File tmpFile = FILE_UTILS.createTempFileName("fixcrlf", "", null, true);
+        File tmpFile = FILE_UTILS.createTempFile("fixcrlf", "", null, true, false);
         try {
             FILE_UTILS.copyFile(srcFile, tmpFile, null, fcv, false, false,
                 encoding, outputEncoding == null ? encoding : outputEncoding,

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Javadoc.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Javadoc.java?rev=608939&r1=608938&r2=608939&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Javadoc.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Javadoc.java Fri Jan  4 09:45:12
2008
@@ -1694,8 +1694,7 @@
              * if requested.
              */
             if (useExternalFile) {
-                tmpList = FILE_UTILS.createTempFile("javadoc", "", null);
-                tmpList.deleteOnExit();
+                tmpList = FILE_UTILS.createTempFile("javadoc", "", null, true, true);
                 toExecute.createArgument()
                     .setValue("@" + tmpList.getAbsolutePath());
                 srcListWriter = new PrintWriter(
@@ -1882,8 +1881,7 @@
         PrintWriter optionsListWriter = null;
         try {
             optionsTmpFile = FILE_UTILS.createTempFile(
-                "javadocOptions", "", null);
-            optionsTmpFile.deleteOnExit();
+                "javadocOptions", "", null, true, true);
             String[] listOpt = toExecute.getArguments();
             toExecute.clearArgs();
             toExecute.createArgument().setValue(

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Replace.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Replace.java?rev=608939&r1=608938&r2=608939&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Replace.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Replace.java Fri Jan  4 09:45:12
2008
@@ -600,7 +600,7 @@
             in = new FileInput(src);
 
             temp = FILE_UTILS.createTempFile("rep", ".tmp",
-                    src.getParentFile());
+                    src.getParentFile(), false, true);
             out = new FileOutput(temp);
 
             int repCountStart = replaceCount;

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=608939&r1=608938&r2=608939&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 Fri Jan  4 09:45:12
2008
@@ -155,15 +155,8 @@
         if (destDir == null) {
             destDir = getProject().resolveFile(".");
         }
-        File tfile;
-        if (createFile) {
-            tfile = FILE_UTILS.createTempFile(prefix, suffix, destDir,
-                    deleteOnExit);
-        } else {
-            tfile = FILE_UTILS.createTempFileName(prefix, suffix, destDir,
-                    deleteOnExit);
-        }
-
+        File tfile = FILE_UTILS.createTempFile(prefix, suffix, destDir,
+                    deleteOnExit, createFile);
         getProject().setNewProperty(property, tfile.toString());
     }
 }

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Zip.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Zip.java?rev=608939&r1=608938&r2=608939&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Zip.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Zip.java Fri Jan  4 09:45:12 2008
@@ -579,8 +579,8 @@
 
     /** rename the zip file. */
     private File renameFile() {
-        File renamedFile = FILE_UTILS.createTempFileName(
-            "zip", ".tmp", zipFile.getParentFile(), true);
+        File renamedFile = FILE_UTILS.createTempFile(
+            "zip", ".tmp", zipFile.getParentFile(), true, false);
         try {
             FILE_UTILS.rename(zipFile, renamedFile);
         } catch (SecurityException e) {

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java?rev=608939&r1=608938&r2=608939&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java
Fri Jan  4 09:45:12 2008
@@ -466,8 +466,7 @@
                 PrintWriter out = null;
                 try {
                     tmpFile = FILE_UTILS.createTempFile(
-                        "files", "", getJavac().getTempdir());
-                    tmpFile.deleteOnExit();
+                        "files", "", getJavac().getTempdir(), true, true);
                     out = new PrintWriter(new FileWriter(tmpFile));
                     for (int i = firstFileName; i < args.length; i++) {
                         if (quoteFiles && args[i].indexOf(" ") > -1) {

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java?rev=608939&r1=608938&r2=608939&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java Fri Jan 
4 09:45:12 2008
@@ -224,8 +224,7 @@
         setCommand("");
         File tmpFile = null;
         try {
-            tmpFile = FILE_UTILS.createTempFile("cvstagdiff", ".log", null);
-            tmpFile.deleteOnExit();
+            tmpFile = FILE_UTILS.createTempFile("cvstagdiff", ".log", null, true, true);
             setOutput(tmpFile);
 
             // run the cvs command

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/Cab.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/Cab.java?rev=608939&r1=608938&r2=608939&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/Cab.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/Cab.java Fri Jan  4 09:45:12
2008
@@ -177,8 +177,7 @@
      */
     protected File createListFile(Vector files)
         throws IOException {
-        File listFile = FILE_UTILS.createTempFile("ant", "", null);
-        listFile.deleteOnExit();
+        File listFile = FILE_UTILS.createTempFile("ant", "", null, true, true);
 
         PrintWriter writer = new PrintWriter(new FileOutputStream(listFile));
 
@@ -314,8 +313,7 @@
                 exec.setDir(baseDir);
 
                 if (!doVerbose) {
-                    outFile = FILE_UTILS.createTempFile("ant", "", null);
-                    outFile.deleteOnExit();
+                    outFile = FILE_UTILS.createTempFile("ant", "", null, true, true);
                     exec.setOutput(outFile);
                 }
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java?rev=608939&r1=608938&r2=608939&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java Fri
Jan  4 09:45:12 2008
@@ -323,8 +323,7 @@
      */
     protected void doReplace(File f, int options)
          throws IOException {
-        File temp = FILE_UTILS.createTempFile("replace", ".txt", null);
-        temp.deleteOnExit();
+        File temp = FILE_UTILS.createTempFile("replace", ".txt", null, true, true);
 
         Reader r = null;
         Writer w = null;

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/NetCommand.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/NetCommand.java?rev=608939&r1=608938&r2=608939&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/NetCommand.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/NetCommand.java
Fri Jan  4 09:45:12 2008
@@ -346,7 +346,7 @@
             //afterwards
             FileOutputStream fos = null;
 
-            temporaryCommandFile = FILE_UTILS.createTempFile("cmd", ".txt", null);
+            temporaryCommandFile = FILE_UTILS.createTempFile("cmd", ".txt", null, false,
true);
             owner.log("Using response file " + temporaryCommandFile, Project.MSG_VERBOSE);
 
             try {

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java?rev=608939&r1=608938&r2=608939&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java Fri
Jan  4 09:45:12 2008
@@ -1145,7 +1145,7 @@
     private File createTempPropertiesFile(String prefix) {
         File propsFile =
             FILE_UTILS.createTempFile(prefix, ".properties",
-                tmpDir != null ? tmpDir : getProject().getBaseDir(), true);
+                tmpDir != null ? tmpDir : getProject().getBaseDir(), true, true);
         return propsFile;
     }
 

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=608939&r1=608938&r2=608939&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 Fri Jan  4
09:45:12 2008
@@ -1827,9 +1827,9 @@
         FTPFile [] theFiles = null;
         final int maxIterations = 1000;
         for (int counter = 1; counter < maxIterations; counter++) {
-            File localFile = FILE_UTILS.createTempFileName(
+            File localFile = FILE_UTILS.createTempFile(
                 "ant" + Integer.toString(counter), ".tmp",
-                null, false);
+                null, false, false);
             String fileName = localFile.getName();
             boolean found = false;
             try {

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java?rev=608939&r1=608938&r2=608939&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java Fri Jan
 4 09:45:12 2008
@@ -409,8 +409,8 @@
         File canfil = linkfil.getCanonicalFile();
 
         // rename the resource, thus breaking the link:
-        File temp = FILE_UTILS.createTempFileName("symlink", ".tmp",
-                                              canfil.getParentFile(), false);
+        File temp = FILE_UTILS.createTempFile("symlink", ".tmp",
+                                              canfil.getParentFile(), false, false);
         try {
             try {
                 FILE_UTILS.rename(canfil, temp);

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/modifiedselector/ModifiedSelector.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/modifiedselector/ModifiedSelector.java?rev=608939&r1=608938&r2=608939&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/modifiedselector/ModifiedSelector.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/modifiedselector/ModifiedSelector.java
Fri Jan  4 09:45:12 2008
@@ -449,7 +449,7 @@
                 // How to handle non-file-Resources? I copy temporarily the
                 // resource to a file and use the file-implementation.
                 FileUtils fu = FileUtils.getFileUtils();
-                File tmpFile = fu.createTempFileName("modified-", ".tmp", null, true);
+                File tmpFile = fu.createTempFile("modified-", ".tmp", null, true, false);
                 Resource tmpResource = new FileResource(tmpFile);
                 ResourceUtils.copyResource(resource, tmpResource);
                 boolean isSelected = isSelected(tmpFile.getParentFile(),

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=608939&r1=608938&r2=608939&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 Fri Jan  4 09:45:12 2008
@@ -784,24 +784,32 @@
     }
 
     /**
-     * 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>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.
-     *
-     * @return a File reference to the new temporary file.
-     * @since Ant 1.5
+     * 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.
+     *            
+     * @deprecated since ant 1.8 use createTempFile(String, String, File, 
+     * boolean, boolean) instead.
+     * @return a File reference to the new, nonexistent temporary file.
      */
     public File createTempFile(String prefix, String suffix, File parentDir) {
-        return createTempFile(prefix, suffix, parentDir, false);
+        return createTempFile(prefix, suffix, parentDir, false, false);
     }
 
     /**
@@ -811,29 +819,43 @@
      * exist before this method was invoked, any subsequent invocation
      * of this method will yield a different file name.</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.
+     * @param createFile true if the file must actually be created. If false
+     * chances exist that a file with the same name is created in the time
+     * between invoking this method and the moment the file is actually created.
+     * If possible set to true.
      *
      * @return a File reference to the new temporary file.
-     * @since Ant 1.7
+     * @since Ant 1.8
      */
     public File createTempFile(String prefix, String suffix, File parentDir,
-                               boolean deleteOnExit) {
+            boolean deleteOnExit, boolean createFile) {
         File result = null;
-        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);
+        String parent = (parentDir == null) ? System
+                .getProperty("java.io.tmpdir") : parentDir.getPath();
+
+        if (createFile) {
+            try {
+                result = File.createTempFile(prefix, suffix, new File(parent));
+            } catch (IOException e) {
+                throw new BuildException("Could not create tempfile in "
+                        + parent, e);
+            }
+        } else {
+            DecimalFormat fmt = new DecimalFormat("#####");
+            synchronized (rand) {
+                do {
+                    result = new File(parent, prefix
+                            + fmt.format(Math.abs(rand.nextInt())) + suffix);
+                } while (result.exists());
+            }
         }
+
         if (deleteOnExit) {
             result.deleteOnExit();
         }
@@ -843,41 +865,33 @@
     /**
      * 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 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.
-     *
+     * 
+     * @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.
+     *            
+     * @deprecated since ant 1.8 use createTempFile(String, String, File, 
+     * boolean, boolean) instead.
      * @return a File reference to the new, nonexistent temporary file.
-     * @since Ant 1.8
      */
-    public File createTempFileName(String prefix, String suffix,
+    public File createTempFile(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);
-            } while (result.exists());
-        }
-        if (deleteOnExit) {
-            result.deleteOnExit();
-        }
-        return result;
+        return createTempFile(prefix, suffix, parentDir, deleteOnExit, false);
     }
 
     /**

Modified: ant/core/trunk/src/main/org/apache/tools/ant/util/JavaEnvUtils.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/JavaEnvUtils.java?rev=608939&r1=608938&r2=608939&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/JavaEnvUtils.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/JavaEnvUtils.java Fri Jan  4 09:45:12
2008
@@ -440,7 +440,7 @@
      */
     public static File createVmsJavaOptionFile(String[] cmd)
             throws IOException {
-        File script = FILE_UTILS.createTempFile("ANT", ".JAVA_OPTS", null);
+        File script = FILE_UTILS.createTempFile("ANT", ".JAVA_OPTS", null, false, true);
         PrintWriter out = null;
         try {
             out = new PrintWriter(new BufferedWriter(new FileWriter(script)));

Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/ExecTaskTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/ExecTaskTest.java?rev=608939&r1=608938&r2=608939&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/ExecTaskTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/ExecTaskTest.java Fri Jan
 4 09:45:12 2008
@@ -347,7 +347,7 @@
             return;
         }
         myBuild = new MonitoredBuild(new File(System.getProperty("root"), BUILD_FILE), "spawn");
-        logFile = FILE_UTILS.createTempFileName("spawn","log", project.getBaseDir(), false);
+        logFile = FILE_UTILS.createTempFile("spawn","log", project.getBaseDir(), false, false);
         // this is guaranteed by FileUtils#createTempFile
         assertTrue("log file not existing", !logFile.exists());
         // make the spawned process run 4 seconds

Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/JavaTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/JavaTest.java?rev=608939&r1=608938&r2=608939&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/JavaTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/JavaTest.java Fri Jan  4
09:45:12 2008
@@ -175,7 +175,7 @@
     }
 
     public void testSpawn() {
-        File logFile = FILE_UTILS.createTempFileName("spawn","log", project.getBaseDir(),
false);
+        File logFile = FILE_UTILS.createTempFile("spawn","log", project.getBaseDir(), false,
false);
         // this is guaranteed by FileUtils#createTempFile
         assertTrue("log file not existing", !logFile.exists());
         project.setProperty("logFile", logFile.getAbsolutePath());

Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java?rev=608939&r1=608938&r2=608939&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java
(original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java
Fri Jan  4 09:45:12 2008
@@ -390,7 +390,7 @@
      * configure() method of ModifiedSelector. This testcase tests that.
      */
     public void testCreatePropertiesCacheViaCustomSelector() {
-        File cachefile = FILE_UTILS.createTempFileName("tmp-cache-", ".properties", null,
false);
+        File cachefile = FILE_UTILS.createTempFile("tmp-cache-", ".properties", null, false,
false);
         try {
             // initialize test environment (called "bed")
             makeBed();

Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java?rev=608939&r1=608938&r2=608939&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java Fri Jan  4
09:45:12 2008
@@ -342,55 +342,50 @@
      */
     public void testCreateTempFile()
     {
-    // null parent dir
-    File tmp1 = FILE_UTILS.createTempFile("pre", ".suf", null, false);
-    String  tmploc = System.getProperty("java.io.tmpdir");
-    String name = tmp1.getName();
-    assertTrue("starts with pre", name.startsWith("pre"));
-    assertTrue("ends with .suf", name.endsWith(".suf"));
-    assertTrue("File was created", tmp1.exists());
-    assertEquals((new File(tmploc, tmp1.getName())).getAbsolutePath(),
-                 tmp1.getAbsolutePath());
-    tmp1.delete();
-    
-    File dir2 = new File(tmploc+"/ant-test");
-    dir2.mkdir();
-    removeThis = dir2;
-    
-    File tmp2 = FILE_UTILS.createTempFile("pre", ".suf", dir2, true);
-    String name2 = tmp2.getName();
-    assertTrue("starts with pre", name2.startsWith("pre"));
-    assertTrue("ends with .suf", name2.endsWith(".suf"));
-    assertTrue("File was created", tmp2.exists());
-    assertEquals((new File(dir2, tmp2.getName())).getAbsolutePath(),
-                 tmp2.getAbsolutePath());
-    tmp2.delete();
-    dir2.delete();
-    }
-    /**
-     * Test createTempFileName
-     */
-    public void testCreateTempFileName() {
+        // null parent dir
+        File tmp1 = FILE_UTILS.createTempFile("pre", ".suf", null, false, true);
+        String tmploc = System.getProperty("java.io.tmpdir");
+        String name = tmp1.getName();
+        assertTrue("starts with pre", name.startsWith("pre"));
+        assertTrue("ends with .suf", name.endsWith(".suf"));
+        assertTrue("File was created", tmp1.exists());
+        assertEquals((new File(tmploc, tmp1.getName())).getAbsolutePath(), tmp1
+                .getAbsolutePath());
+        tmp1.delete();
+
+        File dir2 = new File(tmploc + "/ant-test");
+        dir2.mkdir();
+        removeThis = dir2;
+
+        File tmp2 = FILE_UTILS.createTempFile("pre", ".suf", dir2, true, true);
+        String name2 = tmp2.getName();
+        assertTrue("starts with pre", name2.startsWith("pre"));
+        assertTrue("ends with .suf", name2.endsWith(".suf"));
+        assertTrue("File was created", tmp2.exists());
+        assertEquals((new File(dir2, tmp2.getName())).getAbsolutePath(), tmp2
+                .getAbsolutePath());
+        tmp2.delete();
+        dir2.delete();
+
         File parent = new File((new File("/tmp")).getAbsolutePath());
-        File tmp1 = FILE_UTILS.createTempFileName("pre", ".suf", parent, false);
+        tmp1 = FILE_UTILS.createTempFile("pre", ".suf", parent, false);
         assertTrue("new file", !tmp1.exists());
 
-        String name = tmp1.getName();
+        name = tmp1.getName();
         assertTrue("starts with pre", name.startsWith("pre"));
         assertTrue("ends with .suf", name.endsWith(".suf"));
-        assertEquals("is inside parent dir",
-                     parent.getAbsolutePath(),
-                     tmp1.getParent());
-
-        File tmp2 = FILE_UTILS.createTempFileName("pre", ".suf", parent, false);
-        assertTrue("files are different",
-                   !tmp1.getAbsolutePath().equals(tmp2.getAbsolutePath()));
+        assertEquals("is inside parent dir", parent.getAbsolutePath(), tmp1
+                .getParent());
+
+        tmp2 = FILE_UTILS.createTempFile("pre", ".suf", parent, false);
+        assertTrue("files are different", !tmp1.getAbsolutePath().equals(
+                tmp2.getAbsolutePath()));
 
         // null parent dir
-        File tmp3 = FILE_UTILS.createTempFileName("pre", ".suf", null, false);
-        String  tmploc = System.getProperty("java.io.tmpdir");
-        assertEquals((new File(tmploc, tmp3.getName())).getAbsolutePath(),
-                     tmp3.getAbsolutePath());
+        File tmp3 = FILE_UTILS.createTempFile("pre", ".suf", null, false);
+        tmploc = System.getProperty("java.io.tmpdir");
+        assertEquals((new File(tmploc, tmp3.getName())).getAbsolutePath(), tmp3
+                .getAbsolutePath());
     }
 
     /**



Mime
View raw message