问题
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
回答1:
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.
回答2:
If you are on Linux, you could simply wrap the Get command with the exec target in Ant
This could also be useful
来源:https://stackoverflow.com/questions/4722803/using-ant-fail-if-the-file-contains-success-string