tags:

views:

719

answers:

2

I would like to create a macro as such:

<macrodef name="testing">
  <element name="test" implicit="yes"/>
  <sequential>
    <test/>
  </sequential>
</macrodef>

And then use it:

<testing>
  <echo message="hello world"/>
</testing>

However, I would like to specify a default for the implicit element... something like:

<macrodef name="testing">
  <element name="test" implicit="yes">
    <echo message="hello world"/>
  </element>
  <sequential>
    <test/>
  </sequential>
</macrodef>

So I can then use it as such:

<testing/>

Except where I want to change the default element.

Is this possible without defining a task via a Java class? So far, I don't see any documentation that indicates how to do it, if so.


Update

I ended up resolving my particular issue by using refid for filesets (which is what I actually was trying to pull into an element). Using the refid, it was simple to just use a macrodef attribute, which CAN have a default value.

Another alternative would be to create a new base macro which uses the element, and then I could have kept my existing macro as using that one... but still, there is no real default mechanism for an element (which would be nice).

So, Simon gets the answer since he's correct! Thanks!

A: 

if you define your macrodef as:

<macrodef name="testing">
    <element name="additional" optional="true"/>
    <sequential>
        <echo message="hello"/>
        <additional/>
    </sequential>
</macrodef>

the following invocation:

<target name="testing-call">
    <mylib:testing/>
    <mylib:testing>
        <additional>
            <echo message="world!"/>
        </additional>
    </mylib:testing>
</target>

will output:

[echo] hello
[echo] hello
[echo] world!
Vladimir
Appreciated, but I am looking for an actual default, not optional behavior... I would like the contents of the default to be completely replaced with whatever is actually passed in, but of course only if there is content defined.
Mike Stone
+1  A: 

This is not possible based on the nested element element documentation for the macrodef task.

There is a Bugzilla issue open for exactly the functionality you describe, unfortunately it has been open since 2004.

Simon Lieschke