Reputation: 3260
I am trying to change an application name on compilation through an ant script(which is in the build.xml). Application name is stored in strings.xml. Following is the piece of code,
<target name="changeName">
<property
name="applicationName"
value="30004" />
<replaceregexp
file="C:\Users\<user-name>\git\appname\res\values\strings.xml"
match='<string name="app_name"<test</string<'
replace="\1${applicationName}\2"
byline="true"/>
</target>
But it doesnt change the name in strings.xml. Can someone please correct me on what I am doing wrong? Also please let me know how I can achieve similar operation through relative paths.
Thanks
Edit: Following is the xml that needs to be changed through the above mentioned ant script
<string name="app_name">Test Application</string>
Upvotes: 1
Views: 643
Reputation: 4614
The following replacement will change the "app-name" attribute for any <string>
element that contains this attribute:
<replaceregexp
file="C:\Users\<user-name>\git\appname\res\values\strings.xml"
match="<string name=".+""
replace="<string name="${applicationName}""
/>
To save yourself from escape code hell, you might want to set some properties using CDATA before running the replacement. This way you can clearly see the regex patterns:
<property name="regex.match"><![CDATA[<string name=".+"]]></property>
<property name="regex.replace"><![CDATA[<string name="${applicationName}"]]></property>
<replaceregexp
file="C:\Users\<user-name>\git\appname\res\values\strings.xml"
match="${regex.match}"
replace="${regex.replace}"
/>
Upvotes: 1