开发者

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" u开发者_JS百科nless="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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜