Apache Ant 1.8 宏调用嵌套 [英] Apache Ant 1.8 macro invocation nesting

查看:25
本文介绍了Apache Ant 1.8 宏调用嵌套的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这几乎肯定是重复的,但只是将其简化为最基本的形式:

This is almost certainly a duplicate, but just to reduce it to its most basic form:

我想写一对宏,用作:

<defined-environment>
  <task-in-environment>
  <task-in-environment>
  ...
</defined-environment>

.. 理想情况下,我希望能够将宏定义的包含任务与普通 Ant 任务混合在一起.

.. and ideally I'd like to be able mix the macro-defined contained tasks tasks with normal Ant tasks.

唉,我似乎无法完成这项工作.即使我使 <defined-environment> 的子包装器显式而不是隐式,我也会收到抱怨说 <task-in-environment> 不是我试图环绕它的元素的子元素.这表现得好像 Ant 1.8 根本不理解嵌套宏使用的概念.

Alas, I can't seem to make this work. Even if I make the <defined-environment>'s child wrapper explicit rather than implicit, I get complaints that <task-in-environment> is not expected as a child of the element I'm trying to wrap around it. This is behaving as if Ant 1.8 simply does not understand the concept of nested macro usage.

这真的是真的——Ant 的宏扩展是严格单程和非递归的吗,我是否真的需要编写新的 Ant 实现代码来支持这种用法?还是我遗漏了一些细节使这成为可能?我真的希望现代宏处理器能够处理这种嵌套...

Is that actually true -- is Ant's macro expansion strictly one-pass and nonrecursive, and would I actually have to write new Ant implementation code to support this usage? Or is there some detail I'm missing which will make this possible? I really would expect a modern macro processor to be able to handle this nesting...

(是的,我知道 macrosdefs 可以调用其他宏.这不允许我需要的语法.也不向 <defined-environment> 添加参数,因为包含的任务数量会因一种用法而异.)

(Yes, I know macrosdefs can call other macros. That doesn't allow the syntax I need. Nor does adding parameters to the <defined-environment> since the number of contained tasks will vary from one usage to another.)

附录

好的,看起来人们想要一个明确的例子.这不是我正在做的事情——我的更复杂,这就是为什么我想在宏中隐藏细节——但它具有相同的一般结构并演示了问题......

Ok, looks like folks want an explicit example. This isn't exactly what I'm doing -- mine is more complicated, which is why I want to hide the details in macros -- but it has the same general structure and demonstrates the issue...

<macrodef name="collection">
    <attribute name="id"/>
    <element name="contents" implicit="yes"/>
    <sequential>
          <union id="@{id}">
               <contents/>
          </union>
    </sequential >
 </macrodef>
 <macrodef name="mappedfile">
    <attribute name="fromdir"/>
    <attribute name="todir"/>
    <attribute name="whichfile"/>
    <sequential>
          <mappedresources>
               <globmapper from="*" to="@{todir}/*"/>
                <fileset dir="@{fromdir}" includes="@{whichfile}"/>
          </mappedresources>
    </sequential >
</macrodef>

<collection id="myfiles">
    <mappedfile fromdir="/actual/directory"  whichfile="a.a" todir="/imaginary/directory"/>
    <mappedfile fromdir="/another/directory"  whichfile="b.b" todir="/imaginary/directory"/>
</collection> 

生成一个名为 myfiles 的资源集合,它引用来自两个不同目录的文件,但假装它们都来自虚构的目录.

Produces a resource collection named myfiles which references files from two different directories but pretends they both came from the imaginary directory.

或者应该.据我所知,没有充分的理由它不应该起作用.但似乎 Ant 1.8 无法处理这个问题,我必须编写插件任务定义来获得我正在寻找的语法抽象.或者使用更智能的xml处理工具作为预处理器.

Or should. As far as I can tell, there is no good reason it shouldn't work. But it does seem that Ant 1.8 can't handle this, and that I'd have to code up plug-in task definitions to get the syntax abstraction I'm looking for. Or use a more intelligent xml processing tool as a preprocessor.

推荐答案

无论如何找到了我的版本的解释...

Found the explanation for my version of this, anyway...

ant 中的宏被定义为创建任务,即使它们扩展到的标签是资源.(固定措辞.请注意,Ant 不会抱怨此类宏体;它们只是不起作用.)

Macros in ant are defined as creating tasks, even if the tags they expand to are resources. (Fixed phrasing. Note that Ant doesn't complain about such macro bodies; they just don't work.)

Union 可以将其他资源/资源集合作为子项.不是任务

Union can take other resources/resource collections as children. Not tasks

布拉莫.我什至不需要嵌套的宏调用来阻止我做我想做的事;我根本无法使用内部宏——这是简化我试图支持的逻辑的更重要的宏.

Blammo. I don't even need nested macro calls to keep me from doing what I want; I simply can't use the inner macro -- which s the more important one for simplifying the logic I'm trying to support.

你不能从这里到达那里.

Ya can't get there from here.

还是谢谢大家.

这篇关于Apache Ant 1.8 宏调用嵌套的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆