Ant: how to find out if at least one copy task out of ten copy tasks actually copied a file


I have a goal that has several copy tasks; It basically copies shared banks to our application suite from a central location in the application’s lib folder.
Seeing that this is a common copy task, a jar will only be copied if it is newer than the one in the lib folder.
This is the important part in the build.xml file:

 <target name="libs"/> <copy file=... /> <copy file=... /> <copy file=... /> <antcall target="clean_compiled_classes"/> </target> <target name="clean_compiled_classes" if="anyOfTheLibsWereCopied"> <delete .../> </target> 

I am looking for a way to set the anyOfTheLibsWereCopied property before calling ant on the libs target line, depending on whether any file was really modified.

Thanks,
Ephaya

0
source share
1 answer

I would advise taking a look at the Uptodate task. I have never used it before, but I think that what you are trying to do will be implemented in the following lines:

 <target name="libs"/> <uptodate property="isUpToDate"> <srcfiles dir="${source.dir}" includes="**/*.jar"/> <globmapper from="${source.dir}/*.jar" to="${destination.dir}/*.jar"/> </uptodate> <!-- tasks below will only be executed if there were libs that needed an update --> <antcall target="copy_libs"/> <antcall target="clean_compiled_classes"/> </target> <target name="copy_libs" unless="isUpToDate"> <copy file=... /> <copy file=... /> <copy file=... /> </target> <target name="clean_compiled_classes" unless="isUpToDate"> <delete .../> </target> 

Another option is to implement your own ant task, which will do what you want. This will require a little more work.

+2
source

Source: https://habr.com/ru/post/1333384/


All Articles