You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Stefan Lecho <St...@iconmedialab.be> on 2001/05/10 10:50:36 UTC

Property and refid

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.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Stefan Lecho
  Internet Application Developer
  Wireless Technical Contact
  IconMedialab, Brussels +32.2.506.23.31
http://www.iconmedialab.com


Re: Property and refid

Posted by Peter Donald <do...@apache.org>.
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               |
*-----------------------------------------------------*