在Ant中,我试图完成一个简单的任务:如果修改了几个文件,编译器应该运行.我见过很多使用OutOfDate,UpToDate和Modified的解决方案.我不想使用OutOfDate和UpToDate,因为如果文件在同一天被修改,我将无法使用该任务.我可以使用修改但是没有办法从修改器任务调用另一个任务 - 我的编译器任务.除了这些之外还有其他解决方案吗?
使用<uptodate>以下<antcall>条件<target>将为您提供所需的内容:
<project name="ant-uptodate" default="run-tests">
<tstamp>
<format property="ten.seconds.ago" offset="-10" unit="second"
pattern="MM/dd/yyyy hh:mm aa"/>
</tstamp>
<target name="uptodate-test">
<uptodate property="build.notRequired" targetfile="target-file.txt">
<srcfiles dir= "." includes="source-file.txt"/>
</uptodate>
<antcall target="do-compiler-conditionally"/>
</target>
<target name="do-compiler-conditionally" unless="build.notRequired">
<echo>Call compiler here.</echo>
</target>
<target name="source-older-than-target-test">
<touch file="source-file.txt" datetime="${ten.seconds.ago}"/>
<touch file="target-file.txt" datetime="now"/>
<antcall target="uptodate-test"/>
</target>
<target name="source-newer-than-target-test">
<touch file="target-file.txt" datetime="${ten.seconds.ago}"/>
<touch file="source-file.txt" datetime="now"/>
<antcall target="uptodate-test"/>
</target>
<target name="run-tests"
depends="source-older-than-target-test,source-newer-than-target-test"/>
</project>
Run Code Online (Sandbox Code Playgroud)