在ant中输出几个时间戳 [英] Output several timestamps in ant

查看:65
本文介绍了在ant中输出几个时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的Ant构建文件代码段只是尝试简单地输出每个sql脚本运行之前和之后的时间.我无法更改Ant目标的结构(创建表必须像它一样调用run-sql-script).问题在于属性(时间和time2)是不可变的( http://ant.apache .org/manual/Tasks/property.html ),因此仅对第一次操作计时,而对第二次操作计时.有没有办法做我在Ant中想要做的事情?

The Ant buildfile snippet below is an attempt to simply output the time before and after each sql script is run. I cannot change the structure of the Ant targets (create-tables must call run-sql-script just as it does). The problem is that the properties (time and time2) are immutable (http://ant.apache.org/manual/Tasks/property.html) and thus only time the first operation and not the second. Is there no way to do what I'm trying to do in Ant?

  <target name="create-tables">
    <antcall target="run-sql-script">
      <param name="db.script" value="teams.sql"/>
    </antcall>

    <!-- Create the base UDM schema. -->
    <antcall target="run-sql-script">
      <param name="db.script" value="players.sql"/>
    </antcall>
  </target>
  <target name="run-sql-script">
    <tstamp>
      <format property="time" pattern="MM/dd/yyyy hh:mm:ss aa"
          offset="-5" unit="hour"/>
    </tstamp>
    <echo>before: ${time}</echo>
    <sql
        classpath="${classpath}"
        driver="${db.driver}"
        url="${db.url}"
        userid="${db.userid}"
        password="${db.password}"
        src="${script.dir}/${db.script}"
        delimiter="${script.delimiter}"
        onerror="abort">
    </sql>              
    <tstamp>
      <format property="time2" pattern="MM/dd/yyyy hh:mm:ss aa"
            offset="-5" unit="hour"/>
    </tstamp>
    <echo>after: ${time2}</echo>
  </target>

推荐答案

使用 <macrodef> 任务以及 <local> 任务(已引入在Ant 1.8中):

Use a <macrodef> task together with the <local> task (introduced in Ant 1.8):

<macrodef name="echotimestamp">
  <sequential>
    <local name="timestamp" />
    <tstamp>
      <format property="timestamp" pattern="yyyy-MM-dd HH:mm:ss" />
    </tstamp>
    <echo message="${timestamp}" />
  </sequential>
</macrodef>
<echotimestamp />

这篇关于在ant中输出几个时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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