gpt4 book ai didi

ant - 如果在给定时间内未输入,如何使 Ant 提示使用默认值?

转载 作者:行者123 更新时间:2023-12-04 23:26:59 25 4
gpt4 key购买 nike

我写的很多 Ant 脚本都使用了默认值,而这些默认值几乎是排他性的。 IE。我只是偶尔想在没有默认值的情况下运行它。

很多时候,这些脚本需要足够的时间,所以在它们运行时去做其他事情是有意义的,比如喝咖啡或使用小开发人员的房间。当然,如果上面有提示,而您忘记了,那么您就是SOL。

有什么办法可以在提示上设置超时,所以如果没有输入,哦,假设 30 秒,它只接受默认值,以便当我回到我的工作站时,我有我的 war / 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>
最后一步是为 PropertyFileInputHandler 指定属性文件通过定义 ant.input.properties系统属性。
Linux
export ANT_OPTS=-Dant.input.properties=default.properties

选项 2:使用 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 任务
实现留给读者作为练习。

关于ant - 如果在给定时间内未输入,如何使 Ant 提示使用默认值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11269502/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com