diff --git a/WHATSNEW b/WHATSNEW
index 55ef28963..4f7841a97 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -10,6 +10,9 @@ Other changes:
* rmic has been removed from Java 15. The task will now throw an
exception if you try to use it while running Java 15 or newer.
+ * a new property ant.tmpdir provides improved control over the
+ location Ant uses to create temporary files
+
Changes from Ant 1.9.13 TO Ant 1.9.14
=====================================
diff --git a/manual/Tasks/cab.html b/manual/Tasks/cab.html
index e981827a5..42312f53e 100644
--- a/manual/Tasks/cab.html
+++ b/manual/Tasks/cab.html
@@ -41,6 +41,10 @@ supports most attributes of <fileset>
(dir
becomes basedir
) as well as the nested
<include>
, <exclude>
and
<patternset>
elements.
On non-Unix platforms this task writes the list of files to archive + to the temporary directory.
+set to "true"
to make ant calculate the time difference between client and server.requires write access in the remote directory - Since ant 1.6 |
+ Since ant 1.6No | diff --git a/manual/Tasks/javadoc.html b/manual/Tasks/javadoc.html index 768b44243..fe9d8ef0d 100644 --- a/manual/Tasks/javadoc.html +++ b/manual/Tasks/javadoc.html @@ -451,7 +451,11 @@ to <javadoc> using classpath, classpathref attributes or the package names specified via the packagenames attribute or nested package elements. Since Ant 1.7.0, also applies to all the other command line options. - (all | No | diff --git a/manual/Tasks/replaceregexp.html b/manual/Tasks/replaceregexp.html index eed4c84c4..7a091de7c 100644 --- a/manual/Tasks/replaceregexp.html +++ b/manual/Tasks/replaceregexp.html @@ -31,7 +31,10 @@ in a selected file or set of files.
Attribute | diff --git a/manual/running.html b/manual/running.html index 3bfb500c8..b3815a7f9 100644 --- a/manual/running.html +++ b/manual/running.html @@ -490,6 +490,22 @@ org.apache.tools.ant.Executor implementation specified here.number, seconds since the epoch (midnight 1970-01-01) | The value to use as current time and date for <tstamp> |
java.io.tmpdir |
+ Some tasks need to create temporary files and will write them to
+ the directory specified by this property. This property is set by
+ the Java VM but can be overridden when Ant is started. + See also Temporary Directories. |
+
ant.tmpdir
java.io.tmpdir
if it has been
+ set. Unlike java.io.tmpdir
this property can be set
+ from within the build file.@@ -505,6 +521,36 @@ the return code of the java program. So a successful build returns 0, failed builds return other values.
+java.io.tmpdir
. The default value of it depends
+on the platform and the JVM implementation.
+
+Setting a system property when invoking Ant is not straight forward
+ as the corresponding command line arguments must be sent to the Java
+ executable rather than Ant's main class. When using
+ the ant(.cmd)
wrapper scripts you can do so with the
+ help of the ANT_OPTS
environment variable.
Starting with Ant 1.9.15 we've introduced a new Ant
+ property ant.tmpdir
that takes precedence
+ over java.io.tmpdir
when set. As this is a normal Ant
+ property it can be set via the command line or even from within a
+ build file.
Tasks and types using the temporary directory will state the fact + inside of their respective manual page. In addition every execution + of an external command on OpenVMS will create a temporary file + holding a DCL script that invokes the actual command.
+ +Tasks not provided with the Ant distribution will ignore
+ the ant.tmpdir
property and
+ use java.io.tmpdir
unless they have been adapted to the
+ changed API of Ant 1.9.15.
The Unix launch script that come with Ant works correctly with Cygwin. You
should not have any problems launching Ant from the Cygwin shell. It is
diff --git a/src/main/org/apache/tools/ant/MagicNames.java b/src/main/org/apache/tools/ant/MagicNames.java
index 7c17c05c5..d189654c5 100644
--- a/src/main/org/apache/tools/ant/MagicNames.java
+++ b/src/main/org/apache/tools/ant/MagicNames.java
@@ -302,5 +302,14 @@ public final class MagicNames {
* @since Ant 1.9.10
*/
public static final String TSTAMP_NOW = "ant.tstamp.now";
+
+ /**
+ * Magic property that can be set to override the java.io.tmpdir
+ * system property as the location for Ant's default temporary
+ * directory.
+ * Value: {@value}
+ * @since Ant 1.9.15
+ */
+ public static final String TMPDIR = "ant.tmpdir";
}
diff --git a/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java b/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java
index 01a71289a..290fe66a3 100644
--- a/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java
+++ b/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java
@@ -352,7 +352,7 @@ public class FixCRLF extends MatchingTask implements ChainableReader {
fcv = new Vector
- * The filename is prefixNNNNNsuffix where NNNN is a random number. - *
* - * @param prefix - * prefix before the random number. + * @param prefix file name prefix. * @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.7.1 use createTempFile(String, String, File, + * @deprecated since ant 1.7.1 use createTempFile(Project, String, String, File, * boolean, boolean) instead. * @return a File reference to the new, nonexistent temporary file. */ @@ -902,8 +899,6 @@ public class FileUtils { return createTempFile(prefix, suffix, parentDir, false, false); } - private static final String NULL_PLACEHOLDER = "null"; - /** * Create a temporary file in a given directory. * @@ -911,7 +906,7 @@ public class FileUtils { * exist before this method was invoked, any subsequent invocation * of this method will yield a different file name. * - * @param prefix prefix before the random number. + * @param prefix file name prefix. * @param suffix file extension; include the '.'. * @param parentDir Directory to create the temporary file in; * java.io.tmpdir used if not specified. @@ -924,13 +919,51 @@ public class FileUtils { * * @return a File reference to the new temporary file. * @since Ant 1.7.1 + * @deprecated since Ant 1.9.15 use createTempFile(Project, String, String, File, + * boolean, boolean) instead. */ public File createTempFile(String prefix, String suffix, File parentDir, boolean deleteOnExit, boolean createFile) { + return createTempFile(null, prefix, suffix, parentDir, deleteOnExit, createFile); + } + + private static final String NULL_PLACEHOLDER = "null"; + + /** + * Create a temporary file in a given directory. + * + *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.
+ * + * @param project reference to the current Ant project. + * @param prefix file name prefix. + * @param suffix file extension; include the '.'. + * @param parentDir Directory to create the temporary file in; + * if not specified and {@code project} is not null then the value + * of the property {@code ant.tmpdir} is used if set; + * otherwise {@code java.io.tmpdir} is used. + * @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.9.15 + */ + public File createTempFile(final Project project, String prefix, String suffix, + final File parentDir, final boolean deleteOnExit, final boolean createFile) { File result = null; - String parent = (parentDir == null) - ? System.getProperty("java.io.tmpdir") - : parentDir.getPath(); + final String parent; + if (parentDir != null) { + parent = parentDir.getPath(); + } else if (project != null && project.getProperty(MagicNames.TMPDIR) != null) { + parent = project.getProperty(MagicNames.TMPDIR); + } else { + parent = System.getProperty("java.io.tmpdir"); + } if (prefix == null) { prefix = NULL_PLACEHOLDER; } @@ -970,12 +1003,8 @@ public class FileUtils { * this method was invoked, any subsequent invocation of this method will * yield a different file name. * - *- * The filename is prefixNNNNNsuffix where NNNN is a random number. - *
* - * @param prefix - * prefix before the random number. + * @param prefix file name prefix. * @param suffix * file extension; include the '.'. * @param parentDir @@ -984,7 +1013,7 @@ public class FileUtils { * @param deleteOnExit * whether to set the tempfile for deletion on normal VM exit. * - * @deprecated since ant 1.7.1 use createTempFile(String, String, File, + * @deprecated since ant 1.7.1 use createTempFile(Project, String, String, File, * boolean, boolean) instead. * @return a File reference to the new, nonexistent temporary file. */ diff --git a/src/main/org/apache/tools/ant/util/JavaEnvUtils.java b/src/main/org/apache/tools/ant/util/JavaEnvUtils.java index d8a7bd873..060bb04a9 100644 --- a/src/main/org/apache/tools/ant/util/JavaEnvUtils.java +++ b/src/main/org/apache/tools/ant/util/JavaEnvUtils.java @@ -577,7 +577,7 @@ public final class JavaEnvUtils { */ public static File createVmsJavaOptionFile(String[] cmds) throws IOException { - File script = FILE_UTILS.createTempFile("ANT", ".JAVA_OPTS", null, false, true); + File script = FILE_UTILS.createTempFile(null, "ANT", ".JAVA_OPTS", null, false, true); BufferedWriter out = null; try { out = new BufferedWriter(new FileWriter(script)); diff --git a/src/main/org/apache/tools/ant/util/SymbolicLinkUtils.java b/src/main/org/apache/tools/ant/util/SymbolicLinkUtils.java index 20975dde7..26d25e651 100644 --- a/src/main/org/apache/tools/ant/util/SymbolicLinkUtils.java +++ b/src/main/org/apache/tools/ant/util/SymbolicLinkUtils.java @@ -23,6 +23,7 @@ import java.io.FilenameFilter; import java.io.IOException; import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; import org.apache.tools.ant.taskdefs.Execute; @@ -242,9 +243,9 @@ public class SymbolicLinkUtils { if (task == null || target.getParentFile().canWrite()) { // rename the resource, thus breaking the link: - final File temp = FILE_UTILS.createTempFile("symlink", ".tmp", - target.getParentFile(), false, - false); + final Project project = task == null ? null : task.getProject(); + final File temp = FILE_UTILS.createTempFile(project, "symlink", ".tmp", + target.getParentFile(), false, false); if (FILE_UTILS.isLeadingPath(target, link)) { // link points to a parent directory, renaming the parent diff --git a/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java b/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java index d82b7b694..9877e71ab 100644 --- a/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java +++ b/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java @@ -23,6 +23,7 @@ import java.io.FileOutputStream; import java.io.IOException; import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; import org.apache.tools.ant.taskdefs.condition.Os; import org.junit.After; import org.junit.Before; @@ -342,9 +343,16 @@ public class FileUtilsTest { */ @Test public void testCreateTempFile() { - // null parent dir - File tmp1 = FILE_UTILS.createTempFile("pre", ".suf", null, false, true); - String tmploc = System.getProperty("java.io.tmpdir"); + final String tmploc = System.getProperty("java.io.tmpdir"); + final Project projectWithoutTempDir = new Project(); + final Project projectWithTempDir = new Project(); + final File projectTmpDir = new File(tmploc, "subdir"); + projectTmpDir.mkdir(); + removeThis = projectTmpDir; + projectWithTempDir.setProperty("ant.tmpdir", projectTmpDir.getAbsolutePath()); + + // null parent dir, null project + File tmp1 = FILE_UTILS.createTempFile(null, "pre", ".suf", null, false, true); String name = tmp1.getName(); assertTrue("starts with pre", name.startsWith("pre")); assertTrue("ends with .suf", name.endsWith(".suf")); @@ -353,11 +361,30 @@ public class FileUtilsTest { .getAbsolutePath()); tmp1.delete(); + // null parent dir, project without magic property + tmp1 = FILE_UTILS.createTempFile(projectWithoutTempDir, "pre", ".suf", null, false, true); + 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(); + + // null parent dir, project with magic property + tmp1 = FILE_UTILS.createTempFile(projectWithTempDir, "pre", ".suf", null, false, true); + 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(projectTmpDir, 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); + File tmp2 = FILE_UTILS.createTempFile(null, "pre", ".suf", dir2, true, true); String name2 = tmp2.getName(); assertTrue("starts with pre", name2.startsWith("pre")); assertTrue("ends with .suf", name2.endsWith(".suf")); @@ -365,6 +392,24 @@ public class FileUtilsTest { assertEquals((new File(dir2, tmp2.getName())).getAbsolutePath(), tmp2 .getAbsolutePath()); tmp2.delete(); + + tmp2 = FILE_UTILS.createTempFile(projectWithoutTempDir, "pre", ".suf", dir2, true, true); + 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(); + + tmp2 = FILE_UTILS.createTempFile(projectWithTempDir, "pre", ".suf", dir2, true, true); + 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()); @@ -380,12 +425,6 @@ public class FileUtilsTest { tmp2 = FILE_UTILS.createTempFile("pre", ".suf", parent, false); assertTrue("files are different", !tmp1.getAbsolutePath().equals( tmp2.getAbsolutePath())); - - // null parent dir - File tmp3 = FILE_UTILS.createTempFile("pre", ".suf", null, false); - tmploc = System.getProperty("java.io.tmpdir"); - assertEquals((new File(tmploc, tmp3.getName())).getAbsolutePath(), tmp3 - .getAbsolutePath()); } /**