ant control statements


Loop

The 'loop' task required ant-contrib package, please download from

http://ncu.dl.sourceforge.net/project/ant-contrib/ant-contrib/1.0b3/ant-contrib-1.0b3-bin.zip


Loop all .txt file in a folder, and take action on each file


    <taskdef name="for" classname="net.sf.antcontrib.logic.ForTask" classpath="${lib.dir}/lib/ant-contrib-1.0b3.jar" />

    <target name="loopfolder">
        <for param="filename">
            <path>=>
                <fileset dir="${folder}" excludes="test.txt" includes="*.txt" />
            </path>
            <sequential>
                <echo message="@{filename}"/>
            </sequential>
        </for>
    </target>



Call Another Target


    <taskdef name="for" classname="net.sf.antcontrib.logic.ForTask" classpath="${lib.dir}/lib/ant-contrib-1.0b3.jar" />
    <target name="loopfolder">
        <for param="filename">
            <path>=>
                <fileset dir="${folder}" excludes="test.txt" includes="*.txt" />
            </path>
            <sequential>
                <echo message="@{filename}"/>
                <antcall target="fileaction"/>
            </sequential>
        </for>
    </target>

    <target name="fileaction">
        <property name="infile" value="${data.dir}/demo.txt"/>
        <echo message="${infile}"/>
    </target>


Call Another Target with parameters passing

    <taskdef name="for" classname="net.sf.antcontrib.logic.ForTask" classpath="${lib.dir}/lib/ant-contrib-1.0b3.jar" />
    <target name="loopfolder">
        <for param="filename">
            <path>=>
                <fileset dir="${folder}" excludes="test.txt" includes="*.txt" />
            </path>
            <sequential>
                <echo message="@{filename}"/>
                <antcall target="fileaction">
                    <param name="infile" value="@{filename}"/>
                </antcall>
            </sequential>
        </for>
    </target>

    <target name="fileaction">
        <property name="infile" value="${data.dir}/demo.txt"/>
        <echo message="${infile}"/>
    </target>


If-Then-Else

The 'if' task required ant-contrib package, please refer to 'Loop' task

        <taskdef name="if" classname="net.sf.antcontrib.logic.IfTask" classpath="${lib.dir}/lib/ant-contrib-1.0b3.jar" />
        <if>
            <filesmatch file1="${infile}" file2="${outfile}"/>
        <then>
            <echo message="File ${infile} and file ${outfile} are same" />
        </then>
        <else>
            <echo message="WARNING: File ${infile} and file ${outfile} are same" />
        </else>
        </if>


Failed a build

        <taskdef name="if" classname="net.sf.antcontrib.logic.IfTask" classpath="${lib.dir}/lib/ant-contrib-1.0b3.jar" />
        <if>
            <filesmatch file1="${infile}" file2="${outfile}"/>
        <then>
            <echo message="File ${infile} and file ${outfile} are same" />
        </then>
        <else>
            <fail message="Build failed because file ${infile} and file ${outfile} are not matched." />
        </if>



ant.project.name

This is global project name, its value is define in 'project' element.



<project name="TestProject" default="compile" basedir=".">
        <property name="yourprojectname"     value="${ant.project.name}"/>
        ...</project>




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值