如果只能在监视目录中添加或更改文件,则可以使用antcontrib中的这个简单的OutOfDate任务.
<property name="watched-dir.flagfile"
location="MUST be not in watched dir"/>
<outofdate>
<sourcefiles>
<fileset dir="watched-dir"/>
</sourcefiles>
<targetfiles>
<pathelement location="${watched-dir.flagfile}"/>
</targetfiles>
<sequential>
<!--Tasks when something changes go here-->
<touch file="${watched-dir.flagfile}"/>
</sequential>
</outofdate>
Run Code Online (Sandbox Code Playgroud)
如果文件可以从watch-dir中消失,那么你有更复杂的问题,你可以通过创建监视目录的影子目录结构并检查它是否与watched-dir一致来解决.这个任务比较复杂,但我会给你一个脚本来创建一个影子目录,因为它不是直截了当的:
<property name="TALK" value="true"/>
<property name="shadow-dir"
location="MUST be not in watched dir"/>
<touch
mkdirs="true"
verbose="${TALK}"
>
<fileset dir="watched-dir">
<patterns/>
<type type="file"/>
</fileset>
<!-- That's the tricky globmapper to make touch task work -->
<globmapper from="*" to="${shadow-dir}/*"/>
</touch>
<!--
Due to how touch task with mapped fileset is implemented, it
truncates file access times down to a milliseconds, so if you
would have used outofdate task on shadow dir it would always
show that something is out of date.
Because of that, touching all files in ${shadow-dir} again fixes
that chicken and egg problem.
-->
<touch verbose="${TALK}">
<fileset dir="${shadow-dir}"/>
</touch>
Run Code Online (Sandbox Code Playgroud)
在创建了影子目录的情况下,我将把检查目录一致性的任务留给读者练习.
| 归档时间: |
|
| 查看次数: |
3326 次 |
| 最近记录: |