Merge branch 'stable-3.0' into stable-3.1

* stable-3.0:
  Upgrade bazlets to latest stable-2.16 to build with 2.16.18 API
  Bump Bazel version to 3.1.0

Change-Id: I52ad3e0d6e5559f36727e94377461f1683295690
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitiles/FilteredRepository.java b/src/main/java/com/googlesource/gerrit/plugins/gitiles/FilteredRepository.java
index e0c7928..58f2b0f 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitiles/FilteredRepository.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitiles/FilteredRepository.java
@@ -17,8 +17,8 @@
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Maps;
+import com.google.gerrit.entities.Project;
 import com.google.gerrit.extensions.restapi.AuthException;
-import com.google.gerrit.reviewdb.client.Project;
 import com.google.gerrit.server.CurrentUser;
 import com.google.gerrit.server.git.GitRepositoryManager;
 import com.google.gerrit.server.permissions.PermissionBackend;
@@ -139,6 +139,11 @@
   }
 
   @Override
+  public String getIdentifier() {
+    return delegate.getIdentifier();
+  }
+
+  @Override
   public void scanForRepoChanges() throws IOException {
     throw new UnsupportedOperationException(); // Gitiles is read-only.
   }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitiles/GerritGitilesAccess.java b/src/main/java/com/googlesource/gerrit/plugins/gitiles/GerritGitilesAccess.java
index 3b833ba..a9196ef 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitiles/GerritGitilesAccess.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitiles/GerritGitilesAccess.java
@@ -16,9 +16,9 @@
 
 import com.google.common.collect.Maps;
 import com.google.gerrit.common.Nullable;
+import com.google.gerrit.entities.Project;
 import com.google.gerrit.extensions.common.ProjectInfo;
 import com.google.gerrit.extensions.restapi.BadRequestException;
-import com.google.gerrit.reviewdb.client.Project;
 import com.google.gerrit.server.CurrentUser;
 import com.google.gerrit.server.IdentifiedUser;
 import com.google.gerrit.server.config.AnonymousCowardName;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitiles/HttpModule.java b/src/main/java/com/googlesource/gerrit/plugins/gitiles/HttpModule.java
index d91f831..f1c34c6 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitiles/HttpModule.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitiles/HttpModule.java
@@ -20,7 +20,6 @@
 import com.google.gitiles.GitilesAccess;
 import com.google.gitiles.GitilesServlet;
 import com.google.gitiles.GitilesUrls;
-import com.google.gitiles.GitilesView;
 import com.google.inject.Inject;
 import com.google.inject.Provider;
 import com.google.inject.Provides;
@@ -91,7 +90,7 @@
   protected void configureServlets() {
     // Filter all paths so we can decode escaped entities in the URI
     filter("/*").through(createPathFilter());
-    filter("/*").through(new LoginFilter(userProvider, urls));
+    filter("/*").through(new MenuFilter(userProvider, urls));
 
     // make this plugin's classloader the context classloader to prevent
     // classloader issue when rendering markdown
@@ -108,14 +107,8 @@
       @Named("gitiles") Config cfg,
       GitilesUrls urls,
       GitilesAccess.Factory accessFactory,
-      RepositoryResolver<HttpServletRequest> resolver,
-      MenuFilter menuFilter) {
-    GitilesServlet s =
-        new GitilesServlet(cfg, null, urls, accessFactory, resolver, null, null, null, null);
-    for (GitilesView.Type view : GitilesView.Type.values()) {
-      s.addFilter(view, menuFilter);
-    }
-    return s;
+      RepositoryResolver<HttpServletRequest> resolver) {
+    return new GitilesServlet(cfg, null, urls, accessFactory, resolver, null, null, null, null);
   }
 
   @Provides
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitiles/LoginFilter.java b/src/main/java/com/googlesource/gerrit/plugins/gitiles/LoginFilter.java
deleted file mode 100644
index 7009f1a..0000000
--- a/src/main/java/com/googlesource/gerrit/plugins/gitiles/LoginFilter.java
+++ /dev/null
@@ -1,93 +0,0 @@
-// Copyright (C) 2015 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.googlesource.gerrit.plugins.gitiles;
-
-import com.google.gerrit.extensions.restapi.Url;
-import com.google.gerrit.server.CurrentUser;
-import com.google.gerrit.server.IdentifiedUser;
-import com.google.gitiles.GitilesUrls;
-import com.google.inject.Inject;
-import com.google.inject.Provider;
-import java.io.IOException;
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.http.HttpServletResponseWrapper;
-
-class LoginFilter implements Filter {
-  private final Provider<CurrentUser> userProvider;
-  private final GitilesUrls urls;
-
-  @Inject
-  LoginFilter(Provider<CurrentUser> userProvider, GitilesUrls urls) {
-    this.userProvider = userProvider;
-    this.urls = urls;
-  }
-
-  @Override
-  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
-      throws IOException, ServletException {
-    final HttpServletRequest req = (HttpServletRequest) request;
-    HttpServletResponseWrapper rsp =
-        new HttpServletResponseWrapper((HttpServletResponse) response) {
-          @Override
-          public void sendError(int sc) throws IOException {
-            CurrentUser user = userProvider.get();
-            if (sc == SC_UNAUTHORIZED && !(user instanceof IdentifiedUser)) {
-              sendRedirect(getLoginRedirectUrl(req));
-              return;
-            }
-            super.sendError(sc);
-          }
-
-          @Override
-          public void sendError(int sc, String msg) throws IOException {
-            CurrentUser user = userProvider.get();
-            if (sc == SC_UNAUTHORIZED && !(user instanceof IdentifiedUser)) {
-              sendRedirect(getLoginRedirectUrl(req));
-              return;
-            }
-            super.sendError(sc, msg);
-          }
-        };
-    chain.doFilter(request, rsp);
-  }
-
-  @Override
-  public void init(FilterConfig filterConfig) throws ServletException {}
-
-  @Override
-  public void destroy() {}
-
-  private String getLoginRedirectUrl(HttpServletRequest req) {
-    String baseUrl = urls.getBaseGerritUrl(req);
-    String loginUrl = baseUrl + "login/";
-    String token = req.getRequestURL().toString();
-    if (!baseUrl.isEmpty()) {
-      token = token.substring(baseUrl.length());
-    }
-
-    String queryString = req.getQueryString();
-    if (queryString != null && !queryString.isEmpty()) {
-      token = token.concat("?" + queryString);
-    }
-    return (loginUrl + Url.encode(token));
-  }
-}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitiles/MenuFilter.java b/src/main/java/com/googlesource/gerrit/plugins/gitiles/MenuFilter.java
index 058dd2b..1fd26e2 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitiles/MenuFilter.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitiles/MenuFilter.java
@@ -15,6 +15,7 @@
 package com.googlesource.gerrit.plugins.gitiles;
 
 import com.google.common.collect.Lists;
+import com.google.gerrit.extensions.restapi.Url;
 import com.google.gerrit.server.CurrentUser;
 import com.google.gerrit.server.IdentifiedUser;
 import com.google.gitiles.BaseServlet;
@@ -52,7 +53,7 @@
       entries.add(BaseServlet.menuEntry(((IdentifiedUser) user).getName(), null));
       entries.add(BaseServlet.menuEntry("Sign Out", urls.getBaseGerritUrl(req) + "logout"));
     } else {
-      entries.add(BaseServlet.menuEntry("Sign In", urls.getBaseGerritUrl(req) + "login"));
+      entries.add(BaseServlet.menuEntry("Sign In", getLoginRedirectUrl(req)));
     }
     BaseServlet.putSoyData(req, "menuEntries", entries);
     chain.doFilter(request, response);
@@ -63,4 +64,19 @@
 
   @Override
   public void destroy() {}
+
+  private String getLoginRedirectUrl(HttpServletRequest req) {
+    String baseUrl = urls.getBaseGerritUrl(req);
+    String loginUrl = baseUrl + "login/";
+    String token = req.getRequestURL().toString();
+    if (!baseUrl.isEmpty()) {
+      token = token.substring(baseUrl.length());
+    }
+
+    String queryString = req.getQueryString();
+    if (queryString != null && !queryString.isEmpty()) {
+      token = token.concat("?" + queryString);
+    }
+    return (loginUrl + Url.encode(token));
+  }
 }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitiles/Resolver.java b/src/main/java/com/googlesource/gerrit/plugins/gitiles/Resolver.java
index 0731f81..217dafc 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitiles/Resolver.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitiles/Resolver.java
@@ -16,7 +16,7 @@
 
 import static com.google.common.base.Preconditions.checkState;
 
-import com.google.gerrit.reviewdb.client.Project;
+import com.google.gerrit.entities.Project;
 import com.google.gerrit.server.CurrentUser;
 import com.google.gerrit.server.permissions.PermissionBackendException;
 import com.google.gerrit.server.project.NoSuchProjectException;