ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <Patrizio.Ferl...@b-source.ch>
Subject RE: how to check that a property exist
Date Thu, 12 Jun 2008 11:10:38 GMT

Hi Gilbert,

thanks a lot for your hint but I would like to find a way without using antcontrib...

After some tries here what I've found but I've two issues:

i) a property defined in a target is not visible in another. How could I set, let's say, a
'global property' ?
ii) a way to get 'your' $${${IPEvent}.pollerManagedServer} as value in a property

My tries ....


<target name="test">
    <antcall target="retrievePollerValue"/>
    <echo>pollerValue        : ${pollerValue}</echo>

  <target name="retrievePollerValue" depends="pollerEventIsSet-if,pollerEventIsSet-else"/>
  <target name="check-pollerEventIsSet">
    <condition property="pollerEventIsSet">
      <isset property="${IPEvent}.pollerManagedServer"/>
    </condition>
  </target>
  <target name="pollerEventIsSet-if" depends="check-pollerEventIsSet" if="pollerEventIsSet">
    <property name="pollerValue" value="$${${IPEvent}.pollerManagedServer}"/>
    <echo>pollerEventIsSet, pollerValue: ${pollerValue}</echo>
  </target>
  <target name="pollerEventIsSet-else" depends="check-pollerEventIsSet" unless="pollerEventIsSet">
    <property name="pollerValue" value="${defaultPollerManagedServer}"/>
    <echo>pollerEventIsNotSet, pollerValue: ${pollerValue}</echo>
  </target>

where

<property name="defaultPollerManagedServer" value="A"/>
<property name="TestEvent.pollerManagedServer" value="B"/>
<property name="DummyEvent.pollerManagedServer" value="C"/>

that works more or less ...

I see

1) with a not defined <something>.pollerManagedServer property: 

1.a) OK: pollerEventIsSet-else is called and 'locally' the value is correct

check-pollerEventIsSet:
pollerEventIsSet-if:
pollerEventIsSet-else:
     [echo] pollerEventIsNotSet, pollerValue: bnk01alm01

1.b) but at 'test' target level the value is not visible

test:
     [echo] pollerValue        : ${pollerValue}

2. with a defined <something>.pollerManagedServer property:

2.a) pollerEventIsSet-if is called

check-pollerEventIsSet:
pollerEventIsSet-if:
     [echo] pollerEventIsSet, pollerValue: ${DummyEvent.pollerManagedServer}
pollerEventIsSet-else:

but as you can see it seems that the

 <property name="pollerValue" value="$${${IPEvent}.pollerManagedServer}"/>

is not the propery way to set the value !!!!

So, as you can see your 'if' is achieved in a different way but I'm not able to solve my i)
& ii) issues.

Do you have any idea ?

Regards
Patrizio





-----Original Message-----
From: Rebhan, Gilbert [mailto:Gilbert.Rebhan@huk-coburg.de] 
Sent: mercoledì, 11. giugno 2008 13:45
To: Ant Users List
Subject: RE: how to check that a property exist



 
-----Original Message-----
From: Patrizio.Ferlito@b-source.ch [mailto:Patrizio.Ferlito@b-source.ch]

Sent: Wednesday, June 11, 2008 12:22 PM
To: user@ant.apache.org
Subject: how to check that a property exist

/*
I've a properties file like that:

...
defaultPollerManagedServer=A
TestEvent.pollerManagedServer=B
DummyEvent.pollerManagedServer=C
...

I run my build.xml providing a parameter:

ant -DIPEvent=TestEvent

And I would like to set the value of a property named 'pollerEventValue'
according to these rules:

1) if exists a property like 

    <property name="pollerEvent"
value="${IPEvent}.pollerManagedServer"/>

then the requested value is:

    <property name="pollerEventValue" value="${${pollerEvent}}"/>
?????? but I think the syntax is wrong

2) else take as value

    <property name="pollerEventValue"
value="${defaultPollerManagedServer}"/>

So if I run:

 ant -DIPEvent=TestEvent   the expected value is B
 ant -DIPEvent=other       the expected value is A (the default one)

Could anyone help me to solve that ?
*/


that's a tricky one, i once had a similar problem and discovered, that
it works with the <var> task of antcontrib, so the solution in your case
would be =

ant -DIPEvent=TestEvent -f yourbuild.xml ...

and

<!-- // Taskdefs -->
<!-- Import AntContrib -->
<taskdef resource="net/sf/antcontrib/antlib.xml" />
<!-- Taskdefs // -->

<!-- // Properties -->
<property name="defaultPollerManagedServer" value="A"/>
<property name="TestEvent.pollerManagedServer" value="B"/>
<property name="DummyEvent.pollerManagedServer" value="C"/>
<!-- Properties // -->

<target name="depends"> 
 <if>
  <isset property="${IPEvent}.pollerManagedServer"/>
   <then>
     <var name="pollerEventValue"
value="$${${IPEvent}.pollerManagedServer}"/>
   </then>
   <else>
     <property name="pollerEventValue"
value="${defaultPollerManagedServer}"/>
   </else>
 </if>
</target>

<target name="main" depends="depends">
  <echo>$${pollerEventValue} == ${pollerEventValue}</echo>
</target>
</project>


you need antcontrib =
http://sourceforge.net/project/showfiles.php?group_id=36177


Regards, Gilbert

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


IMPORTANT: 
This e-mail transmission is intended for the named 
addressee(s)only. 
Its contents are private, confidential and protected 
from disclosure and should not be read, copied or
disclosed by any other person. 
If you are not the intended recipient, we kindly ask
you to notify the sender immediately by telephone 
(+41 (0)58 806 50 00), to redirect the message to the 
account "info@b-source.ch" and to delete this e-mail.
E-mail transmissions may be intercepted, altered or 
read by unauthorized persons and may contain viruses.
Therefore, it is recommended that you use regular mail
or courier services for any information intended to be 
confidential. However, by sending us messages through
e-mail, you authorize and instruct us to correspond by 
e-mail in the relevant matter. 
Thank you.


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


Mime
View raw message