How to get the logical results of a regular expression in Ant?

Is there a way in Ant to just use regex to search the file for a string and get a boolean if there is a match or not?

I want to view the log file for the error line. If an error string exists, I want to follow some additional steps.

In the worst case scenario, I could use the Script tag , but would like to avoid this if Ant has a way to do this.

+3
source share
2 answers

After some searching the Ant documentation, I came up with a round way to figure this out. Get the length of the file matching the regular expression. If it is greater than 0, follow the additional steps.

<if>
  <length when="greater" length="0">
    <fileset file="${build.log}">
      <containsregexp expression="\[java\].*error"/>
    </fileset>
  </length>
  <then>
    <!-- perform additional steps -->
  </then>
</if>

, Ant , , Ant 1.6. 5.

+2

if, taskdef :

<taskdef resource="net/sf/antcontrib/antcontrib.properties">
        <classpath>
            <pathelement location="./ant-contrib.jar"/>
        </classpath>
    </taskdef>
0

Source: https://habr.com/ru/post/1740486/


All Articles