You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by ritchie <ga...@baml.com> on 2011/02/11 16:34:54 UTC

Alternative to if else task.

I am using a if else task in my build file and i had to add the additional
jar antelopetasks....jar to my lib folder of ant to make this run. My
problem is for this to work for other developers they all have to add the
jar file to their ant/lib dir, but my organization is not keen with this
idea since there are more than 100 developers who would be using this build
file and they want a alternate solution.
My question is, is there a alternate to if-else task which will not need any
additional jars to run?
-- 
View this message in context: http://ant.1045680.n5.nabble.com/Alternative-to-if-else-task-tp3381392p3381392.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


Re: Alternative to if else task.

Posted by ritchie <ga...@baml.com>.
Yes.
-- 
View this message in context: http://ant.1045680.n5.nabble.com/Alternate-for-if-else-task-tp3381392p3381951.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


Re: Alternative to if else task.

Posted by Rick Genter <ri...@gmail.com>.
On Feb 11, 2011, at 11:35 AM, ritchie wrote:

> 
> <target name="p4changes" depends="-testperforce" if="p4success" ... 
> 
> Are the if and unless attributes supported in Ant 1.7.1 and lower?

I'm pretty sure if and unless have been part of ant since 1.0. They were there when I started to use ant in 2003.

--
Rick Genter
rick.genter@gmail.com


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Alternative to if else task.

Posted by ritchie <ga...@baml.com>.
<target name="p4changes" depends="-testperforce" if="p4success" ... 

Are the if and unless attributes supported in Ant 1.7.1 and lower?
-- 
View this message in context: http://ant.1045680.n5.nabble.com/Alternate-for-if-else-task-tp3381392p3381898.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


Re: Alternative to if else task.

Posted by ritchie <ga...@baml.com>.
Thanks Matt it works. I ran the script -If and unless is supported in v1.7.1.
-- 
View this message in context: http://ant.1045680.n5.nabble.com/Alternate-for-if-else-task-tp3381392p3381949.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


Re: Alternative to if else task.

Posted by Matt Benson <gu...@gmail.com>.
On Fri, Feb 11, 2011 at 9:49 AM, ritchie <ga...@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
>
>

Re: Alternative to if else task.

Posted by ritchie <ga...@baml.com>.
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>
-- 
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


Re: Alternative to if else task.

Posted by Matt Benson <gu...@gmail.com>.
On Fri, Feb 11, 2011 at 9:34 AM, ritchie <ga...@baml.com> wrote:

>
> I am using a if else task in my build file and i had to add the additional
> jar antelopetasks....jar to my lib folder of ant to make this run. My
> problem is for this to work for other developers they all have to add the
> jar file to their ant/lib dir, but my organization is not keen with this
> idea since there are more than 100 developers who would be using this build
> file and they want a alternate solution.
> My question is, is there a alternate to if-else task which will not need
> any
> additional jars to run?
>

The alternative is structured target dependencies per
http://ant.apache.org/manual/targets.html#targets .

HTH,
Matt


> --
> View this message in context:
> http://ant.1045680.n5.nabble.com/Alternative-to-if-else-task-tp3381392p3381392.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
>
>

Re: Alternative to if else task.

Posted by Peter Reilly <pe...@gmail.com>.
You do not need to place the antelope jar in the
ant/lib directory.

It is not in general a good idea to do this for
antlibs.

Add the antelope jar to the project files, for
example in {PROJECT}/lib/ant/
and in the build.xml, use <typedef> to define
the tasks.

In my build.xml I have the following:

 <typedef uri="antlib:net.sf.antcontrib">
    <classpath>
      <fileset dir="lib/ant/ant-contrib" includes="*.jar"/>
    </classpath>
  </typedef>

One can do something similar for the antelope jar.

Peter

On Fri, Feb 11, 2011 at 3:34 PM, ritchie <ga...@baml.com> wrote:
>
> I am using a if else task in my build file and i had to add the additional
> jar antelopetasks....jar to my lib folder of ant to make this run. My
> problem is for this to work for other developers they all have to add the
> jar file to their ant/lib dir, but my organization is not keen with this
> idea since there are more than 100 developers who would be using this build
> file and they want a alternate solution.
> My question is, is there a alternate to if-else task which will not need any
> additional jars to run?
> --
> View this message in context: http://ant.1045680.n5.nabble.com/Alternative-to-if-else-task-tp3381392p3381392.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
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org