Merge branch 'stable-3.1' into stable-3.2
* stable-3.1:
Introduce an optional configuration to define a regex for naming rules
Upgrade bazlets to latest stable-3.1 to build with 3.1.12 API
Change-Id: Ie26bdb0091ec83df53548f0de9718af0abf2b275
diff --git a/WORKSPACE b/WORKSPACE
index 20c601e..b22385d 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -3,7 +3,7 @@
load("//:bazlets.bzl", "load_bazlets")
load_bazlets(
- commit = "87fd5f0d0a89d01df13deaf2d21a4bdb3bc03cfd",
+ commit = "8dc0767541f16b35d2136eccebffd9ebe2b81133",
#local_path = "/home/<user>/projects/bazlets",
)
diff --git a/src/main/java/com/ericsson/gerrit/plugins/projectgroupstructure/DefaultAccessRights.java b/src/main/java/com/ericsson/gerrit/plugins/projectgroupstructure/DefaultAccessRights.java
index 7f0942b..b491d16 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/projectgroupstructure/DefaultAccessRights.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/projectgroupstructure/DefaultAccessRights.java
@@ -15,6 +15,7 @@
package com.ericsson.gerrit.plugins.projectgroupstructure;
import com.google.gerrit.common.data.AccessSection;
+import com.google.gerrit.common.data.GroupReference;
import com.google.gerrit.common.data.Permission;
import com.google.gerrit.common.data.PermissionRule;
import com.google.gerrit.entities.AccountGroup;
@@ -97,15 +98,16 @@
return;
}
- ProjectState project = projectCache.get(Project.NameKey.parse(projectName));
- if (project == null) {
+ Optional<ProjectState> project = projectCache.get(Project.NameKey.parse(projectName));
+ if (!project.isPresent()) {
log.error("Could not retrieve projet {} from cache", projectName);
return;
}
- try (MetaDataUpdate md = metaDataUpdateFactory.create(project.getProject().getNameKey())) {
+ try (MetaDataUpdate md =
+ metaDataUpdateFactory.create(project.get().getProject().getNameKey())) {
ProjectConfig config = projectConfigFactory.read(md);
- setAccessRights(config, project);
+ setAccessRights(config, project.get());
md.setMessage("Set default access rights\n");
config.commit(md);
} catch (Exception e) {
@@ -197,7 +199,7 @@
log.error("Group {} not found", rule.getGroup().getName());
continue;
}
- rule.getGroup().setUUID(group.get().getGroupUUID());
+ rule.setGroup(new GroupReference(group.get().getGroupUUID(), rule.getGroup().getName()));
}
perm.add(rule);
}
diff --git a/src/test/java/com/ericsson/gerrit/plugins/projectgroupstructure/DefaultAccessRightsIT.java b/src/test/java/com/ericsson/gerrit/plugins/projectgroupstructure/DefaultAccessRightsIT.java
index 5d562e0..2f93c5b 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/projectgroupstructure/DefaultAccessRightsIT.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/projectgroupstructure/DefaultAccessRightsIT.java
@@ -32,6 +32,7 @@
import com.google.gerrit.server.project.ProjectState;
import com.google.inject.Inject;
import java.nio.file.Files;
+import java.util.Optional;
import org.junit.Before;
import org.junit.Test;
@@ -83,10 +84,11 @@
in.permissionsOnly = true;
String projectName = name("someProject");
userRestSession.put("/projects/" + projectName, in).assertCreated();
+ projectCache.evict(Project.nameKey(projectName));
- ProjectState projectState = projectCache.get(Project.nameKey(projectName));
- AccountGroup.UUID ownerUUID = projectState.getOwners().iterator().next();
- ProjectConfig projectConfig = projectState.getConfig();
+ Optional<ProjectState> projectState = projectCache.get(Project.nameKey(projectName));
+ AccountGroup.UUID ownerUUID = projectState.get().getOwners().iterator().next();
+ ProjectConfig projectConfig = projectState.get().getConfig();
assertThat(projectConfig.getAccessSections().size()).isEqualTo(2);
@@ -139,7 +141,12 @@
adminRestSession.put("/projects/" + Url.encode(projectName), in).assertCreated();
assertThat(
- projectCache.get(Project.nameKey(projectName)).getConfig().getAccessSections().size())
+ projectCache
+ .get(Project.nameKey(projectName))
+ .get()
+ .getConfig()
+ .getAccessSections()
+ .size())
.isEqualTo(0);
}
}
diff --git a/src/test/java/com/ericsson/gerrit/plugins/projectgroupstructure/ProjectCreationValidatorIT.java b/src/test/java/com/ericsson/gerrit/plugins/projectgroupstructure/ProjectCreationValidatorIT.java
index 24cebcf..0f434f7 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/projectgroupstructure/ProjectCreationValidatorIT.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/projectgroupstructure/ProjectCreationValidatorIT.java
@@ -21,11 +21,11 @@
import com.google.common.base.Charsets;
import com.google.common.collect.Lists;
import com.google.common.hash.Hashing;
-import com.google.gerrit.acceptance.GerritConfig;
import com.google.gerrit.acceptance.LightweightPluginDaemonTest;
import com.google.gerrit.acceptance.RestResponse;
import com.google.gerrit.acceptance.TestPlugin;
import com.google.gerrit.acceptance.UseLocalDisk;
+import com.google.gerrit.acceptance.config.GerritConfig;
import com.google.gerrit.acceptance.testsuite.project.ProjectOperations;
import com.google.gerrit.common.data.GlobalCapability;
import com.google.gerrit.common.data.GroupReference;
@@ -37,6 +37,7 @@
import com.google.gerrit.server.project.ProjectConfig;
import com.google.gerrit.server.project.ProjectState;
import com.google.inject.Inject;
+import java.util.Optional;
import org.junit.Before;
import org.junit.Test;
@@ -213,9 +214,9 @@
ProjectInput in = new ProjectInput();
in.permissionsOnly = true;
userRestSession.put("/projects/" + rootProject, in).assertCreated();
- ProjectState projectState = projectCache.get(Project.nameKey(rootProject));
- assertThat(projectState.getOwners().size()).isEqualTo(1);
- assertThat(projectState.getOwners())
+ Optional<ProjectState> projectState = projectCache.get(Project.nameKey(rootProject));
+ assertThat(projectState.get().getOwners().size()).isEqualTo(1);
+ assertThat(projectState.get().getOwners())
.contains(
groupCache.get(AccountGroup.nameKey(rootProject + "-admins")).get().getGroupUUID());
@@ -225,7 +226,7 @@
gApi.groups().create(existingGroupName);
userRestSession.put("/projects/" + rootProject, in).assertCreated();
projectState = projectCache.get(Project.nameKey(rootProject));
- assertThat(projectState.getOwners().size()).isEqualTo(1);
+ assertThat(projectState.get().getOwners().size()).isEqualTo(1);
String expectedOwnerGroup =
existingGroupName
+ "-"
@@ -233,7 +234,7 @@
.hashString(existingGroupName, Charsets.UTF_8)
.toString()
.substring(0, 7);
- assertThat(projectState.getOwners())
+ assertThat(projectState.get().getOwners())
.contains(groupCache.get(AccountGroup.nameKey(expectedOwnerGroup)).get().getGroupUUID());
}
@@ -305,9 +306,9 @@
in.parent = parent;
String childProject = parent + "/childProject";
userRestSession.put("/projects/" + Url.encode(childProject), in).assertCreated();
- ProjectState projectState = projectCache.get(Project.nameKey(childProject));
- assertThat(projectState.getOwners().size()).isEqualTo(1);
- assertThat(projectState.getOwners())
+ Optional<ProjectState> projectState = projectCache.get(Project.nameKey(childProject));
+ assertThat(projectState.get().getOwners().size()).isEqualTo(1);
+ assertThat(projectState.get().getOwners())
.contains(
groupCache.get(AccountGroup.nameKey(childProject + "-admins")).get().getGroupUUID());
@@ -317,7 +318,7 @@
gApi.groups().create(existingGroupName);
userRestSession.put("/projects/" + Url.encode(childProject2), in).assertCreated();
projectState = projectCache.get(Project.nameKey(childProject2));
- assertThat(projectState.getOwners().size()).isEqualTo(1);
+ assertThat(projectState.get().getOwners().size()).isEqualTo(1);
String expectedOwnerGroup =
existingGroupName
+ "-"
@@ -325,7 +326,7 @@
.hashString(existingGroupName, Charsets.UTF_8)
.toString()
.substring(0, 7);
- assertThat(projectState.getOwners())
+ assertThat(projectState.get().getOwners())
.contains(groupCache.get(AccountGroup.nameKey(expectedOwnerGroup)).get().getGroupUUID());
}
@@ -357,8 +358,8 @@
in.parent = parent;
String childProject = parent + "/childProject";
userRestSession.put("/projects/" + Url.encode(childProject), in).assertCreated();
- ProjectState projectState = projectCache.get(Project.nameKey(childProject));
- assertThat(projectState.getOwners().size()).isEqualTo(0);
+ Optional<ProjectState> projectState = projectCache.get(Project.nameKey(childProject));
+ assertThat(projectState.get().getOwners().size()).isEqualTo(0);
}
@Test
@@ -524,6 +525,8 @@
dGroup.addMembers(user.username());
// the group is in the project.config
Project.NameKey parentNameKey = Project.nameKey(parent);
+ projectCache.evict(parentNameKey);
+
try (ProjectConfigUpdate cfgUpdate = updateProject(parentNameKey)) {
ProjectConfig cfg = cfgUpdate.getConfig();
@@ -533,10 +536,10 @@
ProjectCreationValidator.DELEGATE_PROJECT_CREATION_TO,
new GroupReference(AccountGroup.UUID.parse(gId), delegatingGroup));
cfgUpdate.save();
- }
- String newDelegatingGroup = name("groupC");
- gApi.groups().id(delegatingGroup).name(newDelegatingGroup);
+ String newDelegatingGroup = name("groupC");
+ gApi.groups().id(delegatingGroup).name(newDelegatingGroup);
+ }
userRestSession.put("/projects/" + Url.encode(parent + "/childProject"), in).assertCreated();
}