concept fileset in category ant

appears as: fileset, A fileset, filesets, The fileset, fileset
Ant in Action

This is an excerpt from Manning's book Ant in Action.

Most build processes operate on sets of files, either to compile, copy, delete, or manipulate in any number of other ways. These processes are so central that Ant provides the fileset as a built-in datatype, one of the more generic sets of resource types.

A fileset is a set of files rooted from a single directory. By default, a fileset specified with only a root directory will include all the files in that entire directory tree, including files in all subdirectories recursively. For a concrete running example that will demonstrate fileset features as we discuss them, let’s copy files from one directory to another:

Having covered filesets and patternsets, we can apply the information to the <javac> task. This task is one of the many implicit fileset tasks. Rather than requiring you to add a fileset of source files as a nested element, the task itself supports many of the attributes and elements of a fileset:

<javac srcdir="src" destdir="build/classes">
  <include name="org/antbook/**/*.java"/>
  <exclude name="org/antbook/broken/*.java"/>
</javac>

This task has <javac> acting as a fileset, including some files and excluding some others. Note: you can’t reliably use excludes patterns to tell <javac> which files not to compile. If a Java file you include needs another file, Sun’s javac compiler will search the source tree for it, even if it’s been excluded from the fileset. This is a feature of the compiler, and not Ant. We can exclude only the classes in the org.antbook.broken package because they aren’t imported into any class in the fileset.

Another thing to know is that filesets resolve their files when the declaration is first evaluated. This may not be when it’s declared, but when it’s first used. Once resolved, the set is never updated. This is important to know when referring to a previously defined fileset, as new files and directories matching the patterns may have appeared between the resolution and reference; these new files do not appear in the fileset.

Filesets and paths are some of the most common of Ant’s datatypes and are often passed down to tasks within nested elements.