Merge branch 'stable-3.1'

* stable-3.1:
  Upgrade bazlets to latest stable-3.1 to build with 3.1.7 API
  Upgrade bazlets to latest stable-3.0 to build with 3.0.11 API
  Remove the commented-out snapshot plugin api lines
  Adapt SNAPSHOT plugin api example to the 3.1 version
  Upgrade bazlets to latest stable-3.1
  Prepare for new gerrit_api snapshot version usage
  Upgrade bazlets to latest stable-3.0
  Adapt to changed signature of apply(...) methods
  Upgrade bazlets to latest stable-3.0

Change-Id: Id24cf0dcdd25689a60781405fb6908221b739db4
diff --git a/WORKSPACE b/WORKSPACE
index 8de4e94..88d0986 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -3,7 +3,7 @@
 load("//:bazlets.bzl", "load_bazlets")
 
 load_bazlets(
-    commit = "b6cb89690a5e06261932eb30c95fd8db34a7943a",
+    commit = "53cfe52b1b691040fd03dfe025c0a381df48c6ee",
     #local_path = "/home/<user>/projects/bazlets",
 )
 
diff --git a/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsApiServlet.java b/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsApiServlet.java
index 772a536..59d4e97 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsApiServlet.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/lfs/LfsApiServlet.java
@@ -31,6 +31,7 @@
 import com.google.inject.Inject;
 import com.google.inject.Singleton;
 import com.googlesource.gerrit.plugins.lfs.auth.LfsAuthUserProvider;
+import java.util.Optional;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import org.eclipse.jgit.lfs.errors.LfsException;
@@ -82,13 +83,14 @@
     }
     String projName = matcher.group(1);
     Project.NameKey project = Project.nameKey(ProjectUtil.stripGitSuffix(projName));
-    ProjectState state = projectCache.get(project);
-    if (state == null || state.getProject().getState() == HIDDEN) {
+    Optional<ProjectState> state = projectCache.get(project);
+    if (!state.isPresent() || state.get().getProject().getState() == HIDDEN) {
       throw new LfsRepositoryNotFound(project.get());
     }
-    authorizeUser(userProvider.getUser(auth, projName, request.getOperation()), state, request);
+    authorizeUser(
+        userProvider.getUser(auth, projName, request.getOperation()), state.get(), request);
 
-    if (request.isUpload() && state.getProject().getState() == READ_ONLY) {
+    if (request.isUpload() && state.get().getProject().getState() == READ_ONLY) {
       throw new LfsRepositoryReadOnly(project.get());
     }
 
diff --git a/src/main/java/com/googlesource/gerrit/plugins/lfs/locks/LfsLocksAction.java b/src/main/java/com/googlesource/gerrit/plugins/lfs/locks/LfsLocksAction.java
index b8a6f14..e8d46c2 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/lfs/locks/LfsLocksAction.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/lfs/locks/LfsLocksAction.java
@@ -35,6 +35,7 @@
 import com.googlesource.gerrit.plugins.lfs.auth.LfsAuthUserProvider;
 import com.googlesource.gerrit.plugins.lfs.locks.LfsLocksHandler.LfsLockExistsException;
 import java.io.IOException;
+import java.util.Optional;
 import org.eclipse.jgit.lfs.errors.LfsException;
 import org.eclipse.jgit.lfs.errors.LfsRepositoryNotFound;
 import org.eclipse.jgit.lfs.errors.LfsUnauthorized;
@@ -72,12 +73,12 @@
       String name = getProjectName();
       ProjectState project = getProject(name);
       CurrentUser user = getUser(name);
-      ProjectState state = projectCache.get(project.getNameKey());
-      if (state == null) {
+      Optional<ProjectState> state = projectCache.get(project.getNameKey());
+      if (!state.isPresent()) {
         throw new LfsRepositoryNotFound(project.getNameKey().get());
       }
       try {
-        authorizeUser(permissionBackend.user(user).project(state.getNameKey()));
+        authorizeUser(permissionBackend.user(user).project(state.get().getNameKey()));
       } catch (AuthException | PermissionBackendException e) {
         throwUnauthorizedOp(getAction(), project, user);
       }
@@ -105,11 +106,11 @@
 
   protected ProjectState getProject(String name) throws LfsRepositoryNotFound {
     Project.NameKey project = Project.nameKey(ProjectUtil.stripGitSuffix(name));
-    ProjectState state = projectCache.get(project);
-    if (state == null || state.getProject().getState() == HIDDEN) {
+    Optional<ProjectState> state = projectCache.get(project);
+    if (!state.isPresent() || state.get().getProject().getState() == HIDDEN) {
       throw new LfsRepositoryNotFound(project.get());
     }
-    return state;
+    return state.get();
   }
 
   protected CurrentUser getUser(String project) {