9

私には少し遠い話に聞こえますが、ディレクトリの変更を監視し、ディレクトリが変更されたときに特定のANTクラスを実行するためのANTタスクはありますか?

4

4 に答える 4

5

監視対象ディレクトリにのみファイルを追加または変更できる場合は、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>

ファイルがwatched-dirから消える可能性がある場合は、より複雑な問題があります。これは、watched 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>

シャドウディレクトリを作成したら、ディレクトリの整合性をチェックするタスクを読者の演習として残します。

于 2010-08-26T00:28:35.530 に答える
4

はい、これを行うAntタスクがあります。

https://github.com/chubbard/WatchTask

1.7以上が必要です。任意の数のファイルセットを監視し、元のファイルセットに応じて任意のターゲットを呼び出すことができます。

于 2014-03-05T02:14:07.080 に答える
1

Waitforあなたはあなたが望むことを達成するためにタスクを使うことができるかもしれません。1つ以上の条件(特定のファイルの存在など)が真になるまでブロックします。

于 2010-08-25T22:14:49.143 に答える
0

適用タスクをファイルセットセレクターと組み合わせることができます

<apply executable="somecommand" parallel="false">
  <srcfile/>
  <fileset dir="${watch.dir}">
    <modified/>
  </fileset>
</apply>

ファイルセットは、保存されているMD5チェックサムに対してファイルをチェックして変更を確認します。このチェックを繰り返し実行するには、ANTをループに入れる必要があります。これはUnixで簡単に行えます。

while true
> do
> ant
> sleep 300
> done
于 2010-08-26T21:26:31.430 に答える