You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Tim Gordon <ti...@allustra.com> on 2006/01/27 12:29:15 UTC

Expanding properties

Hi

Say I have a file, called contents.txt, which contains the text:

contents.txt:
The value is ${something}

And I have a property file values.properties which reads

values.propeties:
something=somevalue

How to I turn contents.txt into

contents.txt:
The value is somevalue

I can do this with

    <property file="values.properties"/>
    <replace file="contents.txt">
      <replacefilter token="${something}" value="${something}"/>
    </replace>

But this would be painstaking if I had lots of properties to replace - I'd
have to define each property and then add a <replacefilter> for each one.

I had hoped that this would work:

    <property file="values.properties"/>
    <loadfile property="temp.property" srcfile="contents.txt"/>
    <echo message="${temp.property}"/>

But it doesn't - what I'm really after is a way to re-use the in-file
property expansion performed by <property>. Is there a way to do this?

Tim

Allustra Limited
85 Gracechurch Street
London
EC3V 0AA
Tel +44 (0)20 7469 8640
Fax +44 (0)20 7469 8689
http://www.allustra.com/





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


Re: Expanding properties

Posted by Ninju Bohra <ni...@yahoo.com>.
Or you can use the replacefilterfile='file'  attribute on the <replace> task and specify all the replacements in the 'file'.
 
Later,
 
Ninju
 



----- Original Message ----
From: Ken Gentle <j....@acm.org>
To: Ant Users List <us...@ant.apache.org>
Sent: Friday, January 27, 2006 8:18:51 AM
Subject: Re: Expanding properties


Untried:

     <!-- defines your properties as tokens -->
     <token file="values.properties"/>
     <!-- Loads the file doing "token" substitution -->
<loadfile srcfile="contents.txt" property="tmp.property">

   <filterchain>

     <replacetokens beginToken="$${" endToken="}" />

   </filterchain>

</loadfile>

HTH...
         Ken

At 06:29 2006-01-27, you wrote:
>Hi
>
>Say I have a file, called contents.txt, which contains the text:
>
>contents.txt:
>The value is ${something}
>
>And I have a property file values.properties which reads
>
>values.propeties:
>something=somevalue
>
>How to I turn contents.txt into
>
>contents.txt:
>The value is somevalue
>
>I can do this with
>
>     <property file="values.properties"/>
>     <replace file="contents.txt">
>       <replacefilter token="${something}" value="${something}"/>
>     </replace>
>
>But this would be painstaking if I had lots of properties to replace - I'd
>have to define each property and then add a <replacefilter> for each one.
>
>I had hoped that this would work:
>
>     <property file="values.properties"/>
>     <loadfile property="temp.property" srcfile="contents.txt"/>
>     <echo message="${temp.property}"/>
>
>But it doesn't - what I'm really after is a way to re-use the in-file
>property expansion performed by <property>. Is there a way to do this?
>
>Tim
>
>Allustra Limited
>85 Gracechurch Street
>London
>EC3V 0AA
>Tel +44 (0)20 7469 8640
>Fax +44 (0)20 7469 8689
>http://www.allustra.com/
>
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>For additional commands, e-mail: user-help@ant.apache.org

Re: Expanding properties

Posted by Ken Gentle <j....@acm.org>.
Untried:

     <!-- defines your properties as tokens -->
     <token file="values.properties"/>
     <!-- Loads the file doing "token" substitution -->
<loadfile srcfile="contents.txt" property="tmp.property">

   <filterchain>

     <replacetokens beginToken="$${" endToken="}" />

   </filterchain>

</loadfile>

HTH...
         Ken

At 06:29 2006-01-27, you wrote:
>Hi
>
>Say I have a file, called contents.txt, which contains the text:
>
>contents.txt:
>The value is ${something}
>
>And I have a property file values.properties which reads
>
>values.propeties:
>something=somevalue
>
>How to I turn contents.txt into
>
>contents.txt:
>The value is somevalue
>
>I can do this with
>
>     <property file="values.properties"/>
>     <replace file="contents.txt">
>       <replacefilter token="${something}" value="${something}"/>
>     </replace>
>
>But this would be painstaking if I had lots of properties to replace - I'd
>have to define each property and then add a <replacefilter> for each one.
>
>I had hoped that this would work:
>
>     <property file="values.properties"/>
>     <loadfile property="temp.property" srcfile="contents.txt"/>
>     <echo message="${temp.property}"/>
>
>But it doesn't - what I'm really after is a way to re-use the in-file
>property expansion performed by <property>. Is there a way to do this?
>
>Tim
>
>Allustra Limited
>85 Gracechurch Street
>London
>EC3V 0AA
>Tel +44 (0)20 7469 8640
>Fax +44 (0)20 7469 8689
>http://www.allustra.com/
>
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>For additional commands, e-mail: user-help@ant.apache.org