在ant中输出几个时间戳 [英] Output several timestamps in ant
问题描述
下面的 Ant 构建文件片段试图简单地输出每个 sql 脚本运行前后的时间.我无法更改 Ant 目标的结构(create-tables 必须像它一样调用 run-sql-script).问题是属性(时间和时间2)是不可变的(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>
推荐答案
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屋!