The mapper applies to all the items in the fileset being copied. Your
fileset selects everything, including files and directories. The more
"correct" approach to solving this problem would have been to put a
selector in the fileset that tells Ant to select only the files and not
the directories:
<ant:copy todir="target">
<ant:fileset dir="src">
<ant:type type="file" />
</ant:fileset>
<ant:mapper type="glob" from="*" to="*.xml" />
</ant:copy>
This would copy only the files over, and thus only apply the mapper to
the files as well. Ant will create the directory structure as necessary
to copy the files, but empty directories wouldn't get copied over
(because the fileset doesn't select them and there aren't any files in
the directory to copy). However, this doesn't work with Ant 1.5.3, so
it won't work in Maven (without upgrading Maven's copy of Ant).
The "includeEmptyDirs" approach is really just a hack that works in Ant
1.5.3 because Ant sees itself as copying an empty folder when it applies
the mapping to a directory name.
-----Original Message-----
From: news [mailto:[EMAIL PROTECTED] On Behalf Of Adrian Herscu
Sent: Tuesday, May 17, 2005 1:28 AM
To: [email protected]
Subject: Problem with <ant:copy> global mapper
Thanks David! It works now!
I still do not understand what this have to do with empty directories?
I just wanted to rename files and not their containing directories - why
should I have to think about the "includeEmptyDirs" property?
Again, thanks for your time,
Adrian.
David Jackman wrote:
-----Original Message-----
From: David Jackman
Sent: Monday, May 16, 2005 8:55 AM
To: 'Maven Users List'
Subject: RE: Problem with <ant:copy> global mapper
First, I'll attempt to explain why things happened the way they did for
the lines you marked with "(?)":
<!--
this line has no effect (?)
(from Ant's User Manual)
-->
<ant:globmapper from="*" to="*.xml" />
This one didn't work because doing mappings with a special tag (as
opposed to the mapper tag using the type attribute) wasn't introduced
until Ant 1.6.2, and Maven still uses Ant 1.5.3.
<!--
this line does not copy anything,
only the ${dest.dir} is created (?)
-->
<ant:mapper type="glob" from="*.*" to="*.*.xml" /> According to
the Ant docs, the glob type mapper can have at most one * in the from
and the to attributes. Since this contains 2 in each, it makes sense
that it doesn't work as desired.
<!--
this line appends ".xml" both to
files and directories (?)
-->
<and:mapper type="glob" from="*" to="*.xml" /> This makes sense
because the glob mapper applies itself to everything in the fileset, and
the fileset said to include everything.
Since Ant sees itself as copying the directories with the .xml
extension, you can prevent this by simply adding the includeEmptyDirs
attribute to the copy element:
<ant:copy todir="target" includeEmptyDirs="false">
<ant:fileset dir="src" />
<ant:mapper type="glob" from="*" to="*.xml" />
</ant:copy>
The downside here is that it won't copy empty directories if you have
any. If you do have empty directories, you would need to create a
separate copy task to do this.
Hope this helps,
..David..
-----Original Message-----
From: news [mailto:[EMAIL PROTECTED] On Behalf Of Adrian Herscu
Sent: Saturday, May 14, 2005 7:59 AM
To: [email protected]
Subject: Problem with <ant:copy> global mapper
Hi all,
I have a ${src.dir} like:
src/main/mylang
+treeofpackages
+file1.xxx
+file2.xxx
+file1.yyy
...
Now, I want to write a Maven goal to copy this directory structure into
a ${dest.dir} while appending an ".xml" extension to all files (but not
to directories).
I tried to use:
<ant:copy todir="${dest.dir}">
<!--
this line alone copies the directory
structure and files as expected
-->
<ant:fileset dir="${src.dir}" />
<!--
this line has no effect (?)
(from Ant's User Manual)
-->
<ant:globmapper from="*" to="*.xml" />
<!--
this line appends ".xml" both to
files and directories (?)
-->
<and:mapper type="glob" from="*" to="*.xml" />
<!--
this line does not copy anything,
only the ${dest.dir} is created (?)
-->
<ant:mapper type="glob" from="*.*" to="*.*.xml" />
<!--
this line works as expected :)
-->
<ant:mapper type="glob" from="*.xxx" to="*.xxx.xml" />
</ant:copy>
Is it possible to write this task using only one <ant:copy> task and
without specifying a mapper for each source file extension?
Thanks for your time,
Adrian.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]