Ant: How to know if at least one copy task from ten copy tasks actually copied a file

南楼画角 提交于 2019-12-13 02:56:56

问题



I have a target which has several copy tasks; It basically copies the common jars to our set of applications from a centralized location to the lib folder of the application.
Seeing as this is a regular copy task a jar will be copied only if it is newer than the one currently in the lib folder.
This is the relevant part in the build.xml:

<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'm looking for a way to set the anyOfTheLibsWereCopied property before the ant call in the libs target based on whether or not any of the files has been actually changed.

Thanks,
Ittai


回答1:


I would advise having a look at the Uptodate task. I have never used it before but I guess what you are trying to do will be implemented along 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>

Your other option would be to implement your own ant task that does what you want. This would require a bit more work though.



来源:https://stackoverflow.com/questions/4533925/ant-how-to-know-if-at-least-one-copy-task-from-ten-copy-tasks-actually-copied-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!