Merge branch 'stable-2.14' into stable-2.15
* stable-2.14:
Fix markdown formatting on config.md
Change-Id: I168c18f9d07ee8ff19a2c64c166d7d3b49be5bcc
diff --git a/WORKSPACE b/WORKSPACE
index d22a0ed..3ce504e 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -3,14 +3,14 @@
load("//:bazlets.bzl", "load_bazlets")
load_bazlets(
- commit = "714a32382ebd02919007d3514513af4395768d80",
+ commit = "b54eaed487d37188120da6933b97c571519954ca",
#local_path = "/home/<user>/projects/bazlets",
)
# Snapshot Plugin API
#load(
-# "@com_googlesource_gerrit_bazlets//:gerrit_api_maven_local.bzl",
-# "gerrit_api_maven_local",
+# "@com_googlesource_gerrit_bazlets//:gerrit_api_maven_local.bzl",
+# "gerrit_api_maven_local",
#)
# Load snapshot Plugin API
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/resources/Documentation/build.md b/src/main/resources/Documentation/build.md
index 33d9e99..3ca3dbd 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