public final class PathMatcher extends Object
A path matcher can be given an optional list of include patterns, and an optional list of exclude patterns. A given file path matches the pattern if it is matched by at least one include pattern (or there is a null includes list), and is not matched by any of the exclude patterns (if this list is not null).
The format is based on Ant patterns. Some details:
Some example patterns:
Constructor and Description |
---|
PathMatcher(String includes,
String excludes,
File base)
Create a path matching object.
|
Modifier and Type | Method and Description |
---|---|
Set<File> |
findIncludedRoots()
Find folders which match although their parent folders do not; or folders
which do not match but which contain files which do.
|
boolean |
matches(String path,
boolean useKnownIncludes)
Check whether a given path matches some includes (if not null) and no excludes.
|
String |
toString() |
public PathMatcher(String includes, String excludes, File base)
PathMatcher.matches(java.lang.String, boolean)
multiple times
than to recreate a matcher for each query.includes
- a list of paths to match, or null to match everything by defaultexcludes
- a list of paths to not match, or nullbase
- a base directory to scan for known include roots (see PathMatcher.findIncludedRoots()
), or null if unknownpublic boolean matches(String path, boolean useKnownIncludes)
path
- a relative file path as described in class JavadocuseKnownIncludes
- true to also match in case this path is a parent of some known included rootpublic Set<File> findIncludedRoots() throws IllegalArgumentException
match
are noted, and their minimal paths are returned.
IllegalArgumentException