0

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"  
/>
Kaushik Lele
  • 6,439
  • 13
  • 50
  • 76

1 Answers1

1

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" />
M A
  • 71,713
  • 13
  • 134
  • 174
  • So is it not possible with default libraries of ant ? – Kaushik Lele Jul 15 '15 at 07:54
  • It is possible (see http://stackoverflow.com/questions/1176071/replacing-characters-in-ant-property). But it would take several lines of code. – M A Jul 15 '15 at 08:02