Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create temporary directory in ant?

Tags:

ant

I'd like to create a temporary directory in ant (version 1.6.5) and assign it to a property.

  • The command "mktemp -d" would be ideal for this, but I cannot find similar functionality from inside ant
  • I can't find any official function in the docs apart from the tempfile task which apparently only creates files, not directories.
  • I'm considering using exec to call tempfile and get the result, however this will make my build.xml dependent on UNIX/linux, which I'd like to avoid.

Background: I'm trying to speed up an existing build process which builds inside networked filesystem. The build already copies all the source to a temporary directory, however this is on the same filesystem. I've tested changing this to /tmp/foo and it gives a worthwhile speed increase: 3mins vs 4mins.

like image 254
Adam Avatar asked May 24 '12 09:05

Adam


1 Answers

You could combine the tempfile task with the java.io.tmpdir system property to get a file path to use to create a temporary dir:

<project default="test">

    <target name="test">
        <echo>${java.io.tmpdir}</echo>
        <tempfile property="temp.file" destDir="${java.io.tmpdir}" prefix="build"/>
        <echo>${temp.file}</echo>
    </target>

</project>

Note that the tempfile task does not create the file (unless you ask it to). It just sets a property which you can use to create a file or dir.

This task sets a property to the name of a temporary file. Unlike java.io.File.createTempFile, this task does not actually create the temporary file, but it does guarantee that the file did not exist when the task was executed.

Output in my environment:

test:
     [echo] C:\Users\sudocode\AppData\Local\Temp\
     [echo] C:\Users\sudocode\AppData\Local\Temp\build1749402932
like image 134
sudocode Avatar answered Sep 28 '22 03:09

sudocode