ant conditional execution (if-else statement in ant) and checking that a property isn't empty string

StackOverflow https://stackoverflow.com/questions/23452893

  •  15-07-2023
  •  | 
  •  

Question

Currently I have this code in ant script:

<target name="-pre-compile" if="${log.disabled}">
   <antcall target="remove-logs"/>
</target>

It's pretty self explanatory: if log.disable=true in properties file, then my remove-logs target will be called. Now I need to make minor changes to if/else. Pseudo-code:

<target name="-pre-compile">
   if("${log.disabled}")
      <antcall target="remove-logs"/>
   else if("${log.disabled.level}" != "")
      <antcall target="remove-logs-levels"/>
</target>

how can I write that in ant?

Also, note that all these if/them ant-contrib do not work for me:

<target name="test-xxx">
    <echo level="info">testing</echo>
    <if>
     <equals arg1="${log.disabled}" arg2="true" />
     <then>
       <echo message="true" />
     </then>
     <else>
       <echo message="false" />
     </else>
    </if>
</target>

get's me this output:

custom_rules.xml:73: if doesn't support the nested "equals" element.

PS. Once again, I ended up writing javascript instead of wasting time with ant itself. What a crappy make replacement...

Was it helpful?

Solution

Ant provide conditionals. Frankly using ant-contrib is easier. It provides an if task. See a more detailed answer in ant-contrib - if/then/else task

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top