ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Turner <j...@socialchange.net.au>
Subject Re: wildcarding dir in fileset?
Date Fri, 04 May 2001 11:58:00 GMT
The inventor of the regexp <mapper> type deserves a medal for providing
a solution to this problem.

Let's assume we have this structure:

src/dir1/classes/
src/dir2/classes/
src/dir3/classes/
src/../classes/

We want to jar the contents of all the classes together, but do not know
until runtime the names or number of directories under src/.

One almost-solution is to use the "flatten" attribute as follows:

<copy todir="${allclasses}" flatten="true">
  <fileset dir="src">
    <include name="*/classes/**"/>
    </fileset>
</copy>

Ie, move the wildcard to the include, instead of the dir. This will get
the files in the jar, but unfortunately will lose any structure below
the classes/ directory. Eg if you have:
src/dir1/classes/com/foo/A.class
src/dir2/classes/com/bar/B.class

In your jar, you'll just get "A.class" and "B.class" in the root.
However, this flatten trick is useful for things that don't require
directories, eg if we wanted to copy src/*/lib/*.jar

The best solution is, as mentioned, to use the regexp <mapper> type,
found in recent (1.3?) releases of Ant:

<copy todir="dest/">
  <fileset dir="src"/>
    <mapper type="regexp" from=".*/classes/(.*)" to="\1"/>
</copy>

This will do what we want, and preserve the structure below classes/.

To use the regexp mapper type, you need optional.jar and
jakarta-regexp.jar in your $ANT_HOME/lib directory. The docs describe
this adequately.

I've put together a small demo of the above at
http://kenny.socialchange.net.au/~jeff/ant/ant-wildcard.zip

HTH,

--Jeff

Mime
View raw message