ant 宏定义和元素命名

发布于 2024-12-16 15:32:02 字数 1711 浏览 1 评论 0原文

我有一个宏定义,其中有一个名为“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>

,然后调用该元素,因为

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

我有另一个宏定义,它调用多个宏定义,包括“deploy-libs”。如果这个宏定义也有一个元素“libs”,那就太好了,但是:

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

        <!-- other stuff -->

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

        <!-- other stuff -->

    </sequential>
</macrodef>

显然不起作用(因为):

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

解决方案可以以不同的方式命名“init-glassfish”中的元素:

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

        <!-- other stuff -->

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

        <!-- other stuff -->

    </sequential>
</macrodef>

有没有办法让两个宏定义以相同的方式命名元素?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

隱形的亼 2024-12-23 15:32:02

我找到了我的问题的解决方案,它使用路径 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>

现在,这并不能解决 嵌套 元素标签的问题,但(XY 问题)解决了实际问题。如果知道是否可能出现与原始问题类似的问题,那就太好了。

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.

栩栩如生 2024-12-23 15:32:02

显然,解决方案是根据宏嵌套的深度在原始调用中包装额外的 元素。当然,这是一个可怕的解决方案,因为它要求在调用时知道宏嵌套深度,例如:

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

解决此问题的 Ant bug 29153 不幸地被解决为无效:(。

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 :(.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文