ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Bodewig <>
Subject Re: DirectoryScanner cache to boost performance
Date Mon, 14 Sep 2009 16:12:54 GMT
On 2009-09-13, Raja Nagendra Kumar <> wrote:

> In this context, is there a way to let the DirectoryScanner read the entire
> file list only once in the entire ant session and every instance of
> DirectoryScanner  and its  scans() would use such set to find the files
> based on include and exclude patterns.

As long as all tasks you use can work on ResourceCollections, this may

First, start out with a <fileset> for your directory and no excludes at

fileset caches the DirectoryScanner instance and DirectoryScanner caches
its result, so in theory this would be a single scan then cache setup -
unfortunately it isn't.  Most tasks grab into the fileset, pull out the
directory scanner and invoke scan on it, which clears the cached

Note this has both historical and practical reasons:

* Directoryscanner predates FileSet by more than a year (and a point
  release, FileSet was introduced in Ant 1.2) and both predate resource
  collections by several years and releases.

* sometimes you really want a fileset to pick up changes you've made
  during the build.

OK, back to the intial problem.  The fileset alone won't help as I
pointed out, but there are resource collections that cache their
contents.  One of them, is union. so

<union id="all-files">
  <fileset dir="your-directory"/>

is a resource collection that holds all files below "your-directory" and
it will only ever scan the directory tree once (caching the results).

If you need to apply include/exclude patterns, use a restrict resource
collection and appropriate selectors like

<restrict id="java-files">
  <resource refid="all-files"/>
  <name name="**/*.java"/>

<restrict id="non-test-java-files">
  <resource refid="all-files"/>
    <name name="**/*.java"/>
      <name name="**/*_Test*"/>

I think you get the idea.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message