Here is a method that ant -contrib does not use using loadproperties
and filterchain
(note that replaceregex
is a "string filter" - see the tokenfilter
docs - and not the replaceregexp
task ):
<loadproperties srcFile="version.txt"> <filterchain> <replaceregex pattern="\[([0-9]),([0-9]),([0-9])\]" replace="\1.\2.\3" /> </filterchain> </loadproperties>
Note that the regex is a little different, we treat the file as a properties file.
Alternatively, you can use loadfile
with a filterchain
, for example, if the file you want to load was not in the format properties.
For example, if the contents of the file were just [0,1,0]
, and you wanted to set the version
property to 0.1.0
, you could do something like:
<loadfile srcFile="version.txt" property="version"> <filterchain> <replaceregex pattern="\s+\[([0-9]),([0-9]),([0-9])\]" replace="\1.\2.\3" /> </filterchain> </loadfile>
source share