Ant conditional if within a macrodef

后端 未结 2 1524
醉话见心
醉话见心 2021-01-11 14:19

Within ant, I have a macrodef.

Assuming I have to use this macrodef, and there is a item inside said macrodef that I want to run if the property special.proper

相关标签:
2条回答
  • 2021-01-11 14:46

    This is only possible if the ANT "thingHereThatDependsOn" task supports an "if" attribute.

    As stated above, conditional execution in ANT, normally, only applies to targets.

    <target name="doSomething" if="allowed.to.do.something">
       ..
       ..
    </target>
    
    <target name="doSomethingElse" unless="allowed.to.do.something">
       ..
       ..
    </target>
    
    <target name="go" depends="doSomething,doSomethingElse"/>
    
    0 讨论(0)
  • 2021-01-11 15:06

    In Ant 1.9.1 and higher, there is now a new implementation of if and unless attributes. This might be what you're thinking of.

    First, you need to put them into your namespace. Add them to your <project> header:

    <project name="myproject" basedir="." default="package"
        xmlns:if="ant:if"
        xmlns:unless="ant:unless">
    

    Now, you can add them to almost any Ant task or sub entity:

    <!-- Copy over files from special directory, but only if it exists -->
    <available property="special.dir.available"
        file="${special.dir} type="dir"/>
    
    <copy todir="${target.dir}>
        <fileset dir="${special.dir}" if:true="special.dir.available"/>
        <fileset dir="${other.dir}"/>
    </copy>
    
    <!-- FTP files over to host, but only if it's on line-->
    <condition property="ftp.available">
        <isreachable host="${ftp.host}"/>
    </condition>
    
    <ftp server="${ftp.host}" 
        userid="${userid}"
        passowrd="${password}"
        if:true="ftp.available">
        <fileset dir=".../>
    </ftp>
    
    0 讨论(0)
提交回复
热议问题