Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using ant, Fail if the file contains "SUCCESS" string

Tags:

ant

Basically I want to check if the file contains "SUCCESS" string. If string not found then ant has to exit with error message. Please help me on this. I tried many links but did'nt get this answer

like image 563
sree Avatar asked Jan 18 '11 10:01

sree


1 Answers

You can do this with the Ant fail task, assuming the file to check is called log.txt:

<fail message="SUCCESS Found...failing">
    <condition>
        <resourcecontains resource="log.txt" substring="SUCCESS"/>
    </condition>
</fail>

Here's an alternative approach, that you could adapt if you have more than one file to check.

<fileset id="success.file" dir="." includes="log.txt">
    <contains text="SUCCESS"/>
</fileset>
<fail message="SUCCESS Found...failing">
    <condition>
        <resourcecount when="greater" count="0" refid="success.file" />
    </condition>
</fail>

If none of the files in the fileset contain the string 'SUCCESS' then the fileset will be empty, so the build will not fail.

like image 133
martin clayton Avatar answered Dec 11 '22 09:12

martin clayton