登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

kangzye的博客

加Q群25382780切磋java,加19360923群研究JavaScript

 
 
 

日志

 
 

ant 中条件判断  

2011-02-17 11:56:25|  分类: ant |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
basic elements: istrue isfalse not and or xor available isset equals  filesmatch
    1、istrue isfalse:断言 真 假
<project name="testCondition">
    <target name="test">
        <condition property="scondition">
            <istrue value="true"/>                   
        </condition>
        <antcall target="isTrue"></antcall>
        <antcall target="isFalse"></antcall>       
    </target>
    <target name="isTrue" if="scondition">
        <echo>is ture</echo>
    </target>
    <target name="isFalse" unless="scondition">
        <echo>is false</echo>
    </target>
</project>

    2、逻辑运算
    2.1、not 逻辑非 
<project name="testCondition">
    <target name="test">
        <condition property="scondition">
            <not>
                <istrue value="true"/>                   
            </not>
        </condition>
        <antcall target="isTrue"></antcall>
        <antcall target="isFalse"></antcall>       
    </target>
    <target name="isTrue" if="scondition">
        <echo>is ture</echo>
    </target>
    <target name="isFalse" unless="scondition">
        <echo>is false</echo>
    </target>
</project>
    2.2、and 逻辑与
<project name="testCondition">
    <target name="test">
        <condition property="scondition">
            <and>
                <istrue value="true"/>
                <istrue value="false"/>                   
            </and>
        </condition>
        <antcall target="isTrue"></antcall>
        <antcall target="isFalse"></antcall>       
    </target>
    <target name="isTrue" if="scondition">
        <echo>is ture</echo>
    </target>
    <target name="isFalse" unless="scondition">
        <echo>is false</echo>
    </target>
</project>
    2.3、or 逻辑或 xor异或 (语法上与and类似)

    3、available 是否可用
<project name="testCondition">
    <path id="all.test.classes">        
         <pathelement location="bin"/>
     </path>
    <target name="test">
        <condition property="scondition">
            <!--在指定的classpath路径下是否存在资源 TestTest.class-->
            <available resource="TestTest.class">
                <classpath refid="all.test.classes" />       
            </available>
        </condition>
        <antcall target="isTrue"></antcall>
        <antcall target="isFalse"></antcall>       
    </target>
    <target name="isTrue" if="scondition">
        <echo>is ture</echo>
    </target>
    <target name="isFalse" unless="scondition">
        <echo>is false</echo>
    </target>
</project>

    4、isset 指定属性是否存在
<project name="testCondition">
    <!--属性也可以通过ant参数-D来设置-->
    <property name="name" value="this is name"/>   
    <target name="test">
        <condition property="scondition">
            <!--如果属性name不存在则返回false-->
            <isset property="name"/>
        </condition>
        <antcall target="isTrue"></antcall>
        <antcall target="isFalse"></antcall>       
    </target>
    <target name="isTrue" if="scondition">
        <echo>is ture</echo>
    </target>
    <target name="isFalse" unless="scondition">
        <echo>is false</echo>
    </target>
</project>
    5、equals 是否相等
<project name="testCondition">
    <!--属性也可以通过ant参数-D来设置-->
    <property name="name" value="this is name"/>   
    <target name="test">
        <condition property="scondition">
            <!--如果arg1的值与arg2的值相等返回true,否则为false-->
            <equals arg1="${name}" arg2="this is name"/>
        </condition>
        <antcall target="isTrue"></antcall>
        <antcall target="isFalse"></antcall>       
    </target>
    <target name="isTrue" if="scondition">
        <echo>is ture</echo>
    </target>
    <target name="isFalse" unless="scondition">
        <echo>is false</echo>
    </target>
</project>   
    6、filesmatch 比较文件
<project name="testCondition">       
    <target name="test">
        <condition property="scondition">
            <!--如果file1所代表的文件与file2所代表的文件相等返回true,否则为false-->
            <filesmatch file1="testfile1.txt" file2="testfile2.txt"/>
        </condition>
        <antcall target="isTrue"></antcall>
        <antcall target="isFalse"></antcall>       
    </target>
    <target name="isTrue" if="scondition">
        <echo>is ture</echo>
    </target>
    <target name="isFalse" unless="scondition">
        <echo>is false</echo>
    </target>
</project>

判断文件夹是否存在:
<condition property="buildexists">
            <available file="${basedir}" type="dir"></available>
        </condition>
  评论这张
 
阅读(4181)| 评论(0)

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018