You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Ognjen Blagojevic <og...@etf.bg.ac.yu> on 2007/11/27 13:54:46 UTC

Search and replace in property

Hi all,

I need tho read the properties from the file, and then to do a string 
replacement in their values.

Something like this:

1. read_properties
2. do_something_with_properties
3. replace_in_property('&', '&amp;')
4. do_someting_else_with_escaped_properties

How can I do the step 3?


The only solution I came up with is to use ReplaceRegExp task, and write 
escaped properties to another file, and then, reread them. Is there 
anything smarter than that? Something that avoids creation of another file?

Regards,
Ognjen

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


Re: Search and replace in property

Posted by Ognjen Blagojevic <og...@etf.bg.ac.yu>.
Hi David,

David Weintraub wrote:
> Are you actually doing something with the properties before doing the
> replace? If not, you could use a filter. Unfortunately, <property> doesn't
> support the filter directly, but you could copy the property file, then use
> the <property file="xxx"/> to point to your copy:

Actually, I do.

I figured out that I can read properties, use them, then copy them to 
file, and escape them in file, read them again, and use the escaped 
version. I was just wondering is it possible to do it avoiding the 
writing to the hard drive.

Regards,
Ognjen

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


Re: Search and replace in property

Posted by David Weintraub <qa...@gmail.com>.
Are you actually doing something with the properties before doing the
replace? If not, you could use a filter. Unfortunately, <property> doesn't
support the filter directly, but you could copy the property file, then use
the <property file="xxx"/> to point to your copy:

<copy file="orig.properties"
   tofile="new.properties">
   <filterset>
        <filter token="sometoken" value="somevalue"/>
   <filterset>
 </copy>
 <properties file="new.properties"/>

Remember that you cannot change a property once it is set! If you do need to
change properties look at the AntContrib <variable> task.

On Nov 27, 2007 7:54 AM, Ognjen Blagojevic <og...@etf.bg.ac.yu> wrote:

> Hi all,
>
> I need tho read the properties from the file, and then to do a string
> replacement in their values.
>
> Something like this:
>
> 1. read_properties
> 2. do_something_with_properties
> 3. replace_in_property('&', '&amp;')
> 4. do_someting_else_with_escaped_properties
>
> How can I do the step 3?
>
>
> The only solution I came up with is to use ReplaceRegExp task, and write
> escaped properties to another file, and then, reread them. Is there
> anything smarter than that? Something that avoids creation of another
> file?
>
> Regards,
> Ognjen
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>


-- 
--
David Weintraub
qazwart@gmail.com