I have a target of build.xml
that creates a Zip file. To avoid creating the Zip if no file has been updated, I'd like to check for updates beforehand. AFAIK, uptodate
is the task to use.
Here is the relevant (simplified) script sections:
<filelist id="zip-files">
<file name="C:/main.exe" />
<file name="D:/other.dll" />
</filelist>
<target name="zip" depends="zip-check" unless="zip-uptodate">
<zip destfile="${zip-file}" >
<filelist refid="zip-files" />
</zip>
</target>
<target name="zip-check">
<uptodate property="zip-uptodate"
targetfile="${zip-file}">
<srcfiles refid="zip-files" />
</uptodate>
</target>
However, uptodate
fails because srcfiles
must reference a fileset
, not a filelist
. Still, I can't use a fileset
because it would require a dir
attribute, which I can't set because source files do not share a base directory.
Of course, I could just copy all files to a common directory before zipping them, thus being able to use fileset
, but I was wondering whether there was an alternative solution.
I'm using Ant 1.8.1
Instead of using <srcfiles>
, try using <srcresources>
. <srcfiles>
must be a fileset, but <srcresource>
can be a union of any collection of resources, and that should include a filelist
.
I can't do any test right now, but it should look something like this:
<filelist id="zip-files">
<file name="C:/main.exe" />
<file name="D:/other.dll" />
</filelist>
<target name="zip" depends="zip-check" unless="zip-uptodate">
<zip destfile="${zip-file}" >
<filelist refid="zip-files" />
</zip>
</target>
<target name="zip-check">
<union id="zip-union">
<filelist refid="zip-files"/>
</union>
<uptodate property="zip-uptodate"
targetfile="${zip-file}">
<srcresources refid="zip-union" />
</uptodate>
</target>
Hope it works for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With