实习杂记(23):ant里面condition属性测试

<?xml version="1.0" encoding="UTF-8"?>  
<project basedir="." name="test1" default="condition_istrue">  
      
    <!--测试condition istrue元素-->  
    <target name="condition_istrue">  
        <condition property="condition_1">  
            <istrue value="true"/>  
        </condition> 
		<antcall target="isTrue"/>  
        <antcall target="isFalse"/> 
    </target>  
    <target name="isTrue" if="condition_1">  
        <echo>is true</echo>  
    </target>  
    <target name="isFalse" unless="condition_1">  
        <echo>is false</echo>  
    </target>  
      
</project>



-----------------输出结果

E:\Test\Ant\condition>ant
Buildfile: E:\Test\Ant\condition\build.xml


condition_istrue:


isTrue:
     [echo] is true


isFalse:


BUILD SUCCESSFUL

------------------------------


<?xml version="1.0" encoding="UTF-8"?>  
<project basedir="." name="test1" default="condition_istrue">  
      
    <!--测试condition istrue元素-->  
    <target name="condition_istrue">  
        <condition property="condition_1">  
            <istrue value="false"/>  
        </condition> 
		<antcall target="isTrue"/>  
        <antcall target="isFalse"/> 
    </target>  
    <target name="isTrue" if="condition_1">  
        <echo>is true</echo>  
    </target>  
    <target name="isFalse" unless="condition_1">  
        <echo>is false</echo>  
    </target>  
      
</project>
--------输出结果

E:\Test\Ant\condition>ant
Buildfile: E:\Test\Ant\condition\build.xml


condition_istrue:


isTrue:


isFalse:
     [echo] is false


BUILD SUCCESSFUL
Total time: 0 seconds

-------------------------------------------

    <target name="isTrue" if="condition_1">  
        <echo>is true</echo>  
    </target>  
    <target name="isFalse" unless="condition_1">  
        <echo>is false</echo>  
    </target>
	
    <!--condition equals元素-->  
    <property name="name" value="this is name"/>  
    <target name="condition_equals" >  
        <condition property="condition_2">  
            <equals arg1="${name}" arg2="this is name"/>  
        </condition>  
        <antcall target="isTrue"/>  
        <antcall target="isFalse"/>  
    </target>
arg1和arg2是否相等

输出结果:-------------

E:\Test\Ant\condition>ant condition_equals
Buildfile: E:\Test\Ant\condition\build.xml


condition_equals:


isTrue:


isFalse:
     [echo] is false


BUILD SUCCESSFUL
Total time: 0 seconds

--------------------------------------------

   <target name="isTrue" if="condition_2">  
        <echo>is true</echo>  
    </target>  
    <target name="isFalse" unless="condition_2">  
        <echo>is false</echo>  
    </target>
	
    <!--condition equals元素-->  
    <property name="name" value="this is name"/>  
    <target name="condition_equals" >  
        <condition property="condition_2">  
            <equals arg1="${name}" arg2="this is name"/>  
        </condition>  
        <antcall target="isTrue"/>  
        <antcall target="isFalse"/>  
    </target> 

输出结果:------------------------

E:\Test\Ant\condition>ant condition_equals
Buildfile: E:\Test\Ant\condition\build.xml


condition_equals:


isTrue:
     [echo] is true


isFalse:


BUILD SUCCESSFUL
Total time: 0 seconds

-----------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>  
<project basedir="." name="test1" default="test">  
      
    <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>

输出结果:----------------------------

E:\Test\Ant\condition>ant
Buildfile: E:\Test\Ant\condition\build.xml


test:


isTrue:


isFalse:
     [echo] is false


BUILD SUCCESSFUL
Total time: 0 seconds

------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>  
<project basedir="." name="test1" default="test">  
      
    <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>
输出结果:------------------------

E:\Test\Ant\condition>ant
Buildfile: E:\Test\Ant\condition\build.xml


test:


isTrue:


isFalse:
     [echo] is false


BUILD SUCCESSFUL
Total time: 0 seconds

------------------------------------------


<?xml version="1.0" encoding="UTF-8"?>  
<project basedir="." name="test1" default="test">  
      
    <!--属性也可以通过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>

isset指定属性是否存在

输出结果:------------------------------

E:\Test\Ant\condition>ant
Buildfile: E:\Test\Ant\condition\build.xml


test:


isTrue:
     [echo] is ture


isFalse:


BUILD SUCCESSFUL
Total time: 0 seconds

---------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>  
<project basedir="." name="test1" default="test">  
      
    <!--属性也可以通过ant参数-D来设置-->
    <property name="name" value="this is name"/>    
    <target name="test">
        <condition property="scondition">
            <!--如果属性name不存在则返回false-->
            <isset property="name1"/>
        </condition>
        <antcall target="isTrue"></antcall>
        <antcall target="isFalse"></antcall>        
    </target>

    <fail
            message="scondition is missing. "
            unless="scondition"
    />

    <target name="isTrue" if="scondition">
        <echo>is ture</echo>
    </target>
    <target name="isFalse" unless="scondition">
        <echo>is false</echo>
    </target>
      
</project>

错误输出,并且停止

输出结果:------------------------------


E:\Test\Ant\condition>ant
Buildfile: E:\Test\Ant\condition\build.xml


BUILD FAILED
E:\Test\Ant\condition\build.xml:18: scondition is missing.


Total time: 0 seconds

-----------------------------------------

<?xml version="1.0" encoding="UTF-8"?>  
<project basedir="." name="test1" default="test">  
      
    <path id="all.test.classes">         
         <pathelement location="."/>
     </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>
输出结果:-----------------------------


E:\Test\Ant\condition>ant
Buildfile: E:\Test\Ant\condition\build.xml


test:


isTrue:


isFalse:
     [echo] is false


BUILD SUCCESSFUL
Total time: 0 seconds

-----------------------------------------

<?xml version="1.0" encoding="UTF-8"?>  
<project basedir="." name="test1" default="test">  
      
    <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>
如果两个文件都不存在,他们肯定是相等的
输出结果:------------------------------

E:\Test\Ant\condition>ant
Buildfile: E:\Test\Ant\condition\build.xml


test:


isTrue:
     [echo] is ture


isFalse:


BUILD SUCCESSFUL
Total time: 0 seconds

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值