我编写的许多ant脚本都使用默认值,这些默认值几乎是独占的.即,我偶尔会想要在没有默认值的情况下运行它.
很多时候,这些脚本需要足够的时间才能在运行时去做其他事情,例如喝咖啡或使用Little Developer's Room.当然,如果有提示,你忘了它,那么,你是SOL.
有没有什么方法可以在提示符上设置超时,所以如果没有输入,哦,让我们说30秒,它只接受默认值,这样当我回到我的工作站时,我有我的战争/ jar /什么准备好去?就像是
<input addproperty="branch.tag"
defaultvalue="dev"
timeout="30000">
Which branch would you like to build?
</input>
Run Code Online (Sandbox Code Playgroud)
现在很明显,这个超时功能不存在,但你可以了解我正在努力实现的目标.
您可以通过在属性文件中提供默认输入值,将构建配置为完全自动运行,而不是超时输入提示.
Which\ branch\ would\ you\ like\ to\ build?=dev
Run Code Online (Sandbox Code Playgroud)
要在交互式和自动构建之间切换,可以在调用Ant时指定要使用的输入处理程序的类型:
$ ant -Dhandler.type=propertyfile
Run Code Online (Sandbox Code Playgroud)
$ ant -Dhandler.type=default
Run Code Online (Sandbox Code Playgroud)
需要使用嵌套<handler>元素指定输入处理程序.
<input addproperty="branch.tag" defaultvalue="dev"
message="Which branch would you like to build?">
<handler type="${handler.type}" />
</input>
Run Code Online (Sandbox Code Playgroud)
最后一步是PropertyFileInputHandler通过定义ant.input.properties系统属性来指定属性文件.
export ANT_OPTS=-Dant.input.properties=default.properties
Run Code Online (Sandbox Code Playgroud)
<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>
Run Code Online (Sandbox Code Playgroud)
实施留给读者作为练习.
| 归档时间: |
|
| 查看次数: |
5333 次 |
| 最近记录: |