Using ant, Fail if the file contains “SUCCESS” string

夙愿已清 提交于 2019-12-12 08:33:16

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!