antif-statementdepends

How to write conditional logic using ant-contrib


I am a beginner in ANT.

What am I doing wrong? ant-contrib-1.0b3 , is available. I would like to call the default target as follows:

<target name="build">
<if>
 <equals arg1="${config.name}" arg2="foo" />
 <then>
   <depends="get-all-war,..." />
 </then>
 <elseif>
 <equals arg1="${config.name}" arg2="mark" />
 <then>
   <depends="zip-wars, ..." />
 </then>
 </elseif>
 <else>
    <depends="get-all-war, zip-wars, docs, deleteAll" />
 </else>
</if>


Solution

  • You can do the same thing smartly using macros. If your targets get-all-war, zip-wars, docs, deleteAll take more time you can run them in parallel like this :

    <target name="build">
      <if>
      <equals arg1="${config.name}" arg2="foo" />
      <then>
        <mGetAllWar/>
      </then>
      <elseif>
      <equals arg1="${config.name}" arg2="mark" />
      <then>
        <mZipWars />
      </then>
      </elseif>
      <else>
        <mRestAllTargets/>
      </else>
    </if>
    
    <mGetAllWar>
      <parallel>
        <antcall name="target1">
        <antcall name="target2">
        ... 
      </parallel>
    </mGetAllWar>
    
    <mZipWars >
      <parallel>
        <antcall name="target1">
        <antcall name="target2">
        ... 
      </parallel>
    </mZipWars >
    
    <mRestAllTargets>
      <parallel>
        <antcall name="target1">
        <antcall name="target2">
        ... 
      </parallel>
    </mRestAllTargets>