Using Ant, is it possible to use AND, OR condition in tag IF?

19,440

<If> is based on <condition> and supports (that's my understanding) the same nested elements (conditions).

Give this a try:

<if>
   <or>
    <equals arg1="${var}" arg2="one"/>
    <equals arg1="${var}" arg2="two"/>
    <equals arg1="${var}" arg2="three"/>
    <equals arg1="${var}" arg2="four"/>
   </or>
   <then>
    <echo message="basic dir: ${var}"/>
    <copy todir="../direct" verbose="yes" failonerror="no" overwrite="yes">
        <fileset dir="${var}">
            <include name="**"/>
        </fileset>
    </copy>
   </then>
</if>
Share:
19,440
Krzysztof Miksa
Author by

Krzysztof Miksa

Hello world :)

Updated on June 05, 2022

Comments

  • Krzysztof Miksa
    Krzysztof Miksa almost 2 years

    contrib It's possible to check more condition in tag IF?
    I need to do something like this :

    <if>
    <equals arg1="${var}" arg2="one"/>
    <or>
        <equals arg1="${var}" arg2="two"/>
    </or>
    <or>
        <equals arg1="${var}" arg2="three"/>
    </or>
    <or>
        <equals arg1="${var}" arg2="four"/>
    </or>
    <then>
        <echo message="basic dir: ${var}"/>
        <copy todir="../direct" verbose="yes" failonerror="no" overwrite="yes">
            <fileset dir="${var}">
                <include name="**"/>
            </fileset>
        </copy>
    </then></if>
    

    How to do many conditions in one IF?

    UPDATE: solve:

    <if>
    <or>
        <equals arg1="${var}" arg2="one"/>    
        <equals arg1="${var}" arg2="two"/>
        <equals arg1="${var}" arg2="three"/>
        <equals arg1="${var}" arg2="four"/>
    </or>
    <then>
        <echo message="basic dir: ${var}"/>
        <copy todir="../direct" verbose="yes" failonerror="no" overwrite="yes">
            <fileset dir="${var}">
                <include name="**"/>
            </fileset>
        </copy>
    </then></if>