Skip to content

The Unified and Autonomous Development Platform

midwork

robin shine34bcba1e9307
diff --git a/commons.git/src/main/java/com/pmease/commons/git/Git.java b/commons.git/src/main/java/com/pmease/commons/git/Git.java
index d8efa78a46..31c1dd23ed 100644
--- a/commons.git/src/main/java/com/pmease/commons/git/Git.java
+++ b/commons.git/src/main/java/com/pmease/commons/git/Git.java
@@ -11,6 +11,7 @@ import java.util.Map;
import javax.annotation.Nullable;
import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.ObjectId;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
@@ -77,7 +78,7 @@ public class Git implements Serializable {
throw new GeneralException(String.format("Branch %s already exists.", branchName));
new UpdateRefCommand(repoDir).refName(Constants.R_HEADS + branchName).revision(commitHash)
- .oldRevision(GitUtils.NULL_SHA1).call();
+ .oldRevision(ObjectId.zeroId().name()).call();
return this;
}
diff --git a/commons.git/src/main/java/com/pmease/commons/git/GitUtils.java b/commons.git/src/main/java/com/pmease/commons/git/GitUtils.java
index 3aa55ad3b8..575c04aba7 100644
--- a/commons.git/src/main/java/com/pmease/commons/git/GitUtils.java
+++ b/commons.git/src/main/java/com/pmease/commons/git/GitUtils.java
@@ -26,8 +26,6 @@ import com.google.common.collect.Iterables;
public class GitUtils {
- public static final String NULL_SHA1 = StringUtils.repeat("0", 40);
-
public static final Pattern PATTERN_HASH = Pattern.compile("[a-z0-9]{40}");
public static final int SHORT_SHA_LENGTH = 8;
@@ -36,10 +34,6 @@ public class GitUtils {
return PATTERN_HASH.matcher(sha).matches();
}
- public static boolean isNullHash(String sha) {
- return Objects.equal(NULL_SHA1, sha);
- }
-
public static boolean isEmptyPath(String path) {
return Strings.isNullOrEmpty(path) || Objects.equal(path, DiffEntry.DEV_NULL);
}
diff --git a/commons.util/src/main/java/com/pmease/commons/util/pattern/PatternMatcher.java b/commons.util/src/main/java/com/pmease/commons/util/pattern/PatternMatcher.java
index ab9d2212db..a74d5dff5f 100644
--- a/commons.util/src/main/java/com/pmease/commons/util/pattern/PatternMatcher.java
+++ b/commons.util/src/main/java/com/pmease/commons/util/pattern/PatternMatcher.java
@@ -1,5 +1,5 @@
-package com.pmease.commons.util.pattern;
-
-public interface PatternMatcher {
- boolean matches(String pattern, String input);
-}
+package com.pmease.commons.util.pattern;
+
+public interface PatternMatcher {
+ boolean matches(String pattern, String input);
+}
diff --git a/commons.util/src/main/java/com/pmease/commons/util/pattern/PatternSetMatcher.java b/commons.util/src/main/java/com/pmease/commons/util/pattern/PatternSetMatcher.java
index 2fc1985f67..e4feb6e2cd 100644
--- a/commons.util/src/main/java/com/pmease/commons/util/pattern/PatternSetMatcher.java
+++ b/commons.util/src/main/java/com/pmease/commons/util/pattern/PatternSetMatcher.java
@@ -1,28 +1,46 @@
-package com.pmease.commons.util.pattern;
-
-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;
- }
-
-}
+package com.pmease.commons.util.pattern;
+
+import java.util.List;
+
+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;
+ }
+
+ public boolean matches(List<String> includes, List<String> excludes, String input) {
+ for (String exclude: excludes) {
+ if (patternMatcher.matches(exclude, input))
+ return false;
+ }
+ if (includes.isEmpty()) {
+ return true;
+ } else {
+ for (String include: includes) {
+ if (patternMatcher.matches(include, input))
+ return true;
+ }
+ return false;
+ }
+ }
+
+}
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.java
index 0fc30d402f..9a361f110f 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,152 +1,160 @@
-package com.pmease.commons.util.pattern;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.annotation.Nullable;
-
-import com.pmease.commons.util.Range;
-
-public class WildcardUtils {
-
- private static final PatternMatcher stringPatternSetMatcher = new PatternSetMatcher(new WildcardStringMatcher());
-
- private static final PatternMatcher 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
- * @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
- *
- */
- public static boolean matchPath(String patterns, String path) {
- return pathPatternSetMatcher.matches(patterns, 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
- * 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.
- * @param str
- * the string which must be matched against the pattern. Must not be null.
- * @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 hasWildcards(String input) {
- return (input.indexOf('*') != -1 || input.indexOf('?') != -1);
- }
-
- @Nullable
- public static WildcardApplied 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<Range> literalRanges = new ArrayList<>();
- int pos = 0;
- int index = normalizedWildcard.indexOf('*');
- while (index != -1) {
- if (index>pos)
- literalRanges.add(new Range(pos, index));
- pos = index+1;
- index = normalizedWildcard.indexOf('*', pos);
- }
- if (normalizedWildcard.length()>pos)
- literalRanges.add(new Range(pos, normalizedWildcard.length()));
-
- String appliedText = wildcard;
- int first = -1;
- int last = 0;
- pos = 0;
- for (Range 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;
- appliedText = replaceLiteral(appliedText, literalRange, text.substring(index, pos));
- } else {
- return null;
- }
- }
- if (first != -1 && wildcard.charAt(0) != '*')
- appliedText = text.substring(0, first) + appliedText;
- else
- first = 0;
- if (wildcard.length() == 0 || wildcard.charAt(wildcard.length()-1) != '*') {
- String suffix = text.substring(last);
- last = appliedText.length();
- appliedText = appliedText + suffix;
- } else {
- last = appliedText.length();
- }
- return new WildcardApplied(appliedText, new Range(first, last));
- }
-
- private static String replaceLiteral(String text, Range literalRange, String literal) {
- String prefix = text.substring(0, literalRange.getFrom());
- String suffix = text.substring(literalRange.getTo());
- return prefix + literal + suffix;
- }
-
-}
+package com.pmease.commons.util.pattern;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.annotation.Nullable;
+
+import com.pmease.commons.util.Range;
+
+public class WildcardUtils {
+
+ private static final PatternSetMatcher stringPatternSetMatcher = new PatternSetMatcher(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
+ * @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
+ *
+ */
+ public static boolean matchPath(String patterns, String path) {
+ return pathPatternSetMatcher.matches(patterns, path);
+ }
+
+ public static boolean matchPath(List<String> includes, List<String> excludes, String path) {
+ return pathPatternSetMatcher.matches(includes, excludes, 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
+ * 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.
+ * @param str
+ * the string which must be matched against the pattern. Must not be null.
+ * @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(List<String> includes, List<String> excludes, String str) {
+ return stringPatternSetMatcher.matches(includes, excludes, str);
+ }
+
+ public static boolean hasWildcards(String input) {
+ return (input.indexOf('*') != -1 || input.indexOf('?') != -1);
+ }
+
+ @Nullable
+ public static WildcardApplied 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<Range> literalRanges = new ArrayList<>();
+ int pos = 0;
+ int index = normalizedWildcard.indexOf('*');
+ while (index != -1) {
+ if (index>pos)
+ literalRanges.add(new Range(pos, index));
+ pos = index+1;
+ index = normalizedWildcard.indexOf('*', pos);
+ }
+ if (normalizedWildcard.length()>pos)
+ literalRanges.add(new Range(pos, normalizedWildcard.length()));
+
+ String appliedText = wildcard;
+ int first = -1;
+ int last = 0;
+ pos = 0;
+ for (Range 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;
+ appliedText = replaceLiteral(appliedText, literalRange, text.substring(index, pos));
+ } else {
+ return null;
+ }
+ }
+ if (first != -1 && wildcard.charAt(0) != '*')
+ appliedText = text.substring(0, first) + appliedText;
+ else
+ first = 0;
+ if (wildcard.length() == 0 || wildcard.charAt(wildcard.length()-1) != '*') {
+ String suffix = text.substring(last);
+ last = appliedText.length();
+ appliedText = appliedText + suffix;
+ } else {
+ last = appliedText.length();
+ }
+ return new WildcardApplied(appliedText, new Range(first, last));
+ }
+
+ private static String replaceLiteral(String text, Range literalRange, String literal) {
+ String prefix = text.substring(0, literalRange.getFrom());
+ String suffix = text.substring(literalRange.getTo());
+ return prefix + literal + suffix;
+ }
+
+}
diff --git a/gitplex.core/pom.xml b/gitplex.core/pom.xml
index f86bab9885..277d06acb5 100644
--- a/gitplex.core/pom.xml
+++ b/gitplex.core/pom.xml
@@ -1,109 +1,113 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <artifactId>gitplex.core</artifactId>
- <parent>
- <groupId>com.pmease</groupId>
- <artifactId>parent.general</artifactId>
- <version>1.0.31</version>
- </parent>
- <build>
- <plugins>
- <plugin>
- <groupId>com.pmease</groupId>
- <artifactId>plugin.maven</artifactId>
- </plugin>
- <plugin>
- <artifactId>maven-archetype-plugin</artifactId>
- </plugin>
- <plugin>
- <artifactId>maven-source-plugin</artifactId>
- </plugin>
- <plugin>
- <artifactId>maven-javadoc-plugin</artifactId>
- </plugin>
- </plugins>
- </build>
- <dependencies>
- <dependency>
- <groupId>com.pmease</groupId>
- <artifactId>commons.loader</artifactId>
- <version>1.0.31</version>
- </dependency>
- <dependency>
- <groupId>com.pmease</groupId>
- <artifactId>commons.git</artifactId>
- <version>1.0.0</version>
- </dependency>
- <dependency>
- <groupId>org.jetbrains.xodus</groupId>
- <artifactId>xodus-entity-store</artifactId>
- </dependency>
- <dependency>
- <groupId>com.pmease</groupId>
- <artifactId>commons.git</artifactId>
- <version>1.0.0</version>
- <type>test-jar</type>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>com.pmease</groupId>
- <artifactId>commons.jetty</artifactId>
- <version>1.0.31</version>
- </dependency>
- <dependency>
- <groupId>com.pmease</groupId>
- <artifactId>commons.loader</artifactId>
- <version>1.0.31</version>
- <type>test-jar</type>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>com.pmease</groupId>
- <artifactId>commons.schedule</artifactId>
- <version>1.0.0</version>
- </dependency>
- <dependency>
- <groupId>com.pmease</groupId>
- <artifactId>commons.hibernate</artifactId>
- <version>1.0.30</version>
- </dependency>
- <dependency>
- <groupId>com.pmease</groupId>
- <artifactId>commons.shiro</artifactId>
- <version>1.0.30</version>
- </dependency>
- <dependency>
- <groupId>com.pmease</groupId>
- <artifactId>commons.markdown</artifactId>
- <version>1.0.0</version>
- </dependency>
- <dependency>
- <groupId>com.pmease</groupId>
- <artifactId>commons.lang</artifactId>
- <version>1.0.0</version>
- </dependency>
- </dependencies>
- <repositories>
- <repository>
- <id>pmeaseRepo</id>
- <name>PMEase Repository</name>
- <releases>
- <enabled>true</enabled>
- <updatePolicy>never</updatePolicy>
- <checksumPolicy>fail</checksumPolicy>
- </releases>
- <snapshots>
- <enabled>true</enabled>
- <updatePolicy>always</updatePolicy>
- <checksumPolicy>fail</checksumPolicy>
- </snapshots>
- <url>http://artifact.pmease.com/</url>
- </repository>
- </repositories>
- <properties>
- <moduleClass>com.pmease.gitplex.core.CoreModule</moduleClass>
- </properties>
-</project>
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>gitplex.core</artifactId>
+ <parent>
+ <groupId>com.pmease</groupId>
+ <artifactId>parent.general</artifactId>
+ <version>1.0.31</version>
+ </parent>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>com.pmease</groupId>
+ <artifactId>plugin.maven</artifactId>
+ </plugin>
+ <plugin>
+ <artifactId>maven-archetype-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <artifactId>maven-source-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.antlr</groupId>
+ <artifactId>antlr4-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>com.pmease</groupId>
+ <artifactId>commons.loader</artifactId>
+ <version>1.0.31</version>
+ </dependency>
+ <dependency>
+ <groupId>com.pmease</groupId>
+ <artifactId>commons.git</artifactId>
+ <version>1.0.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jetbrains.xodus</groupId>
+ <artifactId>xodus-entity-store</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.pmease</groupId>
+ <artifactId>commons.git</artifactId>
+ <version>1.0.0</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.pmease</groupId>
+ <artifactId>commons.jetty</artifactId>
+ <version>1.0.31</version>
+ </dependency>
+ <dependency>
+ <groupId>com.pmease</groupId>
+ <artifactId>commons.loader</artifactId>
+ <version>1.0.31</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.pmease</groupId>
+ <artifactId>commons.schedule</artifactId>
+ <version>1.0.0</version>
+ </dependency>
+ <dependency>
+ <groupId>com.pmease</groupId>
+ <artifactId>commons.hibernate</artifactId>
+ <version>1.0.30</version>
+ </dependency>
+ <dependency>
+ <groupId>com.pmease</groupId>
+ <artifactId>commons.shiro</artifactId>
+ <version>1.0.30</version>
+ </dependency>
+ <dependency>
+ <groupId>com.pmease</groupId>
+ <artifactId>commons.markdown</artifactId>
+ <version>1.0.0</version>
+ </dependency>
+ <dependency>
+ <groupId>com.pmease</groupId>
+ <artifactId>commons.lang</artifactId>
+ <version>1.0.0</version>
+ </dependency>
+ </dependencies>
+ <repositories>
+ <repository>
+ <id>pmeaseRepo</id>
+ <name>PMEase Repository</name>
+ <releases>
+ <enabled>true</enabled>
+ <updatePolicy>never</updatePolicy>
+ <checksumPolicy>fail</checksumPolicy>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ <updatePolicy>always</updatePolicy>
+ <checksumPolicy>fail</checksumPolicy>
+ </snapshots>
+ <url>http://artifact.pmease.com/</url>
+ </repository>
+ </repositories>
+ <properties>
+ <moduleClass>com.pmease.gitplex.core.CoreModule</moduleClass>
+ </properties>
+</project>
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/CoreModule.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/CoreModule.java
index 281470bd5b..52044a386c 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/CoreModule.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/CoreModule.java
@@ -70,8 +70,8 @@ import com.pmease.gitplex.core.model.ModelLocator;
import com.pmease.gitplex.core.security.SecurityRealm;
import com.pmease.gitplex.core.setting.SpecifiedGit;
import com.pmease.gitplex.core.setting.SystemGit;
-import com.pmease.gitplex.core.validation.RepositoryNameReservation;
-import com.pmease.gitplex.core.validation.UserNameReservation;
+import com.pmease.gitplex.core.util.validation.RepositoryNameReservation;
+import com.pmease.gitplex.core.util.validation.UserNameReservation;
/**
* NOTE: Do not forget to rename moduleClass property defined in the pom if you've renamed this class.
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/AbstractGateKeeper.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/AbstractGateKeeper.java
index f4b53d2e46..b6255faba8 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/AbstractGateKeeper.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/AbstractGateKeeper.java
@@ -4,6 +4,8 @@ import java.util.List;
import javax.annotation.Nullable;
+import org.eclipse.jgit.lib.ObjectId;
+
import com.google.common.base.Preconditions;
import com.pmease.commons.wicket.editable.annotation.Editable;
import com.pmease.gitplex.core.gatekeeper.checkresult.Blocking;
@@ -12,8 +14,8 @@ import com.pmease.gitplex.core.gatekeeper.checkresult.Failed;
import com.pmease.gitplex.core.gatekeeper.checkresult.Ignored;
import com.pmease.gitplex.core.gatekeeper.checkresult.Passed;
import com.pmease.gitplex.core.gatekeeper.checkresult.Pending;
-import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.Depot;
+import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.User;
@SuppressWarnings("serial")
@@ -47,21 +49,13 @@ public abstract class AbstractGateKeeper implements GateKeeper {
}
@Override
- public CheckResult checkCommit(User user, Depot depot, String branch, String commit) {
+ public CheckResult checkPush(User user, Depot depot, String refName, ObjectId oldCommit, ObjectId newCommit) {
if (isEnabled())
- return doCheckCommit(user, depot, branch, commit);
+ return doCheckPush(user, depot, refName, oldCommit, newCommit);
else
return ignored();
}
- @Override
- public CheckResult checkRef(User user, Depot depot, String refName) {
- if (isEnabled())
- return doCheckRef(user, depot, refName);
- else
- return ignored();
- }
-
/**
* Check gate keeper against specified pull request without considering enable flag. This is
* typically used to determine whether or not to accept a pull request.
@@ -99,23 +93,8 @@ public abstract class AbstractGateKeeper implements GateKeeper {
* @return
* result of the check
*/
- protected abstract CheckResult doCheckCommit(User user, Depot depot, String branch, String commit);
+ protected abstract CheckResult doCheckPush(User user, Depot depot, String refName, ObjectId oldCommit, ObjectId newCommit);
- /**
- * Check if specified user can create/delete specified reference in specified repository,
- * without considering enable flag.
- *
- * @param user
- * user to be checked
- * @param depot
- * repository to be checked
- * @param refName
- * reference name to be checked
- * @return
- * result of the check
- */
- protected abstract CheckResult doCheckRef(User user, Depot depot, String refName);
-
@Override
public final Object trim(@Nullable Object context) {
Preconditions.checkArgument(context instanceof Depot);
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/BranchProtection.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/BranchProtection.java
deleted file mode 100644
index ffd1636161..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/BranchProtection.java
+++ /dev/null
@@ -1,103 +0,0 @@
-package com.pmease.gitplex.core.gatekeeper;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.validation.Valid;
-import javax.validation.constraints.NotNull;
-import javax.validation.constraints.Size;
-
-import com.pmease.commons.wicket.editable.annotation.Editable;
-import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.editable.TeamChoice;
-import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
-import com.pmease.gitplex.core.gatekeeper.helper.branchselection.SpecifyTargetBranchesByNames;
-import com.pmease.gitplex.core.gatekeeper.helper.branchselection.TargetBranchSelection;
-import com.pmease.gitplex.core.manager.TeamManager;
-import com.pmease.gitplex.core.model.PullRequest;
-import com.pmease.gitplex.core.model.Depot;
-import com.pmease.gitplex.core.model.Team;
-import com.pmease.gitplex.core.model.User;
-
-@SuppressWarnings("serial")
-@Editable(order=100, icon="fa-lock", category=GateKeeper.CATEGORY_COMMONLY_USED,
- description="By default, users with write permission of the repository can push "
- + "code to all branches. Use this gate keeper to restrict write access of "
- + "specified branches to specified teams.")
-public class BranchProtection extends AbstractGateKeeper {
-
- private TargetBranchSelection branchSelection = new SpecifyTargetBranchesByNames();
-
- private List<Long> teamIds = new ArrayList<>();
-
- @Editable(name="Branches to Be Protected", order=100)
- @Valid
- @NotNull
- public TargetBranchSelection getBranchSelection() {
- return branchSelection;
- }
-
- public void setBranchSelection(TargetBranchSelection branchSelection) {
- this.branchSelection = branchSelection;
- }
-
- @Editable(name="Restrict Write Access to Below Teams", order=200)
- @TeamChoice(excludes={Team.ANONYMOUS, Team.LOGGEDIN})
- @Size(min=1, message="Please select teams")
- @NotNull
- public List<Long> getTeamIds() {
- return teamIds;
- }
-
- public void setTeamIds(List<Long> teamIds) {
- this.teamIds = teamIds;
- }
-
- @Override
- protected GateKeeper trim(Depot depot) {
- GitPlex.getInstance(TeamManager.class).trim(teamIds);
- if (teamIds.isEmpty())
- return null;
- else
- return this;
- }
-
- private GateKeeper getGateKeeper() {
- IfThenGateKeeper ifThenGate = new IfThenGateKeeper();
- ifThenGate.setIfGate(branchSelection.getGateKeeper());
-
- OrGateKeeper orGateKeeper = new OrGateKeeper();
- for (Long teamId: teamIds) {
- IfApprovedBySpecifiedTeam ifApprovedBySpecifiedTeam = new IfApprovedBySpecifiedTeam();
- ifApprovedBySpecifiedTeam.setTeamId(teamId);
- orGateKeeper.getGateKeepers().add(ifApprovedBySpecifiedTeam);
- IfSubmittedBySpecifiedTeam ifSubmittedBySpecifiedTeam = new IfSubmittedBySpecifiedTeam();
- ifSubmittedBySpecifiedTeam.setTeamId(teamId);
- orGateKeeper.getGateKeepers().add(ifSubmittedBySpecifiedTeam);
- }
- ifThenGate.setThenGate(orGateKeeper);
-
- return ifThenGate;
- }
-
- @Override
- protected CheckResult doCheckRequest(PullRequest request) {
- return getGateKeeper().checkRequest(request);
- }
-
- @Override
- protected CheckResult doCheckFile(User user, Depot depot, String branch, String file) {
- return getGateKeeper().checkFile(user, depot, branch, file);
- }
-
- @Override
- protected CheckResult doCheckCommit(User user, Depot depot, String branch, String commit) {
- return getGateKeeper().checkCommit(user, depot, branch, commit);
- }
-
- @Override
- protected CheckResult doCheckRef(User user, Depot depot, String refName) {
- return getGateKeeper().checkRef(user, depot, refName);
- }
-
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/BuildVerificationOfBranch.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/BuildVerificationOfBranch.java
deleted file mode 100644
index fe1a6389fc..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/BuildVerificationOfBranch.java
+++ /dev/null
@@ -1,110 +0,0 @@
-package com.pmease.gitplex.core.gatekeeper;
-
-import javax.validation.Valid;
-import javax.validation.constraints.Min;
-import javax.validation.constraints.NotNull;
-
-import com.pmease.commons.wicket.editable.annotation.Editable;
-import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
-import com.pmease.gitplex.core.gatekeeper.helper.branchselection.SpecifyTargetBranchesByNames;
-import com.pmease.gitplex.core.gatekeeper.helper.branchselection.TargetBranchSelection;
-import com.pmease.gitplex.core.model.PullRequest;
-import com.pmease.gitplex.core.model.Depot;
-import com.pmease.gitplex.core.model.User;
-
-@Editable(icon="fa-lock", order=300, category=GateKeeper.CATEGORY_COMMONLY_USED,
- description="This gate keeper can be used to configure certain branches to "
- + "only accept commits passing specified build criteria.")
-@SuppressWarnings("serial")
-public class BuildVerificationOfBranch extends AbstractGateKeeper {
-
- private TargetBranchSelection branchSelection = new SpecifyTargetBranchesByNames();
-
- private int buildCount = 1;
-
- private boolean checkMerged = true;
-
- private boolean blockMode = true;
-
- @Editable(name="Branches to Be Checked", order=50)
- @Valid
- @NotNull
- public TargetBranchSelection getBranchSelection() {
- return branchSelection;
- }
-
- public void setBranchSelection(TargetBranchSelection branchSelection) {
- this.branchSelection = branchSelection;
- }
-
- @Override
- protected GateKeeper trim(Depot depot) {
- return this;
- }
-
- @Editable(order=100, description="For each specified branch, this specified number of builds has to be "
- + "reported successful for this gate keeper to be passed. Normally this number represents "
- + "number of build configurations setting up to verify the branch.")
- @Min(1)
- public int getBuildCount() {
- return buildCount;
- }
-
- public void setBuildCount(int buildCount) {
- this.buildCount = buildCount;
- }
-
- @Editable(order=200, description="Enable this to check the merged commit instead of head commit of the "
- + "pull request.")
- public boolean isCheckMerged() {
- return checkMerged;
- }
-
- public void setCheckMerged(boolean checkMerged) {
- this.checkMerged = checkMerged;
- }
-
- @Editable(order=300, description="If this is checked, subsequent gate keepers will not be checked "
- + "while waiting for the build results. This can be used to only notify relevant voters "
- + "when the commit passes build.")
- public boolean isBlockMode() {
- return blockMode;
- }
-
- public void setBlockMode(boolean blockMode) {
- this.blockMode = blockMode;
- }
-
- private GateKeeper getGateKeeper() {
- IfThenGateKeeper ifThenGate = new IfThenGateKeeper();
- ifThenGate.setIfGate(branchSelection.getGateKeeper());
- IfVerifiedByBuilds thenGate = new IfVerifiedByBuilds();
- thenGate.setBlockMode(blockMode);
- thenGate.setLeastPassCount(buildCount);
- thenGate.setCheckIntegrated(checkMerged);
- ifThenGate.setThenGate(thenGate);
-
- return ifThenGate;
- }
-
- @Override
- protected CheckResult doCheckRequest(PullRequest request) {
- return getGateKeeper().checkRequest(request);
- }
-
- @Override
- protected CheckResult doCheckFile(User user, Depot depot, String branch, String file) {
- return getGateKeeper().checkFile(user, depot, branch, file);
- }
-
- @Override
- protected CheckResult doCheckCommit(User user, Depot depot, String branch, String commit) {
- return getGateKeeper().checkCommit(user, depot, branch, commit);
- }
-
- @Override
- protected CheckResult doCheckRef(User user, Depot depot, String refName) {
- return getGateKeeper().checkRef(user, depot, refName);
- }
-
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/CompositeGateKeeper.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/CompositeGateKeeper.java
index ed007de643..5b32b58754 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/CompositeGateKeeper.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/CompositeGateKeeper.java
@@ -1,8 +1,10 @@
package com.pmease.gitplex.core.gatekeeper;
+import org.eclipse.jgit.lib.ObjectId;
+
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
-import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.Depot;
+import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.User;
@SuppressWarnings("serial")
@@ -39,24 +41,13 @@ public abstract class CompositeGateKeeper extends AbstractGateKeeper {
}
@Override
- protected CheckResult doCheckCommit(final User user, final Depot depot, final String branch, final String commit) {
- return aggregate(new Checker() {
-
- @Override
- public CheckResult check(GateKeeper gateKeeper) {
- return gateKeeper.checkCommit(user, depot, branch, commit);
- }
-
- });
- }
-
- @Override
- protected CheckResult doCheckRef(final User user, final Depot depot, final String refName) {
+ protected CheckResult doCheckPush(final User user, final Depot depot, final String refName,
+ final ObjectId oldCommit, final ObjectId newCommit) {
return aggregate(new Checker() {
@Override
public CheckResult check(GateKeeper gateKeeper) {
- return gateKeeper.checkRef(user, depot, refName);
+ return gateKeeper.checkPush(user, depot, refName, oldCommit, newCommit);
}
});
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/DefaultGateKeeper.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/DefaultGateKeeper.java
index c958fe03ad..e26d7e83ef 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/DefaultGateKeeper.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/DefaultGateKeeper.java
@@ -1,9 +1,11 @@
package com.pmease.gitplex.core.gatekeeper;
+import org.eclipse.jgit.lib.ObjectId;
+
import com.pmease.commons.wicket.editable.annotation.Editable;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
-import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.Depot;
+import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.User;
@SuppressWarnings("serial")
@@ -26,12 +28,7 @@ public class DefaultGateKeeper extends AbstractGateKeeper {
}
@Override
- protected CheckResult doCheckCommit(User user, Depot depot, String branch, String commit) {
- return ignored();
- }
-
- @Override
- protected CheckResult doCheckRef(User user, Depot depot, String refName) {
+ protected CheckResult doCheckPush(User user, Depot depot, String refName, ObjectId oldCommit, ObjectId newCommit) {
return ignored();
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/DirectoryAndFileProtection.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/DirectoryAndFileProtection.java
deleted file mode 100644
index 8806fc4a96..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/DirectoryAndFileProtection.java
+++ /dev/null
@@ -1,129 +0,0 @@
-package com.pmease.gitplex.core.gatekeeper;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.annotation.Nullable;
-import javax.validation.Valid;
-import javax.validation.constraints.NotNull;
-import javax.validation.constraints.Size;
-
-import com.pmease.commons.wicket.editable.annotation.Editable;
-import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.editable.TeamChoice;
-import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
-import com.pmease.gitplex.core.gatekeeper.helper.branchselection.TargetBranchSelection;
-import com.pmease.gitplex.core.gatekeeper.helper.pathselection.SpecifyTargetPathsByDirectories;
-import com.pmease.gitplex.core.gatekeeper.helper.pathselection.TargetPathSelection;
-import com.pmease.gitplex.core.manager.TeamManager;
-import com.pmease.gitplex.core.model.PullRequest;
-import com.pmease.gitplex.core.model.Depot;
-import com.pmease.gitplex.core.model.Team;
-import com.pmease.gitplex.core.model.User;
-
-@SuppressWarnings("serial")
-@Editable(order=200, icon="fa-lock", category=GateKeeper.CATEGORY_COMMONLY_USED,
- description="By default, users with write permission of the repository can write to "
- + "all directories/files. Use this gate keeper to restrict write access of "
- + "certain directories/files of specified branches to certain teams. Note "
- + "that if branch is not specified, the restriction will apply to all branches.")
-public class DirectoryAndFileProtection extends AbstractGateKeeper {
-
- private TargetBranchSelection branchSelection;
-
- private TargetPathSelection pathSelection = new SpecifyTargetPathsByDirectories();
-
- private List<Long> teamIds = new ArrayList<>();
-
- @Editable(name="Applicable Branches (Optionally)", order=100)
- @Valid
- @Nullable
- public TargetBranchSelection getBranchSelection() {
- return branchSelection;
- }
-
- public void setBranchSelection(TargetBranchSelection branchSelection) {
- this.branchSelection = branchSelection;
- }
-
- @Editable(name="Directories or Files to Be Protected")
- @Valid
- @NotNull
- public TargetPathSelection getPathSelection() {
- return pathSelection;
- }
-
- public void setPathSelection(TargetPathSelection pathSelection) {
- this.pathSelection = pathSelection;
- }
-
- @Editable(name="Restrict Write Access to Below Teams", order=200)
- @TeamChoice(excludes={Team.ANONYMOUS, Team.LOGGEDIN})
- @Size(min=1)
- @NotNull
- public List<Long> getTeamIds() {
- return teamIds;
- }
-
- public void setTeamIds(List<Long> teamIds) {
- this.teamIds = teamIds;
- }
-
- @Override
- protected GateKeeper trim(Depot depot) {
- GitPlex.getInstance(TeamManager.class).trim(teamIds);
- if (teamIds.isEmpty())
- return null;
- else
- return this;
- }
-
- private GateKeeper getGateKeeper() {
- IfThenGateKeeper ifThenGate = new IfThenGateKeeper();
- ifThenGate.setIfGate(pathSelection.getGateKeeper());
- ifThenGate.setThenGate(getApprovalGate());
-
- if (branchSelection != null) {
- IfThenGateKeeper resultGate = new IfThenGateKeeper();
- resultGate.setIfGate(branchSelection.getGateKeeper());
- resultGate.setThenGate(ifThenGate);
- return resultGate;
- } else {
- return ifThenGate;
- }
- }
-
- private GateKeeper getApprovalGate() {
- OrGateKeeper approvalGate = new OrGateKeeper();
- for (Long teamId: teamIds) {
- IfApprovedBySpecifiedTeam ifApprovedBySpecifiedTeam = new IfApprovedBySpecifiedTeam();
- ifApprovedBySpecifiedTeam.setTeamId(teamId);
- approvalGate.getGateKeepers().add(ifApprovedBySpecifiedTeam);
- IfSubmittedBySpecifiedTeam ifSubmittedBySpecifiedTeam = new IfSubmittedBySpecifiedTeam();
- ifSubmittedBySpecifiedTeam.setTeamId(teamId);
- approvalGate.getGateKeepers().add(ifSubmittedBySpecifiedTeam);
- }
- return approvalGate;
- }
-
- @Override
- protected CheckResult doCheckRequest(PullRequest request) {
- return getGateKeeper().checkRequest(request);
- }
-
- @Override
- protected CheckResult doCheckFile(User user, Depot depot, String branch, String file) {
- return getGateKeeper().checkFile(user, depot, branch, file);
- }
-
- @Override
- protected CheckResult doCheckCommit(User user, Depot depot, String branch, String commit) {
- return getGateKeeper().checkCommit(user, depot, branch, commit);
- }
-
- @Override
- protected CheckResult doCheckRef(User user, Depot depot, String refName) {
- return getGateKeeper().checkRef(user, depot, refName);
- }
-
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/GateKeeper.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/GateKeeper.java
index 7f02910188..490526ea8f 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/GateKeeper.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/GateKeeper.java
@@ -2,19 +2,19 @@ package com.pmease.gitplex.core.gatekeeper;
import java.io.Serializable;
+import org.eclipse.jgit.lib.ObjectId;
+
import com.pmease.commons.util.trimmable.Trimmable;
import com.pmease.commons.wicket.editable.annotation.Editable;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
-import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.Depot;
+import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.User;
@Editable(name="Misc")
public interface GateKeeper extends Trimmable, Serializable {
- String CATEGORY_COMMONLY_USED = "Commonly Used";
-
- String CATEGROY_CHECK_BRANCH = "Check Destination Branch";
+ String CATEGROY_CHECK_REFS = "Check Target Refs";
String CATEGROY_CHECK_FILES = "Check Touched Files";
@@ -45,39 +45,27 @@ public interface GateKeeper extends Trimmable, Serializable {
* @param branch
* branch to be checked
* @param file
- * file to be checked, pass <tt>null</tt> to check any file
+ * file to be checked
* @return
* result of the check.
*/
CheckResult checkFile(User user, Depot depot, String branch, String file);
/**
- * Check if specified user can push specified commit to specified branch.
+ * Check if specified user can push specified commit to specified ref.
*
* @param user
* user to be checked
- * @param branch
- * branch to be checked
- * @param commit
- * commit to be checked
- * @return
- * result of the check
- */
- CheckResult checkCommit(User user, Depot depot, String branch, String commit);
-
- /**
- * Check if specified user can push specified reference to specified repository.
- *
- * @param user
- * user to be checked
- * @param depot
- * repository to be checked
* @param refName
- * reference name to be checked
+ * refName to be checked
+ * @param oldCommitHash
+ * old commit of the ref
+ * @param newCommitHash
+ * new commit of the ref
* @return
* result of the check
*/
- CheckResult checkRef(User user, Depot depot, String refName);
+ CheckResult checkPush(User user, Depot depot, String refName, ObjectId oldCommit, ObjectId newCommit);
boolean isEnabled();
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/HistoryProtection.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/HistoryProtection.java
deleted file mode 100644
index 3366b7fb5e..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/HistoryProtection.java
+++ /dev/null
@@ -1,65 +0,0 @@
-package com.pmease.gitplex.core.gatekeeper;
-
-import javax.validation.Valid;
-import javax.validation.constraints.NotNull;
-
-import com.pmease.commons.wicket.editable.annotation.Editable;
-import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
-import com.pmease.gitplex.core.gatekeeper.helper.branchselection.SpecifyTargetBranchesByNames;
-import com.pmease.gitplex.core.gatekeeper.helper.branchselection.TargetBranchSelection;
-import com.pmease.gitplex.core.model.PullRequest;
-import com.pmease.gitplex.core.model.Depot;
-import com.pmease.gitplex.core.model.User;
-
-@SuppressWarnings("serial")
-@Editable(order=400, icon="fa-lock", category=GateKeeper.CATEGORY_COMMONLY_USED, description=
- "Use this gate keeper to prevent history of certain branches from being rewritten via forced push.")
-public class HistoryProtection extends AbstractGateKeeper {
-
- private TargetBranchSelection branchSelection = new SpecifyTargetBranchesByNames();
-
- @Editable(name="Branches to Be Protected", order=100)
- @Valid
- @NotNull
- public TargetBranchSelection getBranchSelection() {
- return branchSelection;
- }
-
- public void setBranchSelection(TargetBranchSelection branchSelection) {
- this.branchSelection = branchSelection;
- }
-
- @Override
- protected GateKeeper trim(Depot depot) {
- return this;
- }
-
- private GateKeeper getGateKeeper() {
- IfThenGateKeeper ifThenGate = new IfThenGateKeeper();
- ifThenGate.setIfGate(branchSelection.getGateKeeper());
- ifThenGate.setThenGate(new IfPushWithoutRewritingHistory());
-
- return ifThenGate;
- }
-
- @Override
- protected CheckResult doCheckRequest(PullRequest request) {
- return getGateKeeper().checkRequest(request);
- }
-
- @Override
- protected CheckResult doCheckFile(User user, Depot depot, String branch, String file) {
- return getGateKeeper().checkFile(user, depot, branch, file);
- }
-
- @Override
- protected CheckResult doCheckCommit(User user, Depot depot, String branch, String commit) {
- return getGateKeeper().checkCommit(user, depot, branch, commit);
- }
-
- @Override
- protected CheckResult doCheckRef(User user, Depot depot, String refName) {
- return getGateKeeper().checkRef(user, depot, refName);
- }
-
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedByMajoritiesOfSpecifiedTeam.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedByMajoritiesOfSpecifiedTeam.java
index ca5c15c669..8af6acad8e 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedByMajoritiesOfSpecifiedTeam.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedByMajoritiesOfSpecifiedTeam.java
@@ -1,12 +1,14 @@
package com.pmease.gitplex.core.gatekeeper;
+import org.eclipse.jgit.lib.ObjectId;
+
import com.google.common.collect.Lists;
import com.pmease.commons.wicket.editable.annotation.Editable;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
import com.pmease.gitplex.core.gatekeeper.checkresult.Failed;
import com.pmease.gitplex.core.gatekeeper.checkresult.Passed;
-import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.Depot;
+import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.User;
@SuppressWarnings("serial")
@@ -47,20 +49,8 @@ public class IfApprovedByMajoritiesOfSpecifiedTeam extends TeamAwareGateKeeper {
}
@Override
- protected CheckResult doCheckCommit(User user, Depot depot, String branch, String commit) {
- CheckResult result = getGateKeeper().checkCommit(user, depot, branch, commit);
-
- if (result instanceof Passed)
- result = passed(Lists.newArrayList("Approved by majorities of team '" + getTeam().getName() + "'."));
- else if (result instanceof Failed)
- result = failed(Lists.newArrayList("Not approved by majorities of team '" + getTeam().getName() + "'."));
-
- return result;
- }
-
- @Override
- protected CheckResult doCheckRef(User user, Depot depot, String refName) {
- CheckResult result = getGateKeeper().checkRef(user, depot, refName);
+ protected CheckResult doCheckPush(User user, Depot depot, String refName, ObjectId oldCommit, ObjectId newCommit) {
+ CheckResult result = getGateKeeper().checkPush(user, depot, refName, oldCommit, newCommit);
if (result instanceof Passed)
result = passed(Lists.newArrayList("Approved by majorities of team '" + getTeam().getName() + "'."));
@@ -69,5 +59,4 @@ public class IfApprovedByMajoritiesOfSpecifiedTeam extends TeamAwareGateKeeper {
return result;
}
-
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedByRepositoryOwner.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedByRepositoryOwner.java
index 76eff3b183..6a7c1bd37a 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedByRepositoryOwner.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedByRepositoryOwner.java
@@ -1,11 +1,13 @@
package com.pmease.gitplex.core.gatekeeper;
+import org.eclipse.jgit.lib.ObjectId;
+
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.pmease.commons.wicket.editable.annotation.Editable;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
-import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.Depot;
+import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.Review;
import com.pmease.gitplex.core.model.User;
@@ -43,16 +45,8 @@ public class IfApprovedByRepositoryOwner extends AbstractGateKeeper {
}
@Override
- protected CheckResult doCheckCommit(User user, Depot depot, String branch, String commit) {
+ protected CheckResult doCheckPush(User user, Depot depot, String refName, ObjectId oldCommit, ObjectId newCommit) {
return check(user, depot);
}
- @Override
- protected CheckResult doCheckRef(User user, Depot depot, String refName) {
- if (user.equals(depot.getOwner()))
- return passed(Lists.newArrayList("Approved by repository owner."));
- else
- return failed(Lists.newArrayList("Not approved by repository owner."));
- }
-
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedByRepositoryWriters.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedByRepositoryWriters.java
index f8d6681962..7d481a6b73 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedByRepositoryWriters.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedByRepositoryWriters.java
@@ -4,11 +4,13 @@ import java.util.Collection;
import javax.validation.constraints.Min;
+import org.eclipse.jgit.lib.ObjectId;
+
import com.google.common.collect.Lists;
import com.pmease.commons.wicket.editable.annotation.Editable;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
-import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.Depot;
+import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.Review;
import com.pmease.gitplex.core.model.User;
import com.pmease.gitplex.core.permission.operation.DepotOperation;
@@ -89,12 +91,7 @@ public class IfApprovedByRepositoryWriters extends AbstractGateKeeper {
}
@Override
- protected CheckResult doCheckCommit(User user, Depot depot, String branch, String commit) {
- return check(user, depot);
- }
-
- @Override
- protected CheckResult doCheckRef(User user, Depot depot, String refName) {
+ protected CheckResult doCheckPush(User user, Depot depot, String refName, ObjectId oldCommit, ObjectId newCommit) {
return check(user, depot);
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedBySpecifiedTeam.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedBySpecifiedTeam.java
index f9bb902e56..7472a96efe 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedBySpecifiedTeam.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedBySpecifiedTeam.java
@@ -5,12 +5,14 @@ import java.util.HashSet;
import javax.validation.constraints.Min;
+import org.eclipse.jgit.lib.ObjectId;
+
import com.google.common.collect.Lists;
import com.pmease.commons.wicket.editable.annotation.Editable;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
+import com.pmease.gitplex.core.model.Depot;
import com.pmease.gitplex.core.model.Membership;
import com.pmease.gitplex.core.model.PullRequest;
-import com.pmease.gitplex.core.model.Depot;
import com.pmease.gitplex.core.model.Review;
import com.pmease.gitplex.core.model.User;
@@ -93,7 +95,7 @@ public class IfApprovedBySpecifiedTeam extends TeamAwareGateKeeper {
}
@Override
- protected CheckResult doCheckCommit(User user, Depot depot, String branch, String commit) {
+ protected CheckResult doCheckPush(User user, Depot depot, String refName, ObjectId oldCommit, ObjectId newCommit) {
return check(user);
}
@@ -102,9 +104,4 @@ public class IfApprovedBySpecifiedTeam extends TeamAwareGateKeeper {
return check(user);
}
- @Override
- protected CheckResult doCheckRef(User user, Depot depot, String refName) {
- return check(user);
- }
-
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedBySpecifiedUser.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedBySpecifiedUser.java
index 8c0258679f..d774b54f4c 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedBySpecifiedUser.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedBySpecifiedUser.java
@@ -2,17 +2,19 @@ package com.pmease.gitplex.core.gatekeeper;
import javax.validation.constraints.NotNull;
+import org.eclipse.jgit.lib.ObjectId;
+
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.pmease.commons.hibernate.dao.Dao;
import com.pmease.commons.wicket.editable.annotation.Editable;
import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.editable.UserChoice;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
-import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.Depot;
+import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.Review;
import com.pmease.gitplex.core.model.User;
+import com.pmease.gitplex.core.util.editable.UserChoice;
@SuppressWarnings("serial")
@Editable(order=200, icon="fa-user", category=GateKeeper.CATEGROY_CHECK_REVIEW, description=
@@ -71,12 +73,7 @@ public class IfApprovedBySpecifiedUser extends AbstractGateKeeper {
}
@Override
- protected CheckResult doCheckCommit(User user, Depot depot, String branch, String commit) {
- return check(user);
- }
-
- @Override
- protected CheckResult doCheckRef(User user, Depot depot, String refName) {
+ protected CheckResult doCheckPush(User user, Depot depot, String refName, ObjectId oldCommit, ObjectId newCommit) {
return check(user);
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfGetMinScoreFromSpecifiedTeam.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfGetMinScoreFromSpecifiedTeam.java
index 6f607dca4f..590f223a81 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfGetMinScoreFromSpecifiedTeam.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfGetMinScoreFromSpecifiedTeam.java
@@ -5,12 +5,14 @@ import java.util.HashSet;
import javax.validation.constraints.Min;
+import org.eclipse.jgit.lib.ObjectId;
+
import com.google.common.collect.Lists;
import com.pmease.commons.wicket.editable.annotation.Editable;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
+import com.pmease.gitplex.core.model.Depot;
import com.pmease.gitplex.core.model.Membership;
import com.pmease.gitplex.core.model.PullRequest;
-import com.pmease.gitplex.core.model.Depot;
import com.pmease.gitplex.core.model.Review;
import com.pmease.gitplex.core.model.User;
@@ -134,12 +136,7 @@ public class IfGetMinScoreFromSpecifiedTeam extends TeamAwareGateKeeper {
}
@Override
- protected CheckResult doCheckCommit(User user, Depot depot, String branch, String commit) {
- return check(user);
- }
-
- @Override
- protected CheckResult doCheckRef(User user, Depot depot, String refName) {
+ protected CheckResult doCheckPush(User user, Depot depot, String refName, ObjectId oldCommit, ObjectId newCommit) {
return check(user);
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfNotDisapprovedBySpecifiedTeam.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfNotDisapprovedBySpecifiedTeam.java
index 22b34e03d1..b250c6b00a 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfNotDisapprovedBySpecifiedTeam.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfNotDisapprovedBySpecifiedTeam.java
@@ -1,11 +1,13 @@
package com.pmease.gitplex.core.gatekeeper;
+import org.eclipse.jgit.lib.ObjectId;
+
import com.google.common.collect.Lists;
import com.pmease.commons.wicket.editable.annotation.Editable;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
+import com.pmease.gitplex.core.model.Depot;
import com.pmease.gitplex.core.model.Membership;
import com.pmease.gitplex.core.model.PullRequest;
-import com.pmease.gitplex.core.model.Depot;
import com.pmease.gitplex.core.model.Review;
import com.pmease.gitplex.core.model.User;
@@ -32,12 +34,7 @@ public class IfNotDisapprovedBySpecifiedTeam extends TeamAwareGateKeeper {
}
@Override
- protected CheckResult doCheckCommit(User user, Depot depot, String branch, String commit) {
- return passed(Lists.newArrayList("Not disapproved by anyone from team '" + getTeam().getName() + "'."));
- }
-
- @Override
- protected CheckResult doCheckRef(User user, Depot depot, String refName) {
+ protected CheckResult doCheckPush(User user, Depot depot, String refName, ObjectId oldCommit, ObjectId newCommit) {
return passed(Lists.newArrayList("Not disapproved by anyone from team '" + getTeam().getName() + "'."));
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfPushToSpecifiedRefs.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfPushToSpecifiedRefs.java
deleted file mode 100644
index 7ea6c37d91..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfPushToSpecifiedRefs.java
+++ /dev/null
@@ -1,60 +0,0 @@
-package com.pmease.gitplex.core.gatekeeper;
-
-import org.hibernate.validator.constraints.NotEmpty;
-
-import com.google.common.collect.Lists;
-import com.pmease.commons.git.GitUtils;
-import com.pmease.commons.util.pattern.WildcardUtils;
-import com.pmease.commons.wicket.editable.annotation.Editable;
-import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
-import com.pmease.gitplex.core.model.PullRequest;
-import com.pmease.gitplex.core.model.Depot;
-import com.pmease.gitplex.core.model.User;
-
-@Editable(order=200, icon="fa-ext fa-branch-pattern", description="This gate keeper will be passed if push to specified references.")
-@SuppressWarnings("serial")
-public class IfPushToSpecifiedRefs extends AbstractGateKeeper {
-
- private String refPatterns;
-
- @Editable(name="Specify Ref Patterns", description="Specify ref patterns to match. Below is some examples:"
- + "<ul>"
- + "<li><i>refs/tags/*</i>: matches all refs directly under refs/tags."
- + "<li><i>refs/tags/**</i>: matches all refs under refs/tags recursively."
- + "<li><i>refs/**</i>: matches all refs."
- + "<li><i>refs/**/1.0</i>: matches all refs whose last segment is 1.0."
- + "<li><i>-refs/tags/release/**, refs/tags/**</i>: matches all refs under refs/tags except those under refs/tags/release."
- + "</ul>")
- @NotEmpty
- public String getRefPatterns() {
- return refPatterns;
- }
-
- public void setRefPatterns(String refPatterns) {
- this.refPatterns = refPatterns;
- }
-
- @Override
- protected CheckResult doCheckRequest(PullRequest request) {
- return doCheckRef(request.getSubmitter(), request.getTargetDepot(), request.getTargetRef());
- }
-
- @Override
- protected CheckResult doCheckFile(User user, Depot depot, String branch, String file) {
- return doCheckRef(user, depot, GitUtils.branch2ref(branch));
- }
-
- @Override
- protected CheckResult doCheckCommit(User user, Depot depot, String branch, String commit) {
- return doCheckRef(user, depot, GitUtils.branch2ref(branch));
- }
-
- @Override
- protected CheckResult doCheckRef(User user, Depot depot, String refName) {
- if (WildcardUtils.matchPath(getRefPatterns(), refName))
- return passed(Lists.newArrayList("Target ref matches pattern '" + refPatterns + "'."));
- else
- return failed(Lists.newArrayList("Target ref does not match pattern '" + refPatterns + "'."));
- }
-
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfPushWithoutRewritingHistory.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfPushWithoutRewritingHistory.java
index 2c1bf24b45..2ecd9ca00c 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfPushWithoutRewritingHistory.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfPushWithoutRewritingHistory.java
@@ -1,11 +1,12 @@
package com.pmease.gitplex.core.gatekeeper;
+import org.eclipse.jgit.lib.ObjectId;
+
import com.google.common.collect.Lists;
-import com.pmease.commons.git.GitUtils;
import com.pmease.commons.wicket.editable.annotation.Editable;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
-import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.Depot;
+import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.User;
@Editable(order=100, icon="fa-ext fa-repo-lock", description="This gate keeper will be passed if the push "
@@ -26,16 +27,15 @@ public class IfPushWithoutRewritingHistory extends AbstractGateKeeper {
}
@Override
- protected CheckResult doCheckCommit(User user, Depot depot, String branch, String commit) {
- if (depot.isAncestor(GitUtils.branch2ref(branch), commit))
- return passed(Lists.newArrayList("Push operation does not rewrite history."));
- else
- return failed(Lists.newArrayList("Push operation rewrites history."));
- }
-
- @Override
- protected CheckResult doCheckRef(User user, Depot depot, String refName) {
- return ignored();
+ protected CheckResult doCheckPush(User user, Depot depot, String refName, ObjectId oldCommit, ObjectId newCommit) {
+ if (!oldCommit.equals(ObjectId.zeroId()) && !newCommit.equals(ObjectId.zeroId())) {
+ if (depot.isAncestor(oldCommit.name(), newCommit.name()))
+ return passed(Lists.newArrayList("Push operation does not rewrite history."));
+ else
+ return failed(Lists.newArrayList("Push operation rewrites history."));
+ } else {
+ return ignored();
+ }
}
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmitToSpecifiedBranchPatterns.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmitToSpecifiedBranchPatterns.java
deleted file mode 100644
index a7c057c1fd..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmitToSpecifiedBranchPatterns.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package com.pmease.gitplex.core.gatekeeper;
-
-import org.hibernate.validator.constraints.NotEmpty;
-
-import com.google.common.collect.Lists;
-import com.pmease.commons.git.GitUtils;
-import com.pmease.commons.util.pattern.WildcardUtils;
-import com.pmease.commons.wicket.editable.annotation.Editable;
-import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
-import com.pmease.gitplex.core.model.PullRequest;
-import com.pmease.gitplex.core.model.Depot;
-import com.pmease.gitplex.core.model.User;
-
-@SuppressWarnings("serial")
-@Editable(order=200, icon="fa-ext fa-branch-pattern", category=GateKeeper.CATEGROY_CHECK_BRANCH, description=
- "This gate keeper will be passed if the commit is submitted to specified branch pattern.")
-public class IfSubmitToSpecifiedBranchPatterns extends AbstractGateKeeper {
-
- private String branchPatterns;
-
- @Editable(name="Specify Branch Patterns", description="Specify branch patterns to match. Below is some examples:"
- + "<ul>"
- + "<li><i>dev/*</i>: matches all branches directly under dev."
- + "<li><i>dev/**</i>: matches all branches under dev recursively."
- + "<li><i>**</i>: matches all branches."
- + "<li><i>**/bugfix</i>: matches all branches whose last segment is bugfix."
- + "<li><i>-dev/**, **</i>: matches all branches except those under dev."
- + "</ul>")
- @NotEmpty
- public String getBranchPatterns() {
- return branchPatterns;
- }
-
- public void setBranchPatterns(String branchPatterns) {
- this.branchPatterns = branchPatterns;
- }
-
- private CheckResult checkBranch(Depot depot, String branch) {
- if (WildcardUtils.matchPath(getBranchPatterns(), branch))
- return passed(Lists.newArrayList("Target branch matches pattern '" + branchPatterns + "'."));
- else
- return failed(Lists.newArrayList("Target branch does not match pattern '" + branchPatterns + "'."));
- }
-
- @Override
- public CheckResult doCheckRequest(PullRequest request) {
- return checkBranch(request.getTargetDepot(), request.getTargetBranch());
- }
-
- @Override
- protected CheckResult doCheckFile(User user, Depot depot, String branch, String file) {
- return checkBranch(depot, branch);
- }
-
- @Override
- protected CheckResult doCheckCommit(User user, Depot depot, String branch, String commit) {
- return checkBranch(depot, branch);
- }
-
- @Override
- protected CheckResult doCheckRef(User user, Depot depot, String refName) {
- String branch = GitUtils.ref2branch(refName);
- if (branch != null)
- return checkBranch(depot, branch);
- else
- return ignored();
- }
-
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmitToSpecifiedBranches.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmitToSpecifiedBranches.java
deleted file mode 100644
index 0274526f81..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmitToSpecifiedBranches.java
+++ /dev/null
@@ -1,77 +0,0 @@
-package com.pmease.gitplex.core.gatekeeper;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.validation.constraints.NotNull;
-import javax.validation.constraints.Size;
-
-import org.apache.commons.lang3.StringUtils;
-
-import com.google.common.collect.Lists;
-import com.pmease.commons.git.GitUtils;
-import com.pmease.commons.wicket.editable.annotation.Editable;
-import com.pmease.gitplex.core.editable.BranchChoice;
-import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
-import com.pmease.gitplex.core.model.PullRequest;
-import com.pmease.gitplex.core.model.Depot;
-import com.pmease.gitplex.core.model.User;
-
-@SuppressWarnings("serial")
-@Editable(order=100, icon="fa-ext fa-branch", category=GateKeeper.CATEGROY_CHECK_BRANCH, description=
- "This gate keeper will be passed if the commit is submitted to specified branches.")
-public class IfSubmitToSpecifiedBranches extends AbstractGateKeeper {
-
- private List<String> branches = new ArrayList<>();
-
- @Editable(name="Branches", description="Select branches to check.")
- @BranchChoice
- @NotNull
- @Size(min=1)
- public List<String> getBranches() {
- return branches;
- }
-
- public void setBranches(List<String> branches) {
- this.branches = branches;
- }
-
- @Override
- public CheckResult doCheckRequest(PullRequest request) {
- return checkBranch(request.getTargetDepot(), request.getTargetBranch());
- }
-
- private CheckResult checkBranch(Depot depot, String branch) {
- if (branches.size() > 1) {
- if (branches.contains(branch))
- return passed(Lists.newArrayList("Target branch is one of '" + StringUtils.join(branches, ", ") + "'."));
- else
- return failed(Lists.newArrayList("Target branch is not any one of '" + StringUtils.join(branches, ", ") + "'."));
- } else {
- if (branches.contains(branch))
- return passed(Lists.newArrayList("Target branch is '" + branches.get(0) + "'."));
- else
- return failed(Lists.newArrayList("Target branch is not '" + branches.get(0) + "'."));
- }
- }
-
- @Override
- protected CheckResult doCheckFile(User user, Depot depot, String branch, String file) {
- return checkBranch(depot, branch);
- }
-
- @Override
- protected CheckResult doCheckCommit(User user, Depot depot, String branch, String commit) {
- return checkBranch(depot, branch);
- }
-
- @Override
- protected CheckResult doCheckRef(User user, Depot depot, String refName) {
- String branch = GitUtils.ref2branch(refName);
- if (branch != null)
- return checkBranch(depot, branch);
- else
- return ignored();
- }
-
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmitToSpecifiedRefs.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmitToSpecifiedRefs.java
new file mode 100644
index 0000000000..3ac9736dfb
--- /dev/null
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmitToSpecifiedRefs.java
@@ -0,0 +1,56 @@
+package com.pmease.gitplex.core.gatekeeper;
+
+import org.eclipse.jgit.lib.ObjectId;
+import org.hibernate.validator.constraints.NotEmpty;
+
+import com.google.common.collect.Lists;
+import com.pmease.commons.git.GitUtils;
+import com.pmease.commons.wicket.editable.annotation.Editable;
+import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
+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;
+
+@SuppressWarnings("serial")
+@Editable(order=100, icon="fa-ext fa-branch", category=GateKeeper.CATEGROY_CHECK_REFS, description=
+ "This gate keeper will be passed if the commit is submitted to specified refs.")
+public class IfSubmitToSpecifiedRefs extends AbstractGateKeeper {
+
+ private String refMatch;
+
+ @Editable(name="Refs", description="Specify refs to match")
+ @RefMatch
+ @NotEmpty
+ public String getRefMatch() {
+ return refMatch;
+ }
+
+ public void setRefMatch(String refMatch) {
+ this.refMatch = refMatch;
+ }
+
+ @Override
+ public CheckResult doCheckRequest(PullRequest request) {
+ return checkRef(request.getTargetDepot(), request.getTargetRef());
+ }
+
+ private CheckResult checkRef(Depot depot, String refName) {
+ if (RefMatchUtils.matches(refMatch, refName))
+ return passed(Lists.newArrayList("Target ref matches '" + refMatch + "'."));
+ else
+ return failed(Lists.newArrayList("Target ref does not match '" + refMatch + "'."));
+ }
+
+ @Override
+ protected CheckResult doCheckFile(User user, Depot depot, String branch, String file) {
+ return checkRef(depot, GitUtils.branch2ref(branch));
+ }
+
+ @Override
+ protected CheckResult doCheckPush(User user, Depot depot, String refName, ObjectId oldCommit, ObjectId newCommit) {
+ return checkRef(depot, refName);
+ }
+
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmitWithGerritStylePatch.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmitWithGerritStylePatch.java
index 119b555f7a..a77b4ca582 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmitWithGerritStylePatch.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmitWithGerritStylePatch.java
@@ -1,10 +1,12 @@
package com.pmease.gitplex.core.gatekeeper;
+import org.eclipse.jgit.lib.ObjectId;
+
import com.google.common.collect.Lists;
import com.pmease.commons.wicket.editable.annotation.Editable;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
-import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.Depot;
+import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.User;
@Editable(order=150, icon="fa-ext fa-file-diff", description="This gate keeper will be passed if the pull request "
@@ -30,12 +32,7 @@ public class IfSubmitWithGerritStylePatch extends AbstractGateKeeper {
}
@Override
- protected CheckResult doCheckCommit(User user, Depot depot, String branch, String commit) {
- return ignored();
- }
-
- @Override
- protected CheckResult doCheckRef(User user, Depot depot, String refName) {
+ protected CheckResult doCheckPush(User user, Depot depot, String refName, ObjectId oldCommit, ObjectId newCommit) {
return ignored();
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedByRepositoryOwner.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedByRepositoryOwner.java
index 46cde6a2a5..378c44d0a5 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedByRepositoryOwner.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedByRepositoryOwner.java
@@ -1,10 +1,12 @@
package com.pmease.gitplex.core.gatekeeper;
+import org.eclipse.jgit.lib.ObjectId;
+
import com.google.common.collect.Lists;
import com.pmease.commons.wicket.editable.annotation.Editable;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
-import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.Depot;
+import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.User;
@SuppressWarnings("serial")
@@ -30,12 +32,7 @@ public class IfSubmittedByRepositoryOwner extends AbstractGateKeeper {
}
@Override
- protected CheckResult doCheckCommit(User user, Depot depot, String branch, String commit) {
- return check(user, depot);
- }
-
- @Override
- protected CheckResult doCheckRef(User user, Depot depot, String refName) {
+ protected CheckResult doCheckPush(User user, Depot depot, String refName, ObjectId oldCommit, ObjectId newCommit) {
return check(user, depot);
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedByRepositoryWriter.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedByRepositoryWriter.java
index 49d101f27b..e19b9cdcbe 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedByRepositoryWriter.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedByRepositoryWriter.java
@@ -1,5 +1,7 @@
package com.pmease.gitplex.core.gatekeeper;
+import org.eclipse.jgit.lib.ObjectId;
+
import com.google.common.collect.Lists;
import com.pmease.commons.wicket.editable.annotation.Editable;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
@@ -32,12 +34,7 @@ public class IfSubmittedByRepositoryWriter extends AbstractGateKeeper {
}
@Override
- protected CheckResult doCheckCommit(User user, Depot depot, String branch, String commit) {
- return check(user, depot);
- }
-
- @Override
- protected CheckResult doCheckRef(User user, Depot depot, String refName) {
+ protected CheckResult doCheckPush(User user, Depot depot, String refName, ObjectId oldCommit, ObjectId newCommit) {
return check(user, depot);
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedBySpecifiedTeam.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedBySpecifiedTeam.java
index 44d220f503..02b640a291 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedBySpecifiedTeam.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedBySpecifiedTeam.java
@@ -1,11 +1,13 @@
package com.pmease.gitplex.core.gatekeeper;
+import org.eclipse.jgit.lib.ObjectId;
+
import com.google.common.collect.Lists;
import com.pmease.commons.wicket.editable.annotation.Editable;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
+import com.pmease.gitplex.core.model.Depot;
import com.pmease.gitplex.core.model.Membership;
import com.pmease.gitplex.core.model.PullRequest;
-import com.pmease.gitplex.core.model.Depot;
import com.pmease.gitplex.core.model.User;
@SuppressWarnings("serial")
@@ -29,7 +31,7 @@ public class IfSubmittedBySpecifiedTeam extends TeamAwareGateKeeper {
}
@Override
- protected CheckResult doCheckCommit(User user, Depot depot, String branch, String commit) {
+ protected CheckResult doCheckPush(User user, Depot depot, String refName, ObjectId oldCommit, ObjectId newCommit) {
return check(user);
}
@@ -38,9 +40,4 @@ public class IfSubmittedBySpecifiedTeam extends TeamAwareGateKeeper {
return check(user);
}
- @Override
- protected CheckResult doCheckRef(User user, Depot depot, String refName) {
- return check(user);
- }
-
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedBySpecifiedUser.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedBySpecifiedUser.java
index fca3890017..78f0a07322 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedBySpecifiedUser.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedBySpecifiedUser.java
@@ -2,15 +2,17 @@ package com.pmease.gitplex.core.gatekeeper;
import javax.validation.constraints.NotNull;
+import org.eclipse.jgit.lib.ObjectId;
+
import com.google.common.collect.Lists;
import com.pmease.commons.hibernate.dao.Dao;
import com.pmease.commons.wicket.editable.annotation.Editable;
import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.editable.UserChoice;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
-import com.pmease.gitplex.core.model.PullRequest;
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.UserChoice;
@SuppressWarnings("serial")
@Editable(order=200, icon="fa-user", category=GateKeeper.CATEGROY_CHECK_SUBMITTER, description=
@@ -57,12 +59,7 @@ public class IfSubmittedBySpecifiedUser extends AbstractGateKeeper {
}
@Override
- protected CheckResult doCheckCommit(User user, Depot depot, String branch, String commit) {
- return check(user);
- }
-
- @Override
- protected CheckResult doCheckRef(User user, Depot depot, String refName) {
+ protected CheckResult doCheckPush(User user, Depot depot, String refName, ObjectId oldCommit, ObjectId newCommit) {
return check(user);
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfTouchSpecifiedDirectories.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfTouchSpecifiedDirectories.java
deleted file mode 100644
index e842c7de66..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfTouchSpecifiedDirectories.java
+++ /dev/null
@@ -1,85 +0,0 @@
-package com.pmease.gitplex.core.gatekeeper;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.validation.constraints.NotNull;
-import javax.validation.constraints.Size;
-
-import org.eclipse.jgit.lib.FileMode;
-
-import com.google.common.collect.Lists;
-import com.pmease.commons.git.GitUtils;
-import com.pmease.commons.util.pattern.WildcardUtils;
-import com.pmease.commons.wicket.editable.annotation.Editable;
-import com.pmease.gitplex.core.editable.PathChoice;
-import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
-import com.pmease.gitplex.core.model.PullRequest;
-import com.pmease.gitplex.core.model.PullRequestUpdate;
-import com.pmease.gitplex.core.model.Depot;
-import com.pmease.gitplex.core.model.User;
-
-@SuppressWarnings("serial")
-@Editable(order=90, icon="fa-folder-open", category=GateKeeper.CATEGROY_CHECK_FILES, description=
- "This gate keeper will be passed if any commit files are under specified directories.")
-public class IfTouchSpecifiedDirectories extends AbstractGateKeeper {
-
- private List<String> directories = new ArrayList<>();
-
- @Editable(name="Specify Directories", description="Use comma to separate multiple directories.")
- @PathChoice(FileMode.TYPE_TREE)
- @NotNull
- @Size(min=1, message="At least one directory has to be specified.")
- public List<String> getDirectories() {
- return directories;
- }
-
- public void setDirectories(List<String> directories) {
- this.directories = directories;
- }
-
- @Override
- public CheckResult doCheckRequest(PullRequest request) {
- for (PullRequestUpdate update: request.getEffectiveUpdates()) {
- for (String file: update.getChangedFiles()) {
- for (String each: directories) {
- if (WildcardUtils.matchPath(each + "/**", file)) {
- request.setReferentialUpdate(update);
- return passed(Lists.newArrayList("Touched directory '" + each + "'."));
- }
- }
- }
- }
-
- return failed(Lists.newArrayList("Not touched directories '" + getDirectories() + "'."));
- }
-
- @Override
- protected CheckResult doCheckFile(User user, Depot depot, String branch, String file) {
- if (file == null)
- return passed(new ArrayList<String>());
- for (String each: directories) {
- if (WildcardUtils.matchPath(each + "/**", file))
- return passed(Lists.newArrayList("Touched directory '" + each + "'."));
- }
- return failed(Lists.newArrayList("Not touched directories '" + getDirectories() + "'."));
- }
-
- @Override
- protected CheckResult doCheckCommit(User user, Depot depot, String branch, String commit) {
- for (String file: depot.git().listChangedFiles(depot.getObjectId(GitUtils.branch2ref(branch)).name(), commit, null)) {
- for (String each: directories) {
- if (WildcardUtils.matchPath(each + "/**", file))
- return passed(Lists.newArrayList("Touched directory '" + each + "'."));
- }
- }
-
- return failed(Lists.newArrayList("Not touched directories '" + getDirectories() + "'."));
- }
-
- @Override
- protected CheckResult doCheckRef(User user, Depot depot, String refName) {
- return ignored();
- }
-
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfTouchSpecifiedFilePatterns.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfTouchSpecifiedFilePatterns.java
index 431af708b0..afd7590d35 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfTouchSpecifiedFilePatterns.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfTouchSpecifiedFilePatterns.java
@@ -1,17 +1,15 @@
package com.pmease.gitplex.core.gatekeeper;
-import java.util.ArrayList;
-
+import org.eclipse.jgit.lib.ObjectId;
import org.hibernate.validator.constraints.NotEmpty;
import com.google.common.collect.Lists;
-import com.pmease.commons.git.GitUtils;
import com.pmease.commons.util.pattern.WildcardUtils;
import com.pmease.commons.wicket.editable.annotation.Editable;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
+import com.pmease.gitplex.core.model.Depot;
import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.PullRequestUpdate;
-import com.pmease.gitplex.core.model.Depot;
import com.pmease.gitplex.core.model.User;
@SuppressWarnings("serial")
@@ -47,27 +45,24 @@ public class IfTouchSpecifiedFilePatterns extends AbstractGateKeeper {
@Override
protected CheckResult doCheckFile(User user, Depot depot, String branch, String file) {
- if (file == null)
- return passed(new ArrayList<String>());
- else if (WildcardUtils.matchPath(filePatterns, file))
+ if (WildcardUtils.matchPath(filePatterns, file))
return passed(Lists.newArrayList("Touched files match patterns '" + filePatterns + "'."));
else
return failed(Lists.newArrayList("No touched files match patterns '" + filePatterns + "'."));
}
@Override
- protected CheckResult doCheckCommit(User user, Depot depot, String branch, String commit) {
- for (String file: depot.git().listChangedFiles(depot.getObjectId(GitUtils.branch2ref(branch)).name(), commit, null)) {
- if (WildcardUtils.matchPath(filePatterns, file))
- return passed(Lists.newArrayList("Touched files match patterns '" + filePatterns + "'."));
+ 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 (WildcardUtils.matchPath(filePatterns, file))
+ return passed(Lists.newArrayList("Touched files match patterns '" + filePatterns + "'."));
+ }
+
+ return failed(Lists.newArrayList("No touched files match patterns '" + filePatterns + "'."));
+ } else {
+ return ignored();
}
-
- return failed(Lists.newArrayList("No touched files match patterns '" + filePatterns + "'."));
- }
-
- @Override
- protected CheckResult doCheckRef(User user, Depot depot, String refName) {
- return ignored();
}
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfVerifiedByBuilds.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfVerifiedByBuilds.java
index 021d39e9a9..c3b01ca731 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfVerifiedByBuilds.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfVerifiedByBuilds.java
@@ -4,14 +4,16 @@ import java.util.Collection;
import javax.validation.constraints.Min;
+import org.eclipse.jgit.lib.ObjectId;
+
import com.google.common.collect.Lists;
import com.pmease.commons.wicket.editable.annotation.Editable;
import com.pmease.gitplex.core.GitPlex;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
import com.pmease.gitplex.core.manager.VerificationManager;
+import com.pmease.gitplex.core.model.Depot;
import com.pmease.gitplex.core.model.IntegrationPreview;
import com.pmease.gitplex.core.model.PullRequest;
-import com.pmease.gitplex.core.model.Depot;
import com.pmease.gitplex.core.model.User;
import com.pmease.gitplex.core.model.Verification;
@@ -123,17 +125,16 @@ public class IfVerifiedByBuilds extends AbstractGateKeeper {
}
@Override
- protected CheckResult doCheckCommit(User user, Depot depot, String branch, String commit) {
- if (blockMode) {
- return blocking(Lists.newArrayList("Has to be verified by builds."));
+ protected CheckResult doCheckPush(User user, Depot depot, String refName, ObjectId oldCommit, ObjectId newCommit) {
+ if (!newCommit.equals(ObjectId.zeroId())) {
+ if (blockMode) {
+ return blocking(Lists.newArrayList("Has to be verified by builds."));
+ } else {
+ return blocking(Lists.newArrayList("Has to be verified by builds."));
+ }
} else {
- return blocking(Lists.newArrayList("Has to be verified by builds."));
+ return ignored();
}
}
- @Override
- protected CheckResult doCheckRef(User user, Depot depot, String refName) {
- return ignored();
- }
-
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/TeamAwareGateKeeper.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/TeamAwareGateKeeper.java
index 3f88834510..f5eb802149 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/TeamAwareGateKeeper.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/TeamAwareGateKeeper.java
@@ -5,9 +5,9 @@ import javax.validation.constraints.NotNull;
import com.pmease.commons.hibernate.dao.Dao;
import com.pmease.commons.wicket.editable.annotation.Editable;
import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.editable.TeamChoice;
import com.pmease.gitplex.core.model.Depot;
import com.pmease.gitplex.core.model.Team;
+import com.pmease.gitplex.core.util.editable.TeamChoice;
@SuppressWarnings("serial")
public abstract class TeamAwareGateKeeper extends AbstractGateKeeper {
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/helper/branchselection/SpecifyTargetBranchesByNames.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/helper/branchselection/SpecifyTargetBranchesByNames.java
deleted file mode 100644
index 46cf697f38..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/helper/branchselection/SpecifyTargetBranchesByNames.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package com.pmease.gitplex.core.gatekeeper.helper.branchselection;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.validation.constraints.NotNull;
-import javax.validation.constraints.Size;
-
-import com.pmease.commons.wicket.editable.annotation.Editable;
-import com.pmease.commons.wicket.editable.annotation.OmitName;
-import com.pmease.gitplex.core.editable.BranchChoice;
-import com.pmease.gitplex.core.gatekeeper.GateKeeper;
-import com.pmease.gitplex.core.gatekeeper.IfSubmitToSpecifiedBranches;
-
-@SuppressWarnings("serial")
-@Editable(name="Specify Branch Names", order=100)
-public class SpecifyTargetBranchesByNames implements TargetBranchSelection {
-
- private List<String> branches = new ArrayList<>();
-
- @Editable(name="Branch Names")
- @BranchChoice
- @OmitName
- @NotNull
- @Size(min=1, message="At least one branch has to be selected.")
- public List<String> getBranches() {
- return branches;
- }
-
- public void setBranches(List<String> branches) {
- this.branches = branches;
- }
-
- @Override
- public GateKeeper getGateKeeper() {
- IfSubmitToSpecifiedBranches gateKeeper = new IfSubmitToSpecifiedBranches();
- gateKeeper.getBranches().addAll(branches);
- return gateKeeper;
- }
-
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/helper/branchselection/SpecifyTargetBranchesByPatterns.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/helper/branchselection/SpecifyTargetBranchesByPatterns.java
deleted file mode 100644
index 37ba9d22ea..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/helper/branchselection/SpecifyTargetBranchesByPatterns.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package com.pmease.gitplex.core.gatekeeper.helper.branchselection;
-
-import org.hibernate.validator.constraints.NotEmpty;
-
-import com.pmease.commons.wicket.editable.annotation.Editable;
-import com.pmease.commons.wicket.editable.annotation.OmitName;
-import com.pmease.gitplex.core.gatekeeper.GateKeeper;
-import com.pmease.gitplex.core.gatekeeper.IfSubmitToSpecifiedBranchPatterns;
-
-@SuppressWarnings("serial")
-@Editable(order=200, name="Specify Branch Patterns")
-public class SpecifyTargetBranchesByPatterns implements TargetBranchSelection {
-
- private String branchPatterns;
-
- @Editable(name="Branch Patterns", description=
- "Patterns should be specified following the <a href='http://wiki.pmease.com/display/gp/Pattern+Set'>pattern set</a> format.")
- @OmitName
- @NotEmpty
- public String getBranchPatterns() {
- return branchPatterns;
- }
-
- public void setBranchPatterns(String branchPatterns) {
- this.branchPatterns = branchPatterns;
- }
-
- @Override
- public GateKeeper getGateKeeper() {
- IfSubmitToSpecifiedBranchPatterns gateKeeper = new IfSubmitToSpecifiedBranchPatterns();
- gateKeeper.setBranchPatterns(branchPatterns);
- return gateKeeper;
- }
-
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/helper/branchselection/TargetBranchSelection.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/helper/branchselection/TargetBranchSelection.java
deleted file mode 100644
index 0a2a4c2224..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/helper/branchselection/TargetBranchSelection.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package com.pmease.gitplex.core.gatekeeper.helper.branchselection;
-
-import java.io.Serializable;
-
-import com.pmease.commons.wicket.editable.annotation.Editable;
-import com.pmease.gitplex.core.gatekeeper.GateKeeper;
-
-@Editable
-public interface TargetBranchSelection extends Serializable {
-
- GateKeeper getGateKeeper();
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/helper/pathselection/SpecifyTargetPathsByDirectories.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/helper/pathselection/SpecifyTargetPathsByDirectories.java
deleted file mode 100644
index df24b589b0..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/helper/pathselection/SpecifyTargetPathsByDirectories.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package com.pmease.gitplex.core.gatekeeper.helper.pathselection;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.validation.constraints.NotNull;
-import javax.validation.constraints.Size;
-
-import org.eclipse.jgit.lib.FileMode;
-
-import com.pmease.commons.wicket.editable.annotation.Editable;
-import com.pmease.commons.wicket.editable.annotation.OmitName;
-import com.pmease.gitplex.core.editable.PathChoice;
-import com.pmease.gitplex.core.gatekeeper.GateKeeper;
-import com.pmease.gitplex.core.gatekeeper.IfTouchSpecifiedDirectories;
-
-@SuppressWarnings("serial")
-@Editable(name="Specify Directory Paths", order=100)
-public class SpecifyTargetPathsByDirectories implements TargetPathSelection {
-
- private List<String> directories = new ArrayList<>();
-
- @Editable(name="Directories", description="Use comma to separate multiple directories.")
- @PathChoice(FileMode.TYPE_TREE)
- @NotNull
- @Size(min=1, message="At least one directory has to be specified.")
- @OmitName
- public List<String> getDirectories() {
- return directories;
- }
-
- public void setDirectories(List<String> directories) {
- this.directories = directories;
- }
-
- @Override
- public GateKeeper getGateKeeper() {
- IfTouchSpecifiedDirectories gateKeeper = new IfTouchSpecifiedDirectories();
- gateKeeper.setDirectories(directories);
- return gateKeeper;
- }
-
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/helper/pathselection/SpecifyTargetPathsByPatterns.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/helper/pathselection/SpecifyTargetPathsByPatterns.java
deleted file mode 100644
index 226c8514ee..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/helper/pathselection/SpecifyTargetPathsByPatterns.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package com.pmease.gitplex.core.gatekeeper.helper.pathselection;
-
-import org.hibernate.validator.constraints.NotEmpty;
-
-import com.pmease.commons.wicket.editable.annotation.Editable;
-import com.pmease.commons.wicket.editable.annotation.OmitName;
-import com.pmease.gitplex.core.gatekeeper.GateKeeper;
-import com.pmease.gitplex.core.gatekeeper.IfTouchSpecifiedFilePatterns;
-
-@SuppressWarnings("serial")
-@Editable(name="Specify Directory or File Patterns", order=200)
-public class SpecifyTargetPathsByPatterns implements TargetPathSelection {
-
- private String filePatterns;
-
- @Editable(name="File Patterns", description="Specify file patterns to match. Below is some examples:"
- + "<ul>"
- + "<li><i>src/*</i>: matches all files directly under src."
- + "<li><i>src/**</i>: matches all files under src recursively."
- + "<li><i>**</i>: matches all files."
- + "<li><i>**/*.c, **/*.java</i>: matches all C and Java files."
- + "<li><i>-src/**, **</i>: matches all files except those under src."
- + "</ul>")
- @OmitName
- @NotEmpty
- public String getFilePatterns() {
- return filePatterns;
- }
-
- public void setFilePatterns(String filePatterns) {
- this.filePatterns = filePatterns;
- }
-
- @Override
- public GateKeeper getGateKeeper() {
- IfTouchSpecifiedFilePatterns gateKeeper = new IfTouchSpecifiedFilePatterns();
- gateKeeper.setFilePatterns(filePatterns);
- return gateKeeper;
- }
-
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/helper/pathselection/TargetPathSelection.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/helper/pathselection/TargetPathSelection.java
deleted file mode 100644
index 9e24957105..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/helper/pathselection/TargetPathSelection.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.pmease.gitplex.core.gatekeeper.helper.pathselection;
-
-import java.io.Serializable;
-
-import com.pmease.commons.wicket.editable.annotation.Editable;
-import com.pmease.gitplex.core.gatekeeper.GateKeeper;
-
-@Editable
-public interface TargetPathSelection extends Serializable {
- GateKeeper getGateKeeper();
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/hookcallback/GitPostReceiveCallback.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/hookcallback/GitPostReceiveCallback.java
index c16eb99b5f..a4e9d91963 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/hookcallback/GitPostReceiveCallback.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/hookcallback/GitPostReceiveCallback.java
@@ -19,7 +19,6 @@ import org.apache.shiro.SecurityUtils;
import org.eclipse.jgit.lib.ObjectId;
import com.google.common.base.Preconditions;
-import com.pmease.commons.git.GitUtils;
import com.pmease.commons.hibernate.dao.Dao;
import com.pmease.commons.util.StringUtils;
import com.pmease.gitplex.core.listeners.RefListener;
@@ -82,7 +81,7 @@ public class GitPostReceiveCallback extends HttpServlet {
String field = fields.get(pos);
// String oldCommitHash = StringUtils.reverse(field.substring(0, 40));
- if (!newCommitHash.equals(GitUtils.NULL_SHA1)) {
+ if (!newCommitHash.equals(ObjectId.zeroId().name())) {
depot.cacheObjectId(refName, ObjectId.fromString(newCommitHash));
} else {
newCommitHash = null;
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/hookcallback/GitUpdateCallback.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/hookcallback/GitUpdateCallback.java
index 80b25a497c..9b4f36b2a5 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/hookcallback/GitUpdateCallback.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/hookcallback/GitUpdateCallback.java
@@ -15,6 +15,7 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.apache.shiro.SecurityUtils;
+import org.eclipse.jgit.lib.ObjectId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -61,18 +62,6 @@ public class GitUpdateCallback extends HttpServlet {
output.writeLine();
}
- private void checkRef(User user, Depot depot, String refName, Output output) {
- GateKeeper gateKeeper = depot.getGateKeeper();
- CheckResult checkResult = gateKeeper.checkRef(user, depot, refName);
-
- if (!(checkResult instanceof Passed)) {
- List<String> messages = new ArrayList<>();
- for (String each: checkResult.getReasons())
- messages.add(each);
- error(output, messages.toArray(new String[messages.size()]));
- }
- }
-
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String clientIp = request.getHeader("X-Forwarded-For");
@@ -98,8 +87,8 @@ public class GitUpdateCallback extends HttpServlet {
fields = StringUtils.splitAndTrim(new String(baos.toByteArray()), " ");
String refName = fields.get(0);
- String oldCommitHash = fields.get(1);
- String newCommitHash = fields.get(2);
+ ObjectId oldCommit = ObjectId.fromString(fields.get(1));
+ ObjectId newCommit = ObjectId.fromString(fields.get(2));
logger.debug("Executing update hook against reference {}...", refName);
@@ -110,40 +99,21 @@ public class GitUpdateCallback extends HttpServlet {
if (!user.asSubject().isPermitted(ObjectPermission.ofDepotAdmin(depot)))
error(output, "Only repository administrators can update gitplex refs.");
} else {
- String branch = GitUtils.ref2branch(refName);
- if (branch != null) { // push branch ref
- if (oldCommitHash.equals(GitUtils.NULL_SHA1)) { // create new branch
- checkRef(user, depot, refName, output);
- } else {
- if (newCommitHash.equals(GitUtils.NULL_SHA1)) { // deleting a branch ref
- GateKeeper gateKeeper = depot.getGateKeeper();
- CheckResult checkResult = gateKeeper.checkFile(user, depot, branch, null);
-
- if (!(checkResult instanceof Passed)) {
- List<String> messages = new ArrayList<>();
- for (String each: checkResult.getReasons())
- messages.add(each);
- error(output, messages.toArray(new String[messages.size()]));
- }
- } else {
- GateKeeper gateKeeper = depot.getGateKeeper();
- CheckResult checkResult = gateKeeper.checkCommit(user, depot, branch, newCommitHash);
-
- if (!(checkResult instanceof Passed)) {
- List<String> messages = new ArrayList<>();
- for (String each: checkResult.getReasons())
- messages.add(each);
- if (!newCommitHash.equals(GitUtils.NULL_SHA1) && !(checkResult instanceof Failed)) {
- messages.add("");
- messages.add("----------------------------------------------------");
- messages.add("You may submit a pull request instead.");
- }
- error(output, messages.toArray(new String[messages.size()]));
- }
- }
+ GateKeeper gateKeeper = depot.getGateKeeper();
+ CheckResult checkResult = gateKeeper.checkPush(user, depot, refName, oldCommit, newCommit);
+ if (!(checkResult instanceof Passed)) {
+ List<String> messages = new ArrayList<>();
+ for (String each: checkResult.getReasons())
+ messages.add(each);
+ if (GitUtils.ref2branch(refName) != null
+ && !oldCommit.equals(ObjectId.zeroId())
+ && !newCommit.equals(ObjectId.zeroId())
+ && !(checkResult instanceof Failed)) {
+ messages.add("");
+ messages.add("----------------------------------------------------");
+ messages.add("You may submit a pull request instead.");
}
- } else { // push non-branch refs
- checkRef(user, depot, refName, output);
+ error(output, messages.toArray(new String[messages.size()]));
}
}
}
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 195f27d44f..852681c773 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
@@ -690,14 +690,14 @@ public class DefaultPullRequestManager implements PullRequestManager, DepotListe
public void onRefUpdate(Depot depot, String refName, @Nullable String newCommitHash) {
final String branch = GitUtils.ref2branch(refName);
if (branch != null) {
- DepotAndBranch repoAndBranch = new DepotAndBranch(depot, branch);
+ DepotAndBranch depotAndBranch = new DepotAndBranch(depot, branch);
if (newCommitHash != null) {
/**
* Source branch update is key to the logic as it has to create
* pull request update, so we should not postpone it to be executed
* in a executor service like target branch update below
*/
- Criterion criterion = Restrictions.and(ofOpen(), ofSource(repoAndBranch));
+ Criterion criterion = Restrictions.and(ofOpen(), ofSource(depotAndBranch));
for (PullRequest request: dao.query(EntityCriteria.of(PullRequest.class).add(criterion))) {
if (depot.getObjectId(request.getBaseCommitHash(), false) != null)
onSourceBranchUpdate(request, true);
@@ -714,8 +714,8 @@ public class DefaultPullRequestManager implements PullRequestManager, DepotListe
@Override
public void run() {
- DepotAndBranch repoAndBranch = new DepotAndBranch(repoId, branch);
- Criterion criterion = Restrictions.and(ofOpen(), ofTarget(repoAndBranch));
+ DepotAndBranch depotAndBranch = new DepotAndBranch(repoId, branch);
+ Criterion criterion = Restrictions.and(ofOpen(), ofTarget(depotAndBranch));
for (PullRequest request: dao.query(EntityCriteria.of(PullRequest.class).add(criterion))) {
if (request.getSourceDepot().getObjectId(request.getBaseCommitHash(), false) != null)
onTargetBranchUpdate(request);
@@ -732,7 +732,7 @@ public class DefaultPullRequestManager implements PullRequestManager, DepotListe
} else {
Criterion criterion = Restrictions.and(
ofOpen(),
- Restrictions.or(ofSource(repoAndBranch), ofTarget(repoAndBranch)));
+ Restrictions.or(ofSource(depotAndBranch), ofTarget(depotAndBranch)));
for (PullRequest request: dao.query(EntityCriteria.of(PullRequest.class).add(criterion))) {
if (request.getTargetDepot().equals(depot) && request.getTargetBranch().equals(branch))
discard(request, "Target branch is deleted.");
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/CommentPersistListener.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/CommentPersistListener.java
index 16d9f33c62..b0aad3a645 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/CommentPersistListener.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/CommentPersistListener.java
@@ -1,128 +1,128 @@
-package com.pmease.gitplex.core.model;
-
-import java.io.Serializable;
-import java.util.Collection;
-import java.util.Set;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
-import org.hibernate.CallbackException;
-import org.hibernate.criterion.Restrictions;
-import org.hibernate.type.Type;
-
-import com.pmease.commons.hibernate.HibernateListener;
-import com.pmease.commons.hibernate.dao.Dao;
-import com.pmease.commons.hibernate.dao.EntityCriteria;
-import com.pmease.commons.markdown.MarkdownManager;
-import com.pmease.gitplex.core.listeners.PullRequestListener;
-import com.pmease.gitplex.core.manager.UserManager;
-import com.pmease.gitplex.core.markdown.MentionParser;
-import com.pmease.gitplex.core.markdown.PullRequestParser;
-
-@Singleton
-public class CommentPersistListener implements HibernateListener {
-
- private final MarkdownManager markdownManager;
-
- private final Dao dao;
-
- private final UserManager userManager;
-
- private final Set<PullRequestListener> pullRequestListeners;
-
- @Inject
- public CommentPersistListener(MarkdownManager markdownManager, Dao dao,
- UserManager userManager, Set<PullRequestListener> pullRequestListeners) {
- this.markdownManager = markdownManager;
- this.dao = dao;
- this.userManager = userManager;
- this.pullRequestListeners = pullRequestListeners;
- }
-
- @Override
- public boolean onLoad(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)
- throws CallbackException {
- return false;
- }
-
- @Override
- public boolean onFlushDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState,
- String[] propertyNames, Type[] types) throws CallbackException {
- if (entity instanceof Comment) {
- Comment comment = (Comment) entity;
- for (int i=0; i<propertyNames.length; i++) {
- if (propertyNames[i].equals("content")) {
- String content = (String) currentState[i];
- String prevContent = (String) previousState[i];
- if (!content.equals(prevContent)) {
- String html = markdownManager.parse(content);
- String prevHtml = markdownManager.parse(prevContent);
-
- MentionParser mentionParser = new MentionParser();
- Collection<User> mentions = mentionParser.parseMentions(html);
-
- mentions.removeAll(mentionParser.parseMentions(prevHtml));
- for (User user: mentions) {
- for (PullRequestListener listener: pullRequestListeners)
- listener.onMentioned((Comment) entity, user);
- }
-
- Collection<PullRequest> requests = new PullRequestParser().parseRequests(html);
- for (PullRequest request: requests)
- saveReference(request, comment.getRequest());
- }
- break;
- }
- }
- }
- return false;
- }
-
- @Override
- public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)
- throws CallbackException {
- if (entity instanceof Comment) {
- Comment comment = (Comment) entity;
- for (int i=0; i<propertyNames.length; i++) {
- if (propertyNames[i].equals("content")) {
- String content = (String) state[i];
- String html = markdownManager.parse(content);
- Collection<User> mentions = new MentionParser().parseMentions(html);
- for (User user: mentions) {
- for (PullRequestListener listener: pullRequestListeners)
- listener.onMentioned((Comment) entity, user);
- }
-
- Collection<PullRequest> requests = new PullRequestParser().parseRequests(html);
- for (PullRequest request: requests)
- saveReference(request, comment.getRequest());
-
- break;
- }
- }
- }
- return false;
- }
-
- private void saveReference(PullRequest referenced, PullRequest referencedBy) {
- if (!referenced.equals(referencedBy)) {
- EntityCriteria<PullRequestReference> criteria = EntityCriteria.of(PullRequestReference.class);
- criteria.add(Restrictions.eq("referenced", referenced));
- criteria.add(Restrictions.eq("referencedBy", referencedBy));
- if (dao.find(criteria) == null) {
- PullRequestReference reference = new PullRequestReference();
- reference.setReferencedBy(referencedBy);
- reference.setReferenced(referenced);
- reference.setUser(userManager.getCurrent());
- dao.persist(reference);
- }
- }
- }
-
- @Override
- public void onDelete(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)
- throws CallbackException {
- }
-
-}
+package com.pmease.gitplex.core.model;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.Set;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.hibernate.CallbackException;
+import org.hibernate.criterion.Restrictions;
+import org.hibernate.type.Type;
+
+import com.pmease.commons.hibernate.HibernateListener;
+import com.pmease.commons.hibernate.dao.Dao;
+import com.pmease.commons.hibernate.dao.EntityCriteria;
+import com.pmease.commons.markdown.MarkdownManager;
+import com.pmease.gitplex.core.listeners.PullRequestListener;
+import com.pmease.gitplex.core.manager.UserManager;
+import com.pmease.gitplex.core.util.markdown.MentionParser;
+import com.pmease.gitplex.core.util.markdown.PullRequestParser;
+
+@Singleton
+public class CommentPersistListener implements HibernateListener {
+
+ private final MarkdownManager markdownManager;
+
+ private final Dao dao;
+
+ private final UserManager userManager;
+
+ private final Set<PullRequestListener> pullRequestListeners;
+
+ @Inject
+ public CommentPersistListener(MarkdownManager markdownManager, Dao dao,
+ UserManager userManager, Set<PullRequestListener> pullRequestListeners) {
+ this.markdownManager = markdownManager;
+ this.dao = dao;
+ this.userManager = userManager;
+ this.pullRequestListeners = pullRequestListeners;
+ }
+
+ @Override
+ public boolean onLoad(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)
+ throws CallbackException {
+ return false;
+ }
+
+ @Override
+ public boolean onFlushDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState,
+ String[] propertyNames, Type[] types) throws CallbackException {
+ if (entity instanceof Comment) {
+ Comment comment = (Comment) entity;
+ for (int i=0; i<propertyNames.length; i++) {
+ if (propertyNames[i].equals("content")) {
+ String content = (String) currentState[i];
+ String prevContent = (String) previousState[i];
+ if (!content.equals(prevContent)) {
+ String html = markdownManager.parse(content);
+ String prevHtml = markdownManager.parse(prevContent);
+
+ MentionParser mentionParser = new MentionParser();
+ Collection<User> mentions = mentionParser.parseMentions(html);
+
+ mentions.removeAll(mentionParser.parseMentions(prevHtml));
+ for (User user: mentions) {
+ for (PullRequestListener listener: pullRequestListeners)
+ listener.onMentioned((Comment) entity, user);
+ }
+
+ Collection<PullRequest> requests = new PullRequestParser().parseRequests(html);
+ for (PullRequest request: requests)
+ saveReference(request, comment.getRequest());
+ }
+ break;
+ }
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)
+ throws CallbackException {
+ if (entity instanceof Comment) {
+ Comment comment = (Comment) entity;
+ for (int i=0; i<propertyNames.length; i++) {
+ if (propertyNames[i].equals("content")) {
+ String content = (String) state[i];
+ String html = markdownManager.parse(content);
+ Collection<User> mentions = new MentionParser().parseMentions(html);
+ for (User user: mentions) {
+ for (PullRequestListener listener: pullRequestListeners)
+ listener.onMentioned((Comment) entity, user);
+ }
+
+ Collection<PullRequest> requests = new PullRequestParser().parseRequests(html);
+ for (PullRequest request: requests)
+ saveReference(request, comment.getRequest());
+
+ break;
+ }
+ }
+ }
+ return false;
+ }
+
+ private void saveReference(PullRequest referenced, PullRequest referencedBy) {
+ if (!referenced.equals(referencedBy)) {
+ EntityCriteria<PullRequestReference> criteria = EntityCriteria.of(PullRequestReference.class);
+ criteria.add(Restrictions.eq("referenced", referenced));
+ criteria.add(Restrictions.eq("referencedBy", referencedBy));
+ if (dao.find(criteria) == null) {
+ PullRequestReference reference = new PullRequestReference();
+ reference.setReferencedBy(referencedBy);
+ reference.setReferenced(referenced);
+ reference.setUser(userManager.getCurrent());
+ dao.persist(reference);
+ }
+ }
+ }
+
+ @Override
+ public void onDelete(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)
+ throws CallbackException {
+ }
+
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/CommentReplyPersistListener.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/CommentReplyPersistListener.java
index 8d39021997..879daa15b9 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/CommentReplyPersistListener.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/CommentReplyPersistListener.java
@@ -1,122 +1,122 @@
-package com.pmease.gitplex.core.model;
-
-import java.io.Serializable;
-import java.util.Collection;
-import java.util.Set;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
-import org.hibernate.CallbackException;
-import org.hibernate.criterion.Restrictions;
-import org.hibernate.type.Type;
-
-import com.pmease.commons.hibernate.HibernateListener;
-import com.pmease.commons.hibernate.dao.Dao;
-import com.pmease.commons.hibernate.dao.EntityCriteria;
-import com.pmease.commons.markdown.MarkdownManager;
-import com.pmease.gitplex.core.listeners.PullRequestListener;
-import com.pmease.gitplex.core.manager.UserManager;
-import com.pmease.gitplex.core.markdown.MentionParser;
-import com.pmease.gitplex.core.markdown.PullRequestParser;
-
-@Singleton
-public class CommentReplyPersistListener implements HibernateListener {
-
- private final MarkdownManager markdownManager;
-
- private final Set<PullRequestListener> pullRequestListeners;
-
- private final Dao dao;
-
- private final UserManager userManager;
-
- @Inject
- public CommentReplyPersistListener(MarkdownManager markdownManager,
- Set<PullRequestListener> pullRequestListeners, Dao dao, UserManager userManager) {
- this.markdownManager = markdownManager;
- this.pullRequestListeners = pullRequestListeners;
- this.dao = dao;
- this.userManager = userManager;
- }
-
- @Override
- public boolean onLoad(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)
- throws CallbackException {
- return false;
- }
-
- @Override
- public boolean onFlushDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState,
- String[] propertyNames, Type[] types) throws CallbackException {
- if (entity instanceof CommentReply) {
- CommentReply reply = (CommentReply) entity;
- for (int i=0; i<propertyNames.length; i++) {
- if (propertyNames[i].equals("content")) {
- String content = (String) currentState[i];
- String prevContent = (String) previousState[i];
- if (!content.equals(prevContent)) {
- MentionParser parser = new MentionParser();
- String html = markdownManager.parse(content);
- Collection<User> mentions = parser.parseMentions(html);
- mentions.removeAll(parser.parseMentions(markdownManager.parse(prevContent)));
- for (User user: mentions) {
- for (PullRequestListener listener: pullRequestListeners)
- listener.onMentioned((CommentReply) entity, user);
- }
-
- for (PullRequest request: new PullRequestParser().parseRequests(html))
- saveReference(request, reply.getComment().getRequest());
- }
- break;
- }
- }
- }
- return false;
- }
-
- @Override
- public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)
- throws CallbackException {
- if (entity instanceof CommentReply) {
- CommentReply reply = (CommentReply) entity;
- for (int i=0; i<propertyNames.length; i++) {
- if (propertyNames[i].equals("content")) {
- String content = (String) state[i];
- String html = markdownManager.parse(content);
- Collection<User> mentions = new MentionParser().parseMentions(html);
- for (User user: mentions) {
- for (PullRequestListener listener: pullRequestListeners)
- listener.onMentioned((CommentReply) entity, user);
- }
-
- for (PullRequest request: new PullRequestParser().parseRequests(html))
- saveReference(request, reply.getComment().getRequest());
- break;
- }
- }
- }
- return false;
- }
-
- private void saveReference(PullRequest referenced, PullRequest referencedBy) {
- if (!referenced.equals(referencedBy)) {
- EntityCriteria<PullRequestReference> criteria = EntityCriteria.of(PullRequestReference.class);
- criteria.add(Restrictions.eq("referenced", referenced));
- criteria.add(Restrictions.eq("referencedBy", referencedBy));
- if (dao.find(criteria) == null) {
- PullRequestReference reference = new PullRequestReference();
- reference.setReferencedBy(referencedBy);
- reference.setReferenced(referenced);
- reference.setUser(userManager.getCurrent());
- dao.persist(reference);
- }
- }
- }
-
- @Override
- public void onDelete(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)
- throws CallbackException {
- }
-
-}
+package com.pmease.gitplex.core.model;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.Set;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.hibernate.CallbackException;
+import org.hibernate.criterion.Restrictions;
+import org.hibernate.type.Type;
+
+import com.pmease.commons.hibernate.HibernateListener;
+import com.pmease.commons.hibernate.dao.Dao;
+import com.pmease.commons.hibernate.dao.EntityCriteria;
+import com.pmease.commons.markdown.MarkdownManager;
+import com.pmease.gitplex.core.listeners.PullRequestListener;
+import com.pmease.gitplex.core.manager.UserManager;
+import com.pmease.gitplex.core.util.markdown.MentionParser;
+import com.pmease.gitplex.core.util.markdown.PullRequestParser;
+
+@Singleton
+public class CommentReplyPersistListener implements HibernateListener {
+
+ private final MarkdownManager markdownManager;
+
+ private final Set<PullRequestListener> pullRequestListeners;
+
+ private final Dao dao;
+
+ private final UserManager userManager;
+
+ @Inject
+ public CommentReplyPersistListener(MarkdownManager markdownManager,
+ Set<PullRequestListener> pullRequestListeners, Dao dao, UserManager userManager) {
+ this.markdownManager = markdownManager;
+ this.pullRequestListeners = pullRequestListeners;
+ this.dao = dao;
+ this.userManager = userManager;
+ }
+
+ @Override
+ public boolean onLoad(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)
+ throws CallbackException {
+ return false;
+ }
+
+ @Override
+ public boolean onFlushDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState,
+ String[] propertyNames, Type[] types) throws CallbackException {
+ if (entity instanceof CommentReply) {
+ CommentReply reply = (CommentReply) entity;
+ for (int i=0; i<propertyNames.length; i++) {
+ if (propertyNames[i].equals("content")) {
+ String content = (String) currentState[i];
+ String prevContent = (String) previousState[i];
+ if (!content.equals(prevContent)) {
+ MentionParser parser = new MentionParser();
+ String html = markdownManager.parse(content);
+ Collection<User> mentions = parser.parseMentions(html);
+ mentions.removeAll(parser.parseMentions(markdownManager.parse(prevContent)));
+ for (User user: mentions) {
+ for (PullRequestListener listener: pullRequestListeners)
+ listener.onMentioned((CommentReply) entity, user);
+ }
+
+ for (PullRequest request: new PullRequestParser().parseRequests(html))
+ saveReference(request, reply.getComment().getRequest());
+ }
+ break;
+ }
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)
+ throws CallbackException {
+ if (entity instanceof CommentReply) {
+ CommentReply reply = (CommentReply) entity;
+ for (int i=0; i<propertyNames.length; i++) {
+ if (propertyNames[i].equals("content")) {
+ String content = (String) state[i];
+ String html = markdownManager.parse(content);
+ Collection<User> mentions = new MentionParser().parseMentions(html);
+ for (User user: mentions) {
+ for (PullRequestListener listener: pullRequestListeners)
+ listener.onMentioned((CommentReply) entity, user);
+ }
+
+ for (PullRequest request: new PullRequestParser().parseRequests(html))
+ saveReference(request, reply.getComment().getRequest());
+ break;
+ }
+ }
+ }
+ return false;
+ }
+
+ private void saveReference(PullRequest referenced, PullRequest referencedBy) {
+ if (!referenced.equals(referencedBy)) {
+ EntityCriteria<PullRequestReference> criteria = EntityCriteria.of(PullRequestReference.class);
+ criteria.add(Restrictions.eq("referenced", referenced));
+ criteria.add(Restrictions.eq("referencedBy", referencedBy));
+ if (dao.find(criteria) == null) {
+ PullRequestReference reference = new PullRequestReference();
+ reference.setReferencedBy(referencedBy);
+ reference.setReferenced(referenced);
+ reference.setUser(userManager.getCurrent());
+ dao.persist(reference);
+ }
+ }
+ }
+
+ @Override
+ public void onDelete(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)
+ throws CallbackException {
+ }
+
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/Depot.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/Depot.java
index a96f1d93a3..bec342dee5 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/Depot.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/Depot.java
@@ -93,7 +93,7 @@ import com.pmease.gitplex.core.listeners.RefListener;
import com.pmease.gitplex.core.manager.StorageManager;
import com.pmease.gitplex.core.permission.object.ProtectedObject;
import com.pmease.gitplex.core.permission.object.UserBelonging;
-import com.pmease.gitplex.core.validation.DepotName;
+import com.pmease.gitplex.core.util.validation.DepotName;
@Entity
@Table(uniqueConstraints={@UniqueConstraint(columnNames={"owner", "name"})})
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 3e34f3b9f4..b291744bd0 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
@@ -1,81 +1,81 @@
-package com.pmease.gitplex.core.model;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.validation.Valid;
-import javax.validation.constraints.NotNull;
-import javax.validation.constraints.Size;
-
-import com.pmease.commons.wicket.editable.annotation.Editable;
-import com.pmease.commons.wicket.editable.annotation.Horizontal;
-import com.pmease.gitplex.core.branchmatcher.AffinalBranchMatcher;
-import com.pmease.gitplex.core.branchmatcher.LocalBranchMatcher;
-import com.pmease.gitplex.core.model.PullRequest.IntegrationStrategy;
-
-@SuppressWarnings("serial")
-@Editable
-@Horizontal
-public class IntegrationPolicy implements Serializable {
-
- private LocalBranchMatcher targetBranches;
-
- private AffinalBranchMatcher sourceBranches;
-
- private List<IntegrationStrategy> integrationStrategies = new ArrayList<>();
-
- @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;
- }
-
- public void setTargetBranches(LocalBranchMatcher targetBranches) {
- this.targetBranches = targetBranches;
- }
-
- @Editable(name="Source Branches", order=200, description="Specify source branches of pull requests to which "
- + "this policy applies to.")
- @NotNull
- @Valid
- public AffinalBranchMatcher getSourceBranches() {
- return sourceBranches;
- }
-
- public void setSourceBranches(AffinalBranchMatcher sourceBranches) {
- this.sourceBranches = sourceBranches;
- }
-
- @Editable(order=300, descriptionProvider="getIntegrationStrategyHelp")
- @Size(min=1, message="At least one integration strategy should be specified")
- public List<IntegrationStrategy> getIntegrationStrategies() {
- return integrationStrategies;
- }
-
- public void setIntegrationStrategies(List<IntegrationStrategy> integrationStrategies) {
- this.integrationStrategies = integrationStrategies;
- }
-
- @SuppressWarnings("unused")
- private static String getIntegrationStrategyHelp() {
- StringBuilder help = new StringBuilder("<p>Choose one or more integration strategies applicable for pull requests "
- + "matching branch criterias specified above. User can decide to use one of the applicable "
- + "strategy to integrate pull request into target branch. Note that the first selected strategy "
- + "here will appear as default strategy of the pull request. GitPlex for now provides below "
- + "integration strategies:</p>");
-
- help.append("<dl>");
-
- for (IntegrationStrategy strategy: IntegrationStrategy.values()) {
- help.append("<dt>").append(strategy.toString()).append("</dt>");
- help.append("<dd>").append(strategy.getDescription()).append("</dd>");
- }
-
- help.append("</dl>");
-
- return help.toString();
- }
-}
+package com.pmease.gitplex.core.model;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.validation.Valid;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+
+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;
+
+@SuppressWarnings("serial")
+@Editable
+@Horizontal
+public class IntegrationPolicy implements Serializable {
+
+ private LocalBranchMatcher targetBranches;
+
+ private AffinalBranchMatcher sourceBranches;
+
+ private List<IntegrationStrategy> integrationStrategies = new ArrayList<>();
+
+ @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;
+ }
+
+ public void setTargetBranches(LocalBranchMatcher targetBranches) {
+ this.targetBranches = targetBranches;
+ }
+
+ @Editable(name="Source Branches", order=200, description="Specify source branches of pull requests to which "
+ + "this policy applies to.")
+ @NotNull
+ @Valid
+ public AffinalBranchMatcher getSourceBranches() {
+ return sourceBranches;
+ }
+
+ public void setSourceBranches(AffinalBranchMatcher sourceBranches) {
+ this.sourceBranches = sourceBranches;
+ }
+
+ @Editable(order=300, descriptionProvider="getIntegrationStrategyHelp")
+ @Size(min=1, message="At least one integration strategy should be specified")
+ public List<IntegrationStrategy> getIntegrationStrategies() {
+ return integrationStrategies;
+ }
+
+ public void setIntegrationStrategies(List<IntegrationStrategy> integrationStrategies) {
+ this.integrationStrategies = integrationStrategies;
+ }
+
+ @SuppressWarnings("unused")
+ private static String getIntegrationStrategyHelp() {
+ StringBuilder help = new StringBuilder("<p>Choose one or more integration strategies applicable for pull requests "
+ + "matching branch criterias specified above. User can decide to use one of the applicable "
+ + "strategy to integrate pull request into target branch. Note that the first selected strategy "
+ + "here will appear as default strategy of the pull request. GitPlex for now provides below "
+ + "integration strategies:</p>");
+
+ help.append("<dl>");
+
+ for (IntegrationStrategy strategy: IntegrationStrategy.values()) {
+ help.append("<dt>").append(strategy.toString()).append("</dt>");
+ help.append("<dd>").append(strategy.getDescription()).append("</dd>");
+ }
+
+ help.append("</dl>");
+
+ return help.toString();
+ }
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestPersistListener.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestPersistListener.java
index 78ce2bdb71..d49a67393c 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestPersistListener.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestPersistListener.java
@@ -1,137 +1,137 @@
-package com.pmease.gitplex.core.model;
-
-import java.io.Serializable;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
-import org.apache.wicket.util.lang.Objects;
-import org.hibernate.CallbackException;
-import org.hibernate.criterion.Restrictions;
-import org.hibernate.type.Type;
-
-import com.pmease.commons.hibernate.HibernateListener;
-import com.pmease.commons.hibernate.dao.Dao;
-import com.pmease.commons.hibernate.dao.EntityCriteria;
-import com.pmease.commons.markdown.MarkdownManager;
-import com.pmease.gitplex.core.listeners.PullRequestListener;
-import com.pmease.gitplex.core.manager.UserManager;
-import com.pmease.gitplex.core.markdown.MentionParser;
-import com.pmease.gitplex.core.markdown.PullRequestParser;
-
-@Singleton
-public class PullRequestPersistListener implements HibernateListener {
-
- private final MarkdownManager markdownManager;
-
- private final Set<PullRequestListener> pullRequestListeners;
-
- private final Dao dao;
-
- private final UserManager userManager;
-
- @Inject
- public PullRequestPersistListener(MarkdownManager markdownManager,
- Set<PullRequestListener> pullRequestListeners, Dao dao, UserManager userManager) {
- this.markdownManager = markdownManager;
- this.pullRequestListeners = pullRequestListeners;
- this.dao = dao;
- this.userManager = userManager;
- }
-
- @Override
- public boolean onLoad(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)
- throws CallbackException {
- return false;
- }
-
- @Override
- public boolean onFlushDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState,
- String[] propertyNames, Type[] types) throws CallbackException {
- if (entity instanceof PullRequest) {
- PullRequest request = (PullRequest) entity;
- for (int i=0; i<propertyNames.length; i++) {
- if (propertyNames[i].equals("description")) {
- String description = (String) currentState[i];
- String prevDescription = (String) previousState[i];
- if (!Objects.equal(description, prevDescription)) {
- MentionParser mentionParser = new MentionParser();
- Collection<User> mentions;
- String html;
- if (description != null) {
- html = markdownManager.parse(description);
- mentions = mentionParser.parseMentions(html);
- } else {
- mentions = new HashSet<>();
- html = null;
- }
- if (prevDescription != null)
- mentions.removeAll(mentionParser.parseMentions(markdownManager.parse(prevDescription)));
- for (User user: mentions) {
- for (PullRequestListener listener: pullRequestListeners)
- listener.onMentioned((PullRequest) entity, user);
- }
-
- if (html != null) {
- for (PullRequest referenced: new PullRequestParser().parseRequests(html))
- saveReference(referenced, request);
- }
- }
- break;
- }
- }
- }
- return false;
- }
-
- private void saveReference(PullRequest referenced, PullRequest referencedBy) {
- if (!referenced.equals(referencedBy)) {
- EntityCriteria<PullRequestReference> criteria = EntityCriteria.of(PullRequestReference.class);
- criteria.add(Restrictions.eq("referenced", referenced));
- criteria.add(Restrictions.eq("referencedBy", referencedBy));
- if (dao.find(criteria) == null) {
- PullRequestReference reference = new PullRequestReference();
- reference.setReferencedBy(referencedBy);
- reference.setReferenced(referenced);
- reference.setUser(userManager.getCurrent());
- dao.persist(reference);
- }
- }
- }
-
- @Override
- public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)
- throws CallbackException {
- if (entity instanceof PullRequest) {
- PullRequest request = (PullRequest) entity;
- for (int i=0; i<propertyNames.length; i++) {
- if (propertyNames[i].equals("idStr")) {
- state[i] = id.toString();
- } else if (propertyNames[i].equals("description")) {
- String description = (String) state[i];
- if (description != null) {
- String html = markdownManager.parse(description);
- Collection<User> mentions = new MentionParser().parseMentions(html);
- for (User user: mentions) {
- for (PullRequestListener listener: pullRequestListeners)
- listener.onMentioned((PullRequest) entity, user);
- }
-
- for (PullRequest referenced: new PullRequestParser().parseRequests(html))
- saveReference(referenced, request);
- }
- }
- }
- }
- return true;
- }
-
- @Override
- public void onDelete(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)
- throws CallbackException {
- }
-
-}
+package com.pmease.gitplex.core.model;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.apache.wicket.util.lang.Objects;
+import org.hibernate.CallbackException;
+import org.hibernate.criterion.Restrictions;
+import org.hibernate.type.Type;
+
+import com.pmease.commons.hibernate.HibernateListener;
+import com.pmease.commons.hibernate.dao.Dao;
+import com.pmease.commons.hibernate.dao.EntityCriteria;
+import com.pmease.commons.markdown.MarkdownManager;
+import com.pmease.gitplex.core.listeners.PullRequestListener;
+import com.pmease.gitplex.core.manager.UserManager;
+import com.pmease.gitplex.core.util.markdown.MentionParser;
+import com.pmease.gitplex.core.util.markdown.PullRequestParser;
+
+@Singleton
+public class PullRequestPersistListener implements HibernateListener {
+
+ private final MarkdownManager markdownManager;
+
+ private final Set<PullRequestListener> pullRequestListeners;
+
+ private final Dao dao;
+
+ private final UserManager userManager;
+
+ @Inject
+ public PullRequestPersistListener(MarkdownManager markdownManager,
+ Set<PullRequestListener> pullRequestListeners, Dao dao, UserManager userManager) {
+ this.markdownManager = markdownManager;
+ this.pullRequestListeners = pullRequestListeners;
+ this.dao = dao;
+ this.userManager = userManager;
+ }
+
+ @Override
+ public boolean onLoad(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)
+ throws CallbackException {
+ return false;
+ }
+
+ @Override
+ public boolean onFlushDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState,
+ String[] propertyNames, Type[] types) throws CallbackException {
+ if (entity instanceof PullRequest) {
+ PullRequest request = (PullRequest) entity;
+ for (int i=0; i<propertyNames.length; i++) {
+ if (propertyNames[i].equals("description")) {
+ String description = (String) currentState[i];
+ String prevDescription = (String) previousState[i];
+ if (!Objects.equal(description, prevDescription)) {
+ MentionParser mentionParser = new MentionParser();
+ Collection<User> mentions;
+ String html;
+ if (description != null) {
+ html = markdownManager.parse(description);
+ mentions = mentionParser.parseMentions(html);
+ } else {
+ mentions = new HashSet<>();
+ html = null;
+ }
+ if (prevDescription != null)
+ mentions.removeAll(mentionParser.parseMentions(markdownManager.parse(prevDescription)));
+ for (User user: mentions) {
+ for (PullRequestListener listener: pullRequestListeners)
+ listener.onMentioned((PullRequest) entity, user);
+ }
+
+ if (html != null) {
+ for (PullRequest referenced: new PullRequestParser().parseRequests(html))
+ saveReference(referenced, request);
+ }
+ }
+ break;
+ }
+ }
+ }
+ return false;
+ }
+
+ private void saveReference(PullRequest referenced, PullRequest referencedBy) {
+ if (!referenced.equals(referencedBy)) {
+ EntityCriteria<PullRequestReference> criteria = EntityCriteria.of(PullRequestReference.class);
+ criteria.add(Restrictions.eq("referenced", referenced));
+ criteria.add(Restrictions.eq("referencedBy", referencedBy));
+ if (dao.find(criteria) == null) {
+ PullRequestReference reference = new PullRequestReference();
+ reference.setReferencedBy(referencedBy);
+ reference.setReferenced(referenced);
+ reference.setUser(userManager.getCurrent());
+ dao.persist(reference);
+ }
+ }
+ }
+
+ @Override
+ public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)
+ throws CallbackException {
+ if (entity instanceof PullRequest) {
+ PullRequest request = (PullRequest) entity;
+ for (int i=0; i<propertyNames.length; i++) {
+ if (propertyNames[i].equals("idStr")) {
+ state[i] = id.toString();
+ } else if (propertyNames[i].equals("description")) {
+ String description = (String) state[i];
+ if (description != null) {
+ String html = markdownManager.parse(description);
+ Collection<User> mentions = new MentionParser().parseMentions(html);
+ for (User user: mentions) {
+ for (PullRequestListener listener: pullRequestListeners)
+ listener.onMentioned((PullRequest) entity, user);
+ }
+
+ for (PullRequest referenced: new PullRequestParser().parseRequests(html))
+ saveReference(referenced, request);
+ }
+ }
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public void onDelete(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)
+ throws CallbackException {
+ }
+
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/Team.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/Team.java
index 11db66861e..0a9b0924ae 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/Team.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/Team.java
@@ -21,7 +21,7 @@ import org.hibernate.validator.constraints.NotEmpty;
import com.google.common.base.Objects;
import com.pmease.commons.hibernate.AbstractEntity;
import com.pmease.gitplex.core.permission.operation.DepotOperation;
-import com.pmease.gitplex.core.validation.TeamName;
+import com.pmease.gitplex.core.util.validation.TeamName;
@Entity
@Table(uniqueConstraints={
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/User.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/User.java
index 4df6c485c4..043300225e 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/User.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/User.java
@@ -25,7 +25,7 @@ import com.pmease.commons.wicket.editable.annotation.Editable;
import com.pmease.commons.wicket.editable.annotation.Password;
import com.pmease.gitplex.core.permission.object.ProtectedObject;
import com.pmease.gitplex.core.permission.object.UserBelonging;
-import com.pmease.gitplex.core.validation.UserName;
+import com.pmease.gitplex.core.util.validation.UserName;
@SuppressWarnings("serial")
@Entity
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/security/SecurityUtils.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/security/SecurityUtils.java
index b21e5ad1d0..38197d6051 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/security/SecurityUtils.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/security/SecurityUtils.java
@@ -4,17 +4,15 @@ import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
-import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.ObjectId;
-import com.pmease.commons.git.GitUtils;
import com.pmease.commons.hibernate.dao.Dao;
import com.pmease.commons.hibernate.dao.EntityCriteria;
import com.pmease.gitplex.core.GitPlex;
import com.pmease.gitplex.core.manager.UserManager;
import com.pmease.gitplex.core.model.Comment;
-import com.pmease.gitplex.core.model.PullRequest;
-import com.pmease.gitplex.core.model.DepotAndBranch;
import com.pmease.gitplex.core.model.Depot;
+import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.Review;
import com.pmease.gitplex.core.model.Team;
import com.pmease.gitplex.core.model.User;
@@ -66,26 +64,11 @@ public class SecurityUtils extends org.apache.shiro.SecurityUtils {
}
}
- public static boolean canCreate(DepotAndBranch depotAndBranch) {
- return canCreate(depotAndBranch.getDepot(), depotAndBranch.getBranch());
- }
-
- public static boolean canCreate(Depot depot, String branch) {
- User currentUser = GitPlex.getInstance(UserManager.class).getCurrent();
- return currentUser != null
- && currentUser.asSubject().isPermitted(ObjectPermission.ofDepotPush(depot))
- && depot.getGateKeeper().checkRef(currentUser, depot, Constants.R_HEADS + branch).isPassed();
- }
-
- public static boolean canModify(DepotAndBranch depotAndBranch) {
- return canModify(depotAndBranch.getDepot(), GitUtils.branch2ref(depotAndBranch.getBranch()));
- }
-
- public static boolean canModify(Depot depot, String refName) {
+ public static boolean canPushRef(Depot depot, String refName, ObjectId oldCommit, ObjectId newCommit) {
User currentUser = GitPlex.getInstance(UserManager.class).getCurrent();
return currentUser != null
&& currentUser.asSubject().isPermitted(ObjectPermission.ofDepotPush(depot))
- && depot.getGateKeeper().checkRef(currentUser, depot, refName).isPassed();
+ && depot.getGateKeeper().checkPush(currentUser, depot, refName, oldCommit, newCommit).isPassed();
}
public static boolean canManage(User account) {
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/AffinalBranchMatcher.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/branchmatcher/AffinalBranchMatcher.java
similarity index 83%
rename from gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/AffinalBranchMatcher.java
rename to gitplex.core/src/main/java/com/pmease/gitplex/core/util/branchmatcher/AffinalBranchMatcher.java
index 88441a22a1..cd4c7cb741 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/AffinalBranchMatcher.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/branchmatcher/AffinalBranchMatcher.java
@@ -1,4 +1,4 @@
-package com.pmease.gitplex.core.branchmatcher;
+package com.pmease.gitplex.core.util.branchmatcher;
import java.io.Serializable;
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/GlobalBranchMatcher.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/branchmatcher/GlobalBranchMatcher.java
similarity index 83%
rename from gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/GlobalBranchMatcher.java
rename to gitplex.core/src/main/java/com/pmease/gitplex/core/util/branchmatcher/GlobalBranchMatcher.java
index 3928124076..a985b927c7 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/GlobalBranchMatcher.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/branchmatcher/GlobalBranchMatcher.java
@@ -1,4 +1,4 @@
-package com.pmease.gitplex.core.branchmatcher;
+package com.pmease.gitplex.core.util.branchmatcher;
import java.io.Serializable;
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/LocalBranchMatcher.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/branchmatcher/LocalBranchMatcher.java
similarity index 76%
rename from gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/LocalBranchMatcher.java
rename to gitplex.core/src/main/java/com/pmease/gitplex/core/util/branchmatcher/LocalBranchMatcher.java
index 68e4522fc6..d22f74f406 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/LocalBranchMatcher.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/branchmatcher/LocalBranchMatcher.java
@@ -1,10 +1,10 @@
-package com.pmease.gitplex.core.branchmatcher;
-
-import java.io.Serializable;
-
-import com.pmease.commons.wicket.editable.annotation.Editable;
-
-@Editable
-public interface LocalBranchMatcher extends Serializable {
- boolean matches(String branch);
-}
+package com.pmease.gitplex.core.util.branchmatcher;
+
+import java.io.Serializable;
+
+import com.pmease.commons.wicket.editable.annotation.Editable;
+
+@Editable
+public interface LocalBranchMatcher extends Serializable {
+ boolean matches(String branch);
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchAffinalBranchesByNames.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/branchmatcher/MatchAffinalBranchesByNames.java
similarity index 88%
rename from gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchAffinalBranchesByNames.java
rename to gitplex.core/src/main/java/com/pmease/gitplex/core/util/branchmatcher/MatchAffinalBranchesByNames.java
index 40e5ea6517..039f49414c 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchAffinalBranchesByNames.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/branchmatcher/MatchAffinalBranchesByNames.java
@@ -1,4 +1,4 @@
-package com.pmease.gitplex.core.branchmatcher;
+package com.pmease.gitplex.core.util.branchmatcher;
import java.util.ArrayList;
import java.util.List;
@@ -8,9 +8,9 @@ import javax.validation.constraints.Size;
import com.pmease.commons.wicket.editable.annotation.Editable;
import com.pmease.commons.wicket.editable.annotation.OmitName;
-import com.pmease.gitplex.core.editable.BranchChoice;
-import com.pmease.gitplex.core.editable.BranchChoice.Scope;
import com.pmease.gitplex.core.model.DepotAndBranch;
+import com.pmease.gitplex.core.util.editable.BranchChoice;
+import com.pmease.gitplex.core.util.editable.BranchChoice.Scope;
import com.pmease.gitplex.core.model.Depot;
@SuppressWarnings("serial")
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchAffinalBranchesByPatterns.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/branchmatcher/MatchAffinalBranchesByPatterns.java
similarity index 95%
rename from gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchAffinalBranchesByPatterns.java
rename to gitplex.core/src/main/java/com/pmease/gitplex/core/util/branchmatcher/MatchAffinalBranchesByPatterns.java
index 1b9fd8b403..b5b3e26164 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchAffinalBranchesByPatterns.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/branchmatcher/MatchAffinalBranchesByPatterns.java
@@ -1,4 +1,4 @@
-package com.pmease.gitplex.core.branchmatcher;
+package com.pmease.gitplex.core.util.branchmatcher;
import org.hibernate.validator.constraints.NotEmpty;
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchAllAffinalBranches.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/branchmatcher/MatchAllAffinalBranches.java
similarity index 85%
rename from gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchAllAffinalBranches.java
rename to gitplex.core/src/main/java/com/pmease/gitplex/core/util/branchmatcher/MatchAllAffinalBranches.java
index abc2130c24..477e176216 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchAllAffinalBranches.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/branchmatcher/MatchAllAffinalBranches.java
@@ -1,4 +1,4 @@
-package com.pmease.gitplex.core.branchmatcher;
+package com.pmease.gitplex.core.util.branchmatcher;
import com.pmease.commons.wicket.editable.annotation.Editable;
import com.pmease.gitplex.core.model.Depot;
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchAllGlobalBranches.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/branchmatcher/MatchAllGlobalBranches.java
similarity index 85%
rename from gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchAllGlobalBranches.java
rename to gitplex.core/src/main/java/com/pmease/gitplex/core/util/branchmatcher/MatchAllGlobalBranches.java
index d3af6a909c..adb1a970e2 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchAllGlobalBranches.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/branchmatcher/MatchAllGlobalBranches.java
@@ -1,4 +1,4 @@
-package com.pmease.gitplex.core.branchmatcher;
+package com.pmease.gitplex.core.util.branchmatcher;
import com.pmease.commons.wicket.editable.annotation.Editable;
import com.pmease.gitplex.core.model.Depot;
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchAllLocalBranches.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/branchmatcher/MatchAllLocalBranches.java
similarity index 80%
rename from gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchAllLocalBranches.java
rename to gitplex.core/src/main/java/com/pmease/gitplex/core/util/branchmatcher/MatchAllLocalBranches.java
index 9296dad5de..7dcb975117 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchAllLocalBranches.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/branchmatcher/MatchAllLocalBranches.java
@@ -1,14 +1,14 @@
-package com.pmease.gitplex.core.branchmatcher;
-
-import com.pmease.commons.wicket.editable.annotation.Editable;
-
-@SuppressWarnings("serial")
-@Editable(name="All Branches", order=300)
-public class MatchAllLocalBranches implements LocalBranchMatcher {
-
- @Override
- public boolean matches(String branch) {
- return true;
- }
-
-}
+package com.pmease.gitplex.core.util.branchmatcher;
+
+import com.pmease.commons.wicket.editable.annotation.Editable;
+
+@SuppressWarnings("serial")
+@Editable(name="All Branches", order=300)
+public class MatchAllLocalBranches implements LocalBranchMatcher {
+
+ @Override
+ public boolean matches(String branch) {
+ return true;
+ }
+
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchGlobalBranchesByNames.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/branchmatcher/MatchGlobalBranchesByNames.java
similarity index 88%
rename from gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchGlobalBranchesByNames.java
rename to gitplex.core/src/main/java/com/pmease/gitplex/core/util/branchmatcher/MatchGlobalBranchesByNames.java
index 71e49d3719..e788b7d1e6 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchGlobalBranchesByNames.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/branchmatcher/MatchGlobalBranchesByNames.java
@@ -1,4 +1,4 @@
-package com.pmease.gitplex.core.branchmatcher;
+package com.pmease.gitplex.core.util.branchmatcher;
import java.util.ArrayList;
import java.util.List;
@@ -8,9 +8,9 @@ import javax.validation.constraints.Size;
import com.pmease.commons.wicket.editable.annotation.Editable;
import com.pmease.commons.wicket.editable.annotation.OmitName;
-import com.pmease.gitplex.core.editable.BranchChoice;
-import com.pmease.gitplex.core.editable.BranchChoice.Scope;
import com.pmease.gitplex.core.model.DepotAndBranch;
+import com.pmease.gitplex.core.util.editable.BranchChoice;
+import com.pmease.gitplex.core.util.editable.BranchChoice.Scope;
import com.pmease.gitplex.core.model.Depot;
@SuppressWarnings("serial")
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchGlobalBranchesByPatterns.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/branchmatcher/MatchGlobalBranchesByPatterns.java
similarity index 95%
rename from gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchGlobalBranchesByPatterns.java
rename to gitplex.core/src/main/java/com/pmease/gitplex/core/util/branchmatcher/MatchGlobalBranchesByPatterns.java
index 409e00a129..071248939d 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchGlobalBranchesByPatterns.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/branchmatcher/MatchGlobalBranchesByPatterns.java
@@ -1,4 +1,4 @@
-package com.pmease.gitplex.core.branchmatcher;
+package com.pmease.gitplex.core.util.branchmatcher;
import org.hibernate.validator.constraints.NotEmpty;
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchLocalBranchesByNames.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/branchmatcher/MatchLocalBranchesByNames.java
similarity index 85%
rename from gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchLocalBranchesByNames.java
rename to gitplex.core/src/main/java/com/pmease/gitplex/core/util/branchmatcher/MatchLocalBranchesByNames.java
index 10689e02c8..bae37b858c 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchLocalBranchesByNames.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/branchmatcher/MatchLocalBranchesByNames.java
@@ -1,41 +1,41 @@
-package com.pmease.gitplex.core.branchmatcher;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.validation.constraints.NotNull;
-import javax.validation.constraints.Size;
-
-import com.pmease.commons.wicket.editable.annotation.Editable;
-import com.pmease.commons.wicket.editable.annotation.OmitName;
-import com.pmease.gitplex.core.editable.BranchChoice;
-
-@SuppressWarnings("serial")
-@Editable(name="Specify Branch Names", order=100)
-public class MatchLocalBranchesByNames implements LocalBranchMatcher {
-
- private List<String> branches = new ArrayList<>();
-
- @Editable(name="Branch Names")
- @BranchChoice
- @OmitName
- @NotNull
- @Size(min=1, message="At least one branch has to be selected.")
- public List<String> getBranches() {
- return branches;
- }
-
- public void setBranches(List<String> branches) {
- this.branches = branches;
- }
-
- @Override
- public boolean matches(String branch) {
- for (String each: getBranches()) {
- if (each.equals(branch))
- return true;
- }
- return false;
- }
-
-}
+package com.pmease.gitplex.core.util.branchmatcher;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+
+import com.pmease.commons.wicket.editable.annotation.Editable;
+import com.pmease.commons.wicket.editable.annotation.OmitName;
+import com.pmease.gitplex.core.util.editable.BranchChoice;
+
+@SuppressWarnings("serial")
+@Editable(name="Specify Branch Names", order=100)
+public class MatchLocalBranchesByNames implements LocalBranchMatcher {
+
+ private List<String> branches = new ArrayList<>();
+
+ @Editable(name="Branch Names")
+ @BranchChoice
+ @OmitName
+ @NotNull
+ @Size(min=1, message="At least one branch has to be selected.")
+ public List<String> getBranches() {
+ return branches;
+ }
+
+ public void setBranches(List<String> branches) {
+ this.branches = branches;
+ }
+
+ @Override
+ public boolean matches(String branch) {
+ for (String each: getBranches()) {
+ if (each.equals(branch))
+ return true;
+ }
+ return false;
+ }
+
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchLocalBranchesByPatterns.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/branchmatcher/MatchLocalBranchesByPatterns.java
similarity index 91%
rename from gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchLocalBranchesByPatterns.java
rename to gitplex.core/src/main/java/com/pmease/gitplex/core/util/branchmatcher/MatchLocalBranchesByPatterns.java
index 21238f5f9c..13cefd2fea 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/branchmatcher/MatchLocalBranchesByPatterns.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/branchmatcher/MatchLocalBranchesByPatterns.java
@@ -1,32 +1,32 @@
-package com.pmease.gitplex.core.branchmatcher;
-
-import org.hibernate.validator.constraints.NotEmpty;
-
-import com.pmease.commons.util.pattern.WildcardUtils;
-import com.pmease.commons.wicket.editable.annotation.Editable;
-import com.pmease.commons.wicket.editable.annotation.OmitName;
-
-@SuppressWarnings("serial")
-@Editable(order=200, name="Specify Branch Patterns")
-public class MatchLocalBranchesByPatterns implements LocalBranchMatcher {
-
- private String branchPatterns;
-
- @Editable(name="Branch Patterns", description=
- "Patterns should be specified following the <a href='http://wiki.pmease.com/display/gp/Pattern+Set'>pattern set</a> format.")
- @OmitName
- @NotEmpty
- public String getBranchPatterns() {
- return branchPatterns;
- }
-
- public void setBranchPatterns(String branchPatterns) {
- this.branchPatterns = branchPatterns;
- }
-
- @Override
- public boolean matches(String branch) {
- return WildcardUtils.matchPath(getBranchPatterns(), branch);
- }
-
-}
+package com.pmease.gitplex.core.util.branchmatcher;
+
+import org.hibernate.validator.constraints.NotEmpty;
+
+import com.pmease.commons.util.pattern.WildcardUtils;
+import com.pmease.commons.wicket.editable.annotation.Editable;
+import com.pmease.commons.wicket.editable.annotation.OmitName;
+
+@SuppressWarnings("serial")
+@Editable(order=200, name="Specify Branch Patterns")
+public class MatchLocalBranchesByPatterns implements LocalBranchMatcher {
+
+ private String branchPatterns;
+
+ @Editable(name="Branch Patterns", description=
+ "Patterns should be specified following the <a href='http://wiki.pmease.com/display/gp/Pattern+Set'>pattern set</a> format.")
+ @OmitName
+ @NotEmpty
+ public String getBranchPatterns() {
+ return branchPatterns;
+ }
+
+ public void setBranchPatterns(String branchPatterns) {
+ this.branchPatterns = branchPatterns;
+ }
+
+ @Override
+ public boolean matches(String branch) {
+ return WildcardUtils.matchPath(getBranchPatterns(), branch);
+ }
+
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/editable/BranchChoice.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/editable/BranchChoice.java
similarity index 89%
rename from gitplex.core/src/main/java/com/pmease/gitplex/core/editable/BranchChoice.java
rename to gitplex.core/src/main/java/com/pmease/gitplex/core/util/editable/BranchChoice.java
index d7e95214f9..d4e59d0077 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/editable/BranchChoice.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/editable/BranchChoice.java
@@ -1,19 +1,19 @@
-package com.pmease.gitplex.core.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 BranchChoice {
-
- public enum Scope {
- GLOBAL, // choose from all accessible branches in the system
- AFFINAL, // choose from accessible branches with forking relationship with current repository
- LOCAL // choose from branches in current repository
- };
-
- Scope value() default Scope.LOCAL;
-}
+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 BranchChoice {
+
+ public enum Scope {
+ GLOBAL, // choose from all accessible branches in the system
+ AFFINAL, // choose from accessible branches with forking relationship with current repository
+ LOCAL // choose from branches in current repository
+ };
+
+ Scope value() default Scope.LOCAL;
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/editable/PathChoice.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/editable/PathChoice.java
similarity index 84%
rename from gitplex.core/src/main/java/com/pmease/gitplex/core/editable/PathChoice.java
rename to gitplex.core/src/main/java/com/pmease/gitplex/core/util/editable/PathChoice.java
index 8d2d77ab63..8ea7c262c1 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/editable/PathChoice.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/editable/PathChoice.java
@@ -1,16 +1,16 @@
-package com.pmease.gitplex.core.editable;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-import org.eclipse.jgit.lib.FileMode;
-
-@Target(ElementType.METHOD)
-@Retention(RetentionPolicy.RUNTIME)
-public @interface PathChoice {
-
- int[] value() default FileMode.TYPE_FILE;
-
-}
+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;
+
+import org.eclipse.jgit.lib.FileMode;
+
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface PathChoice {
+
+ int[] value() default FileMode.TYPE_FILE;
+
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/util/editable/RefMatch.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/editable/RefMatch.java
new file mode 100644
index 0000000000..5a44798d00
--- /dev/null
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/editable/RefMatch.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 RefMatch {
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/editable/TeamChoice.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/editable/TeamChoice.java
similarity index 83%
rename from gitplex.core/src/main/java/com/pmease/gitplex/core/editable/TeamChoice.java
rename to gitplex.core/src/main/java/com/pmease/gitplex/core/util/editable/TeamChoice.java
index 1389a00954..7ee8c7edbe 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/editable/TeamChoice.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/editable/TeamChoice.java
@@ -1,12 +1,12 @@
-package com.pmease.gitplex.core.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 TeamChoice {
- String[] excludes() default {};
-}
+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 TeamChoice {
+ String[] excludes() default {};
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/editable/UserChoice.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/editable/UserChoice.java
similarity index 81%
rename from gitplex.core/src/main/java/com/pmease/gitplex/core/editable/UserChoice.java
rename to gitplex.core/src/main/java/com/pmease/gitplex/core/util/editable/UserChoice.java
index ba59ca960c..183524906a 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/editable/UserChoice.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/editable/UserChoice.java
@@ -1,11 +1,11 @@
-package com.pmease.gitplex.core.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 UserChoice {
-}
+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 UserChoice {
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/markdown/MentionParser.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/markdown/MentionParser.java
similarity index 94%
rename from gitplex.core/src/main/java/com/pmease/gitplex/core/markdown/MentionParser.java
rename to gitplex.core/src/main/java/com/pmease/gitplex/core/util/markdown/MentionParser.java
index 136d26dd04..e5065a4e97 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/markdown/MentionParser.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/markdown/MentionParser.java
@@ -1,73 +1,73 @@
-package com.pmease.gitplex.core.markdown;
-
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.jsoup.Jsoup;
-import org.jsoup.nodes.Element;
-import org.jsoup.nodes.TextNode;
-import org.jsoup.select.NodeTraversor;
-
-import com.google.common.collect.ImmutableSet;
-import com.pmease.commons.util.JsoupUtils;
-import com.pmease.commons.util.TextNodeVisitor;
-import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.manager.UserManager;
-import com.pmease.gitplex.core.model.User;
-
-public class MentionParser {
-
- private static final Collection<String> IGNORED_TAGS = ImmutableSet.of("pre", "code", "a");
-
- private static final Pattern PATTERN = Pattern.compile("(^|\\s+)@(\\S+)(?=($|\\s+))");
-
- public Collection<User> parseMentions(String html) {
- return parseMentions(Jsoup.parseBodyFragment(html).body());
- }
-
- public Collection<User> parseMentions(Element body) {
- Collection<User> mentions = new HashSet<>();
-
- TextNodeVisitor visitor = new TextNodeVisitor() {
-
- @Override
- protected boolean isApplicable(TextNode node) {
- if (JsoupUtils.hasAncestor(node, IGNORED_TAGS))
- return false;
-
- return node.getWholeText().contains("@"); // fast scan here, do pattern match later
- }
- };
-
- NodeTraversor tranversor = new NodeTraversor(visitor);
- tranversor.traverse(body);
-
- UserManager userManager = GitPlex.getInstance(UserManager.class);
-
- for (TextNode node : visitor.getMatchedNodes()) {
- Matcher matcher = PATTERN.matcher(node.getWholeText());
- while (matcher.find()) {
- String userName = matcher.group(2);
- String userTag;
- User user = userManager.findByName(userName);
- if (user != null) {
- mentions.add(user);
- userTag = toHtml(user);
- } else {
- userTag = "@" + userName;
- }
- JsoupUtils.appendReplacement(matcher, node, matcher.group(1) + userTag + matcher.group(3));
- }
- JsoupUtils.appendTail(matcher, node);
- }
-
- return mentions;
- }
-
- protected String toHtml(User user) {
- return "@" + user.getName();
- }
-
-}
+package com.pmease.gitplex.core.util.markdown;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.jsoup.Jsoup;
+import org.jsoup.nodes.Element;
+import org.jsoup.nodes.TextNode;
+import org.jsoup.select.NodeTraversor;
+
+import com.google.common.collect.ImmutableSet;
+import com.pmease.commons.util.JsoupUtils;
+import com.pmease.commons.util.TextNodeVisitor;
+import com.pmease.gitplex.core.GitPlex;
+import com.pmease.gitplex.core.manager.UserManager;
+import com.pmease.gitplex.core.model.User;
+
+public class MentionParser {
+
+ private static final Collection<String> IGNORED_TAGS = ImmutableSet.of("pre", "code", "a");
+
+ private static final Pattern PATTERN = Pattern.compile("(^|\\s+)@(\\S+)(?=($|\\s+))");
+
+ public Collection<User> parseMentions(String html) {
+ return parseMentions(Jsoup.parseBodyFragment(html).body());
+ }
+
+ public Collection<User> parseMentions(Element body) {
+ Collection<User> mentions = new HashSet<>();
+
+ TextNodeVisitor visitor = new TextNodeVisitor() {
+
+ @Override
+ protected boolean isApplicable(TextNode node) {
+ if (JsoupUtils.hasAncestor(node, IGNORED_TAGS))
+ return false;
+
+ return node.getWholeText().contains("@"); // fast scan here, do pattern match later
+ }
+ };
+
+ NodeTraversor tranversor = new NodeTraversor(visitor);
+ tranversor.traverse(body);
+
+ UserManager userManager = GitPlex.getInstance(UserManager.class);
+
+ for (TextNode node : visitor.getMatchedNodes()) {
+ Matcher matcher = PATTERN.matcher(node.getWholeText());
+ while (matcher.find()) {
+ String userName = matcher.group(2);
+ String userTag;
+ User user = userManager.findByName(userName);
+ if (user != null) {
+ mentions.add(user);
+ userTag = toHtml(user);
+ } else {
+ userTag = "@" + userName;
+ }
+ JsoupUtils.appendReplacement(matcher, node, matcher.group(1) + userTag + matcher.group(3));
+ }
+ JsoupUtils.appendTail(matcher, node);
+ }
+
+ return mentions;
+ }
+
+ protected String toHtml(User user) {
+ return "@" + user.getName();
+ }
+
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/markdown/PullRequestParser.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/markdown/PullRequestParser.java
similarity index 94%
rename from gitplex.core/src/main/java/com/pmease/gitplex/core/markdown/PullRequestParser.java
rename to gitplex.core/src/main/java/com/pmease/gitplex/core/util/markdown/PullRequestParser.java
index e8b5be86ed..6658d452b3 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/markdown/PullRequestParser.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/markdown/PullRequestParser.java
@@ -1,73 +1,73 @@
-package com.pmease.gitplex.core.markdown;
-
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.jsoup.Jsoup;
-import org.jsoup.nodes.Element;
-import org.jsoup.nodes.TextNode;
-import org.jsoup.select.NodeTraversor;
-
-import com.google.common.collect.ImmutableSet;
-import com.pmease.commons.hibernate.dao.Dao;
-import com.pmease.commons.util.JsoupUtils;
-import com.pmease.commons.util.TextNodeVisitor;
-import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.model.PullRequest;
-
-public class PullRequestParser {
-
- private static final Collection<String> IGNORED_TAGS = ImmutableSet.of("pre", "code", "a");
-
- private static final Pattern PATTERN = Pattern.compile("(^|\\s+)#(\\d+)(?=($|\\s+))");
-
- public Collection<PullRequest> parseRequests(String html) {
- return parseRequests(Jsoup.parseBodyFragment(html).body());
- }
-
- public Collection<PullRequest> parseRequests(Element body) {
- Collection<PullRequest> references = new HashSet<>();
-
- TextNodeVisitor visitor = new TextNodeVisitor() {
-
- @Override
- protected boolean isApplicable(TextNode node) {
- if (JsoupUtils.hasAncestor(node, IGNORED_TAGS))
- return false;
-
- return node.getWholeText().contains("#"); // fast scan here, do pattern match later
- }
- };
-
- NodeTraversor tranversor = new NodeTraversor(visitor);
- tranversor.traverse(body);
-
- Dao dao = GitPlex.getInstance(Dao.class);
-
- for (TextNode node : visitor.getMatchedNodes()) {
- Matcher matcher = PATTERN.matcher(node.getWholeText());
- while (matcher.find()) {
- Long requestId = Long.valueOf(matcher.group(2));
- String requestTag;
- PullRequest request = dao.get(PullRequest.class, requestId);
- if (request != null) {
- references.add(request);
- requestTag = toHtml(request);
- } else {
- requestTag = "#" + requestId;
- }
- JsoupUtils.appendReplacement(matcher, node, matcher.group(1) + requestTag + matcher.group(3));
- }
- JsoupUtils.appendTail(matcher, node);
- }
-
- return references;
- }
-
- protected String toHtml(PullRequest request) {
- return "#" + request.getId();
- }
-
-}
+package com.pmease.gitplex.core.util.markdown;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.jsoup.Jsoup;
+import org.jsoup.nodes.Element;
+import org.jsoup.nodes.TextNode;
+import org.jsoup.select.NodeTraversor;
+
+import com.google.common.collect.ImmutableSet;
+import com.pmease.commons.hibernate.dao.Dao;
+import com.pmease.commons.util.JsoupUtils;
+import com.pmease.commons.util.TextNodeVisitor;
+import com.pmease.gitplex.core.GitPlex;
+import com.pmease.gitplex.core.model.PullRequest;
+
+public class PullRequestParser {
+
+ private static final Collection<String> IGNORED_TAGS = ImmutableSet.of("pre", "code", "a");
+
+ private static final Pattern PATTERN = Pattern.compile("(^|\\s+)#(\\d+)(?=($|\\s+))");
+
+ public Collection<PullRequest> parseRequests(String html) {
+ return parseRequests(Jsoup.parseBodyFragment(html).body());
+ }
+
+ public Collection<PullRequest> parseRequests(Element body) {
+ Collection<PullRequest> references = new HashSet<>();
+
+ TextNodeVisitor visitor = new TextNodeVisitor() {
+
+ @Override
+ protected boolean isApplicable(TextNode node) {
+ if (JsoupUtils.hasAncestor(node, IGNORED_TAGS))
+ return false;
+
+ return node.getWholeText().contains("#"); // fast scan here, do pattern match later
+ }
+ };
+
+ NodeTraversor tranversor = new NodeTraversor(visitor);
+ tranversor.traverse(body);
+
+ Dao dao = GitPlex.getInstance(Dao.class);
+
+ for (TextNode node : visitor.getMatchedNodes()) {
+ Matcher matcher = PATTERN.matcher(node.getWholeText());
+ while (matcher.find()) {
+ Long requestId = Long.valueOf(matcher.group(2));
+ String requestTag;
+ PullRequest request = dao.get(PullRequest.class, requestId);
+ if (request != null) {
+ references.add(request);
+ requestTag = toHtml(request);
+ } else {
+ requestTag = "#" + requestId;
+ }
+ JsoupUtils.appendReplacement(matcher, node, matcher.group(1) + requestTag + matcher.group(3));
+ }
+ JsoupUtils.appendTail(matcher, node);
+ }
+
+ return references;
+ }
+
+ protected String toHtml(PullRequest request) {
+ return "#" + request.getId();
+ }
+
+}
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.g4
new file mode 100644
index 0000000000..c1d93f6cd4
--- /dev/null
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/refmatch/RefMatch.g4
@@ -0,0 +1,26 @@
+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 file
diff --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.java
new file mode 100644
index 0000000000..cc649a9186
--- /dev/null
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/refmatch/RefMatchUtils.java
@@ -0,0 +1,57 @@
+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.matchPath(includes, excludes, refName);
+ }
+
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/validation/DepotName.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/validation/DepotName.java
similarity index 80%
rename from gitplex.core/src/main/java/com/pmease/gitplex/core/validation/DepotName.java
rename to gitplex.core/src/main/java/com/pmease/gitplex/core/util/validation/DepotName.java
index a0a3bbcd05..08aca434a8 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/validation/DepotName.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/validation/DepotName.java
@@ -1,4 +1,4 @@
-package com.pmease.gitplex.core.validation;
+package com.pmease.gitplex.core.util.validation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
@@ -13,7 +13,7 @@ import com.pmease.commons.validation.Name;
@Target({ElementType.METHOD, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Name
-@Constraint(validatedBy=RepositoryNameValidator.class)
+@Constraint(validatedBy=DepotNameValidator.class)
public @interface DepotName {
String message() default "";
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/validation/RepositoryNameValidator.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/validation/DepotNameValidator.java
similarity index 88%
rename from gitplex.core/src/main/java/com/pmease/gitplex/core/validation/RepositoryNameValidator.java
rename to gitplex.core/src/main/java/com/pmease/gitplex/core/util/validation/DepotNameValidator.java
index a5313ab2ff..2919a25083 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/validation/RepositoryNameValidator.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/validation/DepotNameValidator.java
@@ -1,4 +1,4 @@
-package com.pmease.gitplex.core.validation;
+package com.pmease.gitplex.core.util.validation;
import java.util.HashSet;
import java.util.Set;
@@ -9,7 +9,7 @@ import javax.validation.ConstraintValidatorContext;
import com.pmease.gitplex.core.GitPlex;
-public class RepositoryNameValidator implements ConstraintValidator<DepotName, String> {
+public class DepotNameValidator implements ConstraintValidator<DepotName, String> {
private static Set<String> reservedNames;
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/validation/RepositoryNameReservation.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/validation/RepositoryNameReservation.java
similarity index 73%
rename from gitplex.core/src/main/java/com/pmease/gitplex/core/validation/RepositoryNameReservation.java
rename to gitplex.core/src/main/java/com/pmease/gitplex/core/util/validation/RepositoryNameReservation.java
index c4d37bdefa..0a040c64ad 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/validation/RepositoryNameReservation.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/validation/RepositoryNameReservation.java
@@ -1,10 +1,10 @@
-package com.pmease.gitplex.core.validation;
-
-import java.util.Set;
-
-import com.pmease.commons.loader.ExtensionPoint;
-
-@ExtensionPoint
-public interface RepositoryNameReservation {
- Set<String> getReserved();
-}
+package com.pmease.gitplex.core.util.validation;
+
+import java.util.Set;
+
+import com.pmease.commons.loader.ExtensionPoint;
+
+@ExtensionPoint
+public interface RepositoryNameReservation {
+ Set<String> getReserved();
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/validation/TeamName.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/validation/TeamName.java
similarity index 88%
rename from gitplex.core/src/main/java/com/pmease/gitplex/core/validation/TeamName.java
rename to gitplex.core/src/main/java/com/pmease/gitplex/core/util/validation/TeamName.java
index afbf27302d..559680c7c8 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/validation/TeamName.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/validation/TeamName.java
@@ -1,24 +1,24 @@
-package com.pmease.gitplex.core.validation;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-import javax.validation.Constraint;
-import javax.validation.Payload;
-
-import com.pmease.commons.validation.Name;
-
-@Target({ElementType.METHOD, ElementType.FIELD})
-@Retention(RetentionPolicy.RUNTIME)
-@Name
-@Constraint(validatedBy=TeamNameValidator.class)
-public @interface TeamName {
-
- String message() default "";
-
- Class<?>[] groups() default {};
-
- Class<? extends Payload>[] payload() default {};
-}
+package com.pmease.gitplex.core.util.validation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import javax.validation.Constraint;
+import javax.validation.Payload;
+
+import com.pmease.commons.validation.Name;
+
+@Target({ElementType.METHOD, ElementType.FIELD})
+@Retention(RetentionPolicy.RUNTIME)
+@Name
+@Constraint(validatedBy=TeamNameValidator.class)
+public @interface TeamName {
+
+ String message() default "";
+
+ Class<?>[] groups() default {};
+
+ Class<? extends Payload>[] payload() default {};
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/validation/TeamNameValidator.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/validation/TeamNameValidator.java
similarity index 91%
rename from gitplex.core/src/main/java/com/pmease/gitplex/core/validation/TeamNameValidator.java
rename to gitplex.core/src/main/java/com/pmease/gitplex/core/util/validation/TeamNameValidator.java
index 2d43f162da..273641d7a8 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/validation/TeamNameValidator.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/validation/TeamNameValidator.java
@@ -1,22 +1,22 @@
-package com.pmease.gitplex.core.validation;
-
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-
-import com.pmease.gitplex.core.model.Team;
-
-public class TeamNameValidator implements ConstraintValidator<TeamName, String> {
-
- public void initialize(TeamName constaintAnnotation) {
- }
-
- public boolean isValid(String value, ConstraintValidatorContext constraintContext) {
- if (value == null) return true;
-
- constraintContext.disableDefaultConstraintViolation();
- constraintContext.buildConstraintViolationWithTemplate(value + " is a reserved word.")
- .addConstraintViolation();
- return !value.equalsIgnoreCase(Team.ANONYMOUS) && !value.equalsIgnoreCase(Team.LOGGEDIN)
- && !value.equalsIgnoreCase(Team.OWNERS);
- }
-}
+package com.pmease.gitplex.core.util.validation;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+import com.pmease.gitplex.core.model.Team;
+
+public class TeamNameValidator implements ConstraintValidator<TeamName, String> {
+
+ public void initialize(TeamName constaintAnnotation) {
+ }
+
+ public boolean isValid(String value, ConstraintValidatorContext constraintContext) {
+ if (value == null) return true;
+
+ constraintContext.disableDefaultConstraintViolation();
+ constraintContext.buildConstraintViolationWithTemplate(value + " is a reserved word.")
+ .addConstraintViolation();
+ return !value.equalsIgnoreCase(Team.ANONYMOUS) && !value.equalsIgnoreCase(Team.LOGGEDIN)
+ && !value.equalsIgnoreCase(Team.OWNERS);
+ }
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/validation/UserName.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/validation/UserName.java
similarity index 88%
rename from gitplex.core/src/main/java/com/pmease/gitplex/core/validation/UserName.java
rename to gitplex.core/src/main/java/com/pmease/gitplex/core/util/validation/UserName.java
index c70906d182..db9ff93e43 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/validation/UserName.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/validation/UserName.java
@@ -1,24 +1,24 @@
-package com.pmease.gitplex.core.validation;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-import javax.validation.Constraint;
-import javax.validation.Payload;
-
-import com.pmease.commons.validation.Name;
-
-@Target({ElementType.METHOD, ElementType.FIELD})
-@Retention(RetentionPolicy.RUNTIME)
-@Name
-@Constraint(validatedBy=UserNameValidator.class)
-public @interface UserName {
-
- String message() default "";
-
- Class<?>[] groups() default {};
-
- Class<? extends Payload>[] payload() default {};
-}
+package com.pmease.gitplex.core.util.validation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import javax.validation.Constraint;
+import javax.validation.Payload;
+
+import com.pmease.commons.validation.Name;
+
+@Target({ElementType.METHOD, ElementType.FIELD})
+@Retention(RetentionPolicy.RUNTIME)
+@Name
+@Constraint(validatedBy=UserNameValidator.class)
+public @interface UserName {
+
+ String message() default "";
+
+ Class<?>[] groups() default {};
+
+ Class<? extends Payload>[] payload() default {};
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/validation/UserNameReservation.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/validation/UserNameReservation.java
similarity index 72%
rename from gitplex.core/src/main/java/com/pmease/gitplex/core/validation/UserNameReservation.java
rename to gitplex.core/src/main/java/com/pmease/gitplex/core/util/validation/UserNameReservation.java
index d5e291a4f8..41d9e11ff9 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/validation/UserNameReservation.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/validation/UserNameReservation.java
@@ -1,10 +1,10 @@
-package com.pmease.gitplex.core.validation;
-
-import java.util.Set;
-
-import com.pmease.commons.loader.ExtensionPoint;
-
-@ExtensionPoint
-public interface UserNameReservation {
- Set<String> getReserved();
-}
+package com.pmease.gitplex.core.util.validation;
+
+import java.util.Set;
+
+import com.pmease.commons.loader.ExtensionPoint;
+
+@ExtensionPoint
+public interface UserNameReservation {
+ Set<String> getReserved();
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/validation/UserNameValidator.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/validation/UserNameValidator.java
similarity index 93%
rename from gitplex.core/src/main/java/com/pmease/gitplex/core/validation/UserNameValidator.java
rename to gitplex.core/src/main/java/com/pmease/gitplex/core/util/validation/UserNameValidator.java
index 87a7697ec3..408b71539c 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/validation/UserNameValidator.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/validation/UserNameValidator.java
@@ -1,48 +1,48 @@
-package com.pmease.gitplex.core.validation;
-
-import java.util.HashSet;
-import java.util.Set;
-import java.util.regex.Pattern;
-
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-
-import com.pmease.gitplex.core.GitPlex;
-
-public class UserNameValidator implements ConstraintValidator<UserName, String> {
-
- private static Set<String> reservedNames;
-
- private static Pattern pattern = Pattern.compile("^[\\w-\\.]+$");
-
- public void initialize(UserName constaintAnnotation) {
- }
-
- public boolean isValid(String value, ConstraintValidatorContext constraintContext) {
- if (value == null) {
- return true;
- } else if (!pattern.matcher(value).find()) {
- constraintContext.disableDefaultConstraintViolation();
- String message = "Only alphanumeric, underscore, dash, and dot are accepted.";
- constraintContext.buildConstraintViolationWithTemplate(message).addConstraintViolation();
- return false;
- } else if (getReservedNames().contains(value)) {
- constraintContext.disableDefaultConstraintViolation();
- constraintContext.buildConstraintViolationWithTemplate(value + " is a reserved word.").addConstraintViolation();
- return false;
- } else {
- return true;
- }
- }
-
- public static synchronized Set<String> getReservedNames() {
- if (reservedNames == null) {
- reservedNames = new HashSet<>();
- for (UserNameReservation each : GitPlex.getExtensions(UserNameReservation.class)) {
- reservedNames.addAll(each.getReserved());
- }
- }
- return reservedNames;
- }
-
-}
+package com.pmease.gitplex.core.util.validation;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.regex.Pattern;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+import com.pmease.gitplex.core.GitPlex;
+
+public class UserNameValidator implements ConstraintValidator<UserName, String> {
+
+ private static Set<String> reservedNames;
+
+ private static Pattern pattern = Pattern.compile("^[\\w-\\.]+$");
+
+ public void initialize(UserName constaintAnnotation) {
+ }
+
+ public boolean isValid(String value, ConstraintValidatorContext constraintContext) {
+ if (value == null) {
+ return true;
+ } else if (!pattern.matcher(value).find()) {
+ constraintContext.disableDefaultConstraintViolation();
+ String message = "Only alphanumeric, underscore, dash, and dot are accepted.";
+ constraintContext.buildConstraintViolationWithTemplate(message).addConstraintViolation();
+ return false;
+ } else if (getReservedNames().contains(value)) {
+ constraintContext.disableDefaultConstraintViolation();
+ constraintContext.buildConstraintViolationWithTemplate(value + " is a reserved word.").addConstraintViolation();
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ public static synchronized Set<String> getReservedNames() {
+ if (reservedNames == null) {
+ reservedNames = new HashSet<>();
+ for (UserNameReservation each : GitPlex.getExtensions(UserNameReservation.class)) {
+ reservedNames.addAll(each.getReserved());
+ }
+ }
+ return reservedNames;
+ }
+
+}
diff --git a/gitplex.core/src/test/java/com/pmease/gitplex/core/gatekeeper/DirectionProtectionTest.java b/gitplex.core/src/test/java/com/pmease/gitplex/core/gatekeeper/DirectionProtectionTest.java
deleted file mode 100644
index 804a38397d..0000000000
--- a/gitplex.core/src/test/java/com/pmease/gitplex/core/gatekeeper/DirectionProtectionTest.java
+++ /dev/null
@@ -1,124 +0,0 @@
-package com.pmease.gitplex.core.gatekeeper;
-
-import static org.junit.Assert.assertTrue;
-
-import org.eclipse.jgit.lib.ObjectId;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-
-import com.google.common.collect.Lists;
-import com.pmease.commons.git.AbstractGitTest;
-import com.pmease.commons.git.Git;
-import com.pmease.commons.hibernate.dao.Dao;
-import com.pmease.commons.loader.AppLoader;
-import com.pmease.gitplex.core.gatekeeper.helper.branchselection.SpecifyTargetBranchesByNames;
-import com.pmease.gitplex.core.gatekeeper.helper.pathselection.SpecifyTargetPathsByDirectories;
-import com.pmease.gitplex.core.model.Membership;
-import com.pmease.gitplex.core.model.Depot;
-import com.pmease.gitplex.core.model.Team;
-import com.pmease.gitplex.core.model.User;
-
-public class DirectionProtectionTest extends AbstractGitTest {
-
- @Mock
- private Dao dao;
-
- @Override
- protected void setup() {
- super.setup();
-
- Mockito.when(AppLoader.getInstance(Dao.class)).thenReturn(dao);
- Team team = new Team();
- team.setName("team");
- team.setId(1L);
- Membership membership = new Membership();
- membership.setTeam(team);
- membership.setUser(new User());
- membership.getUser().setId(1L);
- team.getMemberships().add(membership);
- Mockito.when(dao.load(Team.class, 1L)).thenReturn(team);
- }
-
- @Test
- public void testCheckFile() {
- DirectoryAndFileProtection pathProtection = new DirectoryAndFileProtection();
- SpecifyTargetBranchesByNames branchSelection = new SpecifyTargetBranchesByNames();
- branchSelection.setBranches(Lists.newArrayList("branch1"));
- pathProtection.setBranchSelection(branchSelection);
-
- SpecifyTargetPathsByDirectories pathSelection = new SpecifyTargetPathsByDirectories();
- pathSelection.setDirectories(Lists.newArrayList("src"));
- pathProtection.setPathSelection(pathSelection);
-
- pathProtection.setTeamIds(Lists.newArrayList(1L));
-
- Team team = new Team();
- team.setId(1L);
- User user1 = new User();
- user1.setId(1L);
- Membership membership = new Membership();
- membership.setUser(user1);
- membership.setTeam(team);
- user1.getMemberships().add(membership);
- team.getMemberships().add(membership);
-
- User user2 = new User();
- user2.setId(2L);
-
- Depot repo = new Depot();
- assertTrue(pathProtection.checkFile(user1, repo, "branch1", "src/test.java").isPassed());
- assertTrue(pathProtection.checkFile(user1, repo, "branch1", "doc/test.pdf").isPassed());
- assertTrue(pathProtection.checkFile(user2, repo, "branch1", "src/test.java").isPending());
- assertTrue(pathProtection.checkFile(user2, repo, "branch2", "src/test.java").isPassed());
- }
-
- @SuppressWarnings("serial")
- @Test
- public void testCheckCommit() {
- DirectoryAndFileProtection pathProtection = new DirectoryAndFileProtection();
- SpecifyTargetBranchesByNames branchSelection = new SpecifyTargetBranchesByNames();
- branchSelection.setBranches(Lists.newArrayList("branch1"));
- pathProtection.setBranchSelection(branchSelection);
-
- SpecifyTargetPathsByDirectories pathSelection = new SpecifyTargetPathsByDirectories();
- pathSelection.setDirectories(Lists.newArrayList("src"));
- pathProtection.setPathSelection(pathSelection);
-
- pathProtection.setTeamIds(Lists.newArrayList(1L));
-
- addFileAndCommit("src/file1", "", "add src/file1");
-
- git.checkout("master", "branch1");
- git.checkout("master", "branch2");
-
- Depot repo = new Depot() {
-
- @Override
- public Git git() {
- return git;
- }
-
- };
- repo.cacheObjectId("branch1", ObjectId.fromString(git.parseRevision("branch1", true)));
-
- User user1 = new User();
- user1.setId(1L);
-
- User user2 = new User();
- user2.setId(2L);
-
- addFileAndCommit("src/file2", "", "add src/file2");
-
- assertTrue(pathProtection.checkCommit(user1, repo, "branch1", git.parseRevision("branch2", true)).isPassed());
- assertTrue(pathProtection.checkCommit(user2, repo, "branch1", git.parseRevision("branch2", true)).isPending());
-
- git.checkout("master", "branch3");
-
- addFileAndCommit("docs/file2", "", "add docs/file2");
-
- assertTrue(pathProtection.checkCommit(user1, repo, "branch1", git.parseRevision("branch3", true)).isPassed());
- assertTrue(pathProtection.checkCommit(user2, repo, "branch1", git.parseRevision("branch3", true)).isPassed());
- }
-
-}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/UrlMapper.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/UrlMapper.java
index dcba1ab13e..c43646cdba 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/UrlMapper.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/UrlMapper.java
@@ -11,8 +11,8 @@ import org.apache.wicket.request.Url;
import org.apache.wicket.request.mapper.CompoundRequestMapper;
import com.pmease.commons.util.StringUtils;
-import com.pmease.gitplex.core.validation.RepositoryNameValidator;
-import com.pmease.gitplex.core.validation.UserNameValidator;
+import com.pmease.gitplex.core.util.validation.DepotNameValidator;
+import com.pmease.gitplex.core.util.validation.UserNameValidator;
import com.pmease.gitplex.web.page.account.depots.AccountDepotsPage;
import com.pmease.gitplex.web.page.account.depots.NewAccountDepotPage;
import com.pmease.gitplex.web.page.account.notifications.AccountNotificationsPage;
@@ -57,7 +57,7 @@ public class UrlMapper extends CompoundRequestMapper {
add(new MountedMapper("init", ServerInitPage.class));
addAdministrationPages();
addAccountPages();
- addRepoPages();
+ addDepotPages();
addSecurityPages();
add(new MountedMapper("/test", TestPage.class));
@@ -67,7 +67,7 @@ public class UrlMapper extends CompoundRequestMapper {
}
private void addResources() {
- add(new ResourceMapper("${user}/${repo}/archive", new ArchiveResourceReference()) {
+ add(new ResourceMapper("${user}/${depot}/archive", new ArchiveResourceReference()) {
@Override
public int getCompatibilityScore(Request request) {
@@ -75,7 +75,7 @@ public class UrlMapper extends CompoundRequestMapper {
}
});
- add(new ResourceMapper("${user}/${repo}/raw", new BlobResourceReference()) {
+ add(new ResourceMapper("${user}/${depot}/raw", new BlobResourceReference()) {
@Override
public int getCompatibilityScore(Request request) {
@@ -83,7 +83,7 @@ public class UrlMapper extends CompoundRequestMapper {
}
});
- add(new ResourceMapper("${user}/${repo}/pulls/${request}/attachments/${attachment}", new AttachmentResourceReference()) {
+ add(new ResourceMapper("${user}/${depot}/pulls/${request}/attachments/${attachment}", new AttachmentResourceReference()) {
@Override
public int getCompatibilityScore(Request request) {
@@ -133,16 +133,16 @@ public class UrlMapper extends CompoundRequestMapper {
});
- add(new MountedMapper("${user}/repositories", AccountDepotsPage.class));
- add(new MountedMapper("${user}/repositories/new", NewAccountDepotPage.class));
+ add(new MountedMapper("${user}/depots", AccountDepotsPage.class));
+ add(new MountedMapper("${user}/depots/new", NewAccountDepotPage.class));
add(new MountedMapper("${user}/notifications", AccountNotificationsPage.class));
add(new MountedMapper("${user}/setting/profile", ProfileEditPage.class));
add(new MountedMapper("${user}/setting/avatar", AvatarEditPage.class));
add(new MountedMapper("${user}/setting/password", PasswordEditPage.class));
}
- private void addRepoPages() {
- add(new MountedMapper("${user}/${repo}", DepotFilePage.class) {
+ private void addDepotPages() {
+ add(new MountedMapper("${user}/${depot}", DepotFilePage.class) {
@Override
protected boolean urlStartsWith(Url url, String... segments) {
@@ -153,38 +153,38 @@ public class UrlMapper extends CompoundRequestMapper {
if (UserNameValidator.getReservedNames().contains(userName))
return false;
- String repositoryName = urlSegments.get(1);
- return !RepositoryNameValidator.getReservedNames().contains(repositoryName);
+ String depotName = urlSegments.get(1);
+ return !DepotNameValidator.getReservedNames().contains(depotName);
}
});
-// add(new ParameterAwareMountedMapper("${user}/${repo}/browse", RepoFilePage.class));
- add(new MountedMapper("${user}/${repo}/commit", CommitDetailPage.class));
- add(new MountedMapper("${user}/${repo}/commits", DepotCommitsPage.class));
- add(new MountedMapper("${user}/${repo}/compare", RevisionComparePage.class));
+// add(new ParameterAwareMountedMapper("${user}/${depot}/browse", RepoFilePage.class));
+ add(new MountedMapper("${user}/${depot}/commit", CommitDetailPage.class));
+ add(new MountedMapper("${user}/${depot}/commits", DepotCommitsPage.class));
+ add(new MountedMapper("${user}/${depot}/compare", RevisionComparePage.class));
- add(new MountedMapper("${user}/${repo}/branches", DepotBranchesPage.class));
- add(new MountedMapper("${user}/${repo}/tags", DepotTagsPage.class));
+ add(new MountedMapper("${user}/${depot}/branches", DepotBranchesPage.class));
+ add(new MountedMapper("${user}/${depot}/tags", DepotTagsPage.class));
- add(new MountedMapper("${user}/${repo}/pulls", RequestListPage.class));
- add(new MountedMapper("${user}/${repo}/pulls/new", NewRequestPage.class));
- add(new MountedMapper("${user}/${repo}/pulls/${request}", RequestOverviewPage.class));
+ add(new MountedMapper("${user}/${depot}/pulls", RequestListPage.class));
+ add(new MountedMapper("${user}/${depot}/pulls/new", NewRequestPage.class));
+ add(new MountedMapper("${user}/${depot}/pulls/${request}", RequestOverviewPage.class));
add(new MountedMapper(
- "${user}/${repo}/pulls/${request}/overview", RequestOverviewPage.class));
+ "${user}/${depot}/pulls/${request}/overview", RequestOverviewPage.class));
add(new MountedMapper(
- "${user}/${repo}/pulls/${request}/updates", RequestUpdatesPage.class));
+ "${user}/${depot}/pulls/${request}/updates", RequestUpdatesPage.class));
add(new MountedMapper(
- "${user}/${repo}/pulls/${request}/compare", RequestComparePage.class));
+ "${user}/${depot}/pulls/${request}/compare", RequestComparePage.class));
add(new MountedMapper(
- "${user}/${repo}/pulls/${request}/attachments", RequestAttachmentsPage.class));
+ "${user}/${depot}/pulls/${request}/attachments", RequestAttachmentsPage.class));
- add(new MountedMapper("${user}/${repo}/setting", GeneralSettingPage.class));
- add(new MountedMapper("${user}/${repo}/setting/general", GeneralSettingPage.class));
- add(new MountedMapper("${user}/${repo}/setting/gate-keeper", GateKeeperPage.class));
- add(new MountedMapper("${user}/${repo}/setting/integration-policy", IntegrationPolicyPage.class));
+ add(new MountedMapper("${user}/${depot}/setting", GeneralSettingPage.class));
+ add(new MountedMapper("${user}/${depot}/setting/general", GeneralSettingPage.class));
+ add(new MountedMapper("${user}/${depot}/setting/gate-keeper", GateKeeperPage.class));
+ add(new MountedMapper("${user}/${depot}/setting/integration-policy", IntegrationPolicyPage.class));
- add(new MountedMapper("${user}/${repo}/no-commits", NoCommitsPage.class));
+ add(new MountedMapper("${user}/${depot}/no-commits", NoCommitsPage.class));
}
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/WebModule.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/WebModule.java
index ca5978c632..6d0a7329f4 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/WebModule.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/WebModule.java
@@ -16,7 +16,7 @@ import com.pmease.commons.wicket.AbstractWicketConfig;
import com.pmease.commons.wicket.editable.EditSupport;
import com.pmease.gitplex.core.listeners.PullRequestListener;
import com.pmease.gitplex.core.manager.UrlManager;
-import com.pmease.gitplex.core.validation.UserNameReservation;
+import com.pmease.gitplex.core.util.validation.UserNameReservation;
import com.pmease.gitplex.search.IndexListener;
import com.pmease.gitplex.web.avatar.AvatarManager;
import com.pmease.gitplex.web.avatar.DefaultAvatarManager;
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/WebUserNameReservation.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/WebUserNameReservation.java
index 8b9f0dc183..ed7367e595 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/WebUserNameReservation.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/WebUserNameReservation.java
@@ -1,86 +1,86 @@
-package com.pmease.gitplex.web;
-
-import java.lang.reflect.Field;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-import javax.inject.Inject;
-
-import org.apache.commons.lang3.StringUtils;
-import org.apache.wicket.core.request.mapper.MountedMapper;
-import org.apache.wicket.core.request.mapper.ResourceMapper;
-import org.apache.wicket.request.IRequestMapper;
-import org.apache.wicket.request.mapper.ICompoundRequestMapper;
-import org.eclipse.jetty.servlet.ServletMapping;
-
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Sets;
-import com.pmease.commons.jetty.JettyPlugin;
-import com.pmease.commons.util.ReflectionUtils;
-import com.pmease.gitplex.core.validation.UserNameReservation;
-
-public class WebUserNameReservation implements UserNameReservation {
-
- private final JettyPlugin jettyPlugin;
-
- private final WicketConfig webApp;
-
- @Inject
- public WebUserNameReservation(JettyPlugin jettyPlugin, WicketConfig webApp) {
- this.jettyPlugin = jettyPlugin;
- this.webApp = webApp;
- }
-
- @Override
- public Set<String> getReserved() {
- Set<String> reserved = new HashSet<String>();
- for (ServletMapping mapping: jettyPlugin.getContextHandler().getServletHandler().getServletMappings()) {
- for (String pathSpec: mapping.getPathSpecs()) {
- pathSpec = StringUtils.stripStart(pathSpec, "/");
- pathSpec = StringUtils.substringBefore(pathSpec, "/");
- if (pathSpec.trim().length() != 0)
- reserved.add(pathSpec.trim());
- }
- }
-
- reserved.add("wicket");
-
- for (IRequestMapper mapper: webApp.getRequestMappers()) {
- Set<String> set = getReservedNames(mapper);
- reserved.addAll(set);
- }
-
- return reserved;
- }
-
- private Set<String> getReservedNames(IRequestMapper mapper) {
- if (mapper instanceof MountedMapper || mapper instanceof ResourceMapper) {
- try {
- Field field = ReflectionUtils.findField(mapper.getClass(), "mountSegments");
- Preconditions.checkNotNull(field);
- field.setAccessible(true);
- String[] mountSegments = (String[]) field.get(mapper);
- if (mountSegments != null && mountSegments.length != 0 && mountSegments[0] != null)
- return Collections.singleton(mountSegments[0]);
- else
- return Collections.emptySet();
- } catch (SecurityException | IllegalArgumentException | IllegalAccessException e) {
- throw new RuntimeException(e);
- }
- }
-
- if (mapper instanceof ICompoundRequestMapper) {
- ICompoundRequestMapper m = (ICompoundRequestMapper) mapper;
- Set<String> result = Sets.newHashSet();
- for (IRequestMapper each : m) {
- Set<String> set = getReservedNames(each);
- result.addAll(set);
- }
-
- return result;
- }
-
- return Collections.emptySet();
- }
-}
+package com.pmease.gitplex.web;
+
+import java.lang.reflect.Field;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.inject.Inject;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.wicket.core.request.mapper.MountedMapper;
+import org.apache.wicket.core.request.mapper.ResourceMapper;
+import org.apache.wicket.request.IRequestMapper;
+import org.apache.wicket.request.mapper.ICompoundRequestMapper;
+import org.eclipse.jetty.servlet.ServletMapping;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Sets;
+import com.pmease.commons.jetty.JettyPlugin;
+import com.pmease.commons.util.ReflectionUtils;
+import com.pmease.gitplex.core.util.validation.UserNameReservation;
+
+public class WebUserNameReservation implements UserNameReservation {
+
+ private final JettyPlugin jettyPlugin;
+
+ private final WicketConfig webApp;
+
+ @Inject
+ public WebUserNameReservation(JettyPlugin jettyPlugin, WicketConfig webApp) {
+ this.jettyPlugin = jettyPlugin;
+ this.webApp = webApp;
+ }
+
+ @Override
+ public Set<String> getReserved() {
+ Set<String> reserved = new HashSet<String>();
+ for (ServletMapping mapping: jettyPlugin.getContextHandler().getServletHandler().getServletMappings()) {
+ for (String pathSpec: mapping.getPathSpecs()) {
+ pathSpec = StringUtils.stripStart(pathSpec, "/");
+ pathSpec = StringUtils.substringBefore(pathSpec, "/");
+ if (pathSpec.trim().length() != 0)
+ reserved.add(pathSpec.trim());
+ }
+ }
+
+ reserved.add("wicket");
+
+ for (IRequestMapper mapper: webApp.getRequestMappers()) {
+ Set<String> set = getReservedNames(mapper);
+ reserved.addAll(set);
+ }
+
+ return reserved;
+ }
+
+ private Set<String> getReservedNames(IRequestMapper mapper) {
+ if (mapper instanceof MountedMapper || mapper instanceof ResourceMapper) {
+ try {
+ Field field = ReflectionUtils.findField(mapper.getClass(), "mountSegments");
+ Preconditions.checkNotNull(field);
+ field.setAccessible(true);
+ String[] mountSegments = (String[]) field.get(mapper);
+ if (mountSegments != null && mountSegments.length != 0 && mountSegments[0] != null)
+ return Collections.singleton(mountSegments[0]);
+ else
+ return Collections.emptySet();
+ } catch (SecurityException | IllegalArgumentException | IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ if (mapper instanceof ICompoundRequestMapper) {
+ ICompoundRequestMapper m = (ICompoundRequestMapper) mapper;
+ Set<String> result = Sets.newHashSet();
+ for (IRequestMapper each : m) {
+ Set<String> set = getReservedNames(each);
+ result.addAll(set);
+ }
+
+ return result;
+ }
+
+ return Collections.emptySet();
+ }
+}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/BranchLink.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/BranchLink.java
index e82be6acb8..263c368949 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/BranchLink.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/BranchLink.java
@@ -14,24 +14,24 @@ import com.pmease.gitplex.web.page.depot.file.DepotFilePage.HistoryState;
@SuppressWarnings("serial")
public class BranchLink extends BookmarkablePageLink<Void> {
- private final DepotAndBranch repoAndBranch;
+ private final DepotAndBranch depotAndBranch;
- public BranchLink(String id, DepotAndBranch repoAndBranch) {
- super(id, DepotFilePage.class, getPageParams(repoAndBranch));
- this.repoAndBranch = repoAndBranch;
+ public BranchLink(String id, DepotAndBranch depotAndBranch) {
+ super(id, DepotFilePage.class, getPageParams(depotAndBranch));
+ this.depotAndBranch = depotAndBranch;
}
- private static PageParameters getPageParams(DepotAndBranch repoAndBranch) {
+ private static PageParameters getPageParams(DepotAndBranch depotAndBranch) {
HistoryState state = new HistoryState();
- state.blobIdent.revision = repoAndBranch.getBranch();
- return DepotFilePage.paramsOf(repoAndBranch.getDepot(), state);
+ state.blobIdent.revision = depotAndBranch.getBranch();
+ return DepotFilePage.paramsOf(depotAndBranch.getDepot(), state);
}
@Override
protected void onConfigure() {
super.onConfigure();
- setEnabled(SecurityUtils.canPull(repoAndBranch.getDepot())
- && repoAndBranch.getObjectName(false) != null);
+ setEnabled(SecurityUtils.canPull(depotAndBranch.getDepot())
+ && depotAndBranch.getObjectName(false) != null);
}
@Override
@@ -39,12 +39,12 @@ public class BranchLink extends BookmarkablePageLink<Void> {
String label;
if (getPage() instanceof DepotPage) {
DepotPage page = (DepotPage) getPage();
- if (page.getDepot().equals(repoAndBranch.getDepot()))
- label = repoAndBranch.getBranch();
+ if (page.getDepot().equals(depotAndBranch.getDepot()))
+ label = depotAndBranch.getBranch();
else
- label = repoAndBranch.getFQN();
+ label = depotAndBranch.getFQN();
} else {
- label = repoAndBranch.getFQN();
+ label = depotAndBranch.getFQN();
}
return Model.of(label);
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branchchoice/AffinalBranchMultiChoice.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branchchoice/AffinalBranchMultiChoice.java
index fa9d90a6a9..1e5f0a1bcc 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branchchoice/AffinalBranchMultiChoice.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/branchchoice/AffinalBranchMultiChoice.java
@@ -130,8 +130,8 @@ public class AffinalBranchMultiChoice extends FormComponentPanel<Collection<Stri
return getModelObject();
}
- private void setDepotAndBranches(Collection<String> repoAndBranches) {
- getModel().setObject(repoAndBranches);
+ private void setDepotAndBranches(Collection<String> depotAndBranches) {
+ getModel().setObject(depotAndBranches);
}
@Override
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/MentionTransformer.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/MentionTransformer.java
index b26c1d9d52..c5e6e4745f 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/MentionTransformer.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/MentionTransformer.java
@@ -4,8 +4,8 @@ import org.apache.wicket.request.cycle.RequestCycle;
import org.jsoup.nodes.Element;
import com.pmease.commons.markdown.extensionpoint.HtmlTransformer;
-import com.pmease.gitplex.core.markdown.MentionParser;
import com.pmease.gitplex.core.model.User;
+import com.pmease.gitplex.core.util.markdown.MentionParser;
import com.pmease.gitplex.web.page.account.AccountPage;
import com.pmease.gitplex.web.page.account.depots.AccountDepotsPage;
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/PullRequestTransformer.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/PullRequestTransformer.java
index d0ad512e4b..1b523e8f7f 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/PullRequestTransformer.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/PullRequestTransformer.java
@@ -4,8 +4,8 @@ import org.apache.wicket.request.cycle.RequestCycle;
import org.jsoup.nodes.Element;
import com.pmease.commons.markdown.extensionpoint.HtmlTransformer;
-import com.pmease.gitplex.core.markdown.PullRequestParser;
import com.pmease.gitplex.core.model.PullRequest;
+import com.pmease.gitplex.core.util.markdown.PullRequestParser;
import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.overview.RequestOverviewPage;
public class PullRequestTransformer extends PullRequestParser implements HtmlTransformer {
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/createbranch/CreateBranchLink.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/createbranch/CreateBranchLink.java
index 37968fb4da..8e44d63c52 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/createbranch/CreateBranchLink.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/createbranch/CreateBranchLink.java
@@ -1,10 +1,10 @@
package com.pmease.gitplex.web.component.createbranch;
-import java.util.UUID;
-
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.model.IModel;
+import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.ObjectId;
import com.pmease.commons.wicket.component.modal.ModalLink;
import com.pmease.gitplex.core.model.Depot;
@@ -27,7 +27,9 @@ public abstract class CreateBranchLink extends ModalLink {
@Override
protected void onConfigure() {
super.onConfigure();
- setVisible(SecurityUtils.canCreate(depotModel.getObject(), UUID.randomUUID().toString()));
+
+ ObjectId commitId = depotModel.getObject().getRevCommit(revision);
+ setVisible(SecurityUtils.canPushRef(depotModel.getObject(), Constants.R_HEADS, ObjectId.zeroId(), commitId));
}
@Override
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/createtag/CreateTagLink.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/createtag/CreateTagLink.java
index 396c39df3b..4b1fa0f912 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/createtag/CreateTagLink.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/createtag/CreateTagLink.java
@@ -1,11 +1,10 @@
package com.pmease.gitplex.web.component.createtag;
-import java.util.UUID;
-
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.model.IModel;
import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.ObjectId;
import com.pmease.commons.wicket.component.modal.ModalLink;
import com.pmease.gitplex.core.model.Depot;
@@ -28,7 +27,10 @@ public abstract class CreateTagLink extends ModalLink {
@Override
protected void onConfigure() {
super.onConfigure();
- setVisible(SecurityUtils.canModify(depotModel.getObject(), Constants.R_TAGS + UUID.randomUUID().toString()));
+
+ ObjectId commit = depotModel.getObject().getRevCommit(revision);
+ setVisible(SecurityUtils.canPushRef(depotModel.getObject(), Constants.R_HEADS,
+ ObjectId.zeroId(), commit));
}
@Override
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
new file mode 100644
index 0000000000..9ad8ae845d
--- /dev/null
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/refmatch/RefMatchBehavior.java
@@ -0,0 +1,157 @@
+package com.pmease.gitplex.web.component.refmatch;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.model.IModel;
+import org.eclipse.jgit.lib.Ref;
+
+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.git.GitUtils;
+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;
+
+@SuppressWarnings("serial")
+public class RefMatchBehavior extends ANTLRAssistBehavior {
+
+ private final IModel<Depot> depotModel;
+
+ private static final String VALUE_OPEN = "(";
+
+ private static final String VALUE_CLOSE = ")";
+
+ public RefMatchBehavior(IModel<Depot> depotModel) {
+ super(RefMatchParser.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) {
+ int tokenType = expectedElement.getRoot().getLastMatchedToken().getType();
+ String unfencedLowerCaseMatchWith = unfencedMatchWith.toLowerCase();
+ int numSuggestions = 0;
+ List<InputSuggestion> suggestions = new ArrayList<>();
+ switch (tokenType) {
+ case RefMatchParser.BRANCH:
+ case RefMatchParser.EXCLUDE_BRANCH:
+ for (Ref ref: depotModel.getObject().getBranchRefs()) {
+ String branch = GitUtils.ref2branch(ref.getName());
+ int index = branch.toLowerCase().indexOf(unfencedLowerCaseMatchWith);
+ if (index != -1 && numSuggestions++<count) {
+ Range matchRange = new Range(index, index+unfencedLowerCaseMatchWith.length());
+ suggestions.add(new InputSuggestion(branch, matchRange));
+ }
+ }
+ break;
+ case RefMatchParser.TAG:
+ case RefMatchParser.EXCLUDE_TAG:
+ for (Ref ref: depotModel.getObject().getTagRefs()) {
+ String tag = GitUtils.ref2tag(ref.getName());
+ int index = tag.toLowerCase().indexOf(unfencedLowerCaseMatchWith);
+ if (index != -1 && numSuggestions++<count) {
+ Range matchRange = new Range(index, index+unfencedLowerCaseMatchWith.length());
+ suggestions.add(new InputSuggestion(tag, matchRange));
+ }
+ }
+ 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));
+ }
+ suggestions.add(new InputSuggestion("refs/heads/**", "All branches", null));
+ suggestions.add(new InputSuggestion("refs/tags/**", "All tags", null));
+ }
+ break;
+ }
+ return suggestions;
+ }
+
+ @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)) {
+ int tokenType = expectedElement.getRoot().getLastMatchedToken().getType();
+ if (tokenType == RefMatchParser.PATTERN || tokenType == RefMatchParser.EXCLUDE_PATTERN) {
+ hints.add("Use * to match any character except /");
+ hints.add("Use ** to match any character including /");
+ }
+ }
+ }
+ 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) {
+ 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);
+ }
+
+}
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.java
new file mode 100644
index 0000000000..d1c24c940c
--- /dev/null
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/refmatch/RefMatchInput.java
@@ -0,0 +1,74 @@
+package com.pmease.gitplex.web.component.refmatch;
+
+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.refmatch.RefMatchUtils;
+
+@SuppressWarnings("serial")
+public class RefMatchInput extends TextField<String> {
+
+ private static final Logger logger = LoggerFactory.getLogger(RefMatchInput.class);
+
+ private final IModel<Depot> depotModel;
+
+ public RefMatchInput(String id, IModel<Depot> depotModel, IModel<String> refMatchModel) {
+ super(id, refMatchModel);
+
+ this.depotModel = depotModel;
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ add(new RefMatchBehavior(depotModel));
+ add(new IValidator<String>() {
+
+ @Override
+ public void validate(IValidatable<String> validatable) {
+ try {
+ RefMatchUtils.parse(validatable.getValue());
+ } catch (final Exception e) {
+ logger.error("Error parsing ref 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/repofile/fileedit/FileEditPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/fileedit/FileEditPanel.java
index 9343c0d04a..5c7a242f00 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/fileedit/FileEditPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/fileedit/FileEditPanel.java
@@ -127,7 +127,7 @@ public abstract class FileEditPanel extends Panel {
@Override
public Blob getBlob(BlobIdent blobIdent) {
- if (blobIdent.revision.equals(GitUtils.NULL_SHA1))
+ if (blobIdent.revision.equals(ObjectId.zeroId().name()))
return new Blob(blobIdent, content.getBytes(Charsets.UTF_8));
else
return depotModel.getObject().getBlob(blobIdent);
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branch/AffinalBranchMultiChoiceEditor.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branch/AffinalBranchMultiChoiceEditor.java
index a95f614072..b1f401152e 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branch/AffinalBranchMultiChoiceEditor.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branch/AffinalBranchMultiChoiceEditor.java
@@ -33,9 +33,9 @@ public class AffinalBranchMultiChoiceEditor extends PropertyEditor<List<String>>
@Override
protected Object load() {
- List<String> repoAndBranches = getModelObject();
- if (repoAndBranches != null)
- return repoAndBranches;
+ List<String> depotAndBranches = getModelObject();
+ if (depotAndBranches != null)
+ return depotAndBranches;
else
return new ArrayList<>();
}
@@ -52,11 +52,11 @@ public class AffinalBranchMultiChoiceEditor extends PropertyEditor<List<String>>
@Override
protected List<String> convertInputToValue() throws ConversionException {
- List<String> repoAndBranches = new ArrayList<>();
+ List<String> depotAndBranches = new ArrayList<>();
Collection<String> convertedInput = input.getConvertedInput();
if (convertedInput != null)
- repoAndBranches.addAll(convertedInput);
- return repoAndBranches;
+ depotAndBranches.addAll(convertedInput);
+ return depotAndBranches;
}
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branch/BranchEditSupport.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branch/BranchEditSupport.java
index 0a8a7cb746..3507bde49d 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branch/BranchEditSupport.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branch/BranchEditSupport.java
@@ -19,8 +19,8 @@ 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.editable.BranchChoice;
import com.pmease.gitplex.core.model.DepotAndBranch;
+import com.pmease.gitplex.core.util.editable.BranchChoice;
@SuppressWarnings("serial")
public class BranchEditSupport implements EditSupport {
@@ -45,10 +45,10 @@ public class BranchEditSupport implements EditSupport {
@Override
protected Component newContent(String id, PropertyDescriptor propertyDescriptor) {
- List<String> repoAndBranches = model.getObject();
- if (repoAndBranches != null && !repoAndBranches.isEmpty()) {
+ List<String> depotAndBranches = model.getObject();
+ if (depotAndBranches != null && !depotAndBranches.isEmpty()) {
List<String> branches = new ArrayList<>();
- for (String each: repoAndBranches) {
+ for (String each: depotAndBranches) {
if (isAffinal(getPropertyGetter()) || isGlobal(getPropertyGetter()))
branches.add(new DepotAndBranch(each).getFQN());
else
@@ -83,12 +83,12 @@ public class BranchEditSupport implements EditSupport {
@Override
protected Component newContent(String id, PropertyDescriptor propertyDescriptor) {
- String repoAndBranch = model.getObject();
- if (repoAndBranch != null) {
+ String depotAndBranch = model.getObject();
+ if (depotAndBranch != null) {
if (isAffinal(getPropertyGetter()) || isGlobal(getPropertyGetter()))
- return new Label(id, new DepotAndBranch(repoAndBranch).getFQN());
+ return new Label(id, new DepotAndBranch(depotAndBranch).getFQN());
else
- return new Label(id, repoAndBranch);
+ return new Label(id, depotAndBranch);
} else {
return new NotDefinedLabel(id);
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branch/BranchMultiChoiceEditor.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branch/BranchMultiChoiceEditor.java
index 6462ec7621..2fc91aa00e 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branch/BranchMultiChoiceEditor.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branch/BranchMultiChoiceEditor.java
@@ -42,11 +42,11 @@ public class BranchMultiChoiceEditor extends PropertyEditor<List<String>> {
});
- ArrayList<String> repoAndBranches = new ArrayList<>();
+ ArrayList<String> depotAndBranches = new ArrayList<>();
if (getModelObject() != null)
- repoAndBranches.addAll(getModelObject());
+ depotAndBranches.addAll(getModelObject());
- input = new BranchMultiChoice("input", new Model(repoAndBranches), branchProvider);
+ input = new BranchMultiChoice("input", new Model(depotAndBranches), branchProvider);
add(input);
}
@@ -58,11 +58,11 @@ public class BranchMultiChoiceEditor extends PropertyEditor<List<String>> {
@Override
protected List<String> convertInputToValue() throws ConversionException {
- List<String> repoAndBranches = new ArrayList<>();
+ List<String> depotAndBranches = new ArrayList<>();
Collection<String> convertedInput = input.getConvertedInput();
if (convertedInput != null)
- repoAndBranches.addAll(convertedInput);
- return repoAndBranches;
+ depotAndBranches.addAll(convertedInput);
+ return depotAndBranches;
}
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branch/GlobalBranchMultiChoiceEditor.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branch/GlobalBranchMultiChoiceEditor.java
index 518dd34562..4e3f29f160 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branch/GlobalBranchMultiChoiceEditor.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/branch/GlobalBranchMultiChoiceEditor.java
@@ -50,11 +50,11 @@ public class GlobalBranchMultiChoiceEditor extends PropertyEditor<List<String>>
@Override
protected List<String> convertInputToValue() throws ConversionException {
- List<String> repoAndBranches = new ArrayList<>();
+ List<String> depotAndBranches = new ArrayList<>();
Collection<String> convertedInput = input.getConvertedInput();
if (convertedInput != null)
- repoAndBranches.addAll(convertedInput);
- return repoAndBranches;
+ depotAndBranches.addAll(convertedInput);
+ return depotAndBranches;
}
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/path/PathEditSupport.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/path/PathEditSupport.java
index f4d4471816..0b22b66c1b 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/path/PathEditSupport.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/path/PathEditSupport.java
@@ -1,93 +1,93 @@
-package com.pmease.gitplex.web.editable.path;
-
-import java.lang.reflect.Method;
-import java.util.List;
-
-import org.apache.commons.lang3.StringUtils;
-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.EditableUtils;
-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.editable.PathChoice;
-
-@SuppressWarnings("serial")
-public class PathEditSupport 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(PathChoice.class) != null) {
- if (List.class.isAssignableFrom(propertyGetter.getReturnType())
- && EditableUtils.getElementClass(propertyGetter.getGenericReturnType()) == String.class) {
- return new PropertyContext<List<String>>(propertyDescriptor) {
-
- @Override
- public PropertyViewer renderForView(String componentId, final IModel<List<String>> model) {
- return new PropertyViewer(componentId, this) {
-
- @Override
- protected Component newContent(String id, PropertyDescriptor propertyDescriptor) {
- if (model.getObject() != null && !model.getObject().isEmpty()) {
- return new Label(id, StringUtils.join(model.getObject(), ", "));
- } else {
- return new NotDefinedLabel(id);
- }
- }
-
- };
- }
-
- @Override
- public PropertyEditor<List<String>> renderForEdit(String componentId, IModel<List<String>> model) {
- return new PathMultiChoiceEditor(componentId, this, model);
- }
-
- };
- } else if (propertyGetter.getReturnType() == String.class) {
- 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) {
- if (model.getObject() != null)
- return new Label(id, model.getObject());
- else
- return new NotDefinedLabel(id);
- }
-
- };
- }
-
- @Override
- public PropertyEditor<String> renderForEdit(String componentId, IModel<String> model) {
- return new PathSingleChoiceEditor(componentId, this, model);
- }
-
- };
- } else {
- throw new RuntimeException("Annotation 'DirectoryChoice' should be applied to property with type String or List<String>.");
- }
- } else {
- return null;
- }
- }
-
-}
+package com.pmease.gitplex.web.editable.path;
+
+import java.lang.reflect.Method;
+import java.util.List;
+
+import org.apache.commons.lang3.StringUtils;
+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.EditableUtils;
+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.PathChoice;
+
+@SuppressWarnings("serial")
+public class PathEditSupport 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(PathChoice.class) != null) {
+ if (List.class.isAssignableFrom(propertyGetter.getReturnType())
+ && EditableUtils.getElementClass(propertyGetter.getGenericReturnType()) == String.class) {
+ return new PropertyContext<List<String>>(propertyDescriptor) {
+
+ @Override
+ public PropertyViewer renderForView(String componentId, final IModel<List<String>> model) {
+ return new PropertyViewer(componentId, this) {
+
+ @Override
+ protected Component newContent(String id, PropertyDescriptor propertyDescriptor) {
+ if (model.getObject() != null && !model.getObject().isEmpty()) {
+ return new Label(id, StringUtils.join(model.getObject(), ", "));
+ } else {
+ return new NotDefinedLabel(id);
+ }
+ }
+
+ };
+ }
+
+ @Override
+ public PropertyEditor<List<String>> renderForEdit(String componentId, IModel<List<String>> model) {
+ return new PathMultiChoiceEditor(componentId, this, model);
+ }
+
+ };
+ } else if (propertyGetter.getReturnType() == String.class) {
+ 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) {
+ if (model.getObject() != null)
+ return new Label(id, model.getObject());
+ else
+ return new NotDefinedLabel(id);
+ }
+
+ };
+ }
+
+ @Override
+ public PropertyEditor<String> renderForEdit(String componentId, IModel<String> model) {
+ return new PathSingleChoiceEditor(componentId, this, model);
+ }
+
+ };
+ } else {
+ throw new RuntimeException("Annotation 'DirectoryChoice' should be applied to property with type String or List<String>.");
+ }
+ } else {
+ return null;
+ }
+ }
+
+}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/path/PathMultiChoiceEditor.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/path/PathMultiChoiceEditor.java
index 3898aea381..20fdf4789d 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/path/PathMultiChoiceEditor.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/path/PathMultiChoiceEditor.java
@@ -1,42 +1,42 @@
-package com.pmease.gitplex.web.editable.path;
-
-import java.util.List;
-
-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.editable.PathChoice;
-import com.pmease.gitplex.web.component.pathchoice.PathMultiChoice;
-
-@SuppressWarnings("serial")
-public class PathMultiChoiceEditor extends PropertyEditor<List<String>> {
-
- private PathMultiChoice input;
-
- public PathMultiChoiceEditor(String id, PropertyDescriptor propertyDescriptor, IModel<List<String>> propertyModel) {
- super(id, propertyDescriptor, propertyModel);
- }
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
-
- PathChoice pathChoice = getPropertyDescriptor().getPropertyGetter().getAnnotation(PathChoice.class);
- add(input = new PathMultiChoice("input", getModel(), pathChoice.value()));
- }
-
- @Override
- public ErrorContext getErrorContext(PathSegment pathSegment) {
- return null;
- }
-
- @Override
- protected List<String> convertInputToValue() throws ConversionException {
- return input.getConvertedInput();
- }
-
+package com.pmease.gitplex.web.editable.path;
+
+import java.util.List;
+
+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.util.editable.PathChoice;
+import com.pmease.gitplex.web.component.pathchoice.PathMultiChoice;
+
+@SuppressWarnings("serial")
+public class PathMultiChoiceEditor extends PropertyEditor<List<String>> {
+
+ private PathMultiChoice input;
+
+ public PathMultiChoiceEditor(String id, PropertyDescriptor propertyDescriptor, IModel<List<String>> propertyModel) {
+ super(id, propertyDescriptor, propertyModel);
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ PathChoice pathChoice = getPropertyDescriptor().getPropertyGetter().getAnnotation(PathChoice.class);
+ add(input = new PathMultiChoice("input", getModel(), pathChoice.value()));
+ }
+
+ @Override
+ public ErrorContext getErrorContext(PathSegment pathSegment) {
+ return null;
+ }
+
+ @Override
+ protected List<String> convertInputToValue() throws ConversionException {
+ return input.getConvertedInput();
+ }
+
}
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/path/PathSingleChoiceEditor.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/path/PathSingleChoiceEditor.java
index 1399665992..34f0b220b3 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/path/PathSingleChoiceEditor.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/path/PathSingleChoiceEditor.java
@@ -1,40 +1,40 @@
-package com.pmease.gitplex.web.editable.path;
-
-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.editable.PathChoice;
-import com.pmease.gitplex.web.component.pathchoice.PathSingleChoice;
-
-@SuppressWarnings("serial")
-public class PathSingleChoiceEditor extends PropertyEditor<String> {
-
- private PathSingleChoice input;
-
- public PathSingleChoiceEditor(String id, PropertyDescriptor propertyDescriptor, IModel<String> propertyModel) {
- super(id, propertyDescriptor, propertyModel);
- }
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
-
- PathChoice pathChoice = getPropertyDescriptor().getPropertyGetter().getAnnotation(PathChoice.class);
- add(input = new PathSingleChoice("input", getModel(), pathChoice.value()));
- }
-
- @Override
- public ErrorContext getErrorContext(PathSegment pathSegment) {
- return null;
- }
-
- @Override
- protected String convertInputToValue() throws ConversionException {
- return input.getConvertedInput();
- }
-
+package com.pmease.gitplex.web.editable.path;
+
+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.util.editable.PathChoice;
+import com.pmease.gitplex.web.component.pathchoice.PathSingleChoice;
+
+@SuppressWarnings("serial")
+public class PathSingleChoiceEditor extends PropertyEditor<String> {
+
+ private PathSingleChoice input;
+
+ public PathSingleChoiceEditor(String id, PropertyDescriptor propertyDescriptor, IModel<String> propertyModel) {
+ super(id, propertyDescriptor, propertyModel);
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ PathChoice pathChoice = getPropertyDescriptor().getPropertyGetter().getAnnotation(PathChoice.class);
+ add(input = new PathSingleChoice("input", getModel(), pathChoice.value()));
+ }
+
+ @Override
+ public ErrorContext getErrorContext(PathSegment pathSegment) {
+ return null;
+ }
+
+ @Override
+ protected String convertInputToValue() throws ConversionException {
+ return input.getConvertedInput();
+ }
+
}
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/refmatch/RefMatchEditSupport.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/refmatch/RefMatchEditSupport.java
new file mode 100644
index 0000000000..98b2cab20c
--- /dev/null
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/refmatch/RefMatchEditSupport.java
@@ -0,0 +1,66 @@
+package com.pmease.gitplex.web.editable.refmatch;
+
+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.RefMatch;
+
+@SuppressWarnings("serial")
+public class RefMatchEditSupport 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(RefMatch.class) != null) {
+ if (propertyGetter.getReturnType() != String.class) {
+ throw new RuntimeException("Annotation 'RefMatch' should be applied to property "
+ + "with type 'String' or 'List<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 RefMatchEditor(componentId, this, model);
+ }
+
+ };
+ } else {
+ return null;
+ }
+ }
+
+}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/refmatch/RefMatchEditor.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/refmatch/RefMatchEditor.html
new file mode 100644
index 0000000000..9383fc76b9
--- /dev/null
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/refmatch/RefMatchEditor.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/refmatch/RefMatchEditor.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/refmatch/RefMatchEditor.java
new file mode 100644
index 0000000000..12253f7119
--- /dev/null
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/refmatch/RefMatchEditor.java
@@ -0,0 +1,50 @@
+package com.pmease.gitplex.web.editable.refmatch;
+
+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.refmatch.RefMatchInput;
+import com.pmease.gitplex.web.page.depot.DepotPage;
+
+@SuppressWarnings("serial")
+public class RefMatchEditor extends PropertyEditor<String> {
+
+ private RefMatchInput input;
+
+ public RefMatchEditor(String id, PropertyDescriptor propertyDescriptor, IModel<String> propertyModel) {
+ super(id, propertyDescriptor, propertyModel);
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ input = new RefMatchInput("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();
+ }
+
+}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/team/TeamEditSupport.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/team/TeamEditSupport.java
index 1c3dce6ad8..b9e4b006be 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/team/TeamEditSupport.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/team/TeamEditSupport.java
@@ -1,106 +1,106 @@
-package com.pmease.gitplex.web.editable.team;
-
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.wicket.Component;
-import org.apache.wicket.markup.html.basic.Label;
-import org.apache.wicket.model.IModel;
-import org.eclipse.jgit.util.StringUtils;
-
-import com.pmease.commons.hibernate.dao.Dao;
-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.EditableUtils;
-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.GitPlex;
-import com.pmease.gitplex.core.editable.TeamChoice;
-import com.pmease.gitplex.core.model.Team;
-
-@SuppressWarnings("serial")
-public class TeamEditSupport 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(TeamChoice.class) != null) {
- if (List.class.isAssignableFrom(propertyGetter.getReturnType())
- && EditableUtils.getElementClass(propertyGetter.getGenericReturnType()) == Long.class) {
- return new PropertyContext<List<Long>>(propertyDescriptor) {
-
- @Override
- public PropertyViewer renderForView(String componentId, final IModel<List<Long>> model) {
- return new PropertyViewer(componentId, this) {
-
- @Override
- protected Component newContent(String id, PropertyDescriptor propertyDescriptor) {
- List<Long> teamIds = model.getObject();
- if (teamIds != null && !teamIds.isEmpty()) {
- Dao dao = GitPlex.getInstance(Dao.class);
- List<String> teamNames = new ArrayList<>();
- for (Long teamId: teamIds) {
- teamNames.add(dao.load(Team.class, teamId).getName());
- }
- return new Label(id, StringUtils.join(teamNames, ", " ));
- } else {
- return new NotDefinedLabel(id);
- }
- }
-
- };
- }
-
- @Override
- public PropertyEditor<List<Long>> renderForEdit(String componentId, IModel<List<Long>> model) {
- return new TeamMultiChoiceEditor(componentId, this, model);
- }
-
- };
- } else if (propertyGetter.getReturnType() == Long.class) {
- return new PropertyContext<Long>(propertyDescriptor) {
-
- @Override
- public PropertyViewer renderForView(String componentId, final IModel<Long> model) {
- return new PropertyViewer(componentId, this) {
-
- @Override
- protected Component newContent(String id, PropertyDescriptor propertyDescriptor) {
- Long teamId = model.getObject();
- if (teamId != null) {
- Team team = GitPlex.getInstance(Dao.class).load(Team.class, teamId);
- return new Label(id, team.getName());
- } else {
- return new NotDefinedLabel(id);
- }
- }
-
- };
- }
-
- @Override
- public PropertyEditor<Long> renderForEdit(String componentId, IModel<Long> model) {
- return new TeamSingleChoiceEditor(componentId, this, model);
- }
-
- };
- } else {
- throw new RuntimeException("Annotation 'TeamChoice' should be applied to property with type Long or List<Long>.");
- }
- } else {
- return null;
- }
- }
-
-}
+package com.pmease.gitplex.web.editable.team;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.model.IModel;
+import org.eclipse.jgit.util.StringUtils;
+
+import com.pmease.commons.hibernate.dao.Dao;
+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.EditableUtils;
+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.GitPlex;
+import com.pmease.gitplex.core.model.Team;
+import com.pmease.gitplex.core.util.editable.TeamChoice;
+
+@SuppressWarnings("serial")
+public class TeamEditSupport 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(TeamChoice.class) != null) {
+ if (List.class.isAssignableFrom(propertyGetter.getReturnType())
+ && EditableUtils.getElementClass(propertyGetter.getGenericReturnType()) == Long.class) {
+ return new PropertyContext<List<Long>>(propertyDescriptor) {
+
+ @Override
+ public PropertyViewer renderForView(String componentId, final IModel<List<Long>> model) {
+ return new PropertyViewer(componentId, this) {
+
+ @Override
+ protected Component newContent(String id, PropertyDescriptor propertyDescriptor) {
+ List<Long> teamIds = model.getObject();
+ if (teamIds != null && !teamIds.isEmpty()) {
+ Dao dao = GitPlex.getInstance(Dao.class);
+ List<String> teamNames = new ArrayList<>();
+ for (Long teamId: teamIds) {
+ teamNames.add(dao.load(Team.class, teamId).getName());
+ }
+ return new Label(id, StringUtils.join(teamNames, ", " ));
+ } else {
+ return new NotDefinedLabel(id);
+ }
+ }
+
+ };
+ }
+
+ @Override
+ public PropertyEditor<List<Long>> renderForEdit(String componentId, IModel<List<Long>> model) {
+ return new TeamMultiChoiceEditor(componentId, this, model);
+ }
+
+ };
+ } else if (propertyGetter.getReturnType() == Long.class) {
+ return new PropertyContext<Long>(propertyDescriptor) {
+
+ @Override
+ public PropertyViewer renderForView(String componentId, final IModel<Long> model) {
+ return new PropertyViewer(componentId, this) {
+
+ @Override
+ protected Component newContent(String id, PropertyDescriptor propertyDescriptor) {
+ Long teamId = model.getObject();
+ if (teamId != null) {
+ Team team = GitPlex.getInstance(Dao.class).load(Team.class, teamId);
+ return new Label(id, team.getName());
+ } else {
+ return new NotDefinedLabel(id);
+ }
+ }
+
+ };
+ }
+
+ @Override
+ public PropertyEditor<Long> renderForEdit(String componentId, IModel<Long> model) {
+ return new TeamSingleChoiceEditor(componentId, this, model);
+ }
+
+ };
+ } else {
+ throw new RuntimeException("Annotation 'TeamChoice' should be applied to property with type Long or List<Long>.");
+ }
+ } else {
+ return null;
+ }
+ }
+
+}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/user/UserEditSupport.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/user/UserEditSupport.java
index e5daaebb7d..94b79206a1 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/user/UserEditSupport.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/editable/user/UserEditSupport.java
@@ -1,106 +1,106 @@
-package com.pmease.gitplex.web.editable.user;
-
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.wicket.Component;
-import org.apache.wicket.markup.html.basic.Label;
-import org.apache.wicket.model.IModel;
-import org.eclipse.jgit.util.StringUtils;
-
-import com.pmease.commons.hibernate.dao.Dao;
-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.EditableUtils;
-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.GitPlex;
-import com.pmease.gitplex.core.editable.UserChoice;
-import com.pmease.gitplex.core.model.User;
-
-@SuppressWarnings("serial")
-public class UserEditSupport 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(UserChoice.class) != null) {
- if (List.class.isAssignableFrom(propertyGetter.getReturnType())
- && EditableUtils.getElementClass(propertyGetter.getGenericReturnType()) == Long.class) {
- return new PropertyContext<List<Long>>(propertyDescriptor) {
-
- @Override
- public PropertyViewer renderForView(String componentId, final IModel<List<Long>> model) {
- return new PropertyViewer(componentId, this) {
-
- @Override
- protected Component newContent(String id, PropertyDescriptor propertyDescriptor) {
- List<Long> userIds = model.getObject();
- if (userIds != null && !userIds.isEmpty()) {
- Dao dao = GitPlex.getInstance(Dao.class);
- List<String> userNames = new ArrayList<>();
- for (Long userId: userIds) {
- userNames.add(dao.load(User.class, userId).getDisplayName());
- }
- return new Label(id, StringUtils.join(userNames, ", " ));
- } else {
- return new NotDefinedLabel(id);
- }
- }
-
- };
- }
-
- @Override
- public PropertyEditor<List<Long>> renderForEdit(String componentId, IModel<List<Long>> model) {
- return new UserMultiChoiceEditor(componentId, this, model);
- }
-
- };
- } else if (propertyGetter.getReturnType() == Long.class) {
- return new PropertyContext<Long>(propertyDescriptor) {
-
- @Override
- public PropertyViewer renderForView(String componentId, final IModel<Long> model) {
- return new PropertyViewer(componentId, this) {
-
- @Override
- protected Component newContent(String id, PropertyDescriptor propertyDescriptor) {
- Long userId = model.getObject();
- if (userId != null) {
- User user = GitPlex.getInstance(Dao.class).load(User.class, userId);
- return new Label(id, user.getDisplayName());
- } else {
- return new NotDefinedLabel(id);
- }
- }
-
- };
- }
-
- @Override
- public PropertyEditor<Long> renderForEdit(String componentId, IModel<Long> model) {
- return new UserSingleChoiceEditor(componentId, this, model);
- }
-
- };
- } else {
- throw new RuntimeException("Annotation 'UserChoice' should be applied to property with type 'Long' or 'List<Long>'.");
- }
- } else {
- return null;
- }
- }
-
-}
+package com.pmease.gitplex.web.editable.user;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.model.IModel;
+import org.eclipse.jgit.util.StringUtils;
+
+import com.pmease.commons.hibernate.dao.Dao;
+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.EditableUtils;
+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.GitPlex;
+import com.pmease.gitplex.core.model.User;
+import com.pmease.gitplex.core.util.editable.UserChoice;
+
+@SuppressWarnings("serial")
+public class UserEditSupport 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(UserChoice.class) != null) {
+ if (List.class.isAssignableFrom(propertyGetter.getReturnType())
+ && EditableUtils.getElementClass(propertyGetter.getGenericReturnType()) == Long.class) {
+ return new PropertyContext<List<Long>>(propertyDescriptor) {
+
+ @Override
+ public PropertyViewer renderForView(String componentId, final IModel<List<Long>> model) {
+ return new PropertyViewer(componentId, this) {
+
+ @Override
+ protected Component newContent(String id, PropertyDescriptor propertyDescriptor) {
+ List<Long> userIds = model.getObject();
+ if (userIds != null && !userIds.isEmpty()) {
+ Dao dao = GitPlex.getInstance(Dao.class);
+ List<String> userNames = new ArrayList<>();
+ for (Long userId: userIds) {
+ userNames.add(dao.load(User.class, userId).getDisplayName());
+ }
+ return new Label(id, StringUtils.join(userNames, ", " ));
+ } else {
+ return new NotDefinedLabel(id);
+ }
+ }
+
+ };
+ }
+
+ @Override
+ public PropertyEditor<List<Long>> renderForEdit(String componentId, IModel<List<Long>> model) {
+ return new UserMultiChoiceEditor(componentId, this, model);
+ }
+
+ };
+ } else if (propertyGetter.getReturnType() == Long.class) {
+ return new PropertyContext<Long>(propertyDescriptor) {
+
+ @Override
+ public PropertyViewer renderForView(String componentId, final IModel<Long> model) {
+ return new PropertyViewer(componentId, this) {
+
+ @Override
+ protected Component newContent(String id, PropertyDescriptor propertyDescriptor) {
+ Long userId = model.getObject();
+ if (userId != null) {
+ User user = GitPlex.getInstance(Dao.class).load(User.class, userId);
+ return new Label(id, user.getDisplayName());
+ } else {
+ return new NotDefinedLabel(id);
+ }
+ }
+
+ };
+ }
+
+ @Override
+ public PropertyEditor<Long> renderForEdit(String componentId, IModel<Long> model) {
+ return new UserSingleChoiceEditor(componentId, this, model);
+ }
+
+ };
+ } else {
+ throw new RuntimeException("Annotation 'UserChoice' should be applied to property with type 'Long' or 'List<Long>'.");
+ }
+ } else {
+ return null;
+ }
+ }
+
+}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/branches/DepotBranchesPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/branches/DepotBranchesPage.java
index 6e055871ac..307e4ca65a 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/branches/DepotBranchesPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/branches/DepotBranchesPage.java
@@ -9,7 +9,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
-import java.util.UUID;
import javax.annotation.Nullable;
@@ -210,8 +209,8 @@ public class DepotBranchesPage extends DepotPage {
protected Map<String, PullRequest> load() {
Map<String, PullRequest> requests = new HashMap<>();
PullRequestManager pullRequestManager = GitPlex.getInstance(PullRequestManager.class);
- DepotAndBranch repoAndBranch = new DepotAndBranch(getDepot(), getBaseBranch());
- for (PullRequest request: pullRequestManager.queryOpenTo(repoAndBranch, getDepot()))
+ DepotAndBranch depotAndBranch = new DepotAndBranch(getDepot(), getBaseBranch());
+ for (PullRequest request: pullRequestManager.queryOpenTo(depotAndBranch, getDepot()))
requests.put(request.getSource().getBranch(), request);
return requests;
}
@@ -225,8 +224,8 @@ public class DepotBranchesPage extends DepotPage {
protected Map<String, PullRequest> load() {
Map<String, PullRequest> requests = new HashMap<>();
PullRequestManager pullRequestManager = GitPlex.getInstance(PullRequestManager.class);
- DepotAndBranch repoAndBranch = new DepotAndBranch(getDepot(), getBaseBranch());
- for (PullRequest request: pullRequestManager.queryOpenFrom(repoAndBranch, getDepot()))
+ DepotAndBranch depotAndBranch = new DepotAndBranch(getDepot(), getBaseBranch());
+ for (PullRequest request: pullRequestManager.queryOpenFrom(depotAndBranch, getDepot()))
requests.put(request.getTarget().getBranch(), request);
return requests;
}
@@ -311,12 +310,14 @@ public class DepotBranchesPage extends DepotPage {
private String branchName;
- private String branchRevision;
+ private String branchRevision = getDepot().getDefaultBranch();
@Override
protected void onConfigure() {
super.onConfigure();
- setVisible(SecurityUtils.canCreate(getDepot(), UUID.randomUUID().toString()));
+
+ ObjectId commit = getDepot().getObjectId(branchRevision);
+ setVisible(SecurityUtils.canPushRef(getDepot(), Constants.R_HEADS, ObjectId.zeroId(), commit));
}
private RevisionPicker newRevisionPicker() {
@@ -361,7 +362,6 @@ public class DepotBranchesPage extends DepotPage {
}));
nameInput.setOutputMarkupId(true);
- branchRevision = getDepot().getDefaultBranch();
form.add(newRevisionPicker());
form.add(new AjaxButton("create") {
@@ -635,7 +635,10 @@ public class DepotBranchesPage extends DepotPage {
protected void onConfigure() {
super.onConfigure();
- if (!getDepot().getDefaultBranch().equals(branch) && SecurityUtils.canModify(new DepotAndBranch(getDepot(), branch))) {
+ Ref ref = item.getModelObject();
+ if (!getDepot().getDefaultBranch().equals(branch)
+ && SecurityUtils.canPushRef(getDepot(), ref.getName(), ref.getObjectId(), ObjectId.zeroId())) {
+
User currentUser = getCurrentUser();
if (currentUser != null) {
GateKeeper gateKeeper = getDepot().getGateKeeper();
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/commit/DepotCommitsPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/commit/DepotCommitsPage.java
index b58c7063df..9625a4b5c0 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/commit/DepotCommitsPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/commit/DepotCommitsPage.java
@@ -69,10 +69,10 @@ import com.pmease.gitplex.web.component.contributionpanel.ContributionPanel;
import com.pmease.gitplex.web.component.hashandcode.HashAndCodePanel;
import com.pmease.gitplex.web.page.depot.DepotPage;
import com.pmease.gitplex.web.page.depot.compare.RevisionComparePage;
-import com.pmease.gitplex.web.page.repository.commit.CommitQueryLexer;
-import com.pmease.gitplex.web.page.repository.commit.CommitQueryParser;
-import com.pmease.gitplex.web.page.repository.commit.CommitQueryParser.CriteriaContext;
-import com.pmease.gitplex.web.page.repository.commit.CommitQueryParser.QueryContext;
+import com.pmease.gitplex.web.page.depot.commit.CommitQueryLexer;
+import com.pmease.gitplex.web.page.depot.commit.CommitQueryParser;
+import com.pmease.gitplex.web.page.depot.commit.CommitQueryParser.CriteriaContext;
+import com.pmease.gitplex.web.page.depot.commit.CommitQueryParser.QueryContext;
import de.agilecoders.wicket.core.markup.html.bootstrap.common.NotificationPanel;
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/commit/LogCommandFiller.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/commit/LogCommandFiller.java
index 9ee1648342..8152e6a3e9 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/commit/LogCommandFiller.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/commit/LogCommandFiller.java
@@ -6,17 +6,17 @@ import org.apache.commons.lang3.StringUtils;
import org.unbescape.java.JavaEscape;
import com.pmease.commons.git.command.LogCommand;
-import com.pmease.gitplex.web.page.repository.commit.CommitQueryBaseListener;
-import com.pmease.gitplex.web.page.repository.commit.CommitQueryParser.AfterContext;
-import com.pmease.gitplex.web.page.repository.commit.CommitQueryParser.AuthorContext;
-import com.pmease.gitplex.web.page.repository.commit.CommitQueryParser.BeforeContext;
-import com.pmease.gitplex.web.page.repository.commit.CommitQueryParser.CommitterContext;
-import com.pmease.gitplex.web.page.repository.commit.CommitQueryParser.MessageContext;
-import com.pmease.gitplex.web.page.repository.commit.CommitQueryParser.PathContext;
-import com.pmease.gitplex.web.page.repository.commit.CommitQueryParser.RevisionContext;
-import com.pmease.gitplex.web.page.repository.commit.CommitQueryParser.RevisionExclusionContext;
-import com.pmease.gitplex.web.page.repository.commit.CommitQueryParser.RevisionRangeContext;
-import com.pmease.gitplex.web.page.repository.commit.CommitQueryParser.SingleRevisionContext;
+import com.pmease.gitplex.web.page.depot.commit.CommitQueryBaseListener;
+import com.pmease.gitplex.web.page.depot.commit.CommitQueryParser.AfterContext;
+import com.pmease.gitplex.web.page.depot.commit.CommitQueryParser.AuthorContext;
+import com.pmease.gitplex.web.page.depot.commit.CommitQueryParser.BeforeContext;
+import com.pmease.gitplex.web.page.depot.commit.CommitQueryParser.CommitterContext;
+import com.pmease.gitplex.web.page.depot.commit.CommitQueryParser.MessageContext;
+import com.pmease.gitplex.web.page.depot.commit.CommitQueryParser.PathContext;
+import com.pmease.gitplex.web.page.depot.commit.CommitQueryParser.RevisionContext;
+import com.pmease.gitplex.web.page.depot.commit.CommitQueryParser.RevisionExclusionContext;
+import com.pmease.gitplex.web.page.depot.commit.CommitQueryParser.RevisionRangeContext;
+import com.pmease.gitplex.web.page.depot.commit.CommitQueryParser.SingleRevisionContext;
public class LogCommandFiller extends CommitQueryBaseListener {
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/commit/QueryAssistBehavior.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/commit/QueryAssistBehavior.java
index 3df7b52a38..25112221db 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/commit/QueryAssistBehavior.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/commit/QueryAssistBehavior.java
@@ -27,7 +27,7 @@ import com.pmease.gitplex.core.GitPlex;
import com.pmease.gitplex.core.manager.AuxiliaryManager;
import com.pmease.gitplex.core.model.Depot;
import com.pmease.gitplex.web.Constants;
-import com.pmease.gitplex.web.page.repository.commit.CommitQueryParser;
+import com.pmease.gitplex.web.page.depot.commit.CommitQueryParser;
@SuppressWarnings("serial")
public class QueryAssistBehavior extends ANTLRAssistBehavior {
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/PullRequestOperation.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/PullRequestOperation.java
index 4c408ed06f..5327a220ae 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/PullRequestOperation.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/PullRequestOperation.java
@@ -2,6 +2,8 @@ package com.pmease.gitplex.web.page.depot.pullrequest.requestdetail;
import javax.annotation.Nullable;
+import org.eclipse.jgit.lib.ObjectId;
+
import com.pmease.commons.git.Git;
import com.pmease.gitplex.core.GitPlex;
import com.pmease.gitplex.core.manager.PullRequestManager;
@@ -127,7 +129,7 @@ public enum PullRequestOperation {
&& (request.getSource().getObjectName().equals(preview.getRequestHead())
|| request.getSource().getObjectName().equals(preview.getIntegrated()))
&& SecurityUtils.canModify(request)
- && SecurityUtils.canModify(request.getSource())
+ && SecurityUtils.canPushRef(request.getSourceDepot(), request.getSourceRef(), request.getSource().getObjectId(), ObjectId.zeroId())
&& pullRequestManager.queryOpenTo(request.getSource(), null).isEmpty();
}
@@ -141,8 +143,10 @@ public enum PullRequestOperation {
@Override
public boolean canOperate(PullRequest request) {
- return request.getSourceDepot() != null && request.getSource().getObjectName(false) == null
- && SecurityUtils.canModify(request) && SecurityUtils.canCreate(request.getSource());
+ return request.getSourceDepot() != null
+ && request.getSource().getObjectName(false) == null
+ && SecurityUtils.canModify(request)
+ && SecurityUtils.canPushRef(request.getSourceDepot(), request.getSourceRef(), ObjectId.zeroId(), ObjectId.fromString(request.getLatestUpdate().getHeadCommitHash()));
}
};
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/ResolveConflictInstructionPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/ResolveConflictInstructionPanel.java
index 7eebf0ce84..0b98ea9396 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/ResolveConflictInstructionPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/ResolveConflictInstructionPanel.java
@@ -5,21 +5,21 @@ import static com.pmease.gitplex.core.model.PullRequest.IntegrationStrategy.MERG
import static com.pmease.gitplex.core.model.PullRequest.IntegrationStrategy.REBASE_SOURCE_ONTO_TARGET;
import static com.pmease.gitplex.core.model.PullRequest.IntegrationStrategy.REBASE_TARGET_ONTO_SOURCE;
-import org.apache.shiro.SecurityUtils;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.Fragment;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
+import org.eclipse.jgit.lib.ObjectId;
import com.pmease.gitplex.core.GitPlex;
import com.pmease.gitplex.core.manager.UserManager;
+import com.pmease.gitplex.core.model.Depot;
import com.pmease.gitplex.core.model.IntegrationPreview;
import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.PullRequest.IntegrationStrategy;
-import com.pmease.gitplex.core.model.Depot;
import com.pmease.gitplex.core.model.User;
-import com.pmease.gitplex.core.permission.ObjectPermission;
+import com.pmease.gitplex.core.security.SecurityUtils;
@SuppressWarnings("serial")
class ResolveConflictInstructionPanel extends Panel {
@@ -37,7 +37,6 @@ class ResolveConflictInstructionPanel extends Panel {
Depot targetDepot = request.getTarget().getDepot();
User user = GitPlex.getInstance(UserManager.class).getCurrent();
IntegrationPreview preview = request.getIntegrationPreview();
- String sourceHead = preview.getRequestHead();
IntegrationStrategy strategy = request.getIntegrationStrategy();
boolean sameRepo = request.getTarget().getDepot().equals(request.getSource().getDepot());
if (strategy == MERGE_WITH_SQUASH || strategy == REBASE_SOURCE_ONTO_TARGET) {
@@ -69,8 +68,8 @@ class ResolveConflictInstructionPanel extends Panel {
differentRepoContainer.setVisible(!sameRepo);
fragment.add(differentRepoContainer);
} else if (user != null
- && SecurityUtils.getSubject().isPermitted(ObjectPermission.ofDepotPush(targetDepot))
- && targetDepot.getGateKeeper().checkCommit(user, request.getTargetDepot(), request.getTargetBranch(), sourceHead).allowIntegration()) {
+ && SecurityUtils.canPush(targetDepot)
+ && targetDepot.getGateKeeper().checkPush(user, request.getTargetDepot(), request.getTargetRef(), request.getTarget().getObjectId(), ObjectId.fromString(preview.getRequestHead())).allowIntegration()) {
fragment = new Fragment("content", "mergeInTargetFrag", this);
fragment.add(new Label("destRepoName", request.getTarget().getDepot()));
fragment.add(new Label("destBranchNameForCheckout", request.getTargetBranch()));
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestlist/SearchOption.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestlist/SearchOption.java
index e6d294ed4d..4ad4ee2f51 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestlist/SearchOption.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestlist/SearchOption.java
@@ -10,9 +10,9 @@ import org.hibernate.criterion.Restrictions;
import com.pmease.commons.hibernate.dao.EntityCriteria;
import com.pmease.commons.wicket.editable.annotation.Editable;
-import com.pmease.gitplex.core.editable.BranchChoice;
-import com.pmease.gitplex.core.editable.UserChoice;
import com.pmease.gitplex.core.model.PullRequest;
+import com.pmease.gitplex.core.util.editable.BranchChoice;
+import com.pmease.gitplex.core.util.editable.UserChoice;
import com.pmease.gitplex.core.model.Depot;
@SuppressWarnings("serial")
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/setting/gatekeeper/GateKeeperEditor.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/setting/gatekeeper/GateKeeperEditor.java
index ac1d87292e..24521d2b00 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/setting/gatekeeper/GateKeeperEditor.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/setting/gatekeeper/GateKeeperEditor.java
@@ -63,6 +63,8 @@ public abstract class GateKeeperEditor extends Panel {
}
});
+
+ setOutputMarkupId(true);
}
protected abstract void onCancel(AjaxRequestTarget target);
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/setting/gatekeeper/GateKeeperSelector.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/setting/gatekeeper/GateKeeperSelector.java
index 4f5450ea38..71d0eef100 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/setting/gatekeeper/GateKeeperSelector.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/setting/gatekeeper/GateKeeperSelector.java
@@ -38,8 +38,7 @@ public abstract class GateKeeperSelector extends Panel {
super.onInitialize();
final Map<String, List<Class<?>>> gateKeeperClasses = new LinkedHashMap<>();
- gateKeeperClasses.put(GateKeeper.CATEGORY_COMMONLY_USED, new ArrayList<Class<?>>());
- gateKeeperClasses.put(GateKeeper.CATEGROY_CHECK_BRANCH, new ArrayList<Class<?>>());
+ gateKeeperClasses.put(GateKeeper.CATEGROY_CHECK_REFS, new ArrayList<Class<?>>());
gateKeeperClasses.put(GateKeeper.CATEGROY_CHECK_FILES, new ArrayList<Class<?>>());
gateKeeperClasses.put(GateKeeper.CATEGROY_CHECK_REVIEW, new ArrayList<Class<?>>());
gateKeeperClasses.put(GateKeeper.CATEGROY_CHECK_SUBMITTER, new ArrayList<Class<?>>());
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/tags/DepotTagsPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/tags/DepotTagsPage.java
index bc1f37d263..7fc639a7ca 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/tags/DepotTagsPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/tags/DepotTagsPage.java
@@ -3,7 +3,6 @@ package com.pmease.gitplex.web.page.depot.tags;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
-import java.util.UUID;
import org.apache.wicket.Component;
import org.apache.wicket.RestartResponseException;
@@ -33,6 +32,7 @@ import org.apache.wicket.model.Model;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.request.resource.CssResourceReference;
import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
@@ -112,12 +112,14 @@ public class DepotTagsPage extends DepotPage {
private String tagMessage;
- private String tagRevision;
+ private String tagRevision = getDepot().getDefaultBranch();
@Override
protected void onConfigure() {
super.onConfigure();
- setVisible(SecurityUtils.canModify(getDepot(), Constants.R_TAGS + UUID.randomUUID().toString()));
+
+ ObjectId commit = getDepot().getObjectId(tagRevision);
+ setVisible(SecurityUtils.canPushRef(getDepot(), Constants.R_TAGS, ObjectId.zeroId(), commit));
}
private RevisionPicker newRevisionPicker() {
@@ -179,7 +181,6 @@ public class DepotTagsPage extends DepotPage {
}
}));
- tagRevision = getDepot().getDefaultBranch();
form.add(newRevisionPicker());
form.add(new AjaxButton("create") {
@@ -361,7 +362,9 @@ public class DepotTagsPage extends DepotPage {
protected void onConfigure() {
super.onConfigure();
- if (SecurityUtils.canModify(getDepot(), GitUtils.tag2ref(tagName))) {
+ Ref ref = item.getModelObject();
+ ObjectId commit = getDepot().getRevCommit(ref.getObjectId());
+ if (SecurityUtils.canPushRef(getDepot(), ref.getName(), commit, ObjectId.zeroId())) {
User currentUser = getCurrentUser();
if (currentUser != null) {
GateKeeper gateKeeper = getDepot().getGateKeeper();
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.html
index 795b443f3a..d733c65cfa 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.html
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.html
@@ -1,3 +1,7 @@
<wicket:extend>
- <a wicket:id="test">test</a>
+ <form wicket:id="form">
+ <div wicket:id="feedback"></div>
+ <input wicket:id="input"></input>
+ <input type="submit" value="submit"></input>
+ </form>
</wicket:extend>
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.java
index b401de27d1..b0479ea87e 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.java
@@ -1,23 +1,46 @@
package com.pmease.gitplex.web.page.test;
-import org.apache.wicket.markup.html.link.Link;
+import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.model.AbstractReadOnlyModel;
+import org.apache.wicket.model.PropertyModel;
+import com.pmease.commons.hibernate.dao.Dao;
+import com.pmease.gitplex.core.GitPlex;
+import com.pmease.gitplex.core.model.Depot;
+import com.pmease.gitplex.web.component.refmatch.RefMatchInput;
import com.pmease.gitplex.web.page.base.BasePage;
+import de.agilecoders.wicket.core.markup.html.bootstrap.common.NotificationPanel;
+
@SuppressWarnings("serial")
public class TestPage extends BasePage {
+ private String refMatch;
+
@Override
protected void onInitialize() {
super.onInitialize();
- add(new Link<Void>("test") {
+ Form<?> form = new Form<Void>("form") {
+
+ @Override
+ protected void onSubmit() {
+ super.onSubmit();
+ System.out.println(refMatch);
+ }
+
+ };
+ form.add(new NotificationPanel("feedback", form));
+
+ form.add(new RefMatchInput("input", new AbstractReadOnlyModel<Depot>() {
@Override
- public void onClick() {
-
+ public Depot getObject() {
+ return GitPlex.getInstance(Dao.class).load(Depot.class, 1L);
}
- });
+
+ }, new PropertyModel<String>(this, "refMatch")));
+ add(form);
}
}