Move all static ref pattern related methods into a RefPattern class

The goal of this refactoring is to have a single place where a ref
pattern is validated as regular expression. So far this was done in 2
places (in RefControl and in ProjectConfig). For validating a ref
pattern as regular expression we must remove placeholder variables
such as '${username}' because it would be an invalid regular
expression otherwise. We don't want to do this in several places
especially because we want to support further placeholder variables in
future.

Change-Id: I11c76e37f22233d89b631375ac6f2ef60f97801f
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2016-05-04 14:02:20 +02:00
committed by David Pursehouse
parent 4c7b72bb32
commit 88fcd6bcfa
9 changed files with 117 additions and 86 deletions

View File

@@ -15,7 +15,7 @@
package com.google.gerrit.server.util;
import com.google.gerrit.common.data.RefConfigSection;
import com.google.gerrit.server.project.RefControl;
import com.google.gerrit.server.project.RefPattern;
import org.apache.commons.lang.StringUtils;
@@ -82,8 +82,8 @@ public final class MostSpecificComparator implements
private int distance(String pattern) {
String example;
if (RefControl.isRE(pattern)) {
example = RefControl.shortestExample(pattern);
if (RefPattern.isRE(pattern)) {
example = RefPattern.shortestExample(pattern);
} else if (pattern.endsWith("/*")) {
example = pattern;
@@ -98,8 +98,8 @@ public final class MostSpecificComparator implements
}
private boolean finite(String pattern) {
if (RefControl.isRE(pattern)) {
return RefControl.toRegExp(pattern).toAutomaton().isFinite();
if (RefPattern.isRE(pattern)) {
return RefPattern.toRegExp(pattern).toAutomaton().isFinite();
} else if (pattern.endsWith("/*")) {
return false;
@@ -110,8 +110,8 @@ public final class MostSpecificComparator implements
}
private int transitions(String pattern) {
if (RefControl.isRE(pattern)) {
return RefControl.toRegExp(pattern).toAutomaton()
if (RefPattern.isRE(pattern)) {
return RefPattern.toRegExp(pattern).toAutomaton()
.getNumberOfTransitions();
} else if (pattern.endsWith("/*")) {