使用ant,如果文件包含"SUCCESS",则失败.细绳 [英] Using ant, Fail if the file contains "SUCCESS" string

查看:83
本文介绍了使用ant,如果文件包含"SUCCESS",则失败.细绳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我想检查文件是否包含"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 任务,假设要检查的文件称为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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆