Kiran
Kiran

Reputation: 5526

ant script to compare directories

I have a javascript project with the following structure:

root - 
  /docs
  /dist
  /source
  /resources
  /plugins

Code is in source directory and an ant script is executed to generate compressed files in dist directory. All the files are in source control.

I want to run a directory diff before running the ant script to make sure the list of files in source and dist directories are same. If not, stop execution and tell the user to checkin the needed files before running the build.

I am new to ant and am unable to find any documentation to list differences in files list between 2 directories. Appreciate any inputs.

Upvotes: 2

Views: 2684

Answers (1)

Mark O'Connor
Mark O'Connor

Reputation: 77971

You could try the following. Prints a list of the files to be checked in before failing:

<project name="demo" default="build">

    <target name="check">
        <apply executable="echo" failonerror="false" resultproperty="files.found">
            <arg line="missing file:"/>
            <srcfile/>
            <fileset id="srcfiles" dir="source" includes="*.txt">
                <present present="srconly" targetdir="dist"/>
            </fileset>
        </apply>

        <fail message="Files need to be checked in" if="files.found"/>
    </target>

    <target name="build" depends="check">
        ..
        ..
        ..
    </target>

</project>

Note:

  • Tested on Linux. Probably won't work on windows.

Upvotes: 2

Related Questions