Merge branch 'stable-2.14'
* stable-2.14:
GerritMonitoringFilter: Format with google-java-format
Format BUILD file with buildifier
Add parameters to plugin configuration
Default to using plugin data dir for new installations
Finalize constants in JavamelodyFilter
Format all java files with google-java-formatter
Group Javamelody HTTP request statistics
Change-Id: I2c3bc53601803abf8e9161a0f397daf70f4aba33
diff --git a/WORKSPACE b/WORKSPACE
index eff71ca..8e9f6fa 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -3,27 +3,27 @@
load("//:bazlets.bzl", "load_bazlets")
load_bazlets(
- commit = "e57da7c1ddde1389c15c86154a2ac4019099b050",
+ commit = "42bffc66c0e92753133e4cea2debe65abc359c4d",
#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