Kaushik Lele
Kaushik Lele

Reputation: 6637

Ant task to find and replace in property value

Ant Task "Replace" is for find-and-replace in contents of a file. Can this used (or is there other task) to work directly on a property value.

e.g. I want to find ampersand from a property value and replace it with some other string. Now I achieve it in multiple steps.

 <property name="prop_before" value="ABC&PQR" />
 <echo  file="propFile" message="${prop_before}" />
 <replace file="propFile" token="&amp;" value="ESACAPE_AND" />
 <loadfile property="prop_after" srcFile="propFile"/>

Is there any ant task like below ?

<replace source_property="prop_before" 
         destination_property="prop_after" 
         token="&amp;" 
         value="ESACAPE_AND"  
/>

Upvotes: 0

Views: 2320

Answers (1)

M A
M A

Reputation: 72844

If you can add external libraries, it's probably simplest to use PropertyRegex from the Ant-Contrib project:

<propertyregex property="pack.name"
          input="package.ABC.name"
          regexp="(package)\.[^\.]*\.(name)"
          replace="\1.DEF.\2"
          casesensitive="false" />

Upvotes: 1

Related Questions