After build, I need to modify an HTML file that points the client to download the new app.
I search for a token; replace it with a link and token:
<replace file="index.html" >
<!-- this searches for literal text ${MyTOKEN} -->
<!-- does not "expand" ${MyTOKEN} before searching -->
<replacetoken>${MyTOKEN}</replacetoken>
<replacevalue>"some link" <br> ${MyTOKEN}</replacevalue>
</replace>
This code CANNOT be moved into a template build script because the replacetoken
and replacevalue
tags take the text as literals - they do not expandproperties
in my version of ANT.
I would like to use properties to define the "some link"
and MyTOKEN
values.
Workaround for using properties in "some link"
is to use a filterchain
and copy the file after the replacement:
<copy file="index.html" tofile="index2.html" >
<filterchain>
<!-- this converts the ${xxx} properties into their values -->
<expandproperties />
</filterchain>
</copy>
But that works AFTER the replace
has been done - so it means I still need to hard-code the MyTOKEN
values directly into the build script.
Update: Should I create my own replace
task using copy
, filterreader
and filterchain
? I don't really understand that method properly, but it looks like the way.
Update expanding on accepted answer: I was originally using the <replacetoken>
& <replacevalue>
method because I needed my value to span multiple lines.
By using token
& value
, I was unable to find a way to make line breaks.
The solution to putting line breaks is to use ${line.separator}
as the line break. See docs on the Echo Task.
As an extra, here is a page of some more useful (off topic) ANT properties: Built-in Ant Properties.
Using the token
and value
attributes works here. This works for me with Ant 1.7.1:
build.properties
token=FOO
tokval=some ${token}
build.xml
<project>
<property file="build.properties" />
<target name="repl">
<replace file="test.txt" token="${token}" value="${tokval}" />
</target>
</project>
Hope that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With