You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Russ Fink <ru...@hotmail.com> on 2001/12/03 20:05:03 UTC

newbie - if-then-else task?

Hello,

I'm new at Ant and I will describe what I want to do -- followed with how I 
hope to do it.

I'm trying to copy files from two sources, a system directory followed by a 
local directory.  This is prior to a build, and I'm modifying an existing 
build file.  What I want is to copy a file from a system directory, and if a 
file exists in a similar local structure, I want to copy that version.  Both 
destinations are the same, i.e., a
generated directory.

I tried using the <copy> target to copy from the system location first, then 
the local directory second, and the problem is that the build fails if it 
doesn't find the file in the local directory.

How I want to do this is to use conditional logic.  Basically, if the local 
file exists, I want to use it, but if it doesn't exist, I want to use the 
system copy.

Questions.  Is this how you would do it?  If so, what is the method for 
<if-then-else> or what can I use?

I can't easily do this with <available>, since all that does is set a flag, 
which apparently can only be used in the <target> line.  What I want is 
within a target, being able to evaluate a tag and take some action.

I'm open to suggestions - Thanks,
Russ

PS: the manual is very good, but it would be much better if there were an 
index in it somewhat similar to Javadocs.


_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp


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


Re: newbie - if-then-else task?

Posted by Erik Hatcher <ja...@ehatchersolutions.com>.
Ha!  I knew I'd find a way to get a correction on Diane if I waited long
enough :)

Actually the back-door hack for <available> is being left in (just with a
nasty message if you overwrite a propertys value using it) - that was the
curreent consensus, unfortunately.  This may change before the release of
1.5, but thats how it exists in the nightly builds now though.

    Erik "crossing my fingers that I got this answer right"


----- Original Message -----
From: "Diane Holt" <ho...@yahoo.com>
To: "Ant Users List" <an...@jakarta.apache.org>
Sent: Monday, December 03, 2001 2:58 PM
Subject: Re: newbie - if-then-else task?


> You can use <available>. It doesn't "just set a flag" -- you can assign
> any value to the property it's (potentially) setting, so have the value be
> the path to the file it finds, then reference that property in your <copy>
> task.
>
> If you can use a nightly build rather than a release, you can do this more
> easily, since, if the local file was found and therefore the
> filename-property was set to that, the second check (the one for the
> system file) won't (now) overwrite the value of the filename-property. If
> you need to use a release, you'll need to do it in a couple of more steps,
> but it's still quite doable.
>
> Diane
>
> --- Russ Fink <ru...@hotmail.com> wrote:
> > Hello,
> >
> > I'm new at Ant and I will describe what I want to do -- followed with
> > how I
> > hope to do it.
> >
> > I'm trying to copy files from two sources, a system directory followed
> > by a
> > local directory.  This is prior to a build, and I'm modifying an
> > existing
> > build file.  What I want is to copy a file from a system directory, and
> > if a
> > file exists in a similar local structure, I want to copy that version.
> > Both
> > destinations are the same, i.e., a
> > generated directory.
> >
> > I tried using the <copy> target to copy from the system location first,
> > then
> > the local directory second, and the problem is that the build fails if
> > it
> > doesn't find the file in the local directory.
> >
> > How I want to do this is to use conditional logic.  Basically, if the
> > local
> > file exists, I want to use it, but if it doesn't exist, I want to use
> > the
> > system copy.
> >
> > Questions.  Is this how you would do it?  If so, what is the method for
> > <if-then-else> or what can I use?
> >
> > I can't easily do this with <available>, since all that does is set a
> > flag,
> > which apparently can only be used in the <target> line.  What I want is
> > within a target, being able to evaluate a tag and take some action.
> >
> > I'm open to suggestions - Thanks,
> > Russ
> >
> > PS: the manual is very good, but it would be much better if there were
> > an
> > index in it somewhat similar to Javadocs.
> >
> >
> > _________________________________________________________________
> > Get your FREE download of MSN Explorer at
> > http://explorer.msn.com/intl.asp
> >
> >
> > --
> > To unsubscribe, e-mail:
> > <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> > <ma...@jakarta.apache.org>
> >
>
>
> =====
> (holtdl@yahoo.com)
>
>
>
> __________________________________________________
> Do You Yahoo!?
> Buy the perfect holiday gifts at Yahoo! Shopping.
> http://shopping.yahoo.com
>
> --
> 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>


Re: newbie - if-then-else task?

Posted by Diane Holt <ho...@yahoo.com>.
You can use <available>. It doesn't "just set a flag" -- you can assign
any value to the property it's (potentially) setting, so have the value be
the path to the file it finds, then reference that property in your <copy>
task.

If you can use a nightly build rather than a release, you can do this more
easily, since, if the local file was found and therefore the
filename-property was set to that, the second check (the one for the
system file) won't (now) overwrite the value of the filename-property. If
you need to use a release, you'll need to do it in a couple of more steps,
but it's still quite doable. 

Diane

--- Russ Fink <ru...@hotmail.com> wrote:
> Hello,
> 
> I'm new at Ant and I will describe what I want to do -- followed with
> how I 
> hope to do it.
> 
> I'm trying to copy files from two sources, a system directory followed
> by a 
> local directory.  This is prior to a build, and I'm modifying an
> existing 
> build file.  What I want is to copy a file from a system directory, and
> if a 
> file exists in a similar local structure, I want to copy that version. 
> Both 
> destinations are the same, i.e., a
> generated directory.
> 
> I tried using the <copy> target to copy from the system location first,
> then 
> the local directory second, and the problem is that the build fails if
> it 
> doesn't find the file in the local directory.
> 
> How I want to do this is to use conditional logic.  Basically, if the
> local 
> file exists, I want to use it, but if it doesn't exist, I want to use
> the 
> system copy.
> 
> Questions.  Is this how you would do it?  If so, what is the method for 
> <if-then-else> or what can I use?
> 
> I can't easily do this with <available>, since all that does is set a
> flag, 
> which apparently can only be used in the <target> line.  What I want is 
> within a target, being able to evaluate a tag and take some action.
> 
> I'm open to suggestions - Thanks,
> Russ
> 
> PS: the manual is very good, but it would be much better if there were
> an 
> index in it somewhat similar to Javadocs.
> 
> 
> _________________________________________________________________
> Get your FREE download of MSN Explorer at
> http://explorer.msn.com/intl.asp
> 
> 
> --
> To unsubscribe, e-mail:  
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 


=====
(holtdl@yahoo.com)



__________________________________________________
Do You Yahoo!?
Buy the perfect holiday gifts at Yahoo! Shopping.
http://shopping.yahoo.com

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