Merge branch 'stable-2.14' into stable-2.15
* stable-2.14:
Update bazlets to latest stable-2.14 to use 2.14.12 API
Allow access using Basic Authentication prefix
Update javamelody-core to 1.74.0
Prefer Javamelody's own configuration constants
Change-Id: I878592a8c317855be71302b2bc8f912efa140c97
diff --git a/WORKSPACE b/WORKSPACE
index 154bdef..3076a09 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -3,27 +3,27 @@
load("//:bazlets.bzl", "load_bazlets")
load_bazlets(
- commit = "cbbab83e99c3fa44b6ff37863cbd7bb3e9f84f47",
+ commit = "7ce9a3f58f030635b3a1229b7fb4c62ee7979bc8",
#local_path = "/home/<user>/projects/bazlets",
)
#Snapshot Plugin API
-#load(
-# "@com_googlesource_gerrit_bazlets//:gerrit_api_maven_local.bzl",
-# "gerrit_api_maven_local",
-#)
-
-# Load snapshot Plugin API
-#gerrit_api_maven_local()
-
-# Release Plugin API
load(
- "@com_googlesource_gerrit_bazlets//:gerrit_api.bzl",
- "gerrit_api",
+ "@com_googlesource_gerrit_bazlets//:gerrit_api_maven_local.bzl",
+ "gerrit_api_maven_local",
)
+# Load snapshot Plugin API
+gerrit_api_maven_local()
+
+# Release Plugin API
+# load(
+# "@com_googlesource_gerrit_bazlets//:gerrit_api.bzl",
+# "gerrit_api",
+# )
+
# Load release Plugin API
-gerrit_api()
+# gerrit_api()
load("//:external_plugin_deps.bzl", "external_plugin_deps")
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