Class PathSelector

java.lang.Object
org.apache.maven.impl.PathSelector
All Implemented Interfaces:
PathMatcher

public class PathSelector extends Object implements PathMatcher
Determines whether a path is selected according to include/exclude patterns. The pathnames used for method parameters will be relative to some base directory and use '/' as separator, regardless of the hosting operating system.

Syntax

If a pattern contains the ':' character and the prefix before is longer than 1 character, then that pattern is given verbatim to FileSystem.getPathMatcher(String), which interprets the part before ':' as the syntax (usually "glob" or "regex"). If a pattern does not contain the ':' character, or if the prefix is one character long (interpreted as a Windows drive), then the syntax defaults to a reproduction of the Maven 3 behavior. This is implemented as the "glob" syntax with the following modifications:
  • The platform-specific separator ('\\' on Windows) is replaced by '/'. Note that it means that the backslash cannot be used for escaping characters.
  • Trailing "/" is completed as "/**".
  • The "**" wildcard means "0 or more directories" instead of "1 or more directories". This is implemented by adding variants of the pattern without the "**" wildcard.
  • Bracket characters [ ] and { } are escaped.
  • On Unix only, the escape character '\\' is itself escaped.
If above changes are not desired, put an explicit "glob:" prefix before the pattern. Note that putting such a prefix is recommended anyway for better performances.
Author:
Benjamin Bentmann, Martin Desruisseaux
See Also:
  • Constructor Details

    • PathSelector

      public PathSelector(Path directory, Collection<String> includes, Collection<String> excludes, boolean useDefaultExcludes)
      Creates a new selector from the given includes and excludes.
      Parameters:
      directory - the base directory of the files to filter
      includes - the patterns of the files to include, or null or empty for including all files
      excludes - the patterns of the files to exclude, or null or empty for no exclusion
      useDefaultExcludes - whether to augment the excludes with a default set of SCM patterns
  • Method Details

    • simplify

      public PathMatcher simplify()
      Returns a potentially simpler matcher equivalent to this matcher..
      Returns:
      a potentially simpler matcher equivalent to this matcher
    • matches

      public boolean matches(Path path)
      Determines whether a path is selected. This is true if the given file matches an include pattern and no exclude pattern.
      Specified by:
      matches in interface PathMatcher
      Parameters:
      path - the pathname to test, must not be null
      Returns:
      true if the given path is selected, false otherwise
    • couldHoldSelected

      public boolean couldHoldSelected(Path directory)
      Determines whether a directory could contain selected paths.
      Parameters:
      directory - the directory pathname to test, must not be null
      Returns:
      true if the given directory might contain selected paths, false if the directory will definitively not contain selected paths
    • toString

      public String toString()
      Returns a string representation for logging purposes..
      Overrides:
      toString in class Object
      Returns:
      a string representation for logging purposes