Merge branch 'stable-2.14' into stable-2.15

* stable-2.14:
  Upgrade bazlets to latest stable-2.14 to build with 2.14.21 API

Change-Id: I361f748b3437e394187866621b5f1103f44d11b8
diff --git a/WORKSPACE b/WORKSPACE
index 08f491c..1b0f99b 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -3,7 +3,7 @@
 load("//:bazlets.bzl", "load_bazlets")
 
 load_bazlets(
-    commit = "78c35a7eb33ee5ea0980923e246c7dba37347193",
+    commit = "f53f51fb660552d0581aa0ba52c3836ed63d56a3",
     #local_path = "/home/<user>/projects/bazlets",
 )
 
diff --git a/external_plugin_deps.bzl b/external_plugin_deps.bzl
index e3648d3..863d1ab 100644
--- a/external_plugin_deps.bzl
+++ b/external_plugin_deps.bzl
@@ -3,8 +3,8 @@
 def external_plugin_deps():
     maven_jar(
         name = "javamelody-core",
-        artifact = "net.bull.javamelody:javamelody-core:1.77.0",
-        sha1 = "a2b2dd1d39f21d185ea3215830661002445664a4",
+        artifact = "net.bull.javamelody:javamelody-core:1.80.0",
+        sha1 = "9499869f068a1e57efefa392a06b5a7635613359",
     )
 
     maven_jar(
diff --git a/src/main/java/com/googlesource/gerrit/plugins/javamelody/CapabilityChecker.java b/src/main/java/com/googlesource/gerrit/plugins/javamelody/CapabilityChecker.java
index d8e8fe5..fc7bef2 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/javamelody/CapabilityChecker.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/javamelody/CapabilityChecker.java
@@ -14,27 +14,45 @@
 
 package com.googlesource.gerrit.plugins.javamelody;
 
+import com.google.common.collect.ImmutableSet;
 import com.google.gerrit.extensions.annotations.PluginName;
+import com.google.gerrit.extensions.api.access.PluginPermission;
+import com.google.gerrit.extensions.restapi.AuthException;
 import com.google.gerrit.server.CurrentUser;
-import com.google.gerrit.server.account.CapabilityControl;
+import com.google.gerrit.server.permissions.GlobalPermission;
+import com.google.gerrit.server.permissions.PermissionBackend;
+import com.google.gerrit.server.permissions.PermissionBackendException;
 import com.google.inject.Inject;
 import com.google.inject.Provider;
+import com.google.inject.Singleton;
 
+@Singleton
 public class CapabilityChecker {
+  private final PermissionBackend permissionBackend;
   private final Provider<CurrentUser> userProvider;
-  private final String capabilityName;
+  private final String pluginName;
 
   @Inject
-  CapabilityChecker(Provider<CurrentUser> userProvider, @PluginName String pluginName) {
+  CapabilityChecker(
+      PermissionBackend permissionBackend,
+      Provider<CurrentUser> userProvider,
+      @PluginName String pluginName) {
+    this.permissionBackend = permissionBackend;
     this.userProvider = userProvider;
-    this.capabilityName = String.format("%s-%s", pluginName, MonitoringCapability.ID);
+    this.pluginName = pluginName;
   }
 
   public boolean canMonitor() {
-    if (userProvider.get().isIdentifiedUser()) {
-      CapabilityControl ctl = userProvider.get().getCapabilities();
-      return ctl.canAdministrateServer() || ctl.canPerform(capabilityName);
+    try {
+      permissionBackend
+          .user(userProvider)
+          .checkAny(
+              ImmutableSet.of(
+                  GlobalPermission.ADMINISTRATE_SERVER,
+                  new PluginPermission(pluginName, MonitoringCapability.ID)));
+      return true;
+    } catch (AuthException | PermissionBackendException e) {
+      return false;
     }
-    return false;
   }
 }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/javamelody/MonitoringTopMenu.java b/src/main/java/com/googlesource/gerrit/plugins/javamelody/MonitoringTopMenu.java
index 60ebf86..6e1b0a1 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/javamelody/MonitoringTopMenu.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/javamelody/MonitoringTopMenu.java
@@ -29,7 +29,7 @@
     if (capabilityChecker.canMonitor()) {
       menuEntries.add(
           new MenuEntry(
-              "Monitoring", Collections.singletonList(new MenuItem("JavaMelody", "monitoring"))));
+              "Monitoring", Collections.singletonList(new MenuItem("JavaMelody", "/monitoring"))));
     }
   }
 
diff --git a/src/main/resources/Documentation/build.md b/src/main/resources/Documentation/build.md
index 25725b9..65935ad 100644
--- a/src/main/resources/Documentation/build.md
+++ b/src/main/resources/Documentation/build.md
@@ -89,7 +89,7 @@
   bazel build plugins/javamelody:javamelody
 ```
 
-Note, that the plugin dependencies with the [database interception](database-monitoring.md)
+Note, that the plugin dependencies with [database interception](database-monitoring.md)
 are built separately. To do that, issue this command:
 
 ```
@@ -114,9 +114,15 @@
   bazel test plugins/@PLUGIN@:@PLUGIN@_tests
 ```
 
+[IMPORTANT]
+Both targets above are required and must be deployed to the right
+locations: `javamelody.jar` to `<gerrit_site>/plugins` directory
+and `javamelody-deps_deploy.jar` to `<gerrit_site>/lib` directory.
+
 This project can be imported into the Eclipse IDE.
-Add the plugin name to the `CUSTOM_PLUGINS` set in
-Gerrit core in `tools/bzl/plugins.bzl`, and execute:
+Add the plugin name to the `CUSTOM_PLUGINS` and to the
+`CUSTOM_PLUGINS_TEST_DEPS` set in Gerrit core in
+`tools/bzl/plugins.bzl`, and execute:
 
 ```
   ./tools/eclipse/project.py