I have a source code file which contains, among others, following lines:
public boolean isBetaVersion() {
return true;
}
I try to read this file in ANT and set a property depending on whether the above method returns true or something else:
<loadfile srcfile="path/to/MyFile.java" property="isBetaBuild">
<filterchain>
<striplinebreaks/>
<linecontainsregexp>
<regexp pattern=".*\sisBetaVersion()\s\{\sreturn\strue.*"/>
</linecontainsregexp>
</filterchain>
</loadfile>
but it never matches (unfortunately, I’m a complete regex-noob). Anyone has an idea what could be wrong? Thanks in advance.
You need to escape the parentheses, and allow for more than just one whitespace character. Then,
\banchors can be used to match beginnings and ends of words, which is also helpful here. I suggest you try this:You don’t need the
.*around the regex, since you’re just looking for whether that substring is contained in the source code somewhere.