Merge branch 'stable-3.1' * stable-3.1: Upgrade bazlets to latest stable-2.16 Change-Id: I8238ec4c05e11629f8b6463c9f443494fd9e11d0
diff --git a/WORKSPACE b/WORKSPACE index 55ae3e1..864a80f 100644 --- a/WORKSPACE +++ b/WORKSPACE
@@ -3,7 +3,7 @@ load("//:bazlets.bzl", "load_bazlets") load_bazlets( - commit = "b6cb89690a5e06261932eb30c95fd8db34a7943a", + commit = "74f9d8e76d5014d218ae6fe55127a5288c9a32c3", #local_path = "/home/<user>/projects/bazlets", ) @@ -12,7 +12,7 @@ "gerrit_api", ) -gerrit_api() +gerrit_api(version = "3.3.0-SNAPSHOT") load("//:external_plugin_deps.bzl", "external_plugin_deps")
diff --git a/src/main/java/com/googlesource/gerrit/plugins/renameproject/LockUnlockProject.java b/src/main/java/com/googlesource/gerrit/plugins/renameproject/LockUnlockProject.java index 8904144..91f4d9e 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/renameproject/LockUnlockProject.java +++ b/src/main/java/com/googlesource/gerrit/plugins/renameproject/LockUnlockProject.java
@@ -44,11 +44,11 @@ MetaDataUpdate md = metaDataUpdateFactory.create(key); ProjectConfig projectConfig = projectConfigFactory.read(md); - Project p = projectConfig.getProject(); - p.setState(ProjectState.READ_ONLY); + projectConfig.updateProject(project -> project.setState(ProjectState.READ_ONLY)); md.setMessage(String.format("Lock project while renaming the project %s\n", key.get())); projectConfig.commit(md); + Project p = projectConfig.getProject(); projectCache.evict(p); } @@ -56,11 +56,11 @@ MetaDataUpdate md = metaDataUpdateFactory.create(key); ProjectConfig projectConfig = projectConfigFactory.read(md); - Project p = projectConfig.getProject(); - p.setState(ProjectState.ACTIVE); + projectConfig.updateProject(project -> project.setState(ProjectState.ACTIVE)); md.setMessage(String.format("Unlock project after renaming the project to %s\n", key.get())); projectConfig.commit(md); + Project p = projectConfig.getProject(); projectCache.evict(p); } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/renameproject/RenameCommand.java b/src/main/java/com/googlesource/gerrit/plugins/renameproject/RenameCommand.java index 3625e9a..ef251db 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/renameproject/RenameCommand.java +++ b/src/main/java/com/googlesource/gerrit/plugins/renameproject/RenameCommand.java
@@ -32,6 +32,7 @@ import java.io.IOException; import java.io.InputStreamReader; import java.util.List; +import java.util.NoSuchElementException; import org.kohsuke.args4j.Argument; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -66,7 +67,7 @@ input.name = newProjectName; ProjectResource rsrc = new ProjectResource( - projectCacheProvider.get().get(Project.nameKey(projectControl)), self.get()); + projectCacheProvider.get().get(Project.nameKey(projectControl)).get(), self.get()); try (CommandProgressMonitor monitor = new CommandProgressMonitor(stdout)) { renameProject.assertCanRename(rsrc, input, monitor); List<Change.Id> changeIds = renameProject.getChanges(rsrc, monitor); @@ -79,7 +80,7 @@ stdout.flush(); } } - } catch (RestApiException | IOException e) { + } catch (NoSuchElementException | RestApiException | IOException e) { throw die(e); } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/renameproject/conditions/RenamePreconditions.java b/src/main/java/com/googlesource/gerrit/plugins/renameproject/conditions/RenamePreconditions.java index 204c564..b20f365 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/renameproject/conditions/RenamePreconditions.java +++ b/src/main/java/com/googlesource/gerrit/plugins/renameproject/conditions/RenamePreconditions.java
@@ -25,7 +25,7 @@ import com.google.gerrit.server.project.ProjectResource; import com.google.gerrit.server.restapi.project.ListChildProjects; import com.google.gerrit.server.submit.MergeOpRepoManager; -import com.google.gerrit.server.submit.SubmoduleException; +import com.google.gerrit.server.submit.SubmoduleConflictException; import com.google.gerrit.server.submit.SubmoduleOp; import com.google.inject.Inject; import com.google.inject.Provider; @@ -115,13 +115,13 @@ } SubmoduleOp sub = subOpFactory.create(branches, orm); for (BranchNameKey b : branches) { - if (!sub.superProjectSubscriptionsForSubmoduleBranch(b).isEmpty()) { + if (sub.hasSuperproject(b)) { String message = "Cannot rename a project subscribed to by the other projects"; log.error(message); throw new CannotRenameProjectException(message); } } - } catch (IOException | SubmoduleException e) { + } catch (IOException | SubmoduleConflictException e) { throw new CannotRenameProjectException(e); } }
diff --git a/src/test/java/com/googlesource/gerrit/plugins/renameproject/LockUnlockProjectTest.java b/src/test/java/com/googlesource/gerrit/plugins/renameproject/LockUnlockProjectTest.java index aa3776f..02c47c5 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/renameproject/LockUnlockProjectTest.java +++ b/src/test/java/com/googlesource/gerrit/plugins/renameproject/LockUnlockProjectTest.java
@@ -34,10 +34,13 @@ @Test public void testLockUnlockSucceeds() throws IOException, ConfigInvalidException { - assertThat(projectCache.get(project).getProject().getState()).isEqualTo(ProjectState.ACTIVE); + assertThat(projectCache.get(project).get().getProject().getState()) + .isEqualTo(ProjectState.ACTIVE); lockUnlockInstance.lock(project); - assertThat(projectCache.get(project).getProject().getState()).isEqualTo(ProjectState.READ_ONLY); + assertThat(projectCache.get(project).get().getProject().getState()) + .isEqualTo(ProjectState.READ_ONLY); lockUnlockInstance.unlock(project); - assertThat(projectCache.get(project).getProject().getState()).isEqualTo(ProjectState.ACTIVE); + assertThat(projectCache.get(project).get().getProject().getState()) + .isEqualTo(ProjectState.ACTIVE); } }
diff --git a/src/test/java/com/googlesource/gerrit/plugins/renameproject/RenameIT.java b/src/test/java/com/googlesource/gerrit/plugins/renameproject/RenameIT.java index 41bd819..6a450e9 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/renameproject/RenameIT.java +++ b/src/test/java/com/googlesource/gerrit/plugins/renameproject/RenameIT.java
@@ -29,6 +29,7 @@ import com.google.gerrit.server.project.ProjectState; import com.google.inject.Inject; import java.util.List; +import java.util.Optional; import javax.inject.Named; import org.eclipse.jgit.junit.TestRepository; import org.junit.Test; @@ -55,8 +56,8 @@ adminSshSession.exec(PLUGIN_NAME + " " + project.get() + " " + NEW_PROJECT_NAME); adminSshSession.assertSuccess(); - ProjectState projectState = projectCache.get(Project.nameKey(NEW_PROJECT_NAME)); - assertThat(projectState).isNotNull(); + Optional<ProjectState> projectState = projectCache.get(Project.nameKey(NEW_PROJECT_NAME)); + assertThat(projectState.isPresent()).isTrue(); assertThat(queryProvider.get().byProject(project)).isEmpty(); assertThat(queryProvider.get().byProject(Project.nameKey(NEW_PROJECT_NAME))).isNotEmpty(); } @@ -69,8 +70,8 @@ adminSshSession.exec(PLUGIN_NAME + " " + project.get() + " " + newProjectName); adminSshSession.assertFailure(); - ProjectState projectState = projectCache.get(Project.nameKey(newProjectName)); - assertThat(projectState).isNull(); + Optional<ProjectState> projectState = projectCache.get(Project.nameKey(newProjectName)); + assertThat(projectState.isPresent()).isFalse(); } @Test @@ -80,8 +81,8 @@ adminSshSession.exec(PLUGIN_NAME + " " + allProjects.get() + " " + NEW_PROJECT_NAME); adminSshSession.assertFailure(); - ProjectState projectState = projectCache.get(Project.nameKey(NEW_PROJECT_NAME)); - assertThat(projectState).isNull(); + Optional<ProjectState> projectState = projectCache.get(Project.nameKey(NEW_PROJECT_NAME)); + assertThat(projectState.isPresent()).isFalse(); } @Test
diff --git a/src/test/java/com/googlesource/gerrit/plugins/renameproject/RevertRenameProjectTest.java b/src/test/java/com/googlesource/gerrit/plugins/renameproject/RevertRenameProjectTest.java index c13f2e6..b7d4ebd 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/renameproject/RevertRenameProjectTest.java +++ b/src/test/java/com/googlesource/gerrit/plugins/renameproject/RevertRenameProjectTest.java
@@ -30,6 +30,7 @@ import com.googlesource.gerrit.plugins.renameproject.RenameProject.Step; import com.googlesource.gerrit.plugins.renameproject.monitor.ProgressMonitor; import java.util.List; +import java.util.Optional; import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; @@ -125,22 +126,26 @@ } private void assertReverted() throws Exception { - ProjectState oldProjectState = projectCache.get(oldProjectKey); - assertThat(oldProjectState).isNotNull(); + evictCaches(); - ProjectState newProjectState = projectCache.get(newProjectKey); - assertThat(newProjectState).isNull(); + Optional<ProjectState> oldProjectState = projectCache.get(oldProjectKey); + assertThat(oldProjectState.isPresent()).isTrue(); + + Optional<ProjectState> newProjectState = projectCache.get(newProjectKey); + assertThat(newProjectState.isPresent()).isFalse(); assertThat(queryProvider.get().byProject(oldProjectKey)).isNotEmpty(); assertThat(queryProvider.get().byProject(newProjectKey)).isEmpty(); } private void assertRenamed(Result result) throws Exception { - ProjectState oldProjectState = projectCache.get(oldProjectKey); - assertThat(oldProjectState).isNull(); + evictCaches(); - ProjectState newProjectState = projectCache.get(newProjectKey); - assertThat(newProjectState).isNotNull(); + Optional<ProjectState> oldProjectState = projectCache.get(oldProjectKey); + assertThat(oldProjectState.isPresent()).isFalse(); + + Optional<ProjectState> newProjectState = projectCache.get(newProjectKey); + assertThat(newProjectState.isPresent()).isTrue(); if (renameProject.getStepsPerformed().contains(Step.DATABASE)) { ChangeApi changeApi = gApi.changes().id(NEW_PROJECT_NAME, result.getChange().getId().get()); @@ -152,4 +157,9 @@ assertThat(queryProvider.get().byProject(oldProjectKey)).isEmpty(); } } + + private void evictCaches() { + projectCache.evict(oldProjectKey); + projectCache.evict(newProjectKey); + } }
diff --git a/src/test/java/com/googlesource/gerrit/plugins/renameproject/SubmoduleUtil.java b/src/test/java/com/googlesource/gerrit/plugins/renameproject/SubmoduleUtil.java index be4dc37..5d6b384 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/renameproject/SubmoduleUtil.java +++ b/src/test/java/com/googlesource/gerrit/plugins/renameproject/SubmoduleUtil.java
@@ -54,12 +54,12 @@ throws Exception { try (MetaDataUpdate md = metaDataUpdateFactory.create(sub)) { md.setMessage("Added superproject subscription"); - SubscribeSection s; + SubscribeSection.Builder s; ProjectConfig pc = projectConfigFactory.read(md); if (pc.getSubscribeSections().containsKey(superName)) { - s = pc.getSubscribeSections().get(superName); + s = pc.getSubscribeSections().get(superName).toBuilder(); } else { - s = new SubscribeSection(superName); + s = SubscribeSection.builder(superName); } String refspec; if (superBranch == null) { @@ -72,7 +72,7 @@ } else { s.addMultiMatchRefSpec(refspec); } - pc.addSubscribeSection(s); + pc.addSubscribeSection(s.build()); ObjectId oldId = pc.getRevision(); ObjectId newId = pc.commit(md); assertThat(newId).isNotEqualTo(oldId);
diff --git a/src/test/java/com/googlesource/gerrit/plugins/renameproject/conditions/RenamePreconditionsTest.java b/src/test/java/com/googlesource/gerrit/plugins/renameproject/conditions/RenamePreconditionsTest.java index adc0791..989292b 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/renameproject/conditions/RenamePreconditionsTest.java +++ b/src/test/java/com/googlesource/gerrit/plugins/renameproject/conditions/RenamePreconditionsTest.java
@@ -89,7 +89,7 @@ @Test(expected = CannotRenameProjectException.class) public void testAssertCannotRenameAllProjects() throws Exception { - Project oldProject = new Project(allProjects); + Project oldProject = Project.builder(allProjects).build(); when(oldRsrc.getNameKey()).thenReturn(oldProject.getNameKey()); when(objDb.exists()).thenReturn(false); @@ -98,7 +98,7 @@ @Test(expected = CannotRenameProjectException.class) public void testAssertCannotRenameAllUsers() throws Exception { - Project oldProject = new Project(allUsersName); + Project oldProject = Project.builder(allUsersName).build(); when(oldRsrc.getNameKey()).thenReturn(oldProject.getNameKey()); when(objDb.exists()).thenReturn(false); @@ -107,7 +107,7 @@ @Test(expected = CannotRenameProjectException.class) public void testAssertCannotRenameHasChildren() throws Exception { - Project oldProject = new Project(Project.nameKey("oldProject")); + Project oldProject = Project.builder(Project.nameKey("oldProject")).build(); when(oldRsrc.getNameKey()).thenReturn(oldProject.getNameKey()); when(objDb.exists()).thenReturn(false);