You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by John Volkar <jv...@etransport.com> on 2001/12/27 18:54:58 UTC

Newbie help

Okay, I give, how do I conditionally execute a <task>? (actually in my case
<antcall> a <target>???)

Say I have (somewhere previously) defined:
  <property name="call_local_cleanup" value="true">
This might be specified via the command line or in a calling target.

The target "local-cleanup" does (potentially) horrid things to the users
basedir, notibly things like a mass delete and re-get from version control.
(which is slow and painful, therefore user may desire to skip this.)

What I want to do is something like...

if ${call_local_cleanup}==true
  <antcall target="local-cleanup">
else
  <echo message="skipping local-cleanup">


How would I do something like this?

Thanks in advance...
John Volkar


ps: I'm leaving for the day, time to visit the liquor store for New Years
Eve supplies, so I'll hope to see a response tomorrow... thanks.


  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Newbie help

Posted by Adam Murdoch <ad...@yahoo.com>.
Hi,

You have a few options.  Simplest is to put the condition on the
"local-cleanup" target itself:

<target name="local-cleanup" if="call_local_cleanup">
...
</target>

The contents of the local-cleanup target will only be executed if
"call_local_cleanup" is set (to any value, including values like "false").
With this approach, you miss out on the log message - which might be worth
it for the sake of a simpler build file.

Alternatively, you can create two extra targets - one for each of the
branches of the "if":

<target name="skip-local-cleanup" unless="call_local_cleanup">
    <log>...</log>
</target>

<target name="conditional-local-cleanup" depends="skip-local-cleanup"
if="call_local_cleanup">
    <antcall target="local-cleanup"/>
</target>

Then use "conditional-local-cleanup" instead of "local-cleanup" in depend
lists and <antcall>s.

You could possibly combine the 2 approaches, and roll
"conditional-local-cleanup" up into "local-cleanup".


Adam

> -----Original Message-----
> From: John Volkar [mailto:jvolkar@etransport.com]
> Sent: Friday, 28 December 2001 3:55 AM
> To: Ant Users List
> Subject: Newbie help <condition>
>
>
> Okay, I give, how do I conditionally execute a <task>? (actually
> in my case
> <antcall> a <target>???)
>
> Say I have (somewhere previously) defined:
>   <property name="call_local_cleanup" value="true">
> This might be specified via the command line or in a calling target.
>
> The target "local-cleanup" does (potentially) horrid things to the users
> basedir, notibly things like a mass delete and re-get from
> version control.
> (which is slow and painful, therefore user may desire to skip this.)
>
> What I want to do is something like...
>
> if ${call_local_cleanup}==true
>   <antcall target="local-cleanup">
> else
>   <echo message="skipping local-cleanup">
>
>
> How would I do something like this?
>
> Thanks in advance...
> John Volkar
>
>
> ps: I'm leaving for the day, time to visit the liquor store for New Years
> Eve supplies, so I'll hope to see a response tomorrow... thanks.
>
>
>
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>