BusyB: The WhenFilesChange Trigger


Introduction

News

Reference

Installation

Quick Start

Download

The <whenFileChange> trigger is the most complex BusyB trigger, but it is well worth the effort. This trigger will periodically scan a directory tree and fire a build if any of the files in that tree have changed since the last build.

Here's an example:

<project>

    <whenFilesChange>
        <interval>60</interval>
        <dir>/usr/home/program1/src</dir>
    </whenFilesChange>

    <build>
      ... build sub elements...
    </build>

</project>

The example above tells BusyB to check all of the files under the directory /home/fred/src and trigger a build if any of the files have changed since the last build.

You can specify more than one <dir> -- BusyB will look for changes in all the directories and fire a build if any file in any directory has changed. You can also specify a “grace” period in seconds – BusyB will simply wait that long after noticing a change before actually doing the build. This is handy for giving whoever or whatever is making the change a chance to finish.

Here is a more complex example with two directories and a two minute grace period:

<project>

    < whenFilesChange >
        <interval>60</interval>
        <grace>120</grace>
        <dir>/usr/home/ptogram1/src</dir>
        <dir>/usr/home/ptogram2/src</dir>
    </ whenFilesChange >

    <build>
      ... build sub elements...
    </build>

</project>

Finally, you can narrow the range of files that the whenFilesChange trigger looks at with the <include> and <exclude> elements. Both these elements specify a pattern which has the obvious effect. Specifically, any files which match the included patterns are used, unless they are specifically excluded by an exclude pattern.

The trigger shown below checks for changes to Java and XML files found under /usr/home/program1, but will ignore any changes to java files which begin with the word "generated":

<project>

    < whenFilesChange >
        <interval>60</interval>
         <dir>/usr/home/program1/src</dir>
         <include>*.java</include>
        <include>*.xml</include>
        <exclude>generated*.java</exclude>
    </ whenFilesChange >

    <build>
      ... build sub elements...
    </build>

</project>