The Unified and Autonomous Development Platform
midwork
robin shinee0f0d28db44b
diff --git a/commons.antlr/src/main/java/com/pmease/commons/antlr/codeassist/SurroundingAware.java b/commons.antlr/src/main/java/com/pmease/commons/antlr/codeassist/SurroundingAware.javaindex 8cbdd476b0..70d38394b8 100644--- a/commons.antlr/src/main/java/com/pmease/commons/antlr/codeassist/SurroundingAware.java+++ b/commons.antlr/src/main/java/com/pmease/commons/antlr/codeassist/SurroundingAware.java@@ -66,17 +66,19 @@ public abstract class SurroundingAware {matchWithIncluded = true;}- /*- * if matchWith does not appear in suggestion list, we check to see if it should be surrounded.- * For instance, you may have a rule requiring that value containing spaces should be quoted,- * in this case, below code will suggest you to quote the value if it contains spaces as- * otherwise it will fail the match below- */- if (!matchWithIncluded && !matches(spec, matchWith)) {- matchWith = prefix + matchWith + suffix;- if (matches(spec, matchWith)) {- Highlight highlight = new Highlight(1, matchWith.length()-1);- checkedSuggestions.add(new InputSuggestion(matchWith, getSurroundingDescription(), highlight));+ if (checkedSuggestions.isEmpty()) {+ /*+ * if matchWith does not appear in suggestion list, we check to see if it should be surrounded.+ * For instance, you may have a rule requiring that value containing spaces should be quoted,+ * in this case, below code will suggest you to quote the value if it contains spaces as+ * otherwise it will fail the match below+ */+ if (!matchWithIncluded && !matches(spec, matchWith)) {+ matchWith = prefix + matchWith + suffix;+ if (matches(spec, matchWith)) {+ Highlight highlight = new Highlight(1, matchWith.length()-1);+ checkedSuggestions.add(new InputSuggestion(matchWith, getSurroundingDescription(), highlight));+ }}}return checkedSuggestions;diff --git a/commons.git/src/main/java/com/pmease/commons/git/command/LogCommand.java b/commons.git/src/main/java/com/pmease/commons/git/command/LogCommand.javaindex 7618013ada..cb754f6a8a 100644--- a/commons.git/src/main/java/com/pmease/commons/git/command/LogCommand.java+++ b/commons.git/src/main/java/com/pmease/commons/git/command/LogCommand.java@@ -35,6 +35,8 @@ public class LogCommand extends GitCommand<List<Commit>> {private boolean parentRewriting;+ private boolean ignoreCase;+private boolean listChangedFiles;private List<String> messages = new ArrayList<>();@@ -116,6 +118,15 @@ public class LogCommand extends GitCommand<List<Commit>> {return this;}+ public boolean ignoreCase() {+ return ignoreCase;+ }++ public LogCommand ignoreCase(boolean ignoreCase) {+ this.ignoreCase = ignoreCase;+ return this;+ }+public List<String> messages() {return messages;}@@ -194,6 +205,9 @@ public class LogCommand extends GitCommand<List<Commit>> {if (listChangedFiles)cmd.addArgs("--name-only");+ if (ignoreCase)+ cmd.addArgs("-i");+cmd.addArgs("--");for (String path: paths)diff --git a/commons.util/src/main/java/com/pmease/commons/util/pattern/LiteralRange.java b/commons.util/src/main/java/com/pmease/commons/util/pattern/LiteralRange.javanew file mode 100644index 0000000000..779be25bde--- /dev/null+++ b/commons.util/src/main/java/com/pmease/commons/util/pattern/LiteralRange.java@@ -0,0 +1,31 @@+package com.pmease.commons.util.pattern;++import java.io.Serializable;++public class LiteralRange implements Serializable {++ private static final long serialVersionUID = 1L;++ private final int from;++ private final int to;++ public LiteralRange(int from, int to) {+ this.from = from;+ this.to = to;+ }++ public int getFrom() {+ return from;+ }++ public int getTo() {+ return to;+ }++ @Override+ public String toString() {+ return from + "-" + to;+ }++}diff --git a/commons.util/src/main/java/com/pmease/commons/util/pattern/WildcardUtils.java b/commons.util/src/main/java/com/pmease/commons/util/pattern/WildcardUtils.javaindex 7e013cceed..912dd6d3ff 100644--- a/commons.util/src/main/java/com/pmease/commons/util/pattern/WildcardUtils.java+++ b/commons.util/src/main/java/com/pmease/commons/util/pattern/WildcardUtils.java@@ -1,5 +1,10 @@package com.pmease.commons.util.pattern;+import java.util.ArrayList;+import java.util.List;++import javax.annotation.Nullable;+public class WildcardUtils {private static final PatternMatcher stringPatternSetMatcher = new PatternSetMatcher(new WildcardStringMatcher());@@ -42,7 +47,6 @@ public class WildcardUtils {return pathPatternSetMatcher.matches(patterns, path);}-/*** Tests whether or not a string matches against specified patterns.* <p>@@ -83,4 +87,57 @@ public class WildcardUtils {return (input.indexOf('*') != -1 || input.indexOf('?') != -1);}+ @Nullable+ public static String applyWildcard(String text, String wildcard, boolean caseSensitive) {+ String normalizedText;+ String normalizedWildcard;+ if (caseSensitive) {+ normalizedText = text;+ normalizedWildcard = wildcard;+ } else {+ normalizedText = text.toLowerCase();+ normalizedWildcard = wildcard.toLowerCase();+ }+ List<LiteralRange> literalRanges = new ArrayList<>();+ int pos = 0;+ int index = normalizedWildcard.indexOf('*');+ while (index != -1) {+ if (index>pos)+ literalRanges.add(new LiteralRange(pos, index));+ pos = index+1;+ index = normalizedWildcard.indexOf('*', pos);+ }+ if (normalizedWildcard.length()>pos)+ literalRanges.add(new LiteralRange(pos, normalizedWildcard.length()));++ String applied = wildcard;+ int first = -1;+ int last = 0;+ pos = 0;+ for (LiteralRange literalRange: literalRanges) {+ String literal = wildcard.substring(literalRange.getFrom(), literalRange.getTo());+ index = normalizedText.indexOf(literal, pos);+ if (index != -1) {+ if (first == -1)+ first = index;+ pos = index+literal.length();+ last = pos;+ applied = replaceLiteral(applied, literalRange, text.substring(index, pos));+ } else {+ return null;+ }+ }+ if (first != -1 && wildcard.charAt(0) != '*')+ applied = text.substring(0, first) + applied;+ if (wildcard.length() == 0 || wildcard.charAt(wildcard.length()-1) != '*')+ applied = applied + text.substring(last);+ return applied;+ }++ private static String replaceLiteral(String text, LiteralRange literalRange, String literal) {+ String prefix = text.substring(0, literalRange.getFrom());+ String suffix = text.substring(literalRange.getTo());+ return prefix + literal + suffix;+ }+}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.javaindex 114b9e7619..d4fde27557 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@@ -50,4 +50,13 @@ public class WildcardUtilsTest {assertTrue(matchString("+*.java, -*.java, *.c", "hello.java"));}+ @Test+ public void shouldApplyWildcard() {+ assertEquals("he*llo", applyWildcard("hello", "e*l", false));+ assertEquals(null, applyWildcard("hello world", "*he ld", false));+ assertEquals("*he*ld 2", applyWildcard("hello world 2", "*he*ld", false));+ assertEquals("hello", applyWildcard("hello", "", false));+ assertEquals("*", applyWildcard("hello", "*", false));+ assertEquals("**", applyWildcard("hello", "**", false));+ }}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/commit/QueryAssistBehavior.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/commit/QueryAssistBehavior.javaindex 55745fd253..87f0899d19 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/commit/QueryAssistBehavior.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/commit/QueryAssistBehavior.java@@ -1,11 +1,11 @@package com.pmease.gitplex.web.page.repository.commit;import java.util.ArrayList;+import java.util.Collections;+import java.util.Comparator;import java.util.LinkedHashSet;import java.util.List;import java.util.Set;-import java.util.regex.Matcher;-import java.util.regex.Pattern;import org.apache.wicket.Component;import org.apache.wicket.model.IModel;@@ -17,6 +17,7 @@ import com.pmease.commons.antlr.codeassist.SurroundingAware;import com.pmease.commons.antlr.grammar.LexerRuleRefElementSpec;import com.pmease.commons.git.NameAndEmail;import com.pmease.commons.util.StringUtils;+import com.pmease.commons.util.pattern.WildcardUtils;import com.pmease.commons.wicket.behavior.inputassist.ANTLRAssistBehavior;import com.pmease.gitplex.core.GitPlex;import com.pmease.gitplex.core.manager.AuxiliaryManager;@@ -53,43 +54,50 @@ public class QueryAssistBehavior extends ANTLRAssistBehavior {@Overrideprotected List<InputSuggestion> match(String matchWith) {- String lowerCaseMatchWith = matchWith.toLowerCase();+ matchWith = matchWith.toLowerCase();int numSuggestions = 0;List<InputSuggestion> suggestions = new ArrayList<>();int tokenType = element.getRoot().getLastMatchedToken().getType();if (tokenType == CommitQueryParser.BRANCH) {for (String value: repoModel.getObject().getBranches()) {- int index = value.toLowerCase().indexOf(lowerCaseMatchWith);+ int index = value.toLowerCase().indexOf(matchWith);if (index != -1 && numSuggestions++<count) {- Highlight highlight = new Highlight(index, index+lowerCaseMatchWith.length());+ Highlight highlight = new Highlight(index, index+matchWith.length());suggestions.add(new InputSuggestion(value, highlight));}}} else if (tokenType == CommitQueryParser.TAG) {for (String value: repoModel.getObject().getTags()) {- int index = value.toLowerCase().indexOf(lowerCaseMatchWith);+ int index = value.toLowerCase().indexOf(matchWith);if (index != -1 && numSuggestions++<count) {- Highlight highlight = new Highlight(index, index+lowerCaseMatchWith.length());+ Highlight highlight = new Highlight(index, index+matchWith.length());suggestions.add(new InputSuggestion(value, highlight));}}} else if (tokenType == CommitQueryParser.AUTHOR|| tokenType == CommitQueryParser.COMMITTER) {+ Set<String> suggestedInputs = new LinkedHashSet<>();AuxiliaryManager auxiliaryManager = GitPlex.getInstance(AuxiliaryManager.class);List<NameAndEmail> contributors = auxiliaryManager.getContributors(repoModel.getObject());for (NameAndEmail contributor: contributors) {- if ((contributor.getName().toLowerCase().contains(lowerCaseMatchWith) || contributor.getEmailAddress().toLowerCase().contains(lowerCaseMatchWith))- && numSuggestions++<count) {- String content;- if (StringUtils.isNotBlank(contributor.getEmailAddress()))- content = contributor.getName() + " <" + contributor.getEmailAddress() + ">";- else- content = contributor.getName();- int index = content.toLowerCase().indexOf(lowerCaseMatchWith);- Highlight highlight = new Highlight(index, index+lowerCaseMatchWith.length());- suggestions.add(new InputSuggestion(content.trim(), highlight));+ String content;+ if (StringUtils.isNotBlank(contributor.getEmailAddress()))+ content = contributor.getName() + " <" + contributor.getEmailAddress() + ">";+ else+ content = contributor.getName();+ String wildcarded = WildcardUtils.applyWildcard(content, matchWith, false);+ if (wildcarded != null) {+ suggestedInputs.add(wildcarded);+ if (suggestedInputs.size() == count)+ break;}}++ for (String suggestedInput: suggestedInputs) {+ int index = suggestedInput.toLowerCase().indexOf(matchWith.toLowerCase());+ Highlight highlight = new Highlight(index, index+matchWith.length());+ suggestions.add(new InputSuggestion(suggestedInput, -1, true, null, highlight));+ }} else if (tokenType == CommitQueryParser.BEFORE|| tokenType == CommitQueryParser.AFTER) {if (!matchWith.endsWith(")")) {@@ -99,32 +107,40 @@ public class QueryAssistBehavior extends ANTLRAssistBehavior {suggestions.add(new InputSuggestion(dateExample));}} else if (tokenType == CommitQueryParser.PATH) {- Set<String> suggestedInputs = new LinkedHashSet<>();+ Set<String> suggestedInputSet = new LinkedHashSet<>();++ System.out.println("===============================");+ long time = System.currentTimeMillis();AuxiliaryManager auxiliaryManager = GitPlex.getInstance(AuxiliaryManager.class);- lowerCaseMatchWith = StringUtils.replace(lowerCaseMatchWith, "(", "\\(");- lowerCaseMatchWith = StringUtils.replace(lowerCaseMatchWith, ")", "\\)");- lowerCaseMatchWith = StringUtils.replace(lowerCaseMatchWith, "?", ".");- lowerCaseMatchWith = "^" + StringUtils.replace(lowerCaseMatchWith, "*", ".*");- Pattern pattern = Pattern.compile(lowerCaseMatchWith);for (String path: auxiliaryManager.getFiles(repoModel.getObject())) {- Matcher matcher = pattern.matcher(path.toLowerCase());- if (matcher.find()) {- String suffix = path.substring(matcher.end());+ String wildcarded = WildcardUtils.applyWildcard(path, matchWith, false);+ if (wildcarded != null) {+ int matchEnd = wildcarded.toLowerCase().indexOf(matchWith) + matchWith.length();+ String suffix = wildcarded.substring(matchEnd);int index = suffix.indexOf('/');- String suggestedInput;+ String suggestedInput = wildcarded.substring(0, matchEnd);if (index != -1)- suggestedInput = matchWith + suffix.substring(0, index) + "/";+ suggestedInput += suffix.substring(0, index) + "/";else- suggestedInput = matchWith + suffix;- if (!suggestedInputs.contains(suggestedInput)) {- suggestedInputs.add(suggestedInput);- if (suggestedInputs.size() == count)- break;- }+ suggestedInput += suffix;+ suggestedInputSet.add(suggestedInput);}}+ System.out.println(System.currentTimeMillis()-time);- for (String suggestedInput: suggestedInputs) {+ List<String> suggestedInputList = new ArrayList<>(suggestedInputSet);+ final String matchWithStr = matchWith;+ Collections.sort(suggestedInputList, new Comparator<String>() {++ @Override+ public int compare(String o1, String o2) {+ return o1.toLowerCase().indexOf(matchWithStr) - o2.toLowerCase().indexOf(matchWithStr);+ }++ });+ System.out.println(System.currentTimeMillis()-time);++ for (String suggestedInput: suggestedInputList) {int caret;if (suggestedInput.endsWith("/"))caret = suggestedInput.length();@@ -133,7 +149,10 @@ public class QueryAssistBehavior extends ANTLRAssistBehavior {int index = suggestedInput.toLowerCase().indexOf(matchWith.toLowerCase());Highlight highlight = new Highlight(index, index+matchWith.length());suggestions.add(new InputSuggestion(suggestedInput, caret, true, null, highlight));+ if (suggestions.size() == count)+ break;}+ System.out.println(System.currentTimeMillis()-time);}return suggestions;}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/commit/RepoCommitsPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/commit/RepoCommitsPage.javaindex 31f60f4445..bf94a2f665 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/commit/RepoCommitsPage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/commit/RepoCommitsPage.java@@ -98,7 +98,7 @@ public class RepoCommitsPage extends RepositoryPage {Commits commits = new Commits();LogCommand logCommand = new LogCommand(getRepository().git().repoDir());- logCommand.parentRewriting(true);+ logCommand.parentRewriting(true).ignoreCase(true);List<Commit> logCommits;try {