FileSet Class

Summary

Filesets are groups of files. These files can be found in a directory tree starting in a base directory and are matched by patterns taken from a number of patterns. Filesets can appear inside tasks that support this feature or at the project level, i.e., as children of <project>.
graph BT Type-->Base0["DataTypeBase"] click Base0 "/api/NAnt.Core/DataTypeBase" Base0-->Base1["Element"] click Base1 "/api/NAnt.Core/Element" Base1-->Base2["Object"] Type["FileSet"] class Type type-node Derived0["DirSet"]-->Type click Derived0 "/api/NAnt.Core.Types/DirSet" Derived1["ResourceFileSet"]-->Type click Derived1 "/api/NAnt.DotNet.Types/ResourceFileSet" Derived2["LibDirectorySet"]-->Type click Derived2 "/api/NAnt.DotNet.Types/LibDirectorySet" Derived3["AssemblyFileSet"]-->Type click Derived3 "/api/NAnt.DotNet.Types/AssemblyFileSet" Derived4["CvsFileSet"]-->Type click Derived4 "/api/NAnt.SourceControl.Types/CvsFileSet"

Syntax

[Serializable()]
[ElementName("fileset")]
public class FileSet : DataTypeBase

Examples

Match Matches all files in CVS directories that can be located anywhere in the directory tree. Matches: CVS/Repository org/apache/CVS/Entries org/apache/jakarta/tools/ant/CVS/Entries But not: org/apache/CVS/foo/bar/Entries (foo/bar/ part does not match) Matches all files in the org/apache/jakarta directory tree. Matches: org/apache/jakarta/tools/ant/docs/index.html org/apache/jakarta/test.xml But not: org/apache/xyz.java (jakarta/ part is missing) Matches all files in CVS directories that are located anywhere in the directory tree under org/apache. Matches: org/apache/CVS/Entries org/apache/jakarta/tools/ant/CVS/Entries But not: org/apache/CVS/foo/bar/Entries (foo/bar/ part does not match) Matches all files that have a test element in their path, including test as a filename.
Pattern
**/CVS/*
org/apache/jakarta/**
org/apache/**/CVS/*
**/test/**

Remarks

Patterns

As described earlier, patterns are used for the inclusion and exclusion. These patterns look very much like the patterns used in DOS and UNIX:

  • '*' matches zero or more characters

    For example:

    *.cs matches .cs, x.cs and FooBar.cs, but not FooBar.xml (does not end with .cs).

  • '?' matches one character

    For example:

    ?.cs matches x.cs, A.cs, but not .cs or xyz.cs (both don't have one character before .cs).

Combinations of *'s and ?'s are allowed.

Matching is done per-directory. This means that first the first directory in the pattern is matched against the first directory in the path to match. Then the second directory is matched, and so on. For example, when we have the pattern /?abc/*/*.cs and the path /xabc/foobar/test.cs, the first ?abc is matched with xabc, then * is matched with foobar, and finally *.cs is matched with test.cs. They all match, so the path matches the pattern.

To make things a bit more flexible, we added one extra feature, which makes it possible to match multiple directory levels. This can be used to match a complete directory tree, or a file anywhere in the directory tree. To do this, ** must be used as the name of a directory. When ** is used as the name of a directory in the pattern, it matches zero or more directories. For example: /test/** matches all files/directories under /test/, such as /test/x.cs, or /test/foo/bar/xyz.html, but not /xyz.xml.

There is one "shorthand" - if a pattern ends with / or \, then ** is appended. For example, mypackage/test/ is interpreted as if it were mypackage/test/**.

Case-Sensitivity

By default, pattern matching is case-sensitive on Unix and case-insensitive on other platforms. The NAnt.Core.Types.FileSet.CaseSensitive parameter can be used to override this.

Default Excludes

There are a set of definitions that are excluded by default from all tasks that use filesets. They are:

  • **/.svn
  • **/.svn/**
  • **/_svn
  • **/_svn/**
  • **/.git
  • **/.git/**
  • **/.git* (eg. .gitignore)
  • **/.hg
  • **/.hg/**
  • **/.hg* (eg. .hgignore)
  • **/SCCS
  • **/SCCS/**
  • **/vssver.scc
  • **/vssver2.scc
  • **/_vti_cnf/**
  • **/*~
  • **/#*#
  • **/.#*
  • **/%*%
  • **/CVS
  • **/CVS/**
  • **/.cvsignore
  • **/._*
  • **/.bzr
  • **/.bzr/**
  • **/.bzr* (eg. .bzrignore)
  • **/.DS_Store

If you do not want these default excludes applied, you may disable them by setting NAnt.Core.Types.FileSet.DefaultExcludes to false.

Attributes

Type Description
SerializableAttribute
ElementNameAttribute Indicates that class should be treated as a NAnt element.

Constructors

Name Summary
FileSet() Initializes a new instance of the NAnt.Core.Types.FileSet class.
FileSet(FileSet) copy constructor

Properties

Name Value Summary
AsIs StringCollection
Gets the collection of files that will be added to the NAnt.Core.Types.FileSet without pattern matching or checking if the file exists.
BaseDirectory DirectoryInfo
The base of the directory of this fileset. The default is the project base directory.
CanBeReferenced bool
Gets a value indicating whether a reference to the type can be defined.
Inherited from DataTypeBase
CaseSensitive bool
Indicates whether include and exclude patterns must be treated in a case-sensitive way. The default is true on Unix; otherwise, false.
CustomXmlProcessing bool
Gets a value indicating whether the element is performing additional processing using the NAnt.Core.Element.XmlNode that was used to initialize the element.
Inherited from Element
DefaultExcludes bool
Indicates whether default excludes should be used or not. The default is true.
DirectoryNames StringCollection
Gets the collection of directory names that match the fileset.
ExcludedDirectoryNames StringCollection
Gets the collection of excluded directory names that match the fileset.
ExcludedFileNames StringCollection
Gets the collection of excluded file names that match the fileset.
ExcludeElements FileSet.Exclude[]
The items to exclude from the fileset.
Excludes StringCollection
Gets the collection of exclude patterns.
ExcludesFiles FileSet.ExcludesFile[]
The files from which a list of patterns or files to exclude should be obtained.
FailOnEmpty bool
When set to true, causes the fileset element to throw a NAnt.Core.ValidationException when no files match the includes and excludes criteria. The default is false.
FileNames StringCollection
Gets the collection of file names that match the fileset.
HasEmptyDirectories bool
Gets a value indicating whether this instance contains empty directories.
ID string
The ID used to be referenced later.
Inherited from DataTypeBase
IncludeElements FileSet.Include[]
The items to include in the fileset.
Includes StringCollection
Gets the collection of include patterns.
IncludesFiles FileSet.IncludesFile[]
The files from which a list of patterns or files to include should be obtained.
IsEverythingIncluded bool
Gets a value indicating whether this instance retrieved all files/directories scanned and nothing was excluded.
Location Location
Gets or sets the location in the build file where the element is defined.
Inherited from Element
MostRecentLastWriteTimeFile FileInfo
Determines the most recently modified file in the fileset (by LastWriteTime of the System.IO.FileInfo).
Name string
Gets the name of the data type.
Inherited from DataTypeBase
NamespaceManager XmlNamespaceManager
Gets or sets the System.Xml.XmlNamespaceManager.
Inherited from Element
Parent Object
Gets or sets the parent of the element.
Inherited from Element
PathFiles PathScanner
Project Project
Gets or sets the NAnt.Core.Element.Project to which this element belongs.
Inherited from Element
Properties PropertyDictionary
Gets the properties local to this NAnt.Core.Element and the NAnt.Core.Element.Project.
Inherited from Element
RefID string
The ID to use as the reference.
Inherited from DataTypeBase
ScannedDirectories StringCollection
Gets the collection of directory names that were scanned for files.
SetExcludes FileSet.Exclude[]
The items to exclude from the fileset.
SetIncludes FileSet.Include[]
The items to include in the fileset.
SetIncludesList FileSet.IncludesFile[]
The files from which a list of patterns or files to include should be obtained.
XmlNode XmlNode
Gets or sets the XML node of the element.
Inherited from Element

Methods

Name Value Summary
AddPatternSet(PatternSet) void
Adds a nested set of patterns, or references a standalone patternset.
Clone() Object
Creates a shallow copy of the NAnt.Core.Types.FileSet.
CopyTo(DataTypeBase) void
Copies all instance data of the NAnt.Core.DataTypeBase to a given NAnt.Core.DataTypeBase.
Inherited from DataTypeBase
CopyTo(Element) void
Copies all instance data of the NAnt.Core.Element to a given NAnt.Core.Element.
Inherited from Element
CopyTo(FileSet) void
Copies all instance data of the NAnt.Core.Types.FileSet to a given NAnt.Core.Types.FileSet.
FindMoreRecentLastWriteTime(string, DateTime) string
Determines if a file has a more recent last write time than the given time, or no longer exists.
static
FindMoreRecentLastWriteTime(StringCollection, DateTime) string
Determines if one of the given files has a more recent last write time than the given time. If one of the given files no longer exists, the target will be considered out-of-date.
static
GetAttributeConfigurationNode(FrameworkInfo, string) XmlNode
Locates the XML node for the specified attribute in the project configuration node.
Inherited from Element
GetAttributeConfigurationNode(XmlNode, FrameworkInfo, string) XmlNode
Inherited from Element
GetLocation() Location
Retrieves the location in the build file where the element is defined.
Inherited from Element
Initialize() void
Derived classes should override to this method to provide extra initialization and validation not covered by the base class.
Initialize(XmlNode) void
Performs default initialization.
Inherited from Element
InitializeBuildElement(Element, XmlNode, Element, Type) Element
Initializes the build element.
Inherited from Element
static
InitializeElement(XmlNode) void
Derived classes should override to this method to provide extra initialization and validation not covered by the base class.
Inherited from Element
InitializeXml(XmlNode, PropertyDictionary, FrameworkInfo) void
Initializes all build attributes and child elements.
Inherited from Element
Log(Level, string) void
Logs a message with the given priority.
Inherited from Element
Log(Level, string, Object[]) void
Logs a message with the given priority.
Inherited from Element
Reset() void
Should be overridden by derived classes. clones the referenced types data into the current instance.
Scan() void
ToString() string

See Also

  • NAnt.Core.Types.PatternSet