Merge branch 'stable-3.1'

* stable-3.1:
  Fix bazlets using latest stable-3.1 to build with 3.1.5 API
  Upgrade bazlets to latest stable-3.1 to build with 3.1.5 API
  Upgrade bazlets to latest stable-3.0 to build with 3.0.9 API
  Upgrade bazlets to latest stable-2.16 to build with 2.16.19 API

Change-Id: I02ca8a61bd8a581c6d9b8dea621b836384c5afff
diff --git a/WORKSPACE b/WORKSPACE
index c12ec76..d15b2be 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -3,7 +3,7 @@
 load("//:bazlets.bzl", "load_bazlets")
 
 load_bazlets(
-    commit = "51c1fd2758fcc1b900a80d4ebb037bc373f85d39",
+    commit = "5c26af9e0374ede4cd67939be972adf6c4cda791",
     #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..01b983a 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/projectgroupstructure/DefaultAccessRights.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/projectgroupstructure/DefaultAccessRights.java
@@ -97,15 +97,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) {
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..7eca913 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;
 
@@ -84,9 +85,9 @@
     String projectName = name("someProject");
     userRestSession.put("/projects/" + projectName, in).assertCreated();
 
-    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 +140,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 b190c59..1f1d52c 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/projectgroupstructure/ProjectCreationValidatorIT.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/projectgroupstructure/ProjectCreationValidatorIT.java
@@ -35,6 +35,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;
 
@@ -172,9 +173,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());
 
@@ -184,7 +185,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
             + "-"
@@ -192,7 +193,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());
   }
 
@@ -264,9 +265,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());
 
@@ -276,7 +277,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
             + "-"
@@ -284,7 +285,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());
   }
 
@@ -316,8 +317,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