ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Donald <dona...@apache.org>
Subject Re: Property and refid
Date Thu, 10 May 2001 13:31:00 GMT
At 10:50  10/5/01 +0200, Stefan Lecho wrote:
>In the build file I have, I want to reference to a set of property
>definitions to be used by different targets. Something similar to
>	<property_collection id="common.properties">
>		<property name="myProperty" value="123"/>
>		<property name="yourProperty" value="456"/>
>	</property_collection>
>	<target name="test">
>		<antcall target="first">
>			<property refid="common.properties"/>
>		</antcall>
>		<antcall target="second">
>			<property refid="common.properties"/>
>		</antcall>
>	</target>
>
>Is there a way to achieve this ? I saw that there is a refid attribute in
><property>, but apparently that's only used for path like structures.
>
>Any help is welcome.

One way to solve this would be like

<target name="init-setup">
  <property name="set-${set}" value="true" />
</target>

<target name="setup-one" depends="init-setup" if="set-one">
  <property name="myProperty" value="123"/>
  <property name="yourProperty" value="456"/>
</target>

<target name="setup-two" depends="init-setup" if="set-two">
  <property name="myProperty" value="123"/>
  <property name="yourProperty" value="456"/>
</target>

<target name="setup" depends="setup-one,setup-two" />

<target name="first" depends="setup"/>

<target name="second" depends="setup"/>

<target name="test">
  <antcall target="first">
    <property name="set" value="one"/>
  </antcall>
  <antcall target="second">
    <property name="set" value="one"/>
  </antcall>
</target>

So when you do antcall "set" will be equal to either "one" or "two". Both
targets "first" and "second" indirectly depend on init-setp which will set
the value "set-one" or "set-two" depending on the value of antcall
parameter "set" . Then both of setup-one and setup-two will try to be
executed but only one will be due to their if clauses.

It is a little ugly but thats the way we have to do it in Ant1.x (though in
ant2 this may change).


Cheers,

Pete

*-----------------------------------------------------*
| "Faced with the choice between changing one's mind, |
| and proving that there is no need to do so - almost |
| everyone gets busy on the proof."                   |
|              - John Kenneth Galbraith               |
*-----------------------------------------------------*


Mime
View raw message