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. :
-- EDIT --
If number of filesets varies, remove the fsincludes and fsexcludes attribute if not valid for all filesets and use element like that :
-- EDIT --
To copy a single file with nested fileset use :
-- EDIT -- If you need other copysteps with file tofile, you may use another element if that is sufficient:
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.