很多时候,这些脚本需要足够的时间才能在运行时去做其他事情,例如喝咖啡或使用Little Developer’s Room.当然,如果有提示,你忘了它,那么,你是SOL.
有没有什么方法可以在提示符上设置超时,所以如果没有输入,哦,让我们说30秒,它只接受默认值,这样当我回到我的工作站时,我有我的战争/ jar /什么准备好去?就像是
<input addproperty="branch.tag" defaultvalue="dev" timeout="30000"> Which branch would you like to build? </input>
现在很明显,这个超时功能不存在,但你可以了解我正在努力实现的目标.
选项1:配置构建以自动运行或交互运行您可以通过在属性文件中提供默认输入值,将构建配置为完全自动运行,而不是超时输入提示.
default.properties
Which\ branch\ would\ you\ like\ to\ build?=dev
要在交互式和自动构建之间切换,可以在调用Ant时指定要使用的输入处理程序的类型:
自动构建
$ant -Dhandler.type=propertyfile
互动构建
$ant -Dhandler.type=default
需要使用嵌套的< handler>指定输入处理程序.元件.
<input addproperty="branch.tag" defaultvalue="dev" message="Which branch would you like to build?"> <handler type="${handler.type}" /> </input>
最后一步是通过定义ant.input.properties系统属性来指定PropertyFileInputHandler的属性文件.
export ANT_OPTS=-Dant.input.properties=default.properties
选项2:在macrodef中使用AntContrib Trycatch与Parallel结合使用
<taskdef name="trycatch" classname="net.sf.antcontrib.logic.TryCatchTask"> <classpath> <pathelement location="/your/path/to/ant-contrib.jar"/> </classpath> </taskdef> <macrodef name="input-timeout"> <attribute name="addproperty" /> <attribute name="defaultvalue" default="" /> <attribute name="handlertype" default="default" /> <attribute name="message" default="" /> <attribute name="timeout" default="30000" /> <text name="text" default="" /> <sequential> <trycatch> <try> <parallel threadcount="1" timeout="@{timeout}"> <input addproperty="@{addproperty}" defaultvalue="@{defaultvalue}" message="@{message}"> <handler type="@{handlertype}" /> @{text} </input> </parallel> </try> <catch> <property name="@{addproperty}" value="@{defaultvalue}" /> </catch> </trycatch> </sequential> </macrodef> <target name="test-timeout"> <input-timeout addproperty="branch.tag" defaultvalue="dev" message="Which branch would you like to build?" timeout="5000" /> <echo message="${branch.tag}" /> </target>
选项3:编写自定义Ant任务
实施留给读者作为练习.
精彩评论