How can "if-else" logic be emulated using "condition"?
I know that there is ant-contrib
, which provides "if-else" logic for ant.
But I need to achieve the 开发者_StackOverflow中文版same without ant-contrib
. Is that possible?
Pseudocode which I need to work:
if(property-"myProp"-is-true){
do-this;
}else{
do-that;
}
Thank you!
I would strongly recommend using ant-contribs anyway but if you are testing a property that always has a value I would look into using an ant macro parameter as part of the name of a new property that you then test for
<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>
You can put an "if" attribute in your targets.
<target name="do-this-when-myProp-is-true" if="myProp">
...
</target>
This will fire only if "myProp" is set. You'll need to define myProp elsewhere such that it's set if you want this target to fire & not if you don't. You can use unless for the alternate case:
<target name="do-this-when-myProp-is-false" unless="myProp">
...
</target>
精彩评论