Ant unless 和condition的用法



我们先看这个build.xml, 有三个target,其中dist默认会调用conditionOne的if部分。ifTarget默认因为有if="conditionOne",如果不设置conditionOne属性就不执行。 elseTarget部分因为unless="conditionOne", 默认执行echo,除非设置conditionOne属性


<project name="testAntCondition">  
    <target name="dist">
       <echo>is dist target sart</echo>     
        <condition property="conditionOne">  
            <istrue value="true"/>  
        </condition>
        <antcall target="ifTarget">  
        </antcall>
        <antcall target="elseTarget">  
        </antcall>

        <echo>is dist target end</echo>         
    </target>  
    <target name="ifTarget" if="conditionOne">  
        <echo>is if part</echo>  
    </target>  
    <target name="elseTarget" unless="conditionOne">  
        <echo>is else part</echo>  
    </target>  
</project>


其中dist默认会调用conditionOne的if部分

F:\>ant dist
Buildfile: F:\build.xml

dist:
     [echo] is dist target sart

ifTarget:
     [echo] is if part

elseTarget:
     [echo] is dist target end

BUILD SUCCESSFUL
Total time: 0 seconds

ifTarget默认因为有if="conditionOne",如果不设置conditionOne属性就不执行。
F:\>ant ifTarget
Buildfile: F:\build.xml

ifTarget:

BUILD SUCCESSFUL
Total time: 0 seconds

F:\>ant ifTarget -DconditionOne=yes
Buildfile: F:\build.xml

ifTarget:
     [echo] is if part

BUILD SUCCESSFUL
Total time: 0 seconds

elseTarget部分因为unless="conditionOne", 默认执行echo,除非设置conditionOne属性
F:\>ant elseTarget
Buildfile: F:\build.xml

elseTarget:
     [echo] is else part

BUILD SUCCESSFUL
Total time: 0 seconds

F:\>ant elseTarget -DconditionOne=no
Buildfile: F:\build.xml

elseTarget:

BUILD SUCCESSFUL
Total time: 0 seconds


dist不接受设置的conditionOne属性

F:\>ant dist -DconditionOne=yes
Buildfile: F:\build.xml

dist:
     [echo] is dist target sart

ifTarget:
     [echo] is if part

elseTarget:
     [echo] is dist target end

BUILD SUCCESSFUL
Total time: 0 seconds

F:\>ant dist -DconditionOne=no
Buildfile: F:\build.xml

dist:
     [echo] is dist target sart

ifTarget:
     [echo] is if part

elseTarget:
     [echo] is dist target end

BUILD SUCCESSFUL
Total time: 0 seconds


看执行效果





https://ant.apache.org/manual/

Ant官方手册

ifthe name of the property that must be set in order for this target to execute, orsomething evaluating to true.No
unlessthe name of the property that must not be set in order for this target to execute, orsomething evaluating to false.No


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值