官能与蚂蚁macrodef code的几行 [英] Functionalizing few lines of code with ant macrodef

查看:184
本文介绍了官能与蚂蚁macrodef code的几行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想功能ALIZE使用ant- code的几行 macrodef 。但其导致类似错误:

 拷贝不支持嵌套的我的宏元素。

如果我内联的定义副本任务它的作品中加入filterchian我的宏的。

我的测试目标是这样的 -

 <目标名称=复制文件>
        <&连续GT;
            <副本todir =ABC>
                <文件集DIR =XYZ>
                    <! - 贫困包含/排除 - >
                < /文件集>
                <我的宏/>
            < /复制>
        < /顺序>
 < /目标与GT;

和我的宏是这样的:

 < macrodef NAME =我的宏>
        <&连续GT;
            < filterchain>
                < fixcrlf包括=**EOL =LF/>
            < / filterchain>
        < /顺序>    < / macrodef>

code其中工程(内联一)如下:

 <目标名称=复制文件>
        <&连续GT;
            <副本todir =ABC>
                <文件集DIR =XYZ>
                    <! - 贫困包含/排除 - >
                < /文件集>
                < filterchain>
                < fixcrlf包括=**EOL =LF/>
            < / filterchain>
          < /复制>
 < /顺序>< /目标与GT;


解决方案

复制任务不接受一个嵌套的宏单元,多数民众赞成在errormessage的说的话。结果
把整个副本的东西进入你的macrodef,F.E. :结果

 < macrodef NAME =我的宏>
 <属性名=目标/>
 <属性名=fsdir/>
 <属性名=fsincludes/>
 <属性名=fsexcludes/>
 <属性名=fixincl/>
 <&连续GT;
  <副本todir =@ DEST}>
   <文件集DIR =@ {} fsdir>
    <包括姓名=@ {} fsincludes/>
    <排除NAME =@ {} fsexcludes/>
   < /文件集>
   < filterchain>
    < fixcrlf包括=@ {} fixinclEOL =LF/>
   < / filterchain>
  < /复制>
 < /顺序>
< / macrodef>

- 编辑 - 结果
如果文件集的数量变化,除去fsincludes和fsexcludes属性如果不是适用于所有文件集,并使用这样的元素:结果

 < macrodef NAME =我的宏>
  <属性名=目标/>
  <元素名称=FS描述=嵌套文件集/>
  <属性名=fixincl/>
  <&连续GT;
   <副本todir =@ DEST}>
     <! - 1-N嵌套文​​件集) - GT;
     < FS />
    < filterchain>
     < fixcrlf包括=@ {} fixinclEOL =LF/>
    < / filterchain>
   < /复制>
  < /顺序>
 < / macrodef>
 <我的宏DEST =C:/什么fixincl =**>
   < FS>
     <文件集DIR =。包括=** / *富/>
     <文件集DIR =../富包括=** / * XML。/>
     <! - ... - >
   < / FS>
 < /我的微距>

- 编辑 - 结果
要使用嵌套的文件集使用复制单个文件:结果

 <文件集文件=C:/somepath/some.file/>

- 编辑 -
如果需要其他copysteps与文件TOFILE,您可以使用另一种元素,如果这是足够了:结果

 < macrodef NAME =我的宏>
 <属性名=目标/>
 <元素名称=copyfiles描述=嵌套副本/>
 <元素名称=FS描述=嵌套文件集/>
 <属性名=fixincl/>
 <&连续GT;  <副本todir =@ DEST}>
    <! - 1-N嵌套文​​件集) - GT;
    < FS />
   < filterchain>
    < fixcrlf包括=@ {} fixinclEOL =LF/>
   < / filterchain>
  < /复制>  < copyfiles /> < /顺序>
< / macrodef><我的宏DEST =C:/什么fixincl =**>
 < FS>
  <文件集DIR =。包括=** / *富/>
  <文件集DIR =../富包括=** / * XML。/>
  <! - ... - >
 < / FS>
 < copyfiles>
  <拷贝文件=...TOFILE =.../>
  <! - ... - >
  < / copyfiles>
< /我的微距>

对于通常使用映射大容量文件重命名。结果
毕竟,如果它变得更复杂,你应该考虑的Groovy 或脚本编写自己的Ant任务

I am trying to "function"alize few lines of ant-code using macrodef. But its resulting in error like :

copy doesn't support the nested "my-macro" element. 

If I "inline" definition of my-macro of adding filterchian within copy-task it works.

My test target looks like this -

<target name="copy-files">
        <sequential>
            <copy todir="abc" >
                <fileset dir="xyz">
                    <!--needy includes/excludes -->
                </fileset>
                <my-macro/>
            </copy>
        </sequential>
 </target>

And my-macro looks like this:

 <macrodef name="my-macro">
        <sequential>
            <filterchain>
                <fixcrlf includes="**" eol="lf"/>
            </filterchain>
        </sequential>

    </macrodef>

Code which works (inlined-one ) looks like :

<target name="copy-files">
        <sequential>
            <copy todir="abc" >
                <fileset dir="xyz">
                    <!--needy includes/excludes -->
                </fileset>
                <filterchain>
                <fixcrlf includes="**" eol="lf"/>
            </filterchain>
          </copy>
 </sequential></target>

解决方案

The copy task doesn't accept a nested macro element, thats what the errormessage says.
Put the whole copy stuff into your macrodef, f.e. :

<macrodef name="my-macro">
 <attribute name="dest"/>
 <attribute name="fsdir"/>
 <attribute name="fsincludes"/>
 <attribute name="fsexcludes"/>
 <attribute name="fixincl"/>
 <sequential>
  <copy todir="@dest}">
   <fileset dir="@{fsdir}">
    <include name="@{fsincludes}"/>
    <exclude name="@{fsexcludes}"/>
   </fileset>
   <filterchain>
    <fixcrlf includes="@{fixincl}" eol="lf"/>
   </filterchain>
  </copy>
 </sequential>
</macrodef>

-- EDIT --
If number of filesets varies, remove the fsincludes and fsexcludes attribute if not valid for all filesets and use element like that :

 <macrodef name="my-macro">
  <attribute name="dest"/>
  <element name="fs" description="nested filesets"/>
  <attribute name="fixincl"/>
  <sequential>
   <copy todir="@dest}">
     <!-- 1-n nested filesets) -->
     <fs/>
    <filterchain>
     <fixcrlf includes="@{fixincl}" eol="lf"/>
    </filterchain>
   </copy>
  </sequential>
 </macrodef>


 <my-macro dest="C:/whatever" fixincl="**">
   <fs>
     <fileset dir="." includes="**/*.foo"/>
     <fileset dir="../foo" includes="**/*.xml"/>
     <!-- ... -->
   </fs>
 </my-macro>

-- EDIT --
To copy a single file with nested fileset use :

<fileset file="C:/somepath/some.file"/>

-- EDIT -- If you need other copysteps with file tofile, you may use another element if that is sufficient:

<macrodef name="my-macro">
 <attribute name="dest"/>
 <element name="copyfiles" description="nested copy"/>
 <element name="fs" description="nested filesets"/>
 <attribute name="fixincl"/>
 <sequential>

  <copy todir="@dest}">
    <!-- 1-n nested filesets) -->
    <fs/>
   <filterchain>
    <fixcrlf includes="@{fixincl}" eol="lf"/>
   </filterchain>
  </copy>

  <copyfiles/>

 </sequential>
</macrodef>

<my-macro dest="C:/whatever" fixincl="**">
 <fs>
  <fileset dir="." includes="**/*.foo"/>
  <fileset dir="../foo" includes="**/*.xml"/>
  <!-- ... -->
 </fs>
 <copyfiles>
  <copy file="..." tofile="..."/>
  <!-- ... --> 
  </copyfiles>
</my-macro>

Normally for bulk renaming of files a mapper is used.
After all if it gets more complicated you should consider scripting with Groovy or write your own Ant Task.

这篇关于官能与蚂蚁macrodef code的几行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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