Skip to content

The Unified and Autonomous Development Platform

midwork

robin shinec5484e7fe65f
diff --git a/commons.util/src/main/java/com/pmease/commons/util/match/ExclusiveAwarePattern.java b/commons.util/src/main/java/com/pmease/commons/util/match/ExclusiveAwarePattern.java
deleted file mode 100644
index 7b85ffe5ea..0000000000
--- a/commons.util/src/main/java/com/pmease/commons/util/match/ExclusiveAwarePattern.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package com.pmease.commons.util.match;
-
-public class ExclusiveAwarePattern {
-
- private final String pattern;
-
- private final boolean exclusive;
-
- public ExclusiveAwarePattern(String pattern, boolean exclusive) {
- this.pattern = pattern;
- this.exclusive = exclusive;
- }
-
- public String getPattern() {
- return pattern;
- }
-
- public boolean isExclusive() {
- return exclusive;
- }
-
- @Override
- public String toString() {
- if (exclusive)
- return "-" + pattern;
- else
- return pattern;
- }
-
- public static ExclusiveAwarePattern fromString(String str) {
- str = str.trim();
-
- boolean exclusive = false;
- if (str.startsWith("+"))
- str = str.substring(1).trim();
- if (str.startsWith("-")) {
- str = str.substring(1).trim();
- exclusive = true;
- }
-
- return new ExclusiveAwarePattern(str, exclusive);
- }
-
-}
\ No newline at end of file
diff --git a/commons.util/src/main/java/com/pmease/commons/util/match/IncludeExclude.java b/commons.util/src/main/java/com/pmease/commons/util/match/IncludeExclude.java
index 67cabd7c8a..68b2626204 100644
--- a/commons.util/src/main/java/com/pmease/commons/util/match/IncludeExclude.java
+++ b/commons.util/src/main/java/com/pmease/commons/util/match/IncludeExclude.java
@@ -13,7 +13,7 @@ public class IncludeExclude<T, V> {
this.excludes = excludes;
}
- public boolean matches(RuleMatcher<T, V> matcher, V value) {
+ public boolean matches(Matcher<T, V> matcher, V value) {
for (T exclude: excludes) {
if (matcher.matches(exclude, value))
return false;
diff --git a/commons.util/src/main/java/com/pmease/commons/util/match/Matcher.java b/commons.util/src/main/java/com/pmease/commons/util/match/Matcher.java
new file mode 100644
index 0000000000..a254ff2a24
--- /dev/null
+++ b/commons.util/src/main/java/com/pmease/commons/util/match/Matcher.java
@@ -0,0 +1,5 @@
+package com.pmease.commons.util.match;
+
+public interface Matcher<R, V> {
+ boolean matches(R rule, V value);
+}
diff --git a/commons.util/src/main/java/com/pmease/commons/util/match/PatternMatcher.java b/commons.util/src/main/java/com/pmease/commons/util/match/PatternMatcher.java
index fd24831bd6..2ed03909aa 100644
--- a/commons.util/src/main/java/com/pmease/commons/util/match/PatternMatcher.java
+++ b/commons.util/src/main/java/com/pmease/commons/util/match/PatternMatcher.java
@@ -1,4 +1,4 @@
package com.pmease.commons.util.match;
-public interface PatternMatcher extends RuleMatcher<String, String> {
+public interface PatternMatcher extends Matcher<String, String> {
}
diff --git a/commons.util/src/main/java/com/pmease/commons/util/match/PatternSet.java b/commons.util/src/main/java/com/pmease/commons/util/match/PatternSet.java
deleted file mode 100644
index 2a0b61d649..0000000000
--- a/commons.util/src/main/java/com/pmease/commons/util/match/PatternSet.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package com.pmease.commons.util.match;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import com.pmease.commons.util.StringUtils;
-
-public class PatternSet {
-
- private final List<ExclusiveAwarePattern> patterns;
-
- public PatternSet(List<ExclusiveAwarePattern> patterns) {
- this.patterns = patterns;
- }
-
- public List<ExclusiveAwarePattern> getPatterns() {
- return patterns;
- }
-
- @Override
- public String toString() {
- List<String> list = new ArrayList<String>();
- for (ExclusiveAwarePattern each: getPatterns())
- list.add(each.toString());
- return StringUtils.join(list, ", ").trim();
- }
-
- public static PatternSet fromString(String str) {
- List<ExclusiveAwarePattern> patterns = new ArrayList<ExclusiveAwarePattern>();
- for (String pattern: StringUtils.splitAndTrim(str)) {
- patterns.add(ExclusiveAwarePattern.fromString(pattern));
- }
- return new PatternSet(patterns);
- }
-
-}
diff --git a/commons.util/src/main/java/com/pmease/commons/util/match/PatternSetMatcher.java b/commons.util/src/main/java/com/pmease/commons/util/match/PatternSetMatcher.java
deleted file mode 100644
index 3b29333e51..0000000000
--- a/commons.util/src/main/java/com/pmease/commons/util/match/PatternSetMatcher.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package com.pmease.commons.util.match;
-
-public class PatternSetMatcher implements PatternMatcher {
-
- private final PatternMatcher patternMatcher;
-
- public PatternSetMatcher(PatternMatcher patternMatcher) {
- this.patternMatcher = patternMatcher;
- }
-
- @Override
- public boolean matches(String patterns, String input) {
- boolean lastExclusive = false;
- for (ExclusiveAwarePattern each: PatternSet.fromString(patterns).getPatterns()) {
- if (each.isExclusive()) {
- lastExclusive = true;
- if (patternMatcher.matches(each.getPattern(), input))
- return false;
- } else {
- lastExclusive = false;
- if (patternMatcher.matches(each.getPattern(), input))
- return true;
- }
- }
- return lastExclusive;
- }
-
-}
diff --git a/commons.util/src/main/java/com/pmease/commons/util/match/RuleMatcher.java b/commons.util/src/main/java/com/pmease/commons/util/match/RuleMatcher.java
deleted file mode 100644
index 556d506d46..0000000000
--- a/commons.util/src/main/java/com/pmease/commons/util/match/RuleMatcher.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package com.pmease.commons.util.match;
-
-public interface RuleMatcher<T, V> {
- boolean matches(T rule, V value);
-}
diff --git a/commons.util/src/main/java/com/pmease/commons/util/match/WildcardUtils.java b/commons.util/src/main/java/com/pmease/commons/util/match/WildcardUtils.java
index ce744d71bc..db8d264081 100644
--- a/commons.util/src/main/java/com/pmease/commons/util/match/WildcardUtils.java
+++ b/commons.util/src/main/java/com/pmease/commons/util/match/WildcardUtils.java
@@ -9,70 +9,32 @@ import com.pmease.commons.util.Range;
public class WildcardUtils {
- private static final PatternSetMatcher stringPatternSetMatcher = new PatternSetMatcher(new WildcardStringMatcher());
+ private static final PatternMatcher pathMatcher = new WildcardPathMatcher();
+
+ private static final PatternMatcher stringMatcher = new WildcardStringMatcher();
- private static final PatternSetMatcher pathPatternSetMatcher = new PatternSetMatcher(new WildcardPathMatcher());
-
/**
- * Tests whether or not a given path matches a given patterns.
- * <p>
- * Patterns are separated by comma or line separator, with each pattern using syntax
- * of <a href="http://ant.apache.org/manual/dirtasks.html">Ant path pattern</a>.
- * <p>
- * If a pattern is prefixed with <code>-</code>, it is considered as a negative pattern;
- * if a pattern is prefixed with <code>+</code>, or is not prefixed with both signs,
- * it is considered as positive pattern.
- * <p>
- * When determine if a string matches the patterns, the string will be matched against
- * each pattern in order, until finding a matching negative or positive pattern. If a
- * negative pattern is matched first, the string is considered not matched for the whole
- * patterns, and if a positive pattern is matched first, the string is considered matched
- * for the whole patterns. If no any pattern is matched, the string is considered not
- * matched for the whole patterns.
- * <p>
- * Some examples:
- * <ul>
- * <li>assert(match("-&#42;&#42;/&#42;.java, &#42;&#42;", "Test.java") == false);
- * <li>assert(match("-&#42;&#42;/&#42;.java, &#42;&#42;", "test.c") == true);
- * </ul>
- *
- * @param patterns
- * the patterns to match against. Must not be null
+ * Tests whether or not a given path matches a given pattern using of
+ * <a href="http://ant.apache.org/manual/dirtasks.html">Ant path pattern</a>.
+ *
+ * @param pattern
+ * the pattern to match against. Must not be null
* @param str
* the path to match, as a String. Must not be null
*
* @return
- * true if the patterns matches against the string, or false otherwise
+ * true if the pattern matches the string, or false otherwise
*
*/
- public static boolean matchPath(String patterns, String path) {
- return pathPatternSetMatcher.matches(patterns, path);
+ public static boolean matchPath(String pattern, String path) {
+ return pathMatcher.matches(pattern, path);
}
/**
- * Tests whether or not a string matches against specified patterns.
- * <p>
- * Patterns are separated with comma or line separator, with each pattern may contain
+ * Tests whether or not a string matches specified pattern, which may contain
* two special characters:<br>
* '*' means zero or more characters<br>
* '?' means one and only one character
- * <p>
- * If a pattern is prefixed with <code>-</code>, it is considered as a negative pattern;
- * if a pattern is prefixed with <code>+</code>, or is not prefixed with both signs,
- * it is considered as positive pattern.
- * <p>
- * When determine if a string matches the patterns, the string will be matched against
- * each pattern in order, until finding a matching negative or positive pattern. If a
- * negative pattern is matched first, the string is considered not matched for the whole
- * patterns, and if a positive pattern is matched first, the string is considered matched
- * for the whole patterns. If no any pattern is matched, the string is considered not
- * matched for the whole patterns.
- * <p>
- * Some examples:
- * <ul>
- * <li>assert(wildcardMatch("-Core.java, &#42;.java", "Core.java") == false);
- * <li>assert(wildcardMatch("-Core.java, &#42;.java", "Client.java") == true);
- * </ul>
*
* @param pattern
* the pattern to match against. Must not be null.
@@ -81,8 +43,8 @@ public class WildcardUtils {
* @return
* true if the string matches against the pattern, or false otherwise.
*/
- public static boolean matchString(String patterns, String str) {
- return stringPatternSetMatcher.matches(patterns, str);
+ public static boolean matchString(String pattern, String str) {
+ return stringMatcher.matches(pattern, str);
}
public static boolean hasWildcards(String input) {
diff --git a/commons.util/src/test/java/com/pmease/commons/util/pattern/WildcardUtilsTest.java b/commons.util/src/test/java/com/pmease/commons/util/pattern/WildcardUtilsTest.java
index 71570b898b..9ea2de84cd 100644
--- a/commons.util/src/test/java/com/pmease/commons/util/pattern/WildcardUtilsTest.java
+++ b/commons.util/src/test/java/com/pmease/commons/util/pattern/WildcardUtilsTest.java
@@ -9,7 +9,6 @@ public class WildcardUtilsTest {
@Test
public void shouldMatchPath() {
- assertTrue(matchPath("-*.java", "file.c"));
assertTrue(matchPath("**//*.java", "com/example/Test.java"));
assertFalse(matchPath("**/*.java", "com/example/test.c"));
assertFalse(matchPath("com/*.java", "com/example/Test.java"));
@@ -18,14 +17,6 @@ public class WildcardUtilsTest {
assertTrue(matchPath("src///**/*.java", "src/com/example/Test.java"));
assertFalse(matchPath("/src/**/*.java", "src/com/example/Test.java"));
assertFalse(matchPath("src/**////*.java", "resource/com/example/Test.java"));
-
- assertTrue(matchPath("-**/*.java, **", "test/hello.c"));
- assertFalse(matchPath("-**/*.java, **", "test/hello.java"));
- assertFalse(matchPath("-**/*.java, **/*.java, **/*.c", "test/hello.txt"));
- assertFalse(matchPath("-**/*.java, **/*.java, **/*.c", "test/hello.java"));
- assertTrue(matchPath("+**/*.java, -**/*.java, **/*.c", "test/hello.java"));
- assertTrue(matchPath("-**/generated/**, **/*.xml", "test/test.xml"));
- assertFalse(matchPath("-**/generated/**, **/*.xml", "generated/test.xml"));
}
@Test
@@ -40,14 +31,6 @@ public class WildcardUtilsTest {
assertTrue(matchString("com/*.java", "com/Test.java"));
assertTrue(matchString("src/**/*.java", "src/com/example/Test.java"));
assertFalse(matchString("src/**/*.java", "resource/com/example/Test.java"));
-
- assertTrue(matchString("-*.java", "hello.c"));
- assertFalse(matchString("-*.java", "hello.java"));
- assertTrue(matchString("-*.java, *", "hello.c"));
- assertFalse(matchString("-*.java, *", "hello.java"));
- assertFalse(matchString("-*.java, *.java, *.c", "hello.txt"));
- assertFalse(matchString("-*.java, *.java, *.c", "hello.java"));
- assertTrue(matchString("+*.java, -*.java, *.c", "hello.java"));
}
@Test
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/util/fullbranchmatch/FullBranchMatchUtils.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/fullbranchmatch/FullBranchMatchUtils.java
index 813aecceee..8d71d3a878 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/util/fullbranchmatch/FullBranchMatchUtils.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/fullbranchmatch/FullBranchMatchUtils.java
@@ -3,7 +3,6 @@ package com.pmease.gitplex.core.util.fullbranchmatch;
import java.util.ArrayList;
import java.util.List;
-import javax.annotation.Nullable;
import javax.validation.ValidationException;
import org.antlr.v4.runtime.ANTLRInputStream;
@@ -12,7 +11,7 @@ import org.antlr.v4.runtime.CommonTokenStream;
import org.apache.commons.lang3.StringUtils;
import com.pmease.commons.util.match.IncludeExclude;
-import com.pmease.commons.util.match.RuleMatcher;
+import com.pmease.commons.util.match.Matcher;
import com.pmease.commons.util.match.WildcardUtils;
import com.pmease.gitplex.core.entity.Depot;
import com.pmease.gitplex.core.entity.component.DepotAndBranch;
@@ -45,7 +44,7 @@ public class FullBranchMatchUtils {
}
}
- RuleMatcher<FullBranchMatchContext, DepotAndBranch> matcher = new RuleMatcher<FullBranchMatchContext, DepotAndBranch>() {
+ Matcher<FullBranchMatchContext, DepotAndBranch> matcher = new Matcher<FullBranchMatchContext, DepotAndBranch>() {
@Override
public boolean matches(FullBranchMatchContext rule, DepotAndBranch value) {
@@ -86,9 +85,4 @@ public class FullBranchMatchUtils {
}
}
- @Nullable
- public static String deleteDepot(String match, Depot depot) {
- return null;
- }
-
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/util/includeexclude/IncludeExcludeUtils.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/includeexclude/IncludeExcludeUtils.java
index 790beaee70..d48f3c52c8 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/util/includeexclude/IncludeExcludeUtils.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/includeexclude/IncludeExcludeUtils.java
@@ -10,6 +10,8 @@ import org.antlr.v4.runtime.tree.TerminalNode;
import com.pmease.commons.util.match.IncludeExclude;
import com.pmease.commons.util.match.WildcardStringMatcher;
+import com.pmease.gitplex.core.util.includeexclude.IncludeExcludeLexer;
+import com.pmease.gitplex.core.util.includeexclude.IncludeExcludeParser;
import com.pmease.gitplex.core.util.includeexclude.IncludeExcludeParser.CriteriaContext;
import com.pmease.gitplex.core.util.includeexclude.IncludeExcludeParser.MatchContext;