ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b.@spamcop.net
Subject RE: nested properties anyone?
Date Thu, 15 Aug 2002 20:41:14 GMT
This is great,

However the one problem is, when you actually specify <property file="foo"/> you
will not have ids assigned to the properties, only names and values, and the
test will fail. However it gives me a chance to simply create bunch of
predefined properties right in my build.xml or (I have to investigate it) use
XMLProperty file.

Propertycopy is an interesting option, too bad the manual does not mention it :)

Thank you everyone for the help

Bob


Quoting Dominique Devienne <DDevienne@lgc.com>:

> This kind of things can be achieved indirectly using either <propertycopy>
> from ant-contrib (for sure), or id/refid, provided you can set the ids as
> below (precludes loading the properties file, since cannot assign ids).
> 
> No telling that it's kind of a hack ;-) --DD
> 
> ------- 1.4.1 output -------
> P:\org_apache\antx>ant -buildfile nestedProperties.xml
> Buildfile: nestedProperties.xml
> 
> test:
> Overriding previous definition of reference to host1
> Overriding previous definition of reference to host2
>      [echo] build.host = host2.acme.org
> 
> BUILD SUCCESSFUL
> 
> Total time: 1 second
> 
> ------- 1.5 output -------
> P:\org_apache\antx>C:\pro\ant1.5\bin\ant -buildfile nestedProperties.xml
> Buildfile: nestedProperties.xml
> 
> test:
>      [echo] build.host = host2.acme.org
> 
> BUILD SUCCESSFUL
> Total time: 1 second
> 
> ------- nestedProperties.xml -------
> <?xml version="1.0"?>
> 
> <!-- ANT build file to test a specific feature or bug of ANT.
>      Dominique Devienne <ddevienne@lgc.com>      August 2002
>   -->
> <project name="antx" default="test" basedir=".">
> 
>   <target name="test">
>     <!-- Simulate loading the properties file (kinda!)
>     <property file="hosts.properties"/>
>       -->
>     <property id="host1" name="host1" value="host1.acme.org"/>
>     <property id="host2" name="host2" value="host2.acme.org"/>
> 
>     <!-- Simulate running the 'hostname' command
>     <exec outputproperty="hostname" executable="hostname"/>
>       -->
>     <property name="hostname" value="host2" />
> 
>     <property name="build.host" refid="${hostname}"/>
>     <echo  message="build.host = ${build.host}"/>
>   </target>
> 
> </project>
> 
> 
> -----Original Message-----
> From: bo@spamcop.net [mailto:bo@spamcop.net] 
> Sent: Thursday, August 15, 2002 11:59 AM
> To: ant-user@jakarta.apache.org
> Subject: nested properties anyone?
> 
> Problem:
> From the list of the predefined properties key=value select one based on
> the
> value of some other property and use it as a default
> 
> Example:
> I have a list of servers (hosts.properties), where key is an actual
> hostname
> (obtained from hostname command) and value is a domain, e.g.
> host_one=host_one.somewhere.com
> host_two=host_two.some.place.else.com
> I want to determine on which machine I'm running the script and use a full
> domain name further in the script.
> 
> Solution?
> 1. <property file="hosts.properties"/>
> 2. <exec outputproperty="hostname" executable="hostname"/>
> 3. Now I have a ${hostname} and I want to assign its value to the property
> build.host that I use in my script. My first reaction was to do this:
> <property name="build.host" refid="${${hostname}}"/>
> Well it didn't work because curleys are evaluated only once and I'm getting
> the
> value of build.host literaly as "${hostname}"
> Is there any other way? Any way? 
> And I think that it would be nice feature to reevaluate the nested brackets
> 
> Bob Stone
> 
> --
> To unsubscribe, e-mail:   <mailto:ant-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:ant-user-help@jakarta.apache.org>
> 
> --
> To unsubscribe, e-mail:   <mailto:ant-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:ant-user-help@jakarta.apache.org>
> 
> 



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


Mime
View raw message