Extract group reference prefix into a constant

Change-Id: I73efed5cb5cf5264b4bb9826a3a36120657f1e64
This commit is contained in:
Hugo Arès
2017-06-19 10:47:16 -04:00
parent 62469e1f56
commit aab5fbdf0d
3 changed files with 7 additions and 4 deletions

View File

@@ -18,6 +18,9 @@ import com.google.gerrit.reviewdb.client.AccountGroup;
/** Describes a group within a projects {@link AccessSection}s. */ /** Describes a group within a projects {@link AccessSection}s. */
public class GroupReference implements Comparable<GroupReference> { public class GroupReference implements Comparable<GroupReference> {
public static final String PREFIX = "group ";
/** @return a new reference to the given group description. */ /** @return a new reference to the given group description. */
public static GroupReference forGroup(AccountGroup group) { public static GroupReference forGroup(AccountGroup group) {
return new GroupReference(group.getGroupUUID(), group.getName()); return new GroupReference(group.getGroupUUID(), group.getName());

View File

@@ -204,7 +204,7 @@ public class PermissionRule implements Comparable<PermissionRule> {
r.append(' '); r.append(' ');
} }
r.append("group "); r.append(GroupReference.PREFIX);
r.append(getGroup().getName()); r.append(getGroup().getName());
return r.toString(); return r.toString();
@@ -238,7 +238,7 @@ public class PermissionRule implements Comparable<PermissionRule> {
src = src.substring("+force ".length()).trim(); src = src.substring("+force ".length()).trim();
} }
if (mightUseRange && !src.startsWith("group ")) { if (mightUseRange && !src.startsWith(GroupReference.PREFIX)) {
int sp = src.indexOf(' '); int sp = src.indexOf(' ');
String range = src.substring(0, sp); String range = src.substring(0, sp);
@@ -254,7 +254,7 @@ public class PermissionRule implements Comparable<PermissionRule> {
src = src.substring(sp + 1).trim(); src = src.substring(sp + 1).trim();
} }
if (src.startsWith("group ")) { if (src.startsWith(GroupReference.PREFIX)) {
src = src.substring(6).trim(); src = src.substring(6).trim();
GroupReference group = new GroupReference(); GroupReference group = new GroupReference();
group.setName(src); group.setName(src);

View File

@@ -640,7 +640,7 @@ public class ProjectConfig extends VersionedMetaData implements ValidationError.
n.setHeader(rc.getEnum(NOTIFY, sectionName, KEY_HEADER, NotifyConfig.Header.BCC)); n.setHeader(rc.getEnum(NOTIFY, sectionName, KEY_HEADER, NotifyConfig.Header.BCC));
for (String dst : rc.getStringList(NOTIFY, sectionName, KEY_EMAIL)) { for (String dst : rc.getStringList(NOTIFY, sectionName, KEY_EMAIL)) {
if (dst.startsWith("group ")) { if (dst.startsWith(GroupReference.PREFIX)) {
String groupName = dst.substring(6).trim(); String groupName = dst.substring(6).trim();
GroupReference ref = groupsByName.get(groupName); GroupReference ref = groupsByName.get(groupName);
if (ref == null) { if (ref == null) {