蚂蚁输出时间戳 [英] output timestamp in ant
问题描述
在Ant构建以下代码段是企图简单地输出之前,每个SQL脚本运行后的时间。我不能改变Ant目标的结构(创建桌必须调用运行SQL脚本只是因为它)。问题是,在性质(时间和TIME2)是不可变(http://ant.apache.org/manual/Tasks/property.html),因此只有时间第一操作,而不是第二个。难道就没有办法做我想要的蚂蚁呢?
<目标名称=创造桌>
< antcall目标=运行SQL脚本>
< PARAM NAME =db.scriptVALUE =teams.sql/>
< / antcall> <! - 创建基础架构UDM。 - >
< antcall目标=运行SQL脚本>
< PARAM NAME =db.scriptVALUE =players.sql/>
< / antcall>
< /目标与GT;
<目标名称=运行SQL脚本>
<&TSTAMP GT;
<格式属性=时间模式=MM / DD / YYYY HH:MM:SS AA
偏移量= - 5单位=小时/>
< / TSTAMP>
<回声>前:$ {时间}< /回声>
< SQL
CLASSPATH =$ {}类路径
驱动程序=$ {} db.driver
URL =$ {} db.url配置参数
用户id =$ {} db.userid
密码=$ {} db.password
SRC =$ {script.dir} / $ {} db.script
分隔符=$ {} script.delimiter
的onerror =中止>
< / SQL>
<&TSTAMP GT;
<格式属性=时间2模式=MM / DD / YYYY HH:MM:SS AA
偏移量= - 5单位=小时/>
< / TSTAMP>
<回声>在:$ {时间2}< /回声>
< /目标与GT;
与本地任务(在蚂蚁1.8引入)一起使用MacroDef
< macrodef NAME =echotimestamp>
<&连续GT;
<局部名=时间戳/>
<&TSTAMP GT;
<格式属性=时间戳模式=YYYY-MM-DD HH:MM:SS/>
< / TSTAMP>
<回声消息=$ {}时间戳/>
< /顺序>
< / macrodef>
< echotimestamp />
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 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 />
这篇关于蚂蚁输出时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!