首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用ANT测试最后一行日志文件

使用ANT测试最后一行日志文件
EN

Stack Overflow用户
提问于 2011-07-07 20:50:27
回答 2查看 1.5K关注 0票数 4

我有几个bat文件运行更多的文件来构建这个项目。这是个忙乱的过程。我把蚂蚁的档案做好了.

有一个BAT文件,当它成功运行时,可以在控制台上打印成功的生成。成功构建是控制台输出的最后一行。

到目前为止,我已经在我的ant脚本中写了这个。

代码语言:javascript
运行
复制
<project name="MyProject" basedir=".">
    <property name="buildC" value="${basedir}/build-C" />
    <exec dir="${buildC}" executable="cmd" os="Windows XP">
        <arg line="/c test.bat > test.log"/>
    </exec>

    <loadfile property="buildC.log" srcFile="${buildC}/test.log">
    </loadfile>

</project>

测试( test.log文件的最后一行)是否成功构建。如果是然后执行下一个任务,否则失败。

我试着用失败的任务来帮助你。有人能指点我吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-07-07 21:08:32

可以使用buildC.log任务的嵌套条件检查fail属性:

代码语言:javascript
运行
复制
<fail message="test.bat failed">
   <condition>
       <not>
           <matches pattern="${line.separator}BUILD SUCCESSFUL$" string="${buildC.log}" />
       </not>
   </condition>
</fail>

您可能需要稍微调整一下模式才能使其工作,具体取决于test.bat脚本所编写的内容。默认情况下,matches将应用于整个字符串,因此只有当成功消息构成文件的最后一行时,上面的内容才会匹配。

您还可以考虑使用test.bat任务outputproperty属性捕获来自outputproperty的输出。

代码语言:javascript
运行
复制
<exec dir="." executable="sh" outputproperty="buildC.log">
    <arg line="/c test.bat" />
</exec>

(注意,arg行中删除了shell重定向。)

票数 0
EN

Stack Overflow用户

发布于 2011-07-07 21:29:59

如果要使用最后一行,请使用带尾过滤器lines="1“的过滤器链,请参见蚂蚁手册FilterChains

之后,使用诸如弗拉卡[医]鹿角等if/else构造的Addon来检查属性=

代码语言:javascript
运行
复制
<project xmlns:fl="antlib:it.haefelinger.flaka">
 <loadfile srcfile="your.log" property="buildsuccess">
  <filterchain>
   <tailfilter lines="1" />
    <!-- also possible if needed -->
    <trim/>
    <striplinebreaks/>
    <!-- also possible if needed // -->
  </filterchain>
 </loadfile>

 <fl:choose>
  <fl:when test="'${buildsuccess}' eq 'BUILD SUCCESSFUL'">
   <echo>execute new task..</echo>
  </fl:when>
  <fl:otherwise>
   <fail message="Houston we have a problem.."/>
  </fl:otherwise>
</fl:choose>
</project>

或使用条件=的标准蚂蚁方式

代码语言:javascript
运行
复制
<project default="main">

 <target name="checklog">
  <loadfile srcfile="props.txt" property="buildsuccess">
   <filterchain>
    <tailfilter lines="1" />
    <!-- // also possible if needed -->
    <trim/>
    <striplinebreaks/>
    <!-- also possible if needed // -->
   </filterchain>
  </loadfile>

  <condition property="buildOK">
   <equals arg1="${buildsuccess}" arg2="BUILD SUCCESSFUL"/>
  </condition>    
 </target>

 <target name="whatever">
  <fail message="Houston we have a problem.." unless="buildOK"/>   
  <!-- if not failed then you'll go on with your other tasks here .. -->    
 </target>

 <target name="main" depends="checklog,whatever"/>
</project>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6617007

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档