ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rebhan, Gilbert" <Gilbert.Reb...@huk-coburg.de>
Subject RE: how to check that a property exist
Date Wed, 11 Jun 2008 11:45:15 GMT
 
-----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


Mime
View raw message