Ant:如何知道十个复制任务中是否至少有一个复制任务实际上复制了一个文件 [英] Ant: How to know if at least one copy task from ten copy tasks actually copied a file

查看:13
本文介绍了Ant:如何知道十个复制任务中是否至少有一个复制任务实际上复制了一个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个目标,它有几个复制任务;它基本上将常见的 jar 文件从一个集中位置复制到我们的应用程序集到应用程序的 lib 文件夹中.
由于这是一项常规复制任务,因此只有当 jar 比 lib 文件夹中的当前版本更新时,才会复制它.
这是 build.xml 中的相关部分:


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>

我正在寻找一种方法来在 libs 目标中的 ant 调用之前设置 anyOfTheLibsWereCopied 属性,具体取决于是否有任何文件已实际更改.

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.

谢谢,
意泰

推荐答案

我建议看看 最新 任务.我以前从未使用过它,但我想您要尝试执行的操作将按照以下方式实现:

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>

您的另一个选择是实现您自己的 ant 任务来完成您想要的任务.不过,这需要做更多的工作.

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

这篇关于Ant:如何知道十个复制任务中是否至少有一个复制任务实际上复制了一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆