我知道有ant-contrib
,它为蚂蚁提供了“if-else”逻辑。 但我需要达到相同的没有ant-contrib
。那可能吗?如何使用“条件”模拟“if-else”逻辑?
伪代码,我需要工作:
if(property-"myProp"-is-true){
do-this;
}else{
do-that;
}
谢谢!
我知道有ant-contrib
,它为蚂蚁提供了“if-else”逻辑。 但我需要达到相同的没有ant-contrib
。那可能吗?如何使用“条件”模拟“if-else”逻辑?
伪代码,我需要工作:
if(property-"myProp"-is-true){
do-this;
}else{
do-that;
}
谢谢!
我会强烈建议使用蚂蚁贡献但无论如何,如果你正在测试总是有一个值我会考虑使用蚂蚁宏观参数的部分属性你再测试
<macrodef name="create-myprop-value">
<attribute name="prop"/>
<sequential>
<!-- should create a property called optional.myprop.true or -->
<!-- optional.myprop.false -->
<property name="[email protected]{prop}" value="set" />
</sequential>
</macrodef>
<target name="load-props">
<create-myprop-value prop="${optional.myprop}" />
</target>
<target name="when-myprop-true" if="optional.myprop.true" depends="load-props">
...
</target>
<target name="when-myprop-false" if="optional.myprop.false" depends="load-props">
...
</target>
<target name="do-if-else" depends="when-myprop-true,when-myprop-false">
...
</target>
您可以在目标中放置“if”属性。
<target name="do-this-when-myProp-is-true" if="myProp">
...
</target>
仅当设置了“myProp”时,才会触发。你需要在其他地方定义myProp,如果你想让这个目标在没有的情况下触发&,那么它就会被设置。您可以使用,除非在另一种情况:
<target name="do-this-when-myProp-is-false" unless="myProp">
...
</target>
严格地说新属性的名称,“其他”目标可以被编码为除非=“optional.myprop.true”,而不是如果=“optional.myprop.false”。该宏也可以被通用化以将该属性的名称作为参数来传递。 – 2010-07-12 07:15:19