【问题标题】:How to emulate if-elseif-else in Ant without using Ant-contrib?如何在不使用 Ant-contrib 的情况下在 Ant 中模拟 if-elseif-else?
【发布时间】:2013-04-09 21:33:33
【问题描述】:

我需要 Ant 中的 if-elseif-else 条件语句。

我不想使用 Ant-contrib。

我尝试了解决方案here

    <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 目标中设置属性,这些属性在调用目标中不可见。

有没有其他使用条件的方法?

【问题讨论】:

    标签: ant ant-contrib


    【解决方案1】:

    将依赖关系从if 和else 移出到一个依赖于所有其他目标的新目标中:

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

    【讨论】:

      猜你喜欢
      • 2011-07-04
      • 1970-01-01
      • 1970-01-01
      • 2012-11-20
      • 2013-01-17
      • 1970-01-01
      • 1970-01-01
      • 2018-10-16
      • 1970-01-01
      相关资源
      最近更新 更多