Class PathMatcher

java.lang.Object
org.eclipse.jgit.ignore.internal.AbstractMatcher
org.eclipse.jgit.ignore.internal.PathMatcher
All Implemented Interfaces:
IMatcher

public class PathMatcher extends AbstractMatcher
Matcher built by patterns consists of multiple path segments.

This class is immutable and thread safe.

  • Field Details

    • WILD_NO_DIRECTORY

      private static final WildMatcher WILD_NO_DIRECTORY
    • WILD_ONLY_DIRECTORY

      private static final WildMatcher WILD_ONLY_DIRECTORY
    • matchers

      private final List<IMatcher> matchers
    • slash

      private final char slash
    • beginning

      private final boolean beginning
  • Constructor Details

  • Method Details

    • isSimplePathWithSegments

      private boolean isSimplePathWithSegments(String path)
    • createMatchers

      private static List<IMatcher> createMatchers(List<String> segments, Character pathSeparator, boolean dirOnly) throws InvalidPatternException
      Throws:
      InvalidPatternException
    • createPathMatcher

      public static IMatcher createPathMatcher(String pattern, Character pathSeparator, boolean dirOnly) throws InvalidPatternException
      Create path matcher
      Parameters:
      pattern - a pattern
      pathSeparator - if this parameter isn't null then this character will not match at wildcards(* and ? are wildcards).
      dirOnly - a boolean.
      Returns:
      never null
      Throws:
      InvalidPatternException
    • trim

      private static String trim(String pattern)
      Trim trailing spaces, unless they are escaped with backslash, see https://www.kernel.org/pub/software/scm/git/docs/gitignore.html
      Parameters:
      pattern - non null
      Returns:
      trimmed pattern
    • createNameMatcher0

      private static IMatcher createNameMatcher0(String segment, Character pathSeparator, boolean dirOnly, boolean lastSegment) throws InvalidPatternException
      Throws:
      InvalidPatternException
    • matches

      public boolean matches(String path, boolean assumeDirectory, boolean pathMatch)
      Matches entire given string
      Parameters:
      path - string which is not null, but might be empty
      assumeDirectory - true to assume this path as directory (even if it doesn't end with a slash)
      pathMatch - true if the match is for the full path: prefix-only matches are not allowed
      Returns:
      true if this matcher pattern matches given string
    • simpleMatch

      private boolean simpleMatch(String path, boolean assumeDirectory, boolean pathMatch)
    • matches

      public boolean matches(String segment, int startIncl, int endExcl)
      Matches only part of given string
      Parameters:
      segment - string which is not null, but might be empty
      startIncl - start index, inclusive
      endExcl - end index, exclusive
      Returns:
      true if this matcher pattern matches given string
    • iterate

      private boolean iterate(String path, int startIncl, int endExcl, boolean assumeDirectory, boolean pathMatch)
    • matches

      private boolean matches(int matcherIdx, String path, int startIncl, int endExcl, boolean assumeDirectory, boolean pathMatch)
    • isWild

      private static boolean isWild(IMatcher matcher)