在没有 -q 标志的情况下让 ant 安静? [英] Make ant quiet without the -q flag?

查看:25
本文介绍了在没有 -q 标志的情况下让 ant 安静?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通常在截然不同的环境中运行的 ant 构建文件.默认情况下,我正在寻找与使用相同的行为:

I have an ant buildfile that is often run from vastly different environments. By default, I'm looking for the same behavior as using:

ant -q

然而,由于一些团队成员的配置不同,在每个人的环境中指定 -q 选项并不容易以统一的方式完成(有些人从 eclipse 运行 ant,有些从命令行,有些从调试/分析工具,等等.每个都有不同的方法来指定 ant 参数,例如 -q)

However, since some team member's configurations vary, specifying the -q option in each person's environment is not easily accomplished in a uniform way (some people run ant from eclipse, some from the command line, some from debugging/profiling tools, etc. Each with a different method for specifying ant arguments like -q)

所以我正在寻找一种让 ant 文件能够安静地调用自身的方法...

So I'm seeking a way for the ant file to call itself quietly...

像下面这样的东西是理想的:

Something like the following would be ideal:

<target name="default">
    <antcall quiet="yes" target="build" /> <!-- doesn't work -->
</target>

任何人都可以想到完成这样的事情吗?我所追求的只是让构建在运行默认目标时安静地运行,无论是否设置了 -q.

Can anyone think of anyway to accomplish something like this? All I'm after is for the build to run quietly whenever the default target is ran, regardless of whether -q is set.

推荐答案

一个选项可能是从目标内部设置日志记录级别.

One option might be to set the logging level from within the target.

您可以通过一个简短的脚本任务来访问记录器.类似的东西:

You can access loggers by means of a short script task. Something like:

<target ... >
    <script language="javascript">
        var logger = project.getBuildListeners( ).firstElement( );
        logger.setMessageOutputLevel( 0 );
    </script>
    ...
</target>

我不熟悉 Eclipse 如何调用 Ant,但可能有必要遍历所有构建侦听器以使其全面静音".

I'm not familiar with how Eclipse calls Ant, but it might be necessary to iterate over all the build listeners to get 'silence' all round.

建议无论您最终如何执行此操作,都可以轻松切换回详细运行.

Suggest that how ever you end up doing this, you make it easy to switch back to verbose running.

编辑 - 对评论的回复:您可以使用 project.getProperty() 从脚本内访问项目属性:

Edit - response to comment: You can access project properties from within the script using project.getProperty():

<property name="verboseFlag" value="1" />
<script language="javascript">
    var logger = project.getBuildListeners().firstElement();
    var verboseMode = project.getProperty( "verboseFlag" )
    if ( ! "1".equals( verboseMode ) )
        logger.setMessageOutputLevel( 0 );
</script>

(有点旧)API 文档在这里,包括 项目.

(Somewhat old) API docs are here, including for the project class.

这篇关于在没有 -q 标志的情况下让 ant 安静?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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