【问题标题】:Ant: indent echo output depending on target call-depthAnt:根据目标调用深度缩进回显输出
【发布时间】:2012-07-16 14:42:57
【问题描述】:

对于较大的 ant 构建结构和相当复杂的项目,我想根据目标调用深度缩进信息输出(回显),例如:

[echo] running build from project/build.xml
    [echo] running build from project/sub1/build.xml
    [echo] running build from project/sub2/build.xml
        [echo] running build from project/sub2/sub21/build.xml
        [echo] running build from project/sub2/sub22/build.xml
    [echo] running build from project/sub3/build.xml

BUILD SUCCESSFUL
Total time: x seconds

是否有这样的调整、记录属性或其他什么? ...也许是 xslt/css 或事件监听器?

缩进不是重点,而是查看调用层次结构:避免搜索 build.xml 文件或在所有目标和宏定义中添加自己的 echo 函数。

【问题讨论】:

  • Ant 决定...。你可能需要检查 ant 的源代码...
  • 我想避免理解ant解析并更改代码,而是使用标准机制。
  • thoku,我想做类似的事情。您是否找到任何对我们有帮助的工具/设置?
  • 我也欢迎这个功能。如果没有这样的东西,实际上无法想象严重的调试。现在,我认为这可能很有用ant.apache.org/manual/listeners.html

标签: ant echo callstack auto-indent


【解决方案1】:

https://ant.apache.org/manual/listeners.html

XmlLogger 在那里似乎很有帮助,如果有点过于冗长 - 您可以通过一些脚本提取调用层次结构(也带有回声):

ant -logger org.apache.tools.ant.XmlLogger 构建

Log4j 也取得了一些成功:

ant -listener org.apache.tools.ant.listener.Log4jListener -lib ..../logging-log4j-1.2.17/dist/lib/ -lib 。构建

为此,我使用上面第一个链接中的示例内容在当前目录中放置了一个 log4j.properties 文件。 这将生成一个包含以下内容的 build.log:

[     0]  Project : Build started.
[   908]  Taskdef : Could not load definitions from resource checkstyletask.properties. It could not be found.
[   995]   Target : Target "build" started.
[  4312]     Echo : com.ohmy: ivy.sorted.modules=thirdparty-plugins#com.sun.jaxb
[  4529]  Taskdef : Could not load definitions from resource checkstyletask.properties. It could not be found.
[  4588]   Target : Target "build_empty_unittests_jar_to_fulfill_dependencies" started.
[  4590]   Target : Target "build_empty_unittests_jar_to_fulfill_dependencies" finished.
[  4591]   Target : Target "build_nodeps" started.
[  4591]     Echo : Calling target 'build' for module com.sun.jaxb
[  4770]  Taskdef : Could not load definitions from resource checkstyletask.properties. It could not be found.
[  4846]   Target : Target "check_module_targets_file_exists" started.
[  4847]   Target : Target "check_module_targets_file_exists" finished.
[  4847]   Target : Target "check_module_target_exists" started.
[  4847]   Target : Target "check_module_target_exists" finished.

现在我只需将其导入小红宝石单线黑客以缩进它:

ruby -pe 'BEGIN {$i=0};$i-=1 if /finished\.$/;print " " * $i;$i+=1 if /started\.$/' build.log  

产生

[     0]  Project : Build started.
 [   908]  Taskdef : Could not load definitions from resource checkstyletask.properties. It could not be found.
 [   995]   Target : Target "build" started.
  [  4312]     Echo : com.ohmy: ivy.sorted.modules=thirdparty-plugins#com.sun.jaxb, com.ohmy
  [  4529]  Taskdef : Could not load definitions from resource checkstyletask.properties. It could not be found.
  [  4588]   Target : Target "build_empty_unittests_jar_to_fulfill_dependencies" started.
  [  4590]   Target : Target "build_empty_unittests_jar_to_fulfill_dependencies" finished.
  [  4591]   Target : Target "build_nodeps" started.
   [  4591]     Echo : Calling target 'build' for module com.sun.jaxb
   [  4770]  Taskdef : Could not load definitions from resource checkstyletask.properties. It could not be found.
   [  4846]   Target : Target "check_module_targets_file_exists" started.
   [  4847]   Target : Target "check_module_targets_file_exists" finished.
   [  4847]   Target : Target "check_module_target_exists" started.
   [  4847]   Target : Target "check_module_target_exists" finished.
   [  4847]   Target : Target "module_target" started.
   [  4847]   Target : Target "module_target" finished.
   [  4847]   Target : Target "default_target" started.
    [  4849]   Target : Target "init" started.
     [  4850]   Target : Target "check_module_ivy_file_uptodate" started.
     [  4858]   Target : Target "check_module_ivy_file_uptodate" finished.
     [  4858]   Target : Target "create_module_ivy_file" started.
     [  4858]   Target : Target "create_module_ivy_file" finished.
     [  4859]   Target : Target "check_build_file_uptodate" started.
     [  4862]   Target : Target "check_build_file_uptodate" finished.
     [  4864]   Target : Target "generate_module_build_file" started.
     [  4864]   Target : Target "generate_module_build_file" finished.
     [  4865]   Target : Target "update_module_build_file" started.
      [  4866]   Target : Target "check_module_name" started.
      [  4868]   Target : Target "check_module_name" finished.
      [  4869]   Target : Target "check_manifest_version" started.
       [  4869]     Echo : Calling target 'check_manifest' for module com.sun.jaxb
       [  5041]  Taskdef : Could not load definitions from resource checkstyletask.properties. It could not be found.
       [  5065]   Target : Target "check_module_targets_file_exists" started.
       [  5065]   Target : Target "check_module_targets_file_exists" finished.
       [  5065]   Target : Target "check_module_target_exists" started.
       [  5065]   Target : Target "check_module_target_exists" finished.
       [  5065]   Target : Target "module_target" started.
       [  5065]   Target : Target "module_target" finished.
       [  5066]   Target : Target "default_target" started.
        [  5066]   Target : Target "default_check_manifest" started.
        [  5067]   Target : Target "default_check_manifest" finished.
       [  5067]   Target : Target "default_target" finished.
       [  5067]   Target : Target "module_specific_target" started.
       [  5067]   Target : Target "module_specific_target" finished.
      [  5068]   Target : Target "check_manifest_version" finished.
     [  5068]   Target : Target "update_module_build_file" finished.
     [  5069]   Target : Target "ivy_retrieve" started.
      [  5069]     Echo : Skipping 'ivy_retrieve' as everything is uptodate for com.sun.jaxb
....

当然这可以改进,但现在对我来说已经足够了:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-21
    • 1970-01-01
    • 2021-05-27
    • 1970-01-01
    • 1970-01-01
    • 2013-06-19
    • 1970-01-01
    相关资源
    最近更新 更多