ant macrodefs and element naming

902 Views Asked by At

I have a macrodef with a an element called "libs"

<macrodef name="deploy-libs">
    <element name="libs"/>
    <sequential>
        <copy todir="${glassfish.home}/glassfish/domains/domain1/lib">              
            <fileset dir="${lib}">
                <libs/>
            </fileset>
        </copy>
    </sequential>
</macrodef>

which is then invoked as

<deploy-libs>
    <libs>
        <include name="mysql-connector-*.jar"/>
        <include name="junit-*.jar" />
        <!-- .... -->
    </libs>
</deploy-libs>

I then have another macrodef which calls several macrodefs including "deploy-libs". It would be nice if this macrodef had an element "libs" too but:

<macrodef name="init-glassfish">
    <element name="libs"/>
    <sequential>

        <!-- other stuff -->

        <deploy-libs>
            <libs>
                <libs/>
            </libs>
        </deploy-libs>

        <!-- other stuff -->

    </sequential>
</macrodef>

is obviously not working (because of <libs><libs/></libs>):

Commons/ant-glassfish-server.xml:116: unsupported element include

A solution could be to name the element in "init-glassfish" in a different way:

<macrodef name="init-glassfish">
    <element name="libraries"/>
    <sequential>

        <!-- other stuff -->

        <deploy-libs>
            <libs>
                <libraries/>
            </libs>
        </deploy-libs>

        <!-- other stuff -->

    </sequential>
</macrodef>

Is there a way to have the element to be named in the same way for both macrodefs?

2

There are 2 best solutions below

0
On BEST ANSWER

I found a solution to my question which solves the original problem using a path id

<macrodef name="deploy-libs">

    <attribute name="libraries-path-refid"/>

    <sequential>
         <copy todir="${glassfish.home}/glassfish/domains/domain1/lib">             
            <path refid="@{libraries-path-refid}"/>
         </copy>
    </sequential>
</macrodef>

Now this does not solve the issue with the nested elements tags but (XY problem) solves the practical issue. It would be still be nice to know if something similar to the original question is possible.

0
On

Apparently, the solution is wrapping additional <libs> elements around in the original call depending on how deep the macros nest. Of course this is a horrible solution because it requires that the macro nesting depth is known on invocation, e.g.:

<deploy-libs>
  <libs>
    <libs>
      <include name="mysql-connector-*.jar"/>
      <include name="junit-*.jar" />
      <!-- .... -->
    </libs>
  </libs>
</deploy-libs>

Ant bug 29153 addressing this problem was unfortunately resolved as invalid :(.