soothsayer
soothsayer

Reputation: 333

antcall based on a condition

This is what I am trying to achieve:

if a property is set then call antcall target. is this doable? can someone tell me how?

<condition>
    <isset property="some.property">
        <antcall target="do.something">
    </isset>
</condition>

Upvotes: 9

Views: 14817

Answers (3)

jgritty
jgritty

Reputation: 11935

Something like this should work:

<if>
    <isset property="some.property"/>
    <then>
        <antcall target="do.something"/>
    </then>
</if>

If then conditions require ant-contrib, but so does just about anything useful in ant.

Upvotes: 8

Bill Rawlinson
Bill Rawlinson

Reputation: 600

I know I'm really late to this but here is another way to do this if you are using an of ant-contrib where if doesn't support a nested antcall element (I am using antcontrib 1.02b which doesn't).

<target name="TaskUnderRightCondition" if="some.property">
  ...
</target>

You can further expand this to check to see if some.property should be set just before this target is called by using depends becuase depends is executed before the if attribute is evaluated. Thus you could have this:

<target name="TestSomeValue">
  <condition property="some.property">
    <equals arg1="${someval}" arg2="${someOtherVal}" />
  </condition>
</target>

<target name="TaskUnderRightCondition" if="some.property" depends="TestSomeValue">
  ...
</target>

In this case TestSomeValue is called and, if someval == someOtherVal then some.property is set and finally, TaskUnderRightCondition will be executed. If someval != someOtherVal then TaskUnderRightCondition will be skipped over.

You can learn more about conditions via the documentation.

Upvotes: 6

shabunc
shabunc

Reputation: 24791

Consider also you can invoke groovy for these purposes:

<use-groovy/>
<groovy>
   if (Boolean.valueOf(properties["some.property"])) {
     ant.project.executeTarget("do.something")
   }
</groovy>

Upvotes: -1

Related Questions