The Unified and Autonomous Development Platform
midwork
robin shinec0fc543da918
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/component/modal/modal.js b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/modal/modal.jsindex 6980299282..dd12b97ee8 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/component/modal/modal.js+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/modal/modal.js@@ -11,7 +11,7 @@ pmease.commons.modal = {// use keydown as keypress does not work in chrome/safari$(document).on("keydown", $modal.data("keydown"));- $modal.modal({backdrop: "static"});+ $modal.modal({backdrop: "static", "keyboard": false});},close: function($modal, callCloseCallback) {diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfChangeSpecifiedRefs.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfChangeSpecifiedRefs.javaindex da7ce09f4c..35f5a31052 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfChangeSpecifiedRefs.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfChangeSpecifiedRefs.java@@ -11,7 +11,7 @@ import com.pmease.gitplex.core.model.Depot;import com.pmease.gitplex.core.model.PullRequest;import com.pmease.gitplex.core.model.User;import com.pmease.gitplex.core.util.editable.RefMatch;-import com.pmease.gitplex.core.util.refmatch.RefMatchUtils;+import com.pmease.gitplex.core.util.includeexclude.IncludeExcludeUtils;@SuppressWarnings("serial")@Editable(order=100, icon="fa-code-fork", description=@@ -32,7 +32,7 @@ public class IfChangeSpecifiedRefs extends AbstractGateKeeper {}private CheckResult doCheck(String refName) {- if (RefMatchUtils.matches(refMatch, refName)) {+ if (IncludeExcludeUtils.matches(refMatch, refName)) {return passed(Lists.newArrayList("Target ref matches '" + refMatch + "'."));} else {return failed(Lists.newArrayList("Target ref does not match '" + refMatch + "'."));diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfTouchSpecifiedFiles.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfTouchSpecifiedFiles.javaindex 730d84062e..ceb1bdfe35 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfTouchSpecifiedFiles.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfTouchSpecifiedFiles.java@@ -11,7 +11,7 @@ import com.pmease.gitplex.core.model.PullRequest;import com.pmease.gitplex.core.model.PullRequestUpdate;import com.pmease.gitplex.core.model.User;import com.pmease.gitplex.core.util.editable.PathMatch;-import com.pmease.gitplex.core.util.pathmatch.PathMatchUtils;+import com.pmease.gitplex.core.util.includeexclude.IncludeExcludeUtils;@SuppressWarnings("serial")@Editable(order=300, icon="fa-file-text", description=@@ -35,7 +35,7 @@ public class IfTouchSpecifiedFiles extends AbstractGateKeeper {public CheckResult doCheckRequest(PullRequest request) {for (PullRequestUpdate update: request.getEffectiveUpdates()) {for (String file: update.getChangedFiles()) {- if (PathMatchUtils.matches(pathMatch, file)) {+ if (IncludeExcludeUtils.matches(pathMatch, file)) {request.setReferentialUpdate(update);return passed(Lists.newArrayList("Touched files matches '" + pathMatch + "'."));}@@ -47,7 +47,7 @@ public class IfTouchSpecifiedFiles extends AbstractGateKeeper {@Overrideprotected CheckResult doCheckFile(User user, Depot depot, String branch, String file) {- if (PathMatchUtils.matches(pathMatch, file))+ if (IncludeExcludeUtils.matches(pathMatch, file))return passed(Lists.newArrayList("Touched files match '" + pathMatch + "'."));elsereturn failed(Lists.newArrayList("No touched files match '" + pathMatch + "'."));@@ -57,7 +57,7 @@ public class IfTouchSpecifiedFiles extends AbstractGateKeeper {protected CheckResult doCheckPush(User user, Depot depot, String refName, ObjectId oldCommit, ObjectId newCommit) {if (!oldCommit.equals(ObjectId.zeroId()) && !newCommit.equals(ObjectId.zeroId())) {for (String file: depot.git().listChangedFiles(oldCommit.name(), newCommit.name(), null)) {- if (PathMatchUtils.matches(pathMatch, file))+ if (IncludeExcludeUtils.matches(pathMatch, file))return passed(Lists.newArrayList("Touched files match '" + pathMatch + "'."));}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/util/pathmatch/PathMatch.g4 b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/includeexclude/IncludeExclude.g4similarity index 78%rename from gitplex.core/src/main/java/com/pmease/gitplex/core/util/pathmatch/PathMatch.g4rename to gitplex.core/src/main/java/com/pmease/gitplex/core/util/includeexclude/IncludeExclude.g4index 0298b7b5fe..631f1ae88c 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/util/pathmatch/PathMatch.g4+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/includeexclude/IncludeExclude.g4@@ -1,4 +1,4 @@-grammar PathMatch;+grammar IncludeExclude;match: criteria+ EOF;diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/util/pathmatch/PathMatchUtils.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/includeexclude/IncludeExcludeUtils.javasimilarity index 76%rename from gitplex.core/src/main/java/com/pmease/gitplex/core/util/pathmatch/PathMatchUtils.javarename to gitplex.core/src/main/java/com/pmease/gitplex/core/util/includeexclude/IncludeExcludeUtils.javaindex c595316d7b..582b313f58 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/util/pathmatch/PathMatchUtils.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/includeexclude/IncludeExcludeUtils.java@@ -1,4 +1,4 @@-package com.pmease.gitplex.core.util.pathmatch;+package com.pmease.gitplex.core.util.includeexclude;import java.util.ArrayList;import java.util.List;@@ -9,17 +9,17 @@ import org.antlr.v4.runtime.CommonTokenStream;import org.antlr.v4.runtime.tree.TerminalNode;import com.pmease.commons.util.pattern.WildcardUtils;-import com.pmease.gitplex.core.util.pathmatch.PathMatchParser.CriteriaContext;-import com.pmease.gitplex.core.util.pathmatch.PathMatchParser.MatchContext;+import com.pmease.gitplex.core.util.includeexclude.IncludeExcludeParser.CriteriaContext;+import com.pmease.gitplex.core.util.includeexclude.IncludeExcludeParser.MatchContext;-public class PathMatchUtils {+public class IncludeExcludeUtils {public static MatchContext parse(String refMatch) {ANTLRInputStream is = new ANTLRInputStream(refMatch);- PathMatchLexer lexer = new PathMatchLexer(is);+ IncludeExcludeLexer lexer = new IncludeExcludeLexer(is);lexer.removeErrorListeners();CommonTokenStream tokens = new CommonTokenStream(lexer);- PathMatchParser parser = new PathMatchParser(tokens);+ IncludeExcludeParser parser = new IncludeExcludeParser(tokens);parser.removeErrorListeners();parser.setErrorHandler(new BailErrorStrategy());return parser.match();diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/util/refmatch/RefMatch.g4 b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/refmatch/RefMatch.g4deleted file mode 100644index c1d93f6cd4..0000000000--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/util/refmatch/RefMatch.g4+++ /dev/null@@ -1,26 +0,0 @@-grammar RefMatch;--match: criteria+ EOF;--criteria: branchMatch | tagMatch | patternMatch | excludeBranchMatch | excludeTagMatch | excludePatternMatch;--branchMatch: BRANCH Value;-tagMatch: TAG Value;-patternMatch: PATTERN Value;-excludeBranchMatch: EXCLUDE_BRANCH Value;-excludeTagMatch: EXCLUDE_TAG Value;-excludePatternMatch: EXCLUDE_PATTERN Value;--BRANCH: 'branch';-TAG: 'tag';-PATTERN: 'pattern';-EXCLUDE_BRANCH: 'excludeBranch';-EXCLUDE_TAG: 'excludeTag';-EXCLUDE_PATTERN: 'excludePattern';--Value: '(' (ESCAPE|~[()\\])+? ')';--fragment-ESCAPE: '\\'[()\\];--WS: [ \t\r\n]+ -> skip;\ No newline at end of filediff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/util/refmatch/RefMatchUtils.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/refmatch/RefMatchUtils.javadeleted file mode 100644index d23e8308dc..0000000000--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/util/refmatch/RefMatchUtils.java+++ /dev/null@@ -1,57 +0,0 @@-package com.pmease.gitplex.core.util.refmatch;--import java.util.ArrayList;-import java.util.List;--import org.antlr.v4.runtime.ANTLRInputStream;-import org.antlr.v4.runtime.BailErrorStrategy;-import org.antlr.v4.runtime.CommonTokenStream;-import org.antlr.v4.runtime.tree.TerminalNode;--import com.pmease.commons.git.GitUtils;-import com.pmease.commons.util.pattern.WildcardUtils;-import com.pmease.gitplex.core.util.refmatch.RefMatchParser.CriteriaContext;-import com.pmease.gitplex.core.util.refmatch.RefMatchParser.MatchContext;--public class RefMatchUtils {-- public static MatchContext parse(String refMatch) {- ANTLRInputStream is = new ANTLRInputStream(refMatch);- RefMatchLexer lexer = new RefMatchLexer(is);- lexer.removeErrorListeners();- CommonTokenStream tokens = new CommonTokenStream(lexer);- RefMatchParser parser = new RefMatchParser(tokens);- parser.removeErrorListeners();- parser.setErrorHandler(new BailErrorStrategy());- return parser.match();- }-- private static String getValue(TerminalNode terminal) {- String value = terminal.getText().substring(1);- return value.substring(0, value.length()-1).trim();- }-- public static boolean matches(String refMatch, String refName) {- MatchContext matchContext = parse(refMatch);- List<String> includes = new ArrayList<>();- List<String> excludes = new ArrayList<>();- for (CriteriaContext criteriaContext: matchContext.criteria()) {- if (criteriaContext.branchMatch() != null) {- includes.add(GitUtils.branch2ref(getValue(criteriaContext.branchMatch().Value())));- } else if (criteriaContext.tagMatch() != null) {- includes.add(GitUtils.tag2ref(getValue(criteriaContext.tagMatch().Value())));- } else if (criteriaContext.patternMatch() != null) {- includes.add(getValue(criteriaContext.patternMatch().Value()));- } else if (criteriaContext.excludeBranchMatch() != null) {- excludes.add(GitUtils.branch2ref(getValue(criteriaContext.excludeBranchMatch().Value())));- } else if (criteriaContext.excludeTagMatch() != null) {- excludes.add(GitUtils.tag2ref(getValue(criteriaContext.excludeTagMatch().Value())));- } else if (criteriaContext.excludePatternMatch() != null) {- excludes.add(getValue(criteriaContext.excludeTagMatch().Value()));- }- }-- return WildcardUtils.matchString(includes, excludes, refName);- }--}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/pathmatch/PathMatchBehavior.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/pathmatch/PathMatchBehavior.javaindex ed7a7a8cc0..ee2dc3b003 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/pathmatch/PathMatchBehavior.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/pathmatch/PathMatchBehavior.java@@ -13,7 +13,7 @@ import com.pmease.commons.antlr.grammar.ElementSpec;import com.pmease.commons.antlr.grammar.LexerRuleRefElementSpec;import com.pmease.commons.wicket.behavior.inputassist.ANTLRAssistBehavior;import com.pmease.gitplex.core.model.Depot;-import com.pmease.gitplex.core.util.pathmatch.PathMatchParser;+import com.pmease.gitplex.core.util.includeexclude.IncludeExcludeParser;import com.pmease.gitplex.web.util.SuggestionUtils;@SuppressWarnings("serial")@@ -26,7 +26,7 @@ public class PathMatchBehavior extends ANTLRAssistBehavior {private static final String VALUE_CLOSE = ")";public PathMatchBehavior(IModel<Depot> depotModel) {- super(PathMatchParser.class, "match");+ super(IncludeExcludeParser.class, "match");this.depotModel = depotModel;}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/pathmatch/PathMatchInput.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/pathmatch/PathMatchInput.javaindex d9ce9b3c39..e4e878c142 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/pathmatch/PathMatchInput.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/pathmatch/PathMatchInput.java@@ -12,7 +12,7 @@ import org.slf4j.Logger;import org.slf4j.LoggerFactory;import com.pmease.gitplex.core.model.Depot;-import com.pmease.gitplex.core.util.pathmatch.PathMatchUtils;+import com.pmease.gitplex.core.util.includeexclude.IncludeExcludeUtils;@SuppressWarnings("serial")public class PathMatchInput extends TextField<String> {@@ -37,7 +37,7 @@ public class PathMatchInput extends TextField<String> {@Overridepublic void validate(IValidatable<String> validatable) {try {- PathMatchUtils.parse(validatable.getValue());+ IncludeExcludeUtils.parse(validatable.getValue());} catch (final Exception e) {logger.error("Error parsing ref match string: " + validatable.getValue(), e);if (e.getCause().getMessage() != null) {diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/refmatch/RefMatchBehavior.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/refmatch/RefMatchBehavior.javaindex 520ad3bbdb..c3762c3a30 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/refmatch/RefMatchBehavior.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/refmatch/RefMatchBehavior.java@@ -1,10 +1,13 @@package com.pmease.gitplex.web.component.refmatch;import java.util.ArrayList;+import java.util.Collection;import java.util.List;import org.apache.wicket.Component;import org.apache.wicket.model.IModel;+import org.eclipse.jgit.lib.Constants;+import org.eclipse.jgit.lib.Ref;import com.pmease.commons.antlr.codeassist.FenceAware;import com.pmease.commons.antlr.codeassist.InputSuggestion;@@ -14,8 +17,7 @@ import com.pmease.commons.antlr.grammar.LexerRuleRefElementSpec;import com.pmease.commons.util.Range;import com.pmease.commons.wicket.behavior.inputassist.ANTLRAssistBehavior;import com.pmease.gitplex.core.model.Depot;-import com.pmease.gitplex.core.util.refmatch.RefMatchParser;-import com.pmease.gitplex.web.util.SuggestionUtils;+import com.pmease.gitplex.core.util.includeexclude.IncludeExcludeParser;@SuppressWarnings("serial")public class RefMatchBehavior extends ANTLRAssistBehavior {@@ -26,8 +28,12 @@ public class RefMatchBehavior extends ANTLRAssistBehavior {private static final String VALUE_CLOSE = ")";+ private static final String ANY_BRANCH = "refs/heads/*";++ private static final String ANY_TAG = "refs/tags/*";+public RefMatchBehavior(IModel<Depot> depotModel) {- super(RefMatchParser.class, "match");+ super(IncludeExcludeParser.class, "match");this.depotModel = depotModel;}@@ -46,31 +52,39 @@ public class RefMatchBehavior extends ANTLRAssistBehavior {@Overrideprotected List<InputSuggestion> match(String unfencedMatchWith) {- int tokenType = expectedElement.getRoot().getLastMatchedToken().getType();List<InputSuggestion> suggestions = new ArrayList<>();+Depot depot = depotModel.getObject();- switch (tokenType) {- case RefMatchParser.BRANCH:- case RefMatchParser.EXCLUDE_BRANCH:- suggestions.addAll(SuggestionUtils.suggestBranch(depot, unfencedMatchWith, count));- break;- case RefMatchParser.TAG:- case RefMatchParser.EXCLUDE_TAG:- suggestions.addAll(SuggestionUtils.suggestTag(depot, unfencedMatchWith, count));- break;- case RefMatchParser.PATTERN:- case RefMatchParser.EXCLUDE_PATTERN:- if (!unfencedMatchWith.contains(VALUE_CLOSE)) {- if (unfencedMatchWith.length() != 0) {- String fenced = VALUE_OPEN + unfencedMatchWith + VALUE_CLOSE;- Range matchRange = new Range(0, fenced.length());- suggestions.add(new InputSuggestion(fenced, -1, true, getFencingDescription(), matchRange));++ String lowerCaseMatchWith = unfencedMatchWith.toLowerCase();+ int numSuggestions = 0;+ Collection<String> suggestedValues = new ArrayList<>();+ suggestedValues.add(ANY_BRANCH);+ suggestedValues.add(ANY_TAG);+ for (Ref ref: depot.getRefs(Constants.R_HEADS).values())+ suggestedValues.add(ref.getName());+ for (Ref ref: depot.getRefs(Constants.R_TAGS).values())+ suggestedValues.add(ref.getName());++ for (String suggestedValue: suggestedValues) {+ int index = suggestedValue.toLowerCase().indexOf(lowerCaseMatchWith);+ if (index != -1 && numSuggestions++<count) {+ Range matchRange = new Range(index, index+lowerCaseMatchWith.length());+ if (suggestedValue.equals(ANY_BRANCH)) {+ suggestions.add(new InputSuggestion(suggestedValue, "any branch", matchRange));+ } else if (suggestedValue.equals(ANY_TAG)) {+ suggestions.add(new InputSuggestion(suggestedValue, "any tag", matchRange));+ } else {+ suggestions.add(new InputSuggestion(suggestedValue, matchRange));}- suggestions.add(new InputSuggestion("refs/heads/*", "Any branches", null));- suggestions.add(new InputSuggestion("refs/tags/*", "Any tags", null));}- break;- }+ }++ if (!unfencedMatchWith.contains(VALUE_CLOSE) && unfencedMatchWith.length() != 0) {+ String fenced = VALUE_OPEN + unfencedMatchWith + VALUE_CLOSE;+ Range matchRange = new Range(0, fenced.length());+ suggestions.add(new InputSuggestion(fenced, -1, true, getFencingDescription(), matchRange));+ }return suggestions;}@@ -91,10 +105,7 @@ public class RefMatchBehavior extends ANTLRAssistBehavior {if (expectedElement.getSpec() instanceof LexerRuleRefElementSpec) {LexerRuleRefElementSpec spec = (LexerRuleRefElementSpec) expectedElement.getSpec();if (spec.getRuleName().equals("Value") && !matchWith.contains(VALUE_CLOSE)) {- int tokenType = expectedElement.getRoot().getLastMatchedToken().getType();- if (tokenType == RefMatchParser.PATTERN || tokenType == RefMatchParser.EXCLUDE_PATTERN) {- hints.add("Use * to match any part of ref");- }+ hints.add("Use * to match any part of ref");}}return hints;diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/refmatch/RefMatchInput.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/refmatch/RefMatchInput.javaindex d1c24c940c..e5b0a837e6 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/refmatch/RefMatchInput.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/refmatch/RefMatchInput.java@@ -12,7 +12,7 @@ import org.slf4j.Logger;import org.slf4j.LoggerFactory;import com.pmease.gitplex.core.model.Depot;-import com.pmease.gitplex.core.util.refmatch.RefMatchUtils;+import com.pmease.gitplex.core.util.includeexclude.IncludeExcludeUtils;@SuppressWarnings("serial")public class RefMatchInput extends TextField<String> {@@ -37,7 +37,7 @@ public class RefMatchInput extends TextField<String> {@Overridepublic void validate(IValidatable<String> validatable) {try {- RefMatchUtils.parse(validatable.getValue());+ IncludeExcludeUtils.parse(validatable.getValue());} catch (final Exception e) {logger.error("Error parsing ref match string: " + validatable.getValue(), e);if (e.getCause().getMessage() != null) {diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/setting/gatekeeper/GateKeeperPage.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/setting/gatekeeper/GateKeeperPage.htmlindex b388d9317a..6354f23d8a 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/setting/gatekeeper/GateKeeperPage.html+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/setting/gatekeeper/GateKeeperPage.html@@ -14,9 +14,9 @@Gate keepers plays an important role in GitPlex, for instance, you may use it to:<ul><li>Control write access to certain branches or directories.</li>- <li>Require different parties to review different parts of the system.</li>+ <li>Require different user to approve different tree of the repository.</li><li>Have continuous integration system verifying the code before accepting- the push or pull request.</li>+ the pull request.</li></ul></div></div>