ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Slass <mik...@wrq.com>
Subject Re: Does ANT have an 'if' statement, or equivalent
Date Wed, 26 Jun 2002 14:54:39 GMT
PeterJ Kelly <PeterJ.Kelly@aepona.com> writes:

>Hi,
>  I'm using ANT version 1.4 and was wondering if ANT had an 'if'
>statment, or equivalent?
>Basically I'm creating a build script that will check first if a
>filename exists in a directory.
>If it does it will give the new file a different name, otherwise it'll
>give it the original name.
>
>E.G.  if (originalFileNameExists == true) {
>          tempFile = newFileName
>      } 
>      else { tempFile = originalFileName
>      }
>
>
>Many thanks,
>Peter.
>-- 

The short answer is to use the <available> task, which sets a property
to a value if the named file exists; combine that with the XML rule that a
property, once set, is immutable, and you get something like this:

<available file     = "/path/to/originalFileName"
           property = "tempFile"
           value    = "originalFileName"/>
<property  name     = "tempFile"
           value    = "newFileName"/>

<!-- do something using the ${tempFile} property -->


What this means:

if ( exists(/path/to/originalFileName))
    tempFile = "originalFileName";
tempFile = "newFileName";

Since tempFile can't change once it's set, the second statement will
be ignored if tempFile is set by the first statement.


The same logic may be generalized to other conditions.  Look at the
<condition> task.



-- 
Mike Slass

,----                       WRQ, Inc.
|
| We specialize in integration software and services that let you
| quickly adapt your host-intensive environment to meet new business
| needs.
`----


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


Mime
View raw message