Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 665
soothsayer Avatar asked Jun 27 '12 17:06

soothsayer


People also ask

What is Antcall target?

When a target is invoked by antcall , all of its dependent targets will also be called within the context of any new parameters. For example. if the target doSomethingElse ; depended on the target init , then the antcall of doSomethingElse will call init during the call.


2 Answers

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.

like image 145
jgritty Avatar answered Nov 16 '22 03:11

jgritty


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.

like image 30
Bill Rawlinson Avatar answered Nov 16 '22 04:11

Bill Rawlinson