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

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

问题描述

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

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

我想写一对将用作的宏:

I want to write a pair of macros which will be used as:

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

A,我似乎无法完成这项工作.即使我将< 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...

(是的,我知道macrosdef可以调用其他宏.这不允许我使用的语法.也不能向< 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不会抱怨这样的宏体;它们只是行不通.)

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 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天全站免登陆