我可以根据文件上次修改时间有条件地停止 Ant 脚本吗? [英] Can I conditionally stop an Ant script based on file last modified time?

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

问题描述

我找遍了整个互联网,但在任何地方都找不到答案.我有一个用 ANT 脚本编码的 MQFTE 作业,如果文件没有今天的日期,我在移动文件的过程中遇到困难.我想要做的是一个有条件的停止,比如在执行过程中 return 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?

推荐答案

The Ant fail 任务可用于有条件地停止 Ant 脚本.下面的示例将属性 TODAY 初始化为当前日期,然后使用 fileset 带有嵌套的 元素,以仅选择在今天日期之前修改的文件.pathconvert 任务然后设置属性 files-not-empty 仅当 fileset 中至少有一个文件在今天日期之前被修改.如果没有要复制的文件,则 fail 任务将用于停止 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天全站免登陆