Ant'的默认元素;什么是宏定义?
我想创建这样一个宏:Ant'的默认元素;什么是宏定义?,ant,Ant,我想创建这样一个宏: <macrodef name="testing"> <element name="test" implicit="yes"/> <sequential> <test/> </sequential> </macrodef> 然后使用它: <testing> <echo message="hello world"/> </testing>
<macrodef name="testing">
<element name="test" implicit="yes"/>
<sequential>
<test/>
</sequential>
</macrodef>
然后使用它:
<testing>
<echo message="hello world"/>
</testing>
但是,我想为隐式元素指定一个默认值。。。比如:
<macrodef name="testing">
<element name="test" implicit="yes">
<echo message="hello world"/>
</element>
<sequential>
<test/>
</sequential>
</macrodef>
因此,我可以这样使用它:
<testing/>
除非我想更改默认元素
这在不通过Java类定义任务的情况下是可能的吗?到目前为止,我还没有看到任何说明如何做的文档,如果有的话
更新 我最终通过对文件集使用refid解决了我的特殊问题(这是我实际上试图拉入元素的内容)。使用refid,只需使用macrodef属性即可,该属性可以有一个默认值 另一种选择是创建一个使用该元素的新基宏,然后我可以将现有宏保留为使用该元素的宏。。。但是,对于一个元素,仍然没有真正的默认机制(这会很好)
所以,西蒙得到了答案,因为他是正确的!谢谢 如果将宏定义为:
<macrodef name="testing">
<element name="additional" optional="true"/>
<sequential>
<echo message="hello"/>
<additional/>
</sequential>
</macrodef>
基于的嵌套
元素
元素文档,这是不可能的
很遗憾,您描述的功能自2004年以来一直处于开放状态。非常感谢,但我正在寻找一个实际的默认行为,而不是可选行为。。。我希望缺省值的内容完全替换为实际传入的内容,但当然只有在定义了内容的情况下。
<target name="testing-call">
<mylib:testing/>
<mylib:testing>
<additional>
<echo message="world!"/>
</additional>
</mylib:testing>
</target>
[echo] hello
[echo] hello
[echo] world!