문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top