How to emulate if-else logic with a condition?

I know there is ant-contribone that provides if-else logic for ant. But I need to achieve the same without ant-contrib . Is it possible?

The pseudocode I need to work is:

if(property-"myProp"-is-true){
  do-this;
}else{
  do-that;
}

Thank!

+3
source share
2 answers

I would highly recommend using ant -contribs anyway, but if you are testing a property that always matters, I would consider using the ant macro as part of the name of the new property, which you then checked 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>
+4
source

"".

<target name="do-this-when-myProp-is-true" if="myProp">
...
</target>

"myProp". myProp , , , , . , :

<target name="do-this-when-myProp-is-false" unless="myProp">
...
</target>
+3

Source: https://habr.com/ru/post/1753625/


All Articles