Interface PathMatcherFactory
- All Superinterfaces:
Service
- All Known Implementing Classes:
DefaultPathMatcherFactory
PathMatcher objects that can be used to filter files
based on include/exclude patterns. This service provides a clean API for plugins
to create path matchers without directly depending on implementation classes.
The path matchers created by this service support Maven's traditional include/exclude pattern syntax, which is compatible with the behavior of Maven 3 plugins like maven-compiler-plugin and maven-clean-plugin.
Pattern syntax supports:
- Standard glob patterns with
*,?, and**wildcards - Explicit syntax prefixes like
"glob:"or"regex:" - Maven 3 compatible behavior for patterns without explicit syntax
- Default exclusion patterns for SCM files when requested
- Since:
- 4.0.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault PathMatchercreateExcludeOnlyMatcher(Path baseDirectory, Collection<String> excludes, boolean useDefaultExcludes) Creates a path matcher that includes all files except those matching the exclude patterns.default PathMatchercreateIncludeOnlyMatcher(Path baseDirectory, Collection<String> includes) Creates a path matcher that only includes files matching the include patterns.default PathMatchercreatePathMatcher(Path baseDirectory, Collection<String> includes, Collection<String> excludes) Creates a path matcher for filtering files based on include and exclude patterns, without using default exclusion patterns.createPathMatcher(Path baseDirectory, Collection<String> includes, Collection<String> excludes, boolean useDefaultExcludes) Creates a path matcher for filtering files based on include and exclude patterns.deriveDirectoryMatcher(PathMatcher fileMatcher) Returns a filter for directories that may contain paths accepted by the given matcher.Returns the path matcher that unconditionally returnstruefor all files.default booleanisIncludesAll(PathMatcher matcher) Returns whether the given matcher includes all files.
-
Method Details
-
createPathMatcher
@Nonnull PathMatcher createPathMatcher(@Nonnull Path baseDirectory, Collection<String> includes, Collection<String> excludes, boolean useDefaultExcludes) Creates a path matcher for filtering files based on include and exclude patterns.The pathnames used for matching will be relative to the specified base directory and use
'/'as separator, regardless of the hosting operating system.- Parameters:
baseDirectory- the base directory for relativizing paths during matchingincludes- the patterns of files to include, or null/empty for including all filesexcludes- the patterns of files to exclude, or null/empty for no exclusionuseDefaultExcludes- whether to augment excludes with default SCM exclusion patterns- Returns:
- a PathMatcher that can be used to test if paths should be included
- Throws:
NullPointerException- if baseDirectory is null
-
createPathMatcher
@Nonnull default PathMatcher createPathMatcher(@Nonnull Path baseDirectory, Collection<String> includes, Collection<String> excludes) Creates a path matcher for filtering files based on include and exclude patterns, without using default exclusion patterns.This is equivalent to calling
createPathMatcher(Path, Collection, Collection, boolean)withuseDefaultExcludes = false.- Parameters:
baseDirectory- the base directory for relativizing paths during matchingincludes- the patterns of files to include, or null/empty for including all filesexcludes- the patterns of files to exclude, or null/empty for no exclusion- Returns:
- a PathMatcher that can be used to test if paths should be included
- Throws:
NullPointerException- if baseDirectory is null
-
createExcludeOnlyMatcher
@Nonnull default PathMatcher createExcludeOnlyMatcher(@Nonnull Path baseDirectory, Collection<String> excludes, boolean useDefaultExcludes) Creates a path matcher that includes all files except those matching the exclude patterns.This is equivalent to calling
createPathMatcher(Path, Collection, Collection, boolean)withincludes = null.- Parameters:
baseDirectory- the base directory for relativizing paths during matchingexcludes- the patterns of files to exclude, or null/empty for no exclusionuseDefaultExcludes- whether to augment excludes with default SCM exclusion patterns- Returns:
- a PathMatcher that can be used to test if paths should be included
- Throws:
NullPointerException- if baseDirectory is null
-
createIncludeOnlyMatcher
@Nonnull default PathMatcher createIncludeOnlyMatcher(@Nonnull Path baseDirectory, Collection<String> includes) Creates a path matcher that only includes files matching the include patterns.This is equivalent to calling
createPathMatcher(Path, Collection, Collection, boolean)withexcludes = nullanduseDefaultExcludes = false.- Parameters:
baseDirectory- the base directory for relativizing paths during matchingincludes- the patterns of files to include, or null/empty for including all files- Returns:
- a PathMatcher that can be used to test if paths should be included
- Throws:
NullPointerException- if baseDirectory is null
-
deriveDirectoryMatcher
Returns a filter for directories that may contain paths accepted by the given matcher. The given path matcher should be an instance created by this service. The path matcher returned by this method expects directory paths. If that matcher returnsfalse, then the directory will definitively not contain the paths selected by the matcher given in argument to this method. In such case, the whole directory and all its sub-directories can be skipped. In case of doubt, or if the matcher given in argument is not recognized by this method, then the matcher returned by this method will returntrue.- Parameters:
fileMatcher- a matcher created by one of the other methods of this interface- Returns:
- filter for directories that may contain the selected files
- Throws:
NullPointerException- if fileMatcher is null
-
includesAll
Returns the path matcher that unconditionally returnstruefor all files. It should be the matcher returned by the other methods of this interface when the given patterns match all files.- Returns:
- path matcher that unconditionally returns
truefor all files
-
isIncludesAll
Returns whether the given matcher includes all files.. This method may conservatively returnsfalseif case of doubt. A return value oftruemeans that the pattern is certain to match all files.- Parameters:
matcher- the matcher to test- Returns:
- whether the given matcher includes all files
-