8
我想在Ant中调试macrodef。我似乎无法找到一种方式来显示作为元素发送的参数的内容。Ant macrodef:有没有办法获取元素参数的内容?
<project name='debug.macrodef'>
<macrodef name='def.to.debug'>
<attribute name='attr' />
<element name='elem' />
<sequential>
<echo>Sure, the attribute is easy to debug: @{attr}</echo>
<echo>The element works only in restricted cases: <elem /> </echo>
<!-- This works only if <elem /> doesn't contain anything but a
textnode, if there were any elements in there echo would
complain it doesn't understand them. -->
</sequential>
</macrodef>
<target name='works'>
<def.to.debug attr='contents of attribute'>
<elem>contents of elem</elem>
</def.to.debug>
</target>
<target name='does.not.work'>
<def.to.debug attr='contents of attribute'>
<elem><sub.elem>contents of sub.elem</sub.elem></elem>
</def.to.debug>
</target>
</project>
实例运行:
$ ant works
...
works:
[echo] Sure, the attribute is easy to debug: contents of attribute
[echo] The element works only in restricted cases: contents of elem
...
$ ant does.not.work
...
does.not.work:
[echo] Sure, the attribute is easy to debug: contents of attribute
BUILD FAILED
.../build.xml:21: The following error occurred while executing this line:
.../build.xml:7: echo doesn't support the nested "sub.elem" element.
...
所以我想我需要使用一个办法让<elem />
的内容到属性不知何故(一些扩展macrodef实现可能有),或者我需要一个可以打印出你放入的任何XML树的<element-echo><elem /></element-echo>
。有谁知道这些的实现吗?任何第三种无法预料的数据获取方式当然也是受欢迎的。
的' '元素正是我所期待的,谢谢! –
clacke
2010-07-27 11:52:26
作为奖励,' '即使没有额外的处理来添加XML标头(在Ant 1.8.4上测试过)也可以工作。 –
2013-04-15 10:38:40