Search code examples
antant-contrib

Ant - If condition / and-or


I was wondering if it was possible to make something like that in Ant (v1.9.4): if((a=1 or a=2) and (b=3)) then ...

I tried

<ac:if>
        <or>
            <equals arg1="${aa}" arg2=""/>
            <not>
                <isset property="a"/>
            </not>
        </or>
        <and>
            <contains string="${b}" substring="${c}" casesensitive="false"/>
        </and>
        <then>
            <property name="b" value="true" />
        </then>
</ac:if>

But I got than error while running it...

Thanks for your help,

Regards,


Solution

  • Using Ant-contrib, you must have a single condition under the if task as shown below (you cannot have both <or> and <and>). You also don't need to check if the property is set as it is semantically covered when comparing the property to a value with equals:

    <if>
        <and>
            <or>
                <equals arg1="${a}" arg2="1" />
                <equals arg1="${a}" arg2="2" />
            </or>
            <equals arg1="${b}" arg2="3" />
        </and>
        <then>
            <!-- do stuff -->
        </then>
        <else>
            <!-- do other stuff -->
        </else>
    </if>