-->

如何模拟IF-ELSEIF-ELSE在Ant中不使用蚂蚁的contrib?(How to emula

2019-08-21 01:58发布

我需要一个蚂蚁IF-ELSEIF-ELSE条件语句。

我不想使用Ant-的contrib。

我试过的解决方案在这里

    <target name="condition.check">
    <input message="Please enter something: " addproperty="somethingProp"/>
    <condition property="allIsWellBool">
        <not>
            <equals arg1="${somethingProp}" arg2="" trim="true"/>
        </not>
    </condition>
</target>
<target name="if" depends="condition.check, else" if="allIsWellBool">
    <echo message="if condition executes here"/>
</target>
<target name="else" depends="condition.check" unless="allIsWellBool">
    <echo message="else condition executes here"/>
</target>

但是,我必须设置里面的if和else的目标性能,这将不会在调用目标可见。

有没有其他出路使用条件?

Answer 1:

移动依赖性出来的ifelse成依赖于所有其他目标的一个新的目标:

<project name="ant-if-else" default="newTarget">
    <target name="newTarget" depends="condition.check, if, else"/>

    <target name="condition.check">
        <input message="Please enter something: " addproperty="somethingProp"/>
        <condition property="allIsWellBool">
            <not>
                <equals arg1="${somethingProp}" arg2="" trim="true"/>
            </not>
        </condition>
    </target>

    <target name="if" if="allIsWellBool">
        <echo message="if condition executes here"/>
    </target>
    <target name="else" unless="allIsWellBool">
        <echo message="else condition executes here"/>
    </target>
</project>


文章来源: How to emulate if-elseif-else in Ant without using Ant-contrib?