You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Guy Catz <Gu...@waves.com> on 2008/06/29 11:19:40 UTC

is a property defined?

How can I tell if a property is defined?

I've tried <if> from contrib like this - if .. ${var} = "" ...
That's fine for properties which was set to "", but not for properties who haven't set at all.

Next, I've tried <length string="${var}" property="length.var"...
and then <if> ${length.var}="0", but I always get length.var = 6 because it didn't open the ${var}, which is 6 chars.

Please advise.

Thanks,
    Guy.

Re: is a property defined?

Posted by David Weintraub <qa...@gmail.com>.
This is Nant or Ant? If this is Ant, you'd do it this way:

<if>
   <equals arg1="${var}" arg2=""/>
   <then>
         <echo>blah, blah, blah</echo>
   </then>
   <else>  <!-- OPTIONAL-->
        <echo>Yadda, Yadda, Yadda</echo>
   </else>
</if>

If you want to do not equals, you do this:

<if>
    <not>
       <equals arg1="${var}" arg2=""/>
    </not>
    <then>
       <echo message="Blah, blah, blah"/>
    </then>
<if>


Take a look at the <condition> task's conditions at
<http://ant.apache.org/manual/CoreTasks/conditions.html>

--
David Weintraub
qazwart@gmail.com


On Sun, Jun 29, 2008 at 5:19 AM, Guy Catz <Gu...@waves.com> wrote:
> How can I tell if a property is defined?
>
> I've tried <if> from contrib like this - if .. ${var} = "" ...
> That's fine for properties which was set to "", but not for properties who haven't set at all.
>
> Next, I've tried <length string="${var}" property="length.var"...
> and then <if> ${length.var}="0", but I always get length.var = 6 because it didn't open the ${var}, which is 6 chars.
>
> Please advise.
>
> Thanks,
>    Guy.
>

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


Re: is a property defined?

Posted by Gilbert Rebhan <an...@schillbaer.de>.
Guy Catz schrieb:
> How can I tell if a property is defined?
> 
> I've tried <if> from contrib like this - if .. ${var} = "" ...
> That's fine for properties which was set to "", but not for properties who haven't set at all.

use condition isset, see ant manual conditions,
f.e. =

<condition property="foobar.set">
   <isset property="foobar"/>
</condition>

Regards, Gilbert

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