让没有-q标志蚂蚁安静? [英] Make ant quiet without the -q flag?

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

问题描述

我有一个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选项是不容易以统一的方式实现的(有些人从日食运行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)

所以我在寻找蚂蚁文件来调用本身的方式悄然...

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文档是在这里,包括对<一个href=\"http://cupi2.uniandes.edu.co/web/manualAnt/manual/api/org/apache/tools/ant/Project.html\"><$c$c>project类。

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

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