Search code examples
antmacrodef

ant macrodefs and element naming


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?


Solution

  • 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.