You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Mohit Anchlia <mo...@gmail.com> on 2008/10/14 22:33:07 UTC

If else

I am struggling with a very simple question. How do I test if a
variable is defined or not?

I tried:


        <if>
          <matches string="${jboss.wily.jvmargs}" pattern="^[ \t]+" />

and


        <if>
          <matches string="${jboss.wily.jvmargs}" pattern="" />

and


        <if>
          <length string="${jboss.wily.jvmargs}" trim="true"
when="greater" length="0" />



Nothing seem to work. jboss.wily.jvmargs may or may not be there in
property file

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


RE: If else

Posted by Lucas Albers <sm...@hotmail.com>.
I really like the ant-contrib tasks for this:


<project name="a">
<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>

<osfamily property="os.family"/>
<echo message="os.family:${os.family}"></echo>
<property file="${os.family}.properties"></property>


  <echo> os:${os.name} </echo>
    <echo> os.arch:${os.arch} </echo>
    <echo> os.version:${os.version} </echo>

<property name="linux_compile_dir" value="/nfs/Branch/"/>

<pathconvert property="windows_compile_dir" dirsep="\">
      <map from="/nfs" to='s:'/>
      <path location="${linux_compile_dir}"/>
    </pathconvert>

<echo>"windows_compile_dir:${windows_compile_dir}"</echo>
<echo>"linux_compile_dir:${linux_compile_dir}"</echo>



<if> <equals arg1="${os.family}" arg2="unix" />
        <then>
        <echo> "checking for existence of
directory:${linux_compile_dir}"</echo>

        <available file="${linux_compile_dir}" type="dir"
property="linux.dir.present"/>
                <if> <equals arg1="${linux.dir.present}" arg2="true" />
                <then>
                <echo>"linux dir exists: ${linux_compile_dir}:
${linux.dir.present}"</echo> 
                </then>
                </if>
</then>
</if>

http://ant-contrib.sourceforge.net/tasks/tasks/index.html



-----Original Message-----
From: Mohit Anchlia [mailto:mohitanchlia@gmail.com] 
Sent: Tuesday, October 14, 2008 2:33 PM
To: Ant Users List
Subject: If else

I am struggling with a very simple question. How do I test if a
variable is defined or not?

I tried:


        <if>
          <matches string="${jboss.wily.jvmargs}" pattern="^[ \t]+" />

and


        <if>
          <matches string="${jboss.wily.jvmargs}" pattern="" />

and


        <if>
          <length string="${jboss.wily.jvmargs}" trim="true"
when="greater" length="0" />



Nothing seem to work. jboss.wily.jvmargs may or may not be there in
property file

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



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


RE: If else

Posted by Shawn Castrianni <Sh...@halliburton.com>.
If the jboss.wily.jvmargs property is not set, then ${jboss.wily.jvmargs} doesn't evaluate to anything other than:

${jboss.wily.jvmargs}

which will always have a length greater than 0.

---
Shawn Castrianni

-----Original Message-----
From: Mohit Anchlia [mailto:mohitanchlia@gmail.com]
Sent: Tuesday, October 14, 2008 4:21 PM
To: Ant Users List
Subject: Re: If else

that works. thanks

But I don't understand what I was doing wrong.

On Tue, Oct 14, 2008 at 1:44 PM, Alec Fernandez <Al...@sas.com> wrote:
> try the <isset
> condition
>
>>> -----Original Message-----
>>> From: Mohit Anchlia [mailto:mohitanchlia@gmail.com]
>>> Sent: Tuesday, October 14, 2008 10:33 PM
>>> To: Ant Users List
>>> Subject: If else
>>>
>>> I am struggling with a very simple question. How do I test if a
>>> variable is defined or not?
>>>
>>> I tried:
>>>
>>>
>>>         <if>
>>>           <matches string="${jboss.wily.jvmargs}" pattern="^[ \t]+" />
>>>
>>> and
>>>
>>>
>>>         <if>
>>>           <matches string="${jboss.wily.jvmargs}" pattern="" />
>>>
>>> and
>>>
>>>
>>>         <if>
>>>           <length string="${jboss.wily.jvmargs}" trim="true"
>>> when="greater" length="0" />
>>>
>>>
>>>
>>> Nothing seem to work. jboss.wily.jvmargs may or may not be there in
>>> property file
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>>> For additional commands, e-mail: user-help@ant.apache.org
>>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>

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


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


Re: If else

Posted by Mohit Anchlia <mo...@gmail.com>.
that works. thanks

But I don't understand what I was doing wrong.

On Tue, Oct 14, 2008 at 1:44 PM, Alec Fernandez <Al...@sas.com> wrote:
> try the <isset
> condition
>
>>> -----Original Message-----
>>> From: Mohit Anchlia [mailto:mohitanchlia@gmail.com]
>>> Sent: Tuesday, October 14, 2008 10:33 PM
>>> To: Ant Users List
>>> Subject: If else
>>>
>>> I am struggling with a very simple question. How do I test if a
>>> variable is defined or not?
>>>
>>> I tried:
>>>
>>>
>>>         <if>
>>>           <matches string="${jboss.wily.jvmargs}" pattern="^[ \t]+" />
>>>
>>> and
>>>
>>>
>>>         <if>
>>>           <matches string="${jboss.wily.jvmargs}" pattern="" />
>>>
>>> and
>>>
>>>
>>>         <if>
>>>           <length string="${jboss.wily.jvmargs}" trim="true"
>>> when="greater" length="0" />
>>>
>>>
>>>
>>> Nothing seem to work. jboss.wily.jvmargs may or may not be there in
>>> property file
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>>> For additional commands, e-mail: user-help@ant.apache.org
>>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>

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


RE: If else

Posted by Alec Fernandez <Al...@sas.com>.
try the <isset
condition

>> -----Original Message-----
>> From: Mohit Anchlia [mailto:mohitanchlia@gmail.com]
>> Sent: Tuesday, October 14, 2008 10:33 PM
>> To: Ant Users List
>> Subject: If else
>>
>> I am struggling with a very simple question. How do I test if a
>> variable is defined or not?
>>
>> I tried:
>>
>>
>>         <if>
>>           <matches string="${jboss.wily.jvmargs}" pattern="^[ \t]+" />
>>
>> and
>>
>>
>>         <if>
>>           <matches string="${jboss.wily.jvmargs}" pattern="" />
>>
>> and
>>
>>
>>         <if>
>>           <length string="${jboss.wily.jvmargs}" trim="true"
>> when="greater" length="0" />
>>
>>
>>
>> Nothing seem to work. jboss.wily.jvmargs may or may not be there in
>> property file
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>> For additional commands, e-mail: user-help@ant.apache.org
>>


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