Is there a simple way of taking the value of a property and then copy it to another property with certain characters replaced?
Say propA=This is a value
. I want to replace all the spaces in it into underscores, resulting in propB=This_is_a_value
.
Here is the solution without scripting and no external jars like ant-conrib:
The trick is to use ANT's resources:
This one will replace all " " in propA by "_" and place the result in propB. "filetokenizer" treats the whole input stream (our property) as one token and appies the string replacement on it.
You can do other fancy transformations using other tokenfilters: http://ant.apache.org/manual/Types/filterchain.html
Use the propertyregex task from Ant Contrib.
I think you want:
Unfortunately the examples given aren't terribly clear, but it's worth trying that. You should also check what happens if there aren't any underscores - you may need to use the
defaultValue
option as well.Two possibilities :
via script task and builtin javascript engine (if using jdk >= 1.6)
or using Ant addon Flaka
to overwrite exisiting property propA simply replace propB with propA
Adding an answer more complete example over a previous answer
Or... You can also to try Your Own Task
JAVA CODE:
ANT SCRIPT
CONSOLE:
Just an FYI for answer Replacing characters in Ant property - if you are trying to use this inside of a maven execution, you can't reference maven variables directly. You will need something like this: