Option 1: Configure build to run automated or interactive
Rather than timing out the input prompts, you could configure the build to run fully automated by supplying the default input values in a properties file.
default.properties
Which\ branch\ would\ you\ like\ to\ build?=dev
To switch between interactive and automated builds, the type of input handler to use could be specified when invoking Ant:
Automated build
$ ant -Dhandler.type=propertyfile
Interactive build
$ ant -Dhandler.type=default
The input handler would need to be specified using the nested <handler>
element.
<input addproperty="branch.tag" defaultvalue="dev"
message="Which branch would you like to build?">
<handler type="${handler.type}" />
</input>
The last step is to specify the properties file for the PropertyFileInputHandler
by defining the ant.input.properties
system property.
Linux
export ANT_OPTS=-Dant.input.properties=default.properties
Option 2: Use AntContrib Trycatch combined with Parallel in a macrodef
<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>
Option 3: Write a custom Ant task
Implementation left as an exercise to the reader.