Skip to content

The Unified and Autonomous Development Platform

midwork

robin shineaa372bd56aa6
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestManager.java
index 852681c773..6315f2fe5e 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestManager.java
@@ -73,6 +73,7 @@ import com.pmease.gitplex.core.model.DepotAndBranch;
import com.pmease.gitplex.core.model.Depot;
import com.pmease.gitplex.core.model.ReviewInvitation;
import com.pmease.gitplex.core.model.User;
+import com.pmease.gitplex.core.util.includeexclude.IncludeExcludeUtils;
@Singleton
public class DefaultPullRequestManager implements PullRequestManager, DepotListener, RefListener, LifecycleListener {
@@ -367,7 +368,7 @@ public class DefaultPullRequestManager implements PullRequestManager, DepotListe
public List<IntegrationStrategy> getApplicableIntegrationStrategies(PullRequest request) {
List<IntegrationStrategy> strategies = null;
for (IntegrationPolicy policy: request.getTargetDepot().getIntegrationPolicies()) {
- if (policy.getTargetBranches().matches(request.getTargetBranch())
+ if (IncludeExcludeUtils.matches(policy.getTargetBranchMatch(), request.getTargetBranch())
&& policy.getSourceBranches().matches(request.getSourceDepot(), request.getSourceBranch())) {
strategies = policy.getIntegrationStrategies();
break;
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/IntegrationPolicy.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/IntegrationPolicy.java
index b291744bd0..86bee92a5a 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/IntegrationPolicy.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/IntegrationPolicy.java
@@ -8,18 +8,20 @@ import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
+import org.hibernate.validator.constraints.NotEmpty;
+
import com.pmease.commons.wicket.editable.annotation.Editable;
import com.pmease.commons.wicket.editable.annotation.Horizontal;
import com.pmease.gitplex.core.model.PullRequest.IntegrationStrategy;
import com.pmease.gitplex.core.util.branchmatcher.AffinalBranchMatcher;
-import com.pmease.gitplex.core.util.branchmatcher.LocalBranchMatcher;
+import com.pmease.gitplex.core.util.editable.BranchMatch;
@SuppressWarnings("serial")
@Editable
@Horizontal
public class IntegrationPolicy implements Serializable {
- private LocalBranchMatcher targetBranches;
+ private String targetBranchMatch;
private AffinalBranchMatcher sourceBranches;
@@ -27,14 +29,14 @@ public class IntegrationPolicy implements Serializable {
@Editable(name="Target Branches", order=100, description="Specify target branches of pull requests to which "
+ "this policy applies to.")
- @NotNull
- @Valid
- public LocalBranchMatcher getTargetBranches() {
- return targetBranches;
+ @BranchMatch
+ @NotEmpty
+ public String getTargetBranchMatch() {
+ return targetBranchMatch;
}
- public void setTargetBranches(LocalBranchMatcher targetBranches) {
- this.targetBranches = targetBranches;
+ public void setTargetBranchMatch(String targetBranchMatch) {
+ this.targetBranchMatch = targetBranchMatch;
}
@Editable(name="Source Branches", order=200, description="Specify source branches of pull requests to which "
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/util/editable/BranchMatch.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/editable/BranchMatch.java
new file mode 100644
index 0000000000..ed52a8064c
--- /dev/null
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/editable/BranchMatch.java
@@ -0,0 +1,11 @@
+package com.pmease.gitplex.core.util.editable;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface BranchMatch {
+}
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 582b313f58..f557dfa37a 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
@@ -14,8 +14,8 @@ import com.pmease.gitplex.core.util.includeexclude.IncludeExcludeParser.MatchCon
public class IncludeExcludeUtils {
- public static MatchContext parse(String refMatch) {
- ANTLRInputStream is = new ANTLRInputStream(refMatch);
+ public static MatchContext parse(String match) {
+ ANTLRInputStream is = new ANTLRInputStream(match);
IncludeExcludeLexer lexer = new IncludeExcludeLexer(is);
lexer.removeErrorListeners();
CommonTokenStream tokens = new CommonTokenStream(lexer);
@@ -34,8 +34,8 @@ public class IncludeExcludeUtils {
return value;
}
- public static boolean matches(String pathMatch, String path) {
- MatchContext matchContext = parse(pathMatch);
+ public static boolean matches(String match, String value) {
+ MatchContext matchContext = parse(match);
List<String> includes = new ArrayList<>();
List<String> excludes = new ArrayList<>();
for (CriteriaContext criteriaContext: matchContext.criteria()) {
@@ -46,7 +46,7 @@ public class IncludeExcludeUtils {
}
}
- return WildcardUtils.matchString(includes, excludes, path);
+ return WildcardUtils.matchString(includes, excludes, value);
}
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branchmatch/BranchMatchBehavior.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branchmatch/BranchMatchBehavior.java
new file mode 100644
index 0000000000..3c56f493d8
--- /dev/null
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branchmatch/BranchMatchBehavior.java
@@ -0,0 +1,88 @@
+package com.pmease.gitplex.web.component.branchmatch;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.model.IModel;
+
+import com.pmease.commons.antlr.codeassist.FenceAware;
+import com.pmease.commons.antlr.codeassist.InputSuggestion;
+import com.pmease.commons.antlr.codeassist.ParentedElement;
+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.includeexclude.IncludeExcludeParser;
+import com.pmease.gitplex.web.util.SuggestionUtils;
+
+@SuppressWarnings("serial")
+public class BranchMatchBehavior extends ANTLRAssistBehavior {
+
+ private final IModel<Depot> depotModel;
+
+ private static final String VALUE_OPEN = "(";
+
+ private static final String VALUE_CLOSE = ")";
+
+ public BranchMatchBehavior(IModel<Depot> depotModel) {
+ super(IncludeExcludeParser.class, "match");
+ this.depotModel = depotModel;
+ }
+
+ @Override
+ public void detach(Component component) {
+ super.detach(component);
+ depotModel.detach();
+ }
+
+ @Override
+ protected List<InputSuggestion> suggest(final ParentedElement expectedElement, String matchWith, final int count) {
+ if (expectedElement.getSpec() instanceof LexerRuleRefElementSpec) {
+ LexerRuleRefElementSpec spec = (LexerRuleRefElementSpec) expectedElement.getSpec();
+ if (spec.getRuleName().equals("Value")) {
+ return new FenceAware(codeAssist.getGrammar(), VALUE_OPEN, VALUE_CLOSE) {
+
+ @Override
+ protected List<InputSuggestion> match(String unfencedMatchWith) {
+ return SuggestionUtils.suggestBranch(depotModel.getObject(), unfencedMatchWith, count);
+ }
+
+ @Override
+ protected String getFencingDescription() {
+ return "value needs to be enclosed in brackets";
+ }
+
+ }.suggest(expectedElement.getSpec(), matchWith);
+ }
+ }
+ return null;
+ }
+
+ @Override
+ protected List<String> getHints(ParentedElement expectedElement, String matchWith) {
+ List<String> hints = new ArrayList<>();
+ if (expectedElement.getSpec() instanceof LexerRuleRefElementSpec) {
+ LexerRuleRefElementSpec spec = (LexerRuleRefElementSpec) expectedElement.getSpec();
+ if (spec.getRuleName().equals("Value") && !matchWith.contains(VALUE_CLOSE)) {
+ hints.add("Use * to match any part of branch");
+ }
+ }
+ return hints;
+ }
+
+ @Override
+ protected int getEndOfMatch(ElementSpec spec, String content) {
+ if (content.startsWith(VALUE_OPEN+VALUE_CLOSE))
+ return 2;
+ else
+ return super.getEndOfMatch(spec, content);
+ }
+
+ @Override
+ protected InputSuggestion wrapAsSuggestion(ParentedElement expectedElement,
+ String suggestedLiteral, boolean complete) {
+ return new InputSuggestion(suggestedLiteral);
+ }
+
+}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branchmatch/BranchMatchInput.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branchmatch/BranchMatchInput.java
new file mode 100644
index 0000000000..9e1770442a
--- /dev/null
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branchmatch/BranchMatchInput.java
@@ -0,0 +1,74 @@
+package com.pmease.gitplex.web.component.branchmatch;
+
+import java.io.Serializable;
+
+import org.apache.wicket.markup.html.form.TextField;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.validation.IErrorMessageSource;
+import org.apache.wicket.validation.IValidatable;
+import org.apache.wicket.validation.IValidationError;
+import org.apache.wicket.validation.IValidator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.pmease.gitplex.core.model.Depot;
+import com.pmease.gitplex.core.util.includeexclude.IncludeExcludeUtils;
+
+@SuppressWarnings("serial")
+public class BranchMatchInput extends TextField<String> {
+
+ private static final Logger logger = LoggerFactory.getLogger(BranchMatchInput.class);
+
+ private final IModel<Depot> depotModel;
+
+ public BranchMatchInput(String id, IModel<Depot> depotModel, IModel<String> refMatchModel) {
+ super(id, refMatchModel);
+
+ this.depotModel = depotModel;
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ add(new BranchMatchBehavior(depotModel));
+ add(new IValidator<String>() {
+
+ @Override
+ public void validate(IValidatable<String> validatable) {
+ try {
+ IncludeExcludeUtils.parse(validatable.getValue());
+ } catch (final Exception e) {
+ logger.error("Error parsing branch match string: " + validatable.getValue(), e);
+ if (e.getCause().getMessage() != null) {
+ validatable.error(new IValidationError() {
+
+ @Override
+ public Serializable getErrorMessage(IErrorMessageSource messageSource) {
+ return "Syntax error: " + e.getCause().getMessage();
+ }
+
+ });
+ } else {
+ validatable.error(new IValidationError() {
+
+ @Override
+ public Serializable getErrorMessage(IErrorMessageSource messageSource) {
+ return "Syntax error: " + e.getCause().getClass().getSimpleName();
+ }
+
+ });
+ }
+ }
+ }
+
+ });
+ }
+
+ @Override
+ protected void onDetach() {
+ depotModel.detach();
+ super.onDetach();
+ }
+
+}
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.java
index ee2dc3b003..08dc5e4386 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
@@ -83,18 +83,7 @@ public class PathMatchBehavior extends ANTLRAssistBehavior {
@Override
protected InputSuggestion wrapAsSuggestion(ParentedElement expectedElement,
String suggestedLiteral, boolean complete) {
- String description;
- switch (suggestedLiteral) {
- case "include":
- description = "include file";
- break;
- case "exclude":
- description = "exclude file";
- break;
- default:
- description = null;
- }
- return new InputSuggestion(suggestedLiteral, description, null);
+ return new InputSuggestion(suggestedLiteral);
}
}
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.java
index c3762c3a30..ea8acbec59 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
@@ -122,30 +122,7 @@ public class RefMatchBehavior extends ANTLRAssistBehavior {
@Override
protected InputSuggestion wrapAsSuggestion(ParentedElement expectedElement,
String suggestedLiteral, boolean complete) {
- String description;
- switch (suggestedLiteral) {
- case "branch":
- description = "specify branch";
- break;
- case "tag":
- description = "specify tag";
- break;
- case "pattern":
- description = "specify ref pattern";
- break;
- case "excludeBranch":
- description = "exclude branch";
- break;
- case "excludeTag":
- description = "exclude tag";
- break;
- case "excludePattern":
- description = "exclude ref pattern";
- break;
- default:
- description = null;
- }
- return new InputSuggestion(suggestedLiteral, description, null);
+ return new InputSuggestion(suggestedLiteral);
}
-
+
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branchmatch/BranchMatchEditSupport.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branchmatch/BranchMatchEditSupport.java
new file mode 100644
index 0000000000..b7dd52c662
--- /dev/null
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branchmatch/BranchMatchEditSupport.java
@@ -0,0 +1,66 @@
+package com.pmease.gitplex.web.editable.branchmatch;
+
+import java.lang.reflect.Method;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.model.IModel;
+
+import com.pmease.commons.wicket.editable.BeanContext;
+import com.pmease.commons.wicket.editable.DefaultPropertyDescriptor;
+import com.pmease.commons.wicket.editable.EditSupport;
+import com.pmease.commons.wicket.editable.NotDefinedLabel;
+import com.pmease.commons.wicket.editable.PropertyContext;
+import com.pmease.commons.wicket.editable.PropertyDescriptor;
+import com.pmease.commons.wicket.editable.PropertyEditor;
+import com.pmease.commons.wicket.editable.PropertyViewer;
+import com.pmease.gitplex.core.util.editable.BranchMatch;
+
+@SuppressWarnings("serial")
+public class BranchMatchEditSupport implements EditSupport {
+
+ @Override
+ public BeanContext<?> getBeanEditContext(Class<?> beanClass) {
+ return null;
+ }
+
+ @Override
+ public PropertyContext<?> getPropertyEditContext(Class<?> beanClass, String propertyName) {
+ PropertyDescriptor propertyDescriptor = new DefaultPropertyDescriptor(beanClass, propertyName);
+ Method propertyGetter = propertyDescriptor.getPropertyGetter();
+ if (propertyGetter.getAnnotation(BranchMatch.class) != null) {
+ if (propertyGetter.getReturnType() != String.class) {
+ throw new RuntimeException("Annotation 'BranchMatch' should be applied to property "
+ + "with type 'String'.");
+ }
+ return new PropertyContext<String>(propertyDescriptor) {
+
+ @Override
+ public PropertyViewer renderForView(String componentId, final IModel<String> model) {
+ return new PropertyViewer(componentId, this) {
+
+ @Override
+ protected Component newContent(String id, PropertyDescriptor propertyDescriptor) {
+ String refMatch = model.getObject();
+ if (refMatch != null) {
+ return new Label(id, refMatch);
+ } else {
+ return new NotDefinedLabel(id);
+ }
+ }
+
+ };
+ }
+
+ @Override
+ public PropertyEditor<String> renderForEdit(String componentId, IModel<String> model) {
+ return new BranchMatchEditor(componentId, this, model);
+ }
+
+ };
+ } else {
+ return null;
+ }
+ }
+
+}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branchmatch/BranchMatchEditor.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branchmatch/BranchMatchEditor.html
new file mode 100644
index 0000000000..9383fc76b9
--- /dev/null
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branchmatch/BranchMatchEditor.html
@@ -0,0 +1,3 @@
+<wicket:panel>
+ <input wicket:id="input" spellcheck="false" autocomplete="off" class="form-control"></input>
+</wicket:panel>
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branchmatch/BranchMatchEditor.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branchmatch/BranchMatchEditor.java
new file mode 100644
index 0000000000..5907e148ec
--- /dev/null
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branchmatch/BranchMatchEditor.java
@@ -0,0 +1,50 @@
+package com.pmease.gitplex.web.editable.branchmatch;
+
+import org.apache.wicket.model.AbstractReadOnlyModel;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.util.convert.ConversionException;
+
+import com.pmease.commons.wicket.editable.ErrorContext;
+import com.pmease.commons.wicket.editable.PathSegment;
+import com.pmease.commons.wicket.editable.PropertyDescriptor;
+import com.pmease.commons.wicket.editable.PropertyEditor;
+import com.pmease.gitplex.core.model.Depot;
+import com.pmease.gitplex.web.component.branchmatch.BranchMatchInput;
+import com.pmease.gitplex.web.page.depot.DepotPage;
+
+@SuppressWarnings("serial")
+public class BranchMatchEditor extends PropertyEditor<String> {
+
+ private BranchMatchInput input;
+
+ public BranchMatchEditor(String id, PropertyDescriptor propertyDescriptor, IModel<String> propertyModel) {
+ super(id, propertyDescriptor, propertyModel);
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ input = new BranchMatchInput("input", new AbstractReadOnlyModel<Depot>() {
+
+ @Override
+ public Depot getObject() {
+ return ((DepotPage) getPage()).getDepot();
+ }
+
+ }, getModel());
+
+ add(input);
+ }
+
+ @Override
+ public ErrorContext getErrorContext(PathSegment pathSegment) {
+ return null;
+ }
+
+ @Override
+ protected String convertInputToValue() throws ConversionException {
+ return input.getConvertedInput();
+ }
+
+}