2014-12-02 79 views
1

我想从另一个宏的元素中调用宏。 让我们假设我有以下宏:蚂蚁嵌套宏调用

<macrodef name="jc"> 
    <attribute name="name" /> 
    <attribute name="destdir" /> 
    <element name="fileset-list" optional="false" /> 
    <sequential> 
     <jar destfile="@{destdir}${file.separator}@{name}.jar" update="false"> 
      <fileset-list /> 
      <manifest> 
       <attribute name="Manifest-Version" value="1.0" />  
      </manifest> 
     </jar> 
    </sequential> 
</macrodef> 

和另一个宏

<macrodef name="defaultfs" description="Defines the default fileset"> 
    <attribute name="path" /> 
    <sequential> 
     <fileset dir="${dir.build.classes}"> 
      <include name="@{path}/**/*.class" /> 
     </fileset> 
     <fileset dir="${src.ehs}"> 
      <include name="@{path}/**/icons/**" /> 
      <include name="@{path}/**/sounds/**" /> 
      <include name="@{path}/**/*.gif" /> 
      <include name="@{path}/**/*.png" /> 
      <include name="@{path}/**/*.wav" /> 
      <include name="@{path}/**/*.jpg" /> 
      <include name="@{path}/**/*.properties" /> 
      <include name="@{path}/**/*.xml" /> 
      <include name="@{path}/**/jaxb.index" /> 
     </fileset> 
    </sequential> 
</macrodef> 

我使用这些宏如下:

<jc destdir="${dir.build.jar}" name="thejar"> 
    <fileset-list> 
     <defaultfs path="org/path/inner" /> 
    </fileset-list> 
</jc> 

我得到的是以下错误消息:

jar doesn't support the nested "defaultfs" element. 

什么是错的?

+0

未将“jar”ANT任务编写为支持“defaultfs”XML元素。 ANT中的宏有些不同,它们更像模板。 – 2014-12-02 21:05:57

+0

你是对的,但我的要求是以更广泛的方式使用jc,并且我有一些使用类似文件集构建的jar。 宏是否只评估一次? – landal79 2014-12-03 10:03:48

+0

我有一个类似的情况,我想在一个宏(隐式)元素参数中使用宏。还没有想出如何 - 或者如果可能的话 - 在外部宏之前获得内部宏评估。如果你能找到答案,我绝对有兴趣! (不,结合这两个宏并不是一个答案 - 我希望其中的每一个独立行动,就像它是一个普通的Ant任务一样,用户不必意识到它们是宏。) – keshlam 2015-03-17 12:44:23

回答

0

你可以试试你的主要宏观“JC”内进行宏调用,并通过文件集路径考虑作为附加属性

<macrodef name="jc"> 
    <attribute name="name" /> 
    <attribute name="destdir" /> 
    <attribute name="fileset.path.to.consider" /> 
    <sequential> 
     <jar destfile="@{destdir}${file.separator}@{name}.jar" update="false"> 
      <defaultfs path="@{fileset.path.to.consider}"/> 
      <manifest> 
       <attribute name="Manifest-Version" value="1.0" /> 
      </manifest> 
     </jar> 
    </sequential> 
</macrodef> 

然后你的主宏调用可能看起来像:

<jc destdir="${dir.build.jar}" name="thejar" fileset.path.to.consider="org/path/inner"/> 

(未经测试,您可以试试看)

+0

谢谢,但不是我想要的。 – landal79 2014-12-03 10:04:27