10

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

Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
Eleno
  • 2,864
  • 3
  • 33
  • 39

1 Answers1

15

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.

David W.
  • 105,218
  • 39
  • 216
  • 337
  • It works, thanks. I don't know how to mark this topic "solved" by you, sorry. – Eleno Jan 03 '11 at 09:48
  • 1
    There's a white check under the "number of votes" for the answer. Click on the check mark, and it'll turn green meaning the question has been answered. – David W. Jan 03 '11 at 14:38