我可以有条件地停止基于文件的Ant脚本最后修改时间? [英] Can I conditionally stop an Ant script based on file last modified time?

查看:339
本文介绍了我可以有条件地停止基于文件的Ant脚本最后修改时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找所有在互联网上,但不能在任何地方找到答案。我在ANT脚本中MQFTE工作codeD和我在与,如果一个文件没有今天的日期移动文件的过程中的困难。我想这样做是有条件的停止,就像一个在执行这样的任务是不会去通过进一步的常规和刚刚结束的中间返回true 值;如果文件被标识作为被跳过。

I've been looking all over the Internet, but couldn't find an answer anywhere. I have an MQFTE job coded in ANT script and I'm having difficulty with a process that moves files if a file doesn't have today's date. What I would like to do is a conditional stop, something like a return true value in a middle of the execution so the job is not going to go through the further routine and just end if the file is identified as to be skipped.

这是可能的ANT?或者它必须经过每个<目标> 脚本

Is that possible in ANT? Or does it have to go through every <target> in the script?

推荐答案

蚂蚁 失败 任务可以用来有条件地停止Ant脚本。下面的示例初始化属性今天为当前日期,然后使用的 文件集 一个嵌套的&LT;日期&GT; 元素,只选择文件之前,今天的日期修改。该 pathconvert 任务则设置该属性文件而不是空只有存在至少在一个文件中的文件集修改之前,今天的日期。那么失败任务是用来阻止Ant脚本,如果没有要复制的文件。

The Ant fail task may be used to conditionally stop an Ant script. The example below initializes the property TODAY to the current date and then uses a fileset with a nested <date> element to only select files modified prior to today's date. The pathconvert task then sets the property files-not-empty only if there is at least one file in the fileset modified prior to today's date. The fail task is then used to stop the Ant script if there are no files to copy.

<target name="copy-if-not-modified-today">
  <property name="copy-from.dir" value="${basedir}" />
  <property name="copy-to.dir" value="${basedir}/build/copied_files" />
  <mkdir dir="${copy-to.dir}" />

  <tstamp>
    <format property="TODAY" pattern="MM/dd/yyyy" />
  </tstamp>

  <fileset id="files" dir="${copy-from.dir}" includes="*">
    <date datetime="${TODAY} 12:00 AM" when="before"/>
  </fileset>
  <pathconvert property="files-not-empty" setonempty="false" refid="files" />

  <!--
    Stop the Ant script if there are no files to copy that were modified prior
    to today's date.
  -->
  <fail unless="files-not-empty" />

  <copy todir="${copy-to.dir}" preservelastmodified="true">
    <fileset refid="files" />
  </copy>
</target>

这篇关于我可以有条件地停止基于文件的Ant脚本最后修改时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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