Reputation: 22947
I need to load properties from a file and change the string the following way :
prop1=value1
prop2=value2
prop3=value3
into :
-Pprop1=value1 -Pprop2=value2 -Pprop3=value3
(Basically I want to add -P in the beginning of each line and remove the newlines)
I have used tokenfilter
the following way :
<loadfile property="temp.properties" srcFile="${properties.file}">
<filterchain>
<tokenfilter delimoutput=" -P">
<ignoreblank />
</tokenfilter>
</filterchain>
</loadfile>
The problem with this approach is that if, lets say the file ends with empty new lines, I get the following string :
prop1=value1 -Pprop2=value2 -Pprop3=value3 -P
-P
on the first property (nothing has to do with the newlines at the end of the file). This is easy to overcome with Ant by just concatenating a -P
string with the result stringAlso, a nice addition would be to ignore properties comments - lines that start with #
but if it's complicates stuff too much, it's not important.
Thanks
Upvotes: 1
Views: 2441
Reputation: 123508
Does the following work for you?
<filterchain>
<replaceregex pattern="^[#].*" replace="" />
<ignoreblank />
<prefixlines prefix=" -P" />
<striplinebreaks />
</filterchain>
Upvotes: 3