You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Alex Smith <as...@hotmail.com> on 2000/09/29 00:37:45 UTC

Eager evaluation of properties

Hello,

I tried looking in the archives (covalent.net?) except that I couldn't find 
them :)

I am trying to substitute a value twice where the second substitution is 
based on the results of the first. This amounts to a recursive evaluation 
and since I can't do this with tokens, I am trying a hack with properties. 
It almost works except that I am being foiled by properties-evaluate-first 
mechanism, even if I define a property after my first substitution that 
generates the property file which contains the desired properties referenced 
thereafter.

Concrete example: I have a file that looks like this

@myProperty.foo@=10
@myProperty.bar@=20
@myProperty.baz@=30

where 'foo', 'bar' and 'baz' are users on my box. I have another file that 
looks like this

targetProperty=@myProperty@

and I want @myProperty@ to be replaced with '10' if I am user 'foo'. To this 
end I copy the first file to a temporary location, substituting all tokens 
that match @myProperty.foo@ with the string 'targetProperty'. Then I 
reference this newly built property file with <property file="..."> and copy 
the second file while substituting @myProperty@ with ${myProperty}. The last 
step doesn't work because ${myProperty} is empty since the property task 
read the file in before it was created...even though <property file="..."> 
is defined after the task that created the file referenced therein. (I also 
trying explicit dependency instead of defining one after another in the same 
task).

Help? I am running Ant 1.1

Thanks,

Alex


_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

Share information about yourself, create your own public profile at 
http://profiles.msn.com.


Re: Eager evaluation of properties

Posted by Stefan Bodewig <bo...@bost.de>.
>>>>> "AS" == Alex Smith <as...@hotmail.com> writes:

 AS> Hello, I tried looking in the archives (covalent.net?) except
 AS> that I couldn't find them :)

archive.covalent.net.

 AS> Help? I am running Ant 1.1

Try Ant 1.2alpha2 or higher - any nightly build since about two weeks.

Other than that I think it would be easier for you to actually write a
task of your own to do the whole thing in one pass instead of
(ab)using three or four different built-in tasks to do what you want -
this will probably be a lot easier to understand for others as well
(read I lost track of the exact details why you've been doing what
myself 8^).

Stefan

Re: Eager evaluation of properties

Posted by "Julian M. Savage" <js...@fisci.com>.
I have a similar need, but I took a slightly different approach. I'm not
sure whether the following works on 1.1 or not - I'm using 1.2alpha3 or
something.

It looks like you might be defining different port numbers for different
developers on the same machine. That's my need, in any case.

I wrote a perl script which creates a simple properties file for each user
in their home directory, with slightly different values for each user, and
once the initial version is created, they can modify it to suit themselves.
Of course, new users will have to create their own configuration files (or
run the script), but then, at least you won't have to change your build file
every time a new developer joins your project.

In addition I made it so that the user can override the name of the property
file itself, so that if they want to make different builds in different
directories with slightly different options, they can do it quickly by
writing a couple of different property files.

ie:
<project name="myproject" default="compile" basedir=".">
    <property name="pref.file" value="${user.home}/.ant.preferences"/>
    <property file="${pref.file}"/>

    <!-- Start defining project properties. -->

</project>


ant -Dpref.file=ant-set1 dist
ant -Dpref.file=ant-set2 dist

Julian.

----- Original Message -----
From: "Alex Smith" <as...@hotmail.com>
To: <an...@jakarta.apache.org>
Sent: Friday, September 29, 2000 7:37 AM
Subject: Eager evaluation of properties


> Hello,
>
> I tried looking in the archives (covalent.net?) except that I couldn't
find
> them :)
>
> I am trying to substitute a value twice where the second substitution is
> based on the results of the first. This amounts to a recursive evaluation
> and since I can't do this with tokens, I am trying a hack with properties.
> It almost works except that I am being foiled by properties-evaluate-first
> mechanism, even if I define a property after my first substitution that
> generates the property file which contains the desired properties
referenced
> thereafter.
>
> Concrete example: I have a file that looks like this
>
> @myProperty.foo@=10
> @myProperty.bar@=20
> @myProperty.baz@=30
>
> where 'foo', 'bar' and 'baz' are users on my box. I have another file that
> looks like this
>
> targetProperty=@myProperty@
>
> and I want @myProperty@ to be replaced with '10' if I am user 'foo'. To
this
> end I copy the first file to a temporary location, substituting all tokens
> that match @myProperty.foo@ with the string 'targetProperty'. Then I
> reference this newly built property file with <property file="..."> and
copy
> the second file while substituting @myProperty@ with ${myProperty}. The
last
> step doesn't work because ${myProperty} is empty since the property task
> read the file in before it was created...even though <property file="...">
> is defined after the task that created the file referenced therein. (I
also
> trying explicit dependency instead of defining one after another in the
same
> task).
>
> Help? I am running Ant 1.1
>
> Thanks,
>
> Alex
>
>
> _________________________________________________________________________
> Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
>
> Share information about yourself, create your own public profile at
> http://profiles.msn.com.
>
>