@@ -10,6 +10,9 @@ Other changes: | |||||
* rmic has been removed from Java 15. The task will now throw an | * 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. | 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 | Changes from Ant 1.9.13 TO Ant 1.9.14 | ||||
===================================== | ===================================== | ||||
@@ -41,6 +41,10 @@ supports most attributes of <code><fileset></code> | |||||
(<code>dir</code> becomes <code>basedir</code>) as well as the nested | (<code>dir</code> becomes <code>basedir</code>) as well as the nested | ||||
<code><include></code>, <code><exclude></code> and | <code><include></code>, <code><exclude></code> and | ||||
<code><patternset></code> elements.</p> | <code><patternset></code> elements.</p> | ||||
<p>On non-Unix platforms this task writes the list of files to archive | |||||
to the <a href="../running.html#tmpdir">temporary directory</a>.</p> | |||||
<h3>Parameters</h3> | <h3>Parameters</h3> | ||||
<table border="1" cellpadding="2" cellspacing="0"> | <table border="1" cellpadding="2" cellspacing="0"> | ||||
<tr> | <tr> | ||||
@@ -33,6 +33,8 @@ with the Unix version from cvshome.org, this is not completely true | |||||
for certain other cvs clients - like CVSNT for example - and some | for certain other cvs clients - like CVSNT for example - and some | ||||
operation may fail when using such an incompatible client. | operation may fail when using such an incompatible client. | ||||
</p> | </p> | ||||
<p>This task captures the output of the CVS command in a file inside of | |||||
the <a href="../running.html#tmpdir">temporary directory</a>.</p> | |||||
<h3>Parameters</h3> | <h3>Parameters</h3> | ||||
<table border="1" cellpadding="2" cellspacing="0"> | <table border="1" cellpadding="2" cellspacing="0"> | ||||
<tr> | <tr> | ||||
@@ -1613,6 +1613,9 @@ the ejbjar task (for example, basejarname, basenameterminator, and flatdestdir) | |||||
as well as the iplanet element (for example, suffix). Refer to the appropriate | as well as the iplanet element (for example, suffix). Refer to the appropriate | ||||
documentation for more details.</p> | documentation for more details.</p> | ||||
<p>This task creates a directory for scratch data inside of | |||||
the <a href="../running.html#tmpdir">temporary directory</a>.</p> | |||||
<h3> Parameters:</h3> | <h3> Parameters:</h3> | ||||
<table border="1" cellspacing="0" cellpadding="2"> | <table border="1" cellspacing="0" cellpadding="2"> | ||||
@@ -97,6 +97,8 @@ OpenJDK build instructions for cygwin</a>. | |||||
<code><arg></code> elements is executed exactly as specified | <code><arg></code> elements is executed exactly as specified | ||||
inside a temporary DCL script. This has some implications: | inside a temporary DCL script. This has some implications: | ||||
<ul> | <ul> | ||||
<li>the DCL script will be created inside | |||||
the <a href="../running.html#tmpdir">temporary directory</a>.</li> | |||||
<li>paths have to be written in VMS style</li> | <li>paths have to be written in VMS style</li> | ||||
<li>if your <code>executable</code> points to a DCL script remember to | <li>if your <code>executable</code> points to a DCL script remember to | ||||
prefix it with an <code>@</code>-sign | prefix it with an <code>@</code>-sign | ||||
@@ -58,7 +58,9 @@ | |||||
The output file is only written if it is a new file, or if it | The output file is only written if it is a new file, or if it | ||||
differs from the existing file. This prevents spurious | differs from the existing file. This prevents spurious | ||||
rebuilds based on unchanged files which have been regenerated | rebuilds based on unchanged files which have been regenerated | ||||
by this task. | |||||
by this task. In order to assess whether a file has changed, this | |||||
task will create a pre-processed version of the source file inside of | |||||
the <a href="../running.html#tmpdir">temporary directory</a>. | |||||
</p> | </p> | ||||
<p> | <p> | ||||
@@ -150,7 +150,12 @@ try to set up a new connection.</p> | |||||
<td valign="top">set to <code>"true"</code> | <td valign="top">set to <code>"true"</code> | ||||
to make ant calculate the time difference between client and server.<br> | to make ant calculate the time difference between client and server.<br> | ||||
<em>requires write access in the remote directory</em><br> | <em>requires write access in the remote directory</em><br> | ||||
Since ant 1.6</td> | |||||
Since ant 1.6<br/> | |||||
If this is set to <code>true</code> then Ant will create an empty | |||||
file inside of the <a href="../running.html#tmpdir">temporary | |||||
directory</a> and transfer it to the remote server - deleting it on | |||||
both sides once the difference has been determined. | |||||
</td> | |||||
<td valign="top" align="center">No</td> | <td valign="top" align="center">No</td> | ||||
</tr> | </tr> | ||||
<a name="timestampGranularity"/> | <a name="timestampGranularity"/> | ||||
@@ -451,7 +451,11 @@ to <javadoc> using <tt>classpath</tt>, <tt>classpathref</tt> attributes or | |||||
the package names specified via the packagenames attribute or | the package names specified via the packagenames attribute or | ||||
nested package elements. <em>Since Ant 1.7.0</em>, also applies | nested package elements. <em>Since Ant 1.7.0</em>, also applies | ||||
to all the other command line options. | to all the other command line options. | ||||
(<code>yes</code> | <code>no</code>). Default is no.</td> | |||||
(<code>yes</code> | <code>no</code>). Default is no.<br/> | |||||
If enabled, the file will be written to | |||||
the <a href="../running.html#tmpdir">temporary | |||||
directory</a>.</p> | |||||
</td> | |||||
<td align="center" valign="top">all</td> | <td align="center" valign="top">all</td> | ||||
<td valign="top" align="center">No</td> | <td valign="top" align="center">No</td> | ||||
</tr> | </tr> | ||||
@@ -31,7 +31,10 @@ in a selected file or set of files.</p> | |||||
<p>The output file is only written if it differs from the existing | <p>The output file is only written if it differs from the existing | ||||
file. This prevents spurious rebuilds based on unchanged files which | file. This prevents spurious rebuilds based on unchanged files which | ||||
have been regenerated by this task.</p> | |||||
have been regenerated by this task. In order to assess whether a file | |||||
has changed, this task will create a pre-processed version of the | |||||
source file inside of the <a href="../running.html#tmpdir">temporary | |||||
directory</a>.</p> | |||||
<p>Similar to <a href="../Types/mapper.html#regexp-mapper">regexp | <p>Similar to <a href="../Types/mapper.html#regexp-mapper">regexp | ||||
type mappers</a> this task needs a supporting regular expression | type mappers</a> this task needs a supporting regular expression | ||||
@@ -728,6 +728,10 @@ | |||||
to (<b>attention!</b>) copy the content into a local file for computing the | to (<b>attention!</b>) copy the content into a local file for computing the | ||||
hashvalue.</p> | hashvalue.</p> | ||||
<p>If the source resource is not a filesystem resource the | |||||
modified selector will download it to | |||||
the <a href="../running.html#tmpdir">temporary directory</a>.</p> | |||||
<table border="1" cellpadding="2" cellspacing="0"> | <table border="1" cellpadding="2" cellspacing="0"> | ||||
<tr> | <tr> | ||||
<td valign="top"><b>Attribute</b></td> | <td valign="top"><b>Attribute</b></td> | ||||
@@ -490,6 +490,22 @@ org.apache.tools.ant.Executor implementation specified here. | |||||
<td>number, seconds since the epoch (midnight 1970-01-01)</td> | <td>number, seconds since the epoch (midnight 1970-01-01)</td> | ||||
<td>The value to use as current time and date for <tstamp></td> | <td>The value to use as current time and date for <tstamp></td> | ||||
</tr> | </tr> | ||||
<tr> | |||||
<td><code>java.io.tmpdir</code></td> | |||||
<td>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.<br/> | |||||
See also <a href="#tmpdir">Temporary Directories</a>.</td> | |||||
</table> | |||||
<tr> | |||||
<td><code>ant.tmpdir</code></td> | |||||
<td><em>Since Ant 1.9.15</em><br/> | |||||
Some tasks need to create temporary files and will write them to | |||||
the directory specified by this property. This property takes | |||||
precedence over <code>java.io.tmpdir</code> if it has been | |||||
set. Unlike <code>java.io.tmpdir</code> this property can be set | |||||
from within the build file.<br/> | |||||
See also <a href="#tmpdir">Temporary Directories</a>.</td> | |||||
</table> | </table> | ||||
<p> | <p> | ||||
@@ -505,6 +521,36 @@ the return code of the java program. So a successful build returns 0, | |||||
failed builds return other values. | failed builds return other values. | ||||
</p> | </p> | ||||
<h2><a name="tmpdir">Temporary Directories</a></h2> | |||||
Some Ant tasks and types need to create temporary files. By default | |||||
they use the default temporary directory of the Java VM they are | |||||
running in - which can be set by setting the system | |||||
property <code>java.io.tmpdir</code>. The default value of it depends | |||||
on the platform and the JVM implementation.</p> | |||||
<p>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 <code>ant(.cmd)</code> wrapper scripts you can do so with the | |||||
help of the <code>ANT_OPTS</code> environment variable.</p> | |||||
<p>Starting with Ant 1.9.15 we've introduced a new Ant | |||||
property <code>ant.tmpdir</code> that takes precedence | |||||
over <code>java.io.tmpdir</code> when set. As this is a normal Ant | |||||
property it can be set via the command line or even from within a | |||||
build file.</p> | |||||
<p>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.</p> | |||||
<p>Tasks not provided with the Ant distribution will ignore | |||||
the <code>ant.tmpdir</code> property and | |||||
use <code>java.io.tmpdir</code> unless they have been adapted to the | |||||
changed API of Ant 1.9.15.</p> | |||||
<h2><a name="cygwin">Cygwin Users</a></h2> | <h2><a name="cygwin">Cygwin Users</a></h2> | ||||
<p>The Unix launch script that come with Ant works correctly with Cygwin. You | <p>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 | should not have any problems launching Ant from the Cygwin shell. It is | ||||
@@ -302,5 +302,14 @@ public final class MagicNames { | |||||
* @since Ant 1.9.10 | * @since Ant 1.9.10 | ||||
*/ | */ | ||||
public static final String TSTAMP_NOW = "ant.tstamp.now"; | 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"; | |||||
} | } | ||||
@@ -352,7 +352,7 @@ public class FixCRLF extends MatchingTask implements ChainableReader { | |||||
fcv = new Vector<FilterChain>(1); | fcv = new Vector<FilterChain>(1); | ||||
fcv.add(fc); | fcv.add(fc); | ||||
} | } | ||||
File tmpFile = FILE_UTILS.createTempFile("fixcrlf", "", null, true, true); | |||||
File tmpFile = FILE_UTILS.createTempFile(getProject(), "fixcrlf", "", null, true, true); | |||||
try { | try { | ||||
FILE_UTILS.copyFile(srcFile, tmpFile, null, fcv, true, false, | FILE_UTILS.copyFile(srcFile, tmpFile, null, fcv, true, false, | ||||
encoding, outputEncoding == null ? encoding : outputEncoding, | encoding, outputEncoding == null ? encoding : outputEncoding, | ||||
@@ -1880,7 +1880,7 @@ public class Javadoc extends Task { | |||||
*/ | */ | ||||
BufferedWriter srcListWriter = null; | BufferedWriter srcListWriter = null; | ||||
if (useExternalFile) { | if (useExternalFile) { | ||||
tmpList = FILE_UTILS.createTempFile("javadoc", "", null, true, true); | |||||
tmpList = FILE_UTILS.createTempFile(getProject(), "javadoc", "", null, true, true); | |||||
toExecute.createArgument() | toExecute.createArgument() | ||||
.setValue("@" + tmpList.getAbsolutePath()); | .setValue("@" + tmpList.getAbsolutePath()); | ||||
wr = new FileWriter(tmpList.getAbsolutePath(), true); | wr = new FileWriter(tmpList.getAbsolutePath(), true); | ||||
@@ -2065,7 +2065,7 @@ public class Javadoc extends Task { | |||||
BufferedWriter optionsListWriter = null; | BufferedWriter optionsListWriter = null; | ||||
try { | try { | ||||
optionsTmpFile = FILE_UTILS.createTempFile( | optionsTmpFile = FILE_UTILS.createTempFile( | ||||
"javadocOptions", "", null, true, true); | |||||
getProject(), "javadocOptions", "", null, true, true); | |||||
final String[] listOpt = toExecute.getArguments(); | final String[] listOpt = toExecute.getArguments(); | ||||
toExecute.clearArgs(); | toExecute.clearArgs(); | ||||
toExecute.createArgument().setValue( | toExecute.createArgument().setValue( | ||||
@@ -87,7 +87,7 @@ public class Jikes { | |||||
&& args.length > MAX_FILES_ON_COMMAND_LINE) { | && args.length > MAX_FILES_ON_COMMAND_LINE) { | ||||
BufferedWriter out = null; | BufferedWriter out = null; | ||||
try { | try { | ||||
tmpFile = FileUtils.getFileUtils().createTempFile("jikes", | |||||
tmpFile = FileUtils.getFileUtils().createTempFile(project, "jikes", | |||||
"tmp", null, false, true); | "tmp", null, false, true); | ||||
out = new BufferedWriter(new FileWriter(tmpFile)); | out = new BufferedWriter(new FileWriter(tmpFile)); | ||||
for (String arg : args) { | for (String arg : args) { | ||||
@@ -665,7 +665,7 @@ public class Replace extends MatchingTask { | |||||
logFilterChain(src.getPath()); | logFilterChain(src.getPath()); | ||||
try { | try { | ||||
File temp = FILE_UTILS.createTempFile("rep", ".tmp", | |||||
File temp = FILE_UTILS.createTempFile(getProject(), "rep", ".tmp", | |||||
src.getParentFile(), false, true); | src.getParentFile(), false, true); | ||||
try { | try { | ||||
FileInput in = new FileInput(src); | FileInput in = new FileInput(src); | ||||
@@ -156,7 +156,7 @@ public class TempFile extends Task { | |||||
if (destDir == null) { | if (destDir == null) { | ||||
destDir = getProject().resolveFile("."); | destDir = getProject().resolveFile("."); | ||||
} | } | ||||
File tfile = FILE_UTILS.createTempFile(prefix, suffix, destDir, | |||||
File tfile = FILE_UTILS.createTempFile(getProject(), prefix, suffix, destDir, | |||||
deleteOnExit, createFile); | deleteOnExit, createFile); | ||||
getProject().setNewProperty(property, tfile.toString()); | getProject().setNewProperty(property, tfile.toString()); | ||||
} | } | ||||
@@ -819,7 +819,7 @@ public class Zip extends MatchingTask { | |||||
/** rename the zip file. */ | /** rename the zip file. */ | ||||
private File renameFile() { | private File renameFile() { | ||||
final File renamedFile = FILE_UTILS.createTempFile( | final File renamedFile = FILE_UTILS.createTempFile( | ||||
"zip", ".tmp", zipFile.getParentFile(), true, false); | |||||
getProject(), "zip", ".tmp", zipFile.getParentFile(), true, false); | |||||
try { | try { | ||||
FILE_UTILS.rename(zipFile, renamedFile); | FILE_UTILS.rename(zipFile, renamedFile); | ||||
} catch (final SecurityException e) { | } catch (final SecurityException e) { | ||||
@@ -556,7 +556,7 @@ public abstract class DefaultCompilerAdapter | |||||
BufferedWriter out = null; | BufferedWriter out = null; | ||||
try { | try { | ||||
tmpFile = FILE_UTILS.createTempFile( | tmpFile = FILE_UTILS.createTempFile( | ||||
"files", "", getJavac().getTempdir(), true, true); | |||||
getProject(), "files", "", getJavac().getTempdir(), true, true); | |||||
out = new BufferedWriter(new FileWriter(tmpFile)); | out = new BufferedWriter(new FileWriter(tmpFile)); | ||||
for (int i = firstFileName; i < args.length; i++) { | for (int i = firstFileName; i < args.length; i++) { | ||||
if (quoteFiles && args[i].contains(" ")) { | if (quoteFiles && args[i].contains(" ")) { | ||||
@@ -263,7 +263,7 @@ public class CvsTagDiff extends AbstractCvsTask { | |||||
try { | try { | ||||
handlePackageNames(); | handlePackageNames(); | ||||
tmpFile = FILE_UTILS.createTempFile("cvstagdiff", ".log", null, | |||||
tmpFile = FILE_UTILS.createTempFile(getProject(), "cvstagdiff", ".log", null, | |||||
true, true); | true, true); | ||||
setOutput(tmpFile); | setOutput(tmpFile); | ||||
@@ -52,7 +52,7 @@ public class VmsCommandLauncher extends Java13CommandLauncher { | |||||
@Override | @Override | ||||
public Process exec(Project project, String[] cmd, String[] env) | public Process exec(Project project, String[] cmd, String[] env) | ||||
throws IOException { | throws IOException { | ||||
File cmdFile = createCommandFile(cmd, env); | |||||
File cmdFile = createCommandFile(project, cmd, env); | |||||
Process p = super.exec(project, new String[] {cmdFile.getPath()}, env); | Process p = super.exec(project, new String[] {cmdFile.getPath()}, env); | ||||
deleteAfter(cmdFile, p); | deleteAfter(cmdFile, p); | ||||
return p; | return p; | ||||
@@ -79,7 +79,7 @@ public class VmsCommandLauncher extends Java13CommandLauncher { | |||||
@Override | @Override | ||||
public Process exec(Project project, String[] cmd, String[] env, | public Process exec(Project project, String[] cmd, String[] env, | ||||
File workingDir) throws IOException { | File workingDir) throws IOException { | ||||
File cmdFile = createCommandFile(cmd, env); | |||||
File cmdFile = createCommandFile(project, cmd, env); | |||||
Process p = super.exec(project, new String[] {cmdFile.getPath()}, env, workingDir); | Process p = super.exec(project, new String[] {cmdFile.getPath()}, env, workingDir); | ||||
deleteAfter(cmdFile, p); | deleteAfter(cmdFile, p); | ||||
return p; | return p; | ||||
@@ -93,9 +93,9 @@ public class VmsCommandLauncher extends Java13CommandLauncher { | |||||
* @return the command File. | * @return the command File. | ||||
* @throws IOException if errors are encountered creating the file. | * @throws IOException if errors are encountered creating the file. | ||||
*/ | */ | ||||
private File createCommandFile(String[] cmd, String[] env) | |||||
private File createCommandFile(final Project project, String[] cmd, String[] env) | |||||
throws IOException { | throws IOException { | ||||
File script = FILE_UTILS.createTempFile("ANT", ".COM", null, true, true); | |||||
File script = FILE_UTILS.createTempFile(project, "ANT", ".COM", null, true, true); | |||||
BufferedWriter out = null; | BufferedWriter out = null; | ||||
try { | try { | ||||
out = new BufferedWriter(new FileWriter(script)); | out = new BufferedWriter(new FileWriter(script)); | ||||
@@ -140,4 +140,4 @@ public class VmsCommandLauncher extends Java13CommandLauncher { | |||||
} | } | ||||
}.start(); | }.start(); | ||||
} | } | ||||
} | |||||
} |
@@ -179,7 +179,7 @@ public class Cab extends MatchingTask { | |||||
*/ | */ | ||||
protected File createListFile(Vector files) | protected File createListFile(Vector files) | ||||
throws IOException { | throws IOException { | ||||
File listFile = FILE_UTILS.createTempFile("ant", "", null, true, true); | |||||
File listFile = FILE_UTILS.createTempFile(getProject(), "ant", "", null, true, true); | |||||
BufferedWriter writer = null; | BufferedWriter writer = null; | ||||
try { | try { | ||||
@@ -319,7 +319,7 @@ public class Cab extends MatchingTask { | |||||
exec.setDir(baseDir); | exec.setDir(baseDir); | ||||
if (!doVerbose) { | if (!doVerbose) { | ||||
outFile = FILE_UTILS.createTempFile("ant", "", null, true, true); | |||||
outFile = FILE_UTILS.createTempFile(getProject(), "ant", "", null, true, true); | |||||
exec.setOutput(outFile); | exec.setOutput(outFile); | ||||
} | } | ||||
@@ -360,7 +360,7 @@ public class ReplaceRegExp extends Task { | |||||
*/ | */ | ||||
protected void doReplace(File f, int options) | protected void doReplace(File f, int options) | ||||
throws IOException { | throws IOException { | ||||
File temp = FILE_UTILS.createTempFile("replace", ".txt", null, true, true); | |||||
File temp = FILE_UTILS.createTempFile(getProject(), "replace", ".txt", null, true, true); | |||||
try { | try { | ||||
boolean changes = false; | boolean changes = false; | ||||
@@ -1453,7 +1453,7 @@ public class JUnitTask extends Task { | |||||
*/ | */ | ||||
private File createTempPropertiesFile(final String prefix) { | private File createTempPropertiesFile(final String prefix) { | ||||
final File propsFile = | final File propsFile = | ||||
FILE_UTILS.createTempFile(prefix, ".properties", | |||||
FILE_UTILS.createTempFile(getProject(), prefix, ".properties", | |||||
tmpDir != null ? tmpDir : getProject().getBaseDir(), true, true); | tmpDir != null ? tmpDir : getProject().getBaseDir(), true, true); | ||||
return propsFile; | return propsFile; | ||||
} | } | ||||
@@ -1977,7 +1977,7 @@ public class FTP extends Task implements FTPTaskConfig { | |||||
FTPFile[] files = null; | FTPFile[] files = null; | ||||
final int maxIterations = 1000; | final int maxIterations = 1000; | ||||
for (int counter = 1; counter < maxIterations; counter++) { | for (int counter = 1; counter < maxIterations; counter++) { | ||||
File localFile = FILE_UTILS.createTempFile( | |||||
File localFile = FILE_UTILS.createTempFile(getProject(), | |||||
"ant" + Integer.toString(counter), ".tmp", | "ant" + Integer.toString(counter), ".tmp", | ||||
null, false, false); | null, false, false); | ||||
String fileName = localFile.getName(); | String fileName = localFile.getName(); | ||||
@@ -1366,7 +1366,7 @@ public class FTPTaskMirrorImpl implements FTPTaskMirror { | |||||
FTPFile[] files = null; | FTPFile[] files = null; | ||||
final int maxIterations = 1000; | final int maxIterations = 1000; | ||||
for (int counter = 1; counter < maxIterations; counter++) { | for (int counter = 1; counter < maxIterations; counter++) { | ||||
File localFile = FILE_UTILS.createTempFile( | |||||
File localFile = FILE_UTILS.createTempFile(task.getProject(), | |||||
"ant" + Integer.toString(counter), ".tmp", | "ant" + Integer.toString(counter), ".tmp", | ||||
null, false, false); | null, false, false); | ||||
String fileName = localFile.getName(); | String fileName = localFile.getName(); | ||||
@@ -449,7 +449,7 @@ public class ModifiedSelector extends BaseExtendSelector | |||||
// How to handle non-file-Resources? I copy temporarily the | // How to handle non-file-Resources? I copy temporarily the | ||||
// resource to a file and use the file-implementation. | // resource to a file and use the file-implementation. | ||||
FileUtils fu = FileUtils.getFileUtils(); | FileUtils fu = FileUtils.getFileUtils(); | ||||
File tmpFile = fu.createTempFile("modified-", ".tmp", null, true, false); | |||||
File tmpFile = fu.createTempFile(getProject(), "modified-", ".tmp", null, true, false); | |||||
Resource tmpResource = new FileResource(tmpFile); | Resource tmpResource = new FileResource(tmpFile); | ||||
ResourceUtils.copyResource(resource, tmpResource); | ResourceUtils.copyResource(resource, tmpResource); | ||||
boolean isSelected = isSelected(tmpFile.getParentFile(), | boolean isSelected = isSelected(tmpFile.getParentFile(), | ||||
@@ -43,6 +43,7 @@ import java.util.Vector; | |||||
import java.util.jar.JarFile; | import java.util.jar.JarFile; | ||||
import org.apache.tools.ant.BuildException; | import org.apache.tools.ant.BuildException; | ||||
import org.apache.tools.ant.MagicNames; | |||||
import org.apache.tools.ant.PathTokenizer; | import org.apache.tools.ant.PathTokenizer; | ||||
import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
import org.apache.tools.ant.launch.Locator; | import org.apache.tools.ant.launch.Locator; | ||||
@@ -882,19 +883,15 @@ public class FileUtils { | |||||
* this method was invoked, any subsequent invocation of this method will | * this method was invoked, any subsequent invocation of this method will | ||||
* yield a different file name. | * yield a different file name. | ||||
* </p> | * </p> | ||||
* <p> | |||||
* The filename is prefixNNNNNsuffix where NNNN is a random number. | |||||
* </p> | |||||
* | * | ||||
* @param prefix | |||||
* prefix before the random number. | |||||
* @param prefix file name prefix. | |||||
* @param suffix | * @param suffix | ||||
* file extension; include the '.'. | * file extension; include the '.'. | ||||
* @param parentDir | * @param parentDir | ||||
* Directory to create the temporary file in; java.io.tmpdir used | * Directory to create the temporary file in; java.io.tmpdir used | ||||
* if not specified. | * 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. | * boolean, boolean) instead. | ||||
* @return a File reference to the new, nonexistent temporary file. | * @return a File reference to the new, nonexistent temporary file. | ||||
*/ | */ | ||||
@@ -902,8 +899,6 @@ public class FileUtils { | |||||
return createTempFile(prefix, suffix, parentDir, false, false); | return createTempFile(prefix, suffix, parentDir, false, false); | ||||
} | } | ||||
private static final String NULL_PLACEHOLDER = "null"; | |||||
/** | /** | ||||
* Create a temporary file in a given directory. | * Create a temporary file in a given directory. | ||||
* | * | ||||
@@ -911,7 +906,7 @@ public class FileUtils { | |||||
* exist before this method was invoked, any subsequent invocation | * exist before this method was invoked, any subsequent invocation | ||||
* of this method will yield a different file name.</p> | * of this method will yield a different file name.</p> | ||||
* | * | ||||
* @param prefix prefix before the random number. | |||||
* @param prefix file name prefix. | |||||
* @param suffix file extension; include the '.'. | * @param suffix file extension; include the '.'. | ||||
* @param parentDir Directory to create the temporary file in; | * @param parentDir Directory to create the temporary file in; | ||||
* java.io.tmpdir used if not specified. | * java.io.tmpdir used if not specified. | ||||
@@ -924,13 +919,51 @@ public class FileUtils { | |||||
* | * | ||||
* @return a File reference to the new temporary file. | * @return a File reference to the new temporary file. | ||||
* @since Ant 1.7.1 | * @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, | public File createTempFile(String prefix, String suffix, File parentDir, | ||||
boolean deleteOnExit, boolean createFile) { | 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. | |||||
* | |||||
* <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> | |||||
* | |||||
* @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; | 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) { | if (prefix == null) { | ||||
prefix = NULL_PLACEHOLDER; | prefix = NULL_PLACEHOLDER; | ||||
} | } | ||||
@@ -970,12 +1003,8 @@ public class FileUtils { | |||||
* this method was invoked, any subsequent invocation of this method will | * this method was invoked, any subsequent invocation of this method will | ||||
* yield a different file name. | * yield a different file name. | ||||
* </p> | * </p> | ||||
* <p> | |||||
* The filename is prefixNNNNNsuffix where NNNN is a random number. | |||||
* </p> | |||||
* | * | ||||
* @param prefix | |||||
* prefix before the random number. | |||||
* @param prefix file name prefix. | |||||
* @param suffix | * @param suffix | ||||
* file extension; include the '.'. | * file extension; include the '.'. | ||||
* @param parentDir | * @param parentDir | ||||
@@ -984,7 +1013,7 @@ public class FileUtils { | |||||
* @param deleteOnExit | * @param deleteOnExit | ||||
* whether to set the tempfile for deletion on normal VM exit. | * 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. | * boolean, boolean) instead. | ||||
* @return a File reference to the new, nonexistent temporary file. | * @return a File reference to the new, nonexistent temporary file. | ||||
*/ | */ | ||||
@@ -577,7 +577,7 @@ public final class JavaEnvUtils { | |||||
*/ | */ | ||||
public static File createVmsJavaOptionFile(String[] cmds) | public static File createVmsJavaOptionFile(String[] cmds) | ||||
throws IOException { | 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; | BufferedWriter out = null; | ||||
try { | try { | ||||
out = new BufferedWriter(new FileWriter(script)); | out = new BufferedWriter(new FileWriter(script)); | ||||
@@ -23,6 +23,7 @@ import java.io.FilenameFilter; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import org.apache.tools.ant.BuildException; | import org.apache.tools.ant.BuildException; | ||||
import org.apache.tools.ant.Project; | |||||
import org.apache.tools.ant.Task; | import org.apache.tools.ant.Task; | ||||
import org.apache.tools.ant.taskdefs.Execute; | import org.apache.tools.ant.taskdefs.Execute; | ||||
@@ -242,9 +243,9 @@ public class SymbolicLinkUtils { | |||||
if (task == null || target.getParentFile().canWrite()) { | if (task == null || target.getParentFile().canWrite()) { | ||||
// rename the resource, thus breaking the link: | // 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)) { | if (FILE_UTILS.isLeadingPath(target, link)) { | ||||
// link points to a parent directory, renaming the parent | // link points to a parent directory, renaming the parent | ||||
@@ -23,6 +23,7 @@ import java.io.FileOutputStream; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import org.apache.tools.ant.BuildException; | import org.apache.tools.ant.BuildException; | ||||
import org.apache.tools.ant.Project; | |||||
import org.apache.tools.ant.taskdefs.condition.Os; | import org.apache.tools.ant.taskdefs.condition.Os; | ||||
import org.junit.After; | import org.junit.After; | ||||
import org.junit.Before; | import org.junit.Before; | ||||
@@ -342,9 +343,16 @@ public class FileUtilsTest { | |||||
*/ | */ | ||||
@Test | @Test | ||||
public void testCreateTempFile() { | 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(); | String name = tmp1.getName(); | ||||
assertTrue("starts with pre", name.startsWith("pre")); | assertTrue("starts with pre", name.startsWith("pre")); | ||||
assertTrue("ends with .suf", name.endsWith(".suf")); | assertTrue("ends with .suf", name.endsWith(".suf")); | ||||
@@ -353,11 +361,30 @@ public class FileUtilsTest { | |||||
.getAbsolutePath()); | .getAbsolutePath()); | ||||
tmp1.delete(); | 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"); | File dir2 = new File(tmploc + "/ant-test"); | ||||
dir2.mkdir(); | 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(); | String name2 = tmp2.getName(); | ||||
assertTrue("starts with pre", name2.startsWith("pre")); | assertTrue("starts with pre", name2.startsWith("pre")); | ||||
assertTrue("ends with .suf", name2.endsWith(".suf")); | assertTrue("ends with .suf", name2.endsWith(".suf")); | ||||
@@ -365,6 +392,24 @@ public class FileUtilsTest { | |||||
assertEquals((new File(dir2, tmp2.getName())).getAbsolutePath(), tmp2 | assertEquals((new File(dir2, tmp2.getName())).getAbsolutePath(), tmp2 | ||||
.getAbsolutePath()); | .getAbsolutePath()); | ||||
tmp2.delete(); | 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(); | dir2.delete(); | ||||
File parent = new File((new File("/tmp")).getAbsolutePath()); | File parent = new File((new File("/tmp")).getAbsolutePath()); | ||||
@@ -380,12 +425,6 @@ public class FileUtilsTest { | |||||
tmp2 = FILE_UTILS.createTempFile("pre", ".suf", parent, false); | tmp2 = FILE_UTILS.createTempFile("pre", ".suf", parent, false); | ||||
assertTrue("files are different", !tmp1.getAbsolutePath().equals( | assertTrue("files are different", !tmp1.getAbsolutePath().equals( | ||||
tmp2.getAbsolutePath())); | 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()); | |||||
} | } | ||||
/** | /** | ||||