Tuesday 15 September 2015

Ant LineContains comma seperated Value -



Ant LineContains comma seperated Value -

i have property contained string , want alter comma separated list test lines in file.

currently 1 value next works:

<loadfile property="contents" srcfile="output.log"> <filterchain> <linecontains> <contains value="${findvalue}"></contains> </linecontains> </filterchain> </loadfile>

so if line in file contains: hello world!

and value of findvalue = 'world' find line. want find lines may match multiple words. if lines of file contain: hello world! bye everyone!

we want set property findvalue = world,everyone , pickup both lines of file. making sense on this, little hard me explain. ideas on how best accomplish this?

one way utilize linecontainsregexp filter lines match regular expression. trick convert comma-separated list of values single regex.

if property findvalue world,everyone, regex world|everyone, means line contains either world or everyone.

<property name="findvalue" value="world,everyone" /> <loadresource property="findvalueregex"> <propertyresource name="findvalue"/> <filterchain> <tokenfilter> <filetokenizer/> <replacestring from="," to="|" /> </tokenfilter> </filterchain> </loadresource>

then pass findvalueregex property containing regex linecontainsregexp filter:

<loadfile property="contents" srcfile="output.log"> <filterchain> <linecontainsregexp> <regexp pattern="${findvalueregex}" /> </linecontainsregexp> </filterchain> </loadfile>

ant

No comments:

Post a Comment