オプション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:macrodefでParallelと組み合わせたAntContribTrycatchを使用する
<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タスクを作成する
実装は読者の練習問題として残されました。