diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/attributes/AttributesRule.java b/org.eclipse.jgit/src/org/eclipse/jgit/attributes/AttributesRule.java index 53812442b..2f9929591 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/attributes/AttributesRule.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/attributes/AttributesRule.java @@ -9,7 +9,7 @@ */ package org.eclipse.jgit.attributes; -import static org.eclipse.jgit.ignore.internal.IMatcher.NO_MATCH; +import static org.eclipse.jgit.ignore.IMatcher.NO_MATCH; import java.util.ArrayList; import java.util.Collections; @@ -18,7 +18,7 @@ import org.eclipse.jgit.attributes.Attribute.State; import org.eclipse.jgit.errors.InvalidPatternException; import org.eclipse.jgit.ignore.FastIgnoreRule; -import org.eclipse.jgit.ignore.internal.IMatcher; +import org.eclipse.jgit.ignore.IMatcher; import org.eclipse.jgit.ignore.internal.PathMatcher; /** diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/ignore/FastIgnoreRule.java b/org.eclipse.jgit/src/org/eclipse/jgit/ignore/FastIgnoreRule.java index a1866c85a..26bbd41b7 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/ignore/FastIgnoreRule.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/ignore/FastIgnoreRule.java @@ -9,13 +9,12 @@ */ package org.eclipse.jgit.ignore; -import static org.eclipse.jgit.ignore.internal.IMatcher.NO_MATCH; +import static org.eclipse.jgit.ignore.IMatcher.NO_MATCH; import static org.eclipse.jgit.ignore.internal.Strings.isDirectoryPattern; import static org.eclipse.jgit.ignore.internal.Strings.stripTrailing; import static org.eclipse.jgit.ignore.internal.Strings.stripTrailingWhitespace; import org.eclipse.jgit.errors.InvalidPatternException; -import org.eclipse.jgit.ignore.internal.IMatcher; import org.eclipse.jgit.ignore.internal.PathMatcher; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/ignore/internal/IMatcher.java b/org.eclipse.jgit/src/org/eclipse/jgit/ignore/IMatcher.java similarity index 60% rename from org.eclipse.jgit/src/org/eclipse/jgit/ignore/internal/IMatcher.java rename to org.eclipse.jgit/src/org/eclipse/jgit/ignore/IMatcher.java index d93cc9a8a..3cbb069ff 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/ignore/internal/IMatcher.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/ignore/IMatcher.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014, 2017 Andrey Loskutov and others + * Copyright (C) 2014, 2020 Andrey Loskutov and others * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0 which is available at @@ -7,10 +7,16 @@ * * SPDX-License-Identifier: BSD-3-Clause */ -package org.eclipse.jgit.ignore.internal; +package org.eclipse.jgit.ignore; + +import org.eclipse.jgit.annotations.NonNull; +import org.eclipse.jgit.errors.InvalidPatternException; +import org.eclipse.jgit.ignore.internal.PathMatcher; /** - * Generic string matcher + * Generic path matcher. + * + * @since 5.7 */ public interface IMatcher { @@ -18,6 +24,7 @@ public interface IMatcher { * Matcher that does not match any pattern. */ public static final IMatcher NO_MATCH = new IMatcher() { + @Override public boolean matches(String path, boolean assumeDirectory, boolean pathMatch) { @@ -30,6 +37,25 @@ public boolean matches(String segment, int startIncl, int endExcl) { } }; + /** + * Creates a path matcher for the given pattern. A pattern may contain the + * wildcards "?", "*", and "**". The directory separator is '/'. + * + * @param pattern + * to match + * @param dirOnly + * whether to match only directories + * @return a matcher for the given pattern + * @throws InvalidPatternException + * if the pattern is invalid + */ + @NonNull + public static IMatcher createPathMatcher(@NonNull String pattern, + boolean dirOnly) throws InvalidPatternException { + return PathMatcher.createPathMatcher(pattern, + Character.valueOf(FastIgnoreRule.PATH_SEPARATOR), dirOnly); + } + /** * Matches entire given string * @@ -40,10 +66,7 @@ public boolean matches(String segment, int startIncl, int endExcl) { * with a slash) * @param pathMatch * {@code true} if the match is for the full path: prefix-only - * matches are not allowed, and - * {@link org.eclipse.jgit.ignore.internal.NameMatcher}s must - * match only the last component (if they can -- they may not, if - * they are anchored at the beginning) + * matches are not allowed * @return true if this matcher pattern matches given string */ boolean matches(String path, boolean assumeDirectory, boolean pathMatch); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/ignore/internal/AbstractMatcher.java b/org.eclipse.jgit/src/org/eclipse/jgit/ignore/internal/AbstractMatcher.java index a77061f50..0737ed887 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/ignore/internal/AbstractMatcher.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/ignore/internal/AbstractMatcher.java @@ -9,6 +9,8 @@ */ package org.eclipse.jgit.ignore.internal; +import org.eclipse.jgit.ignore.IMatcher; + /** * Base class for default methods as {@link #toString()} and such. *

diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/ignore/internal/PathMatcher.java b/org.eclipse.jgit/src/org/eclipse/jgit/ignore/internal/PathMatcher.java index 8226a5247..ba77b3dd8 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/ignore/internal/PathMatcher.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/ignore/internal/PathMatcher.java @@ -19,6 +19,7 @@ import java.util.List; import org.eclipse.jgit.errors.InvalidPatternException; +import org.eclipse.jgit.ignore.IMatcher; import org.eclipse.jgit.ignore.internal.Strings.PatternState; /**