我知道有ant-contrib
,它为ant提供了“if-else”逻辑。
但我需要实现相同的没有 ant-contrib
。这可能吗?
我需要使用的伪代码:
if(property-"myProp"-is-true){
do-this;
}else{
do-that;
}
谢谢!
最佳答案
无论如何,我强烈建议使用 ant-contribs,但如果您正在测试一个始终具有值的属性,我会考虑使用 ant 宏参数作为您随后测试的新属性名称的一部分
<macrodef name="create-myprop-value">
<attribute name="prop"/>
<sequential>
<!-- should create a property called optional.myprop.true or -->
<!-- optional.myprop.false -->
<property name="optional.myprop.@{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>
关于ant - 如何使用 "if-else"模拟 "condition"逻辑?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3200056/