tags:

views:

163

answers:

1

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.

+1  A: 

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.

Matt McCormick