开发者

How can I check if a set of files exists in an Ant build?

I'm wondering if there's a way to, using Ant, check if several files are available on disk. Currently, I have a task that looks 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 created earlier in the build. 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 builds can fail dramatically at a later step because of a missing resource.

I've tried setting 'failonerror' to true in the hope 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 though. So I dead-ended 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 a custom Ant task, but maybe ther开发者_开发知识库e's something more obvious.


Rather than using a fileset, which will only include files that do exist in the file system, and silently ignore those that don't, try a filelist. Filelists can contain files that don't exist in the file system, so can be used for your check - Ant will throw an error when it tries to process a non-existent file in the filelist.

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    # No bar.xml in src dir.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜