Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use filelist as fileset in uptodate Ant command?

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

like image 900
Eleno Avatar asked Dec 30 '10 17:12

Eleno


1 Answers

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.

like image 109
David W. Avatar answered Sep 23 '22 04:09

David W.