tempfileタスク覚書
はじめに
最初に結論を言うとこんな.
- タスクを実行には,ファイル名は決まるがファイルはできない.
- createfile="true"を指定すると,タスク実行時にファイルができる.
- ant終了時に一時ファイルを削除する場合はdeleteonexit="true"を指定する.
タスク実行時には,ファイル名は決まるがファイルはできない
以下のbuild.xmlをantで実行する.sleepしている間にファイルを確認しても一時ファイルはできていない.
<!-- build.xml -->
<project name="temp-file" default="default">
    <target name="default">
        <tempfile property="temp.file"/>
        <echo>${temp.file}</echo>
        <echo>sleep begin.</echo>
        <sleep seconds="5"/>
        <echo>sleep end.</echo>
    </target>       
</project>
$ ant &
[1] 1816
$ Buildfile: /usr/home/foo/test/build.xml
default:
     [echo] /usr/home/foo/test/null891780157
     [echo] sleep begin.
$ ls
build.xml
$ [echo] sleep end.
BUILD SUCCESSFUL
Total time: 5 seconds
[1]    終了                        ant
$ ls
build.xml
一時ファイルに何か出力するとファイルはできる(当たり前だが).
<!-- build.xml -->
<project name="temp-file" default="default">
    <target name="default">
        <tempfile property="temp.file"/>
        <echo>${temp.file}</echo>
        <echo file="${temp.file}">foo</echo>
    </target>
</project>
$ ls
build.xml   null877489431
$ cat null*
foo
タスク実行時にファイルを作る
以下のbuild.xmlをantで実行すると,タスク実行時にファイルができる.createfile="true"を指定している.
<!-- build.xml -->
<project name="temp-file" default="default">
    <target name="default">
        <tempfile property="temp.file" createfile="true"/>
        <echo>${temp.file}</echo>
    </target>       
</project>
$ ls
build.xml
$ ant
Buildfile: /usr/home/foo/test/build.xml
default:
    [echo] /usr/home/foo/test/null968399343
BUILD SUCCESSFUL
Total time: 0 seconds
$ ls
build.xml   null968399343
ant終了時に一時ファイルを削除
終了時に一時ファイルを削除する場合はdeleteonexit="true"を指定する.
<!-- build.xml -->
<project name="temp-file" default="default">
    <target name="default">
        <tempfile property="temp.file" deleteonexit="true"/>
        <echo>${temp.file}</echo>
        <echo file="${temp.file}">foo</echo>
    </target>       
</project>
$ ls
build.xml
$ ant
Buildfile: /usr/home/foo/test/build.xml
default:
    [echo] /usr/home/foo/test/null40491443
BUILD SUCCESSFUL
Total time: 0 seconds
$ ls
build.xml
実行環境
- ant 1.9.7
- FreeBSD 11.0