Ant “怎么可能?”;如有其他",;可以使用“模拟逻辑”;条件;?
我知道有Ant “怎么可能?”;如有其他",;可以使用“模拟逻辑”;条件;?,ant,conditional,if-statement,ant-contrib,Ant,Conditional,If Statement,Ant Contrib,我知道有antcontrib,它为ant提供“if-else”逻辑。 但是我需要在没有ant contrib的情况下实现同样的。可能吗 我需要使用的伪代码: if(property-"myProp"-is-true){ do-this; }else{ do-that; } 谢谢大家! 您可以在目标中添加“如果”属性 <target name="do-this-when-myProp-is-true" if="myProp"> ... </target> ..
antcontrib
,它为ant提供“if-else”逻辑。
但是我需要在没有ant contrib的情况下实现同样的。可能吗
我需要使用的伪代码:
if(property-"myProp"-is-true){
do-this;
}else{
do-that;
}
谢谢大家! 您可以在目标中添加“如果”属性
<target name="do-this-when-myProp-is-true" if="myProp">
...
</target>
...
仅当设置了“myProp”时,此选项才会触发。您需要在其他地方定义myProp,以便在希望此目标开火时设置它&而不是在不开火时。您可以使用,除非用于其他情况:
<target name="do-this-when-myProp-is-false" unless="myProp">
...
</target>
...
无论如何,我强烈建议您使用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>
...
...
...
严格来说,“else”目标可以被编码为除非=“optional.myprop.true”,而不是if=“optional.myprop.false”。宏也可以泛化为将属性的名称作为参数传递。