使用Ant,是否可以在标签IF中使用AND,OR条件?

时间:2010-12-03 11:12:30

标签: java ant task ant-contrib

contrib可以检查标签IF中的更多条件吗? 我需要做这样的事情:

<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>

如何在一个IF中做很多条件?

更新:解决:

<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>

1 个答案:

答案 0 :(得分:16)

<If>基于<condition>并支持(我的理解)相同的nested elements (conditions)

尝试一下:

<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>