How to get boolean results of regex match in Ant?
Is there a way in Ant to just use regex to search through a file for a line and get a boolean result if there is a match or not?
I want to look through开发者_运维问答 a log file for an error line. If the error line exists, I want to perform some additional steps.
In the worst case, I could use the Script tag but would like to avoid it if Ant has a way of doing it.
After some searching around in the Ant documentation, I came up with a round-about way of figuring this out. Get the length of the file that matches the regex. If it is greater than 0, perform the extra steps.
<if>
<length when="greater" length="0">
<fileset file="${build.log}">
<containsregexp expression="\[java\].*error"/>
</fileset>
</length>
<then>
<!-- perform additional steps -->
</then>
</if>
I found that Ant has a matches condition but couldn't make use of it as I am using Ant 1.6.5.
To use if tag, you need to use the taskdef below in my case:
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="./ant-contrib.jar"/>
</classpath>
</taskdef>
精彩评论