You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Mikael Petterson <mi...@ericsson.com> on 2009/08/26 10:43:56 UTC
Condition to set property value if file exist
Hi,
I have the following scenario.
I will check if I have the following directories:
/tmp/test
/local/test
I want to set a property called "local" to
/tmp/test if directory exists.
If it does not exist I will check if /local/test exist.
If it does I will set "local" to /local/test.
If none of these directories exist I will set "local" to current
directory.
Any ideas how I can do this in ant 1.6.5
//mike
Mikael Petterson
Software Designer
Ericsson AB, Stockholm, Sweden
Visiting address: Torshamnsgatan 42, Kista
Phone: +46 70 2673044
E-mail: mikael.petterson@ericsson.com
Re: Condition to set property value if file exist
Posted by Stefan Bodewig <bo...@apache.org>.
On 2009-08-26, Francis GALIEGUE <fg...@one2team.com> wrote:
> On Wed, Aug 26, 2009 at 11:19, Stefan Bodewig<bo...@apache.org> wrote:
>> On 2009-08-26, Mikael Petterson <mi...@ericsson.com> wrote:
>>> I want to set a property called "local" to
>>> /tmp/test if directory exists.
>>> If it does not exist I will check if /local/test exist.
>>> If it does I will set "local" to /local/test.
>>> If none of these directories exist I will set "local" to current
>>> directory.
>>> Any ideas how I can do this in ant 1.6.5
>> <available property="local" value="/tmp/test"
>> file="/tmp/test"/>
>> <available property="local" value="/local/test"
>> file="/local/test"/>
>> <property name="local" location="."/>
>> Since properties are immutable, if either of the first two available
>> tasks sets the property, the later tasks won't do anything.
> These <available> tasks will also match on plain files!
> To be safe, you should specify type="dir" to each <available> tasks.
True. I missed that "directory" was a requirement. Thanks
Stefan
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Condition to set property value if file exist
Posted by Francis GALIEGUE <fg...@one2team.com>.
On Wed, Aug 26, 2009 at 11:19, Stefan Bodewig<bo...@apache.org> wrote:
> On 2009-08-26, Mikael Petterson <mi...@ericsson.com> wrote:
>
>> I want to set a property called "local" to
>
>> /tmp/test if directory exists.
>> If it does not exist I will check if /local/test exist.
>> If it does I will set "local" to /local/test.
>> If none of these directories exist I will set "local" to current
>> directory.
>
>> Any ideas how I can do this in ant 1.6.5
>
> <available property="local" value="/tmp/test"
> file="/tmp/test"/>
> <available property="local" value="/local/test"
> file="/local/test"/>
> <property name="local" location="."/>
>
> Since properties are immutable, if either of the first two available
> tasks sets the property, the later tasks won't do anything.
>
These <available> tasks will also match on plain files!
To be safe, you should specify type="dir" to each <available> tasks.
--
Francis Galiegue
ONE2TEAM
Ingénieur système
Mob : +33 (0) 683 877 875
Tel : +33 (0) 178 945 552
fge@one2team.com
40 avenue Raymond Poincaré
75116 Paris
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Condition to set property value if file exist
Posted by Stefan Bodewig <bo...@apache.org>.
On 2009-08-26, Mikael Petterson <mi...@ericsson.com> wrote:
> I want to set a property called "local" to
> /tmp/test if directory exists.
> If it does not exist I will check if /local/test exist.
> If it does I will set "local" to /local/test.
> If none of these directories exist I will set "local" to current
> directory.
> Any ideas how I can do this in ant 1.6.5
<available property="local" value="/tmp/test"
file="/tmp/test"/>
<available property="local" value="/local/test"
file="/local/test"/>
<property name="local" location="."/>
Since properties are immutable, if either of the first two available
tasks sets the property, the later tasks won't do anything.
Stefan
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org