避免在ant退出目标后打印Build success



我有一个从另一个脚本调用目标的ant脚本。当这个目标完全执行后,第二个脚本退出,并显示"Build Successful"消息,这对用户来说有点困惑。我不希望第二个ant脚本在退出时返回"Build Successful"。我的代码是

<target name="startRemoteJboss" description="Starts Remote Instance of Jboss">
        <echo message="starting Remote Jboss" />
        <sshexec output="remoteJboss.txt" trust="true" host="${jboss.remote.host}" username="${jboss.remote.username}" password="${jboss.remote.password}" command="ant -f build.xml startJboss" port="${jboss.remote.port}" failonerror="no"/>
    </target>
第二个构建文件目标看起来像
<target name="startJboss" description="Starts Jboss">
        <echo message="starting Jboss" />
        <exec executable="${jboss.home}/bin/run.sh" spawn="true">
            <arg line="-b 0.0.0.0 -c default" />
        </exec>
        <sleep seconds="150" />
        <echo message="Jboss is UP" />
    </target>

当startJboss完成它的执行,我希望它不打印"Build Successful"

[sshexec] BUILD SUCCESSFUL
  [sshexec] Total time: 10 seconds

由于您正在捕获输出到文件(

<concat>
    <fileset dir="." includes="remoteJboss.txt" />
    <filterchain>
        <linecontains negate="true">
           <contains value="[sshexec] BUILD SUCCESSFUL"/>
        </linecontains>
        <linecontains negate="true">
           <contains value="[sshexec] Total time:"/>
        </linecontains>
    </filterchain>
</concat>

输出给用户(假设您已经在使用concat),或者使用destFile属性指定输出文件的副本,其中这些行被删除:

<concat destfile="remoteJboss_short.txt" >

最佳实践是使用macrodef来共享功能,这意味着对startJboss目标进行macrodef,而不是在新的项目范围内启动另一个ant实例。
这也会避免BUILD success输出。

编辑

"BUILD SUCCESSFUL"字符串来自ant的DefaultLogger#getBuildSuccessfulMessage() .
你可以编写自己的日志记录器,返回空字符串或任何其他字符串,详细信息请参阅ant手动侦听器和日志记录器。