ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matt Benson <gudnabr...@gmail.com>
Subject Re: Alternative to if else task.
Date Fri, 11 Feb 2011 15:57:17 GMT
On Fri, Feb 11, 2011 at 9:49 AM, ritchie <ganesh.devarajulu@baml.com> wrote:

>
> Matt,
>  The target option would be good if the other target does not fail, but in
> my build file i have target which executes perforce command and i capture
> the result of the exec task in resultproperty. If the value of result
> property is ==0 then i execute another target else execute a different
> target.
>
> <target name="testperforce" depends="stage">
>    <exec executable="p4.exe" spawn="false" failonerror="false"
> resultproperty="p4result">
>    <arg value="changes"/>
>    <arg value="-m1"/>
>    <arg value="${file.name}"/>
>    </exec>
>   <if name="p4result" value="0">
>   <antcall target ="p4changes"/>
>   </if>
>   <else>
>   <antcall target="defaultchangenumber"/>
>   </else>
> </target>
>

So:

<target name="-testperforce" depends="stage">
  <exec executable="p4.exe" spawn="false"
failonerror="false" resultproperty="p4result">
    <arg value="changes"/>
    <arg value="-m1"/>
    <arg value="${file.name}"/>
  </exec>
  <condition property="p4success">
    <equals arg1="${p4result}" arg2="0" />
  </condition>
</target>

<target name="testperforce" depends="p4changes,defaultchangenumber" />

<target name="p4changes" depends="-testperforce" if="p4success" ...
<target name="defaultchangenumber" depends="-testperforce"
unless="p4success" ...

See?  This also avoids the expensive antcalls.

Matt


> --
> View this message in context:
> http://ant.1045680.n5.nabble.com/Alternate-for-if-else-task-tp3381392p3381432.html
> Sent from the Ant - Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message