使用 ant,如果文件包含“SUCCESS"则失败细绳 [英] Using ant, Fail if the file contains "SUCCESS" string
问题描述
基本上我想检查文件是否包含SUCCESS"字符串.如果未找到字符串,则 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
推荐答案
您可以使用 Ant fail
任务,假设要检查的文件名为log.txt
:
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>
如果文件集中的文件都不包含字符串SUCCESS",则文件集将为空,因此构建不会失败.
If none of the files in the fileset contain the string 'SUCCESS' then the fileset will be empty, so the build will not fail.
这篇关于使用 ant,如果文件包含“SUCCESS"则失败细绳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!