tags:

views:

17

answers:

1

I'm wondering if there's some way to use ant to check if multiple files are available on disk. Currently, I have an ant task that looks very much like this:

<target name="copyArtworkToOutputDir" if="artworkContent">
  <copy todir="${imageOutputDir}" failonerror="true">
    <fileset dir="${sourceDir}" includesfile="${buildDir}/artworklist"/>
  </copy>
</target>

artworklist is a list of files that I've created earlier in the build process. I can pass it as a fileset to the copy task, and I should end up with a folder that contains all of the files in the list. Unfortunately, sometimes that doesn't work, and some of the builds fail dramatically at a later step because of a missing resource.

I've tried setting failonerror to true in the hopes that it will throw an exception if a file specified in the artworklist doesn't exist in the source location. For whatever reason this doesn't seem to work as I expect.

So, my next thought was to use something like the available task to validate that the contents of the artwork list now exist at the output location. Available seems to be restricted to single files only though. So I deadended a bit here too.

Can someone suggest a way that I can verify that all of the files that I expect to be in ${buildDir} after the copy are actually there? At this point, I'm thinking of custom ant tasks, but maybe there's something more obvious that I'm missing.

A: 

Rather than using a fileset, which will only include files that do exist, try a filelist. Filelists can contain files that don't exist in the file system, so can be used for your check.

Small example:

<filelist
    id="artworkfiles"
    dir="${src.dir}"
    files="foo.xml,bar.xml"/>

<copy todir="${dest.dir}" failonerror="true" >
    <filelist refid="artworkfiles" />
</copy>

...
BUILD FAILED
build.xml:14: Warning: Could not find resource file ".../src/bar.xml" to copy.

$ ls src
foo.xml
martin clayton