Using ant, check if a particular string is found in a file

后端 未结 1 536
栀梦
栀梦 2021-01-02 21:04

My requirement is that, using waitfor condition, ant should periodically check if string \"Build Successful\" is displayed in log file. If the string is found, then particul

相关标签:
1条回答
  • 2021-01-02 21:43

    Here's an example of one way you might do this:

    <target name="wait-for">
        <waitfor maxwait="15" maxwaitunit="second" timeoutproperty="build.timeout">
            <resourcecontains resource="build.log" substring="Build Successful" />
        </waitfor>
        <antcall target="build-success" />
    </target>
    
    <target name="build-success" depends="build-fail" unless="build.timeout">
        <echo message="Success" />
    </target>
    <target name="build-fail" if="build.timeout">
        <echo message="Fail" />
    </target>
    

    Use the resourcecontains condition to look for the string in the named resource - in this case the file 'build.log'. If it's not found in the allotted time, the build.timeout property is set. There are two targets, one that is to be run if the string is found, the other if not. The 'target' attributes if, unless, and depends are used to make the if-else logic need. If you only need to take an action in the case of success or failure, you can simplify slightly.

    0 讨论(0)
提交回复
热议问题