Add support for Bazel in Gerrit tree build
Change-Id: I3538e808d31d31e544be72fa1c798f5082d46cb6
diff --git a/BUILD b/BUILD
new file mode 100644
index 0000000..076068f
--- /dev/null
+++ b/BUILD
@@ -0,0 +1,34 @@
+load("//tools/bzl:plugin.bzl", "gerrit_plugin")
+
+gerrit_plugin(
+ name = "javamelody",
+ srcs = glob(
+ ["src/main/java/**/*.java"],
+ exclude = ["src/main/java/com/googlesource/gerrit/plugins/javamelody/MonitoringDataSourceInterceptor.java"],
+ ),
+ manifest_entries = [
+ "Gerrit-PluginName: javamelody",
+ "Gerrit-Module: com.googlesource.gerrit.plugins.javamelody.Module",
+ "Gerrit-HttpModule: com.googlesource.gerrit.plugins.javamelody.HttpModule",
+ "Implementation-Title: Javamelody plugin",
+ "Implementation-URL: https://gerrit-review.googlesource.com/#/admin/projects/plugins/javamelody",
+ ],
+ resources = glob(["src/main/resources/**/*"]),
+ deps = ["@javamelody_lib//jar:neverlink"],
+)
+
+java_binary(
+ name = "javamelody-deps",
+ main_class = "Dummy",
+ runtime_deps = [":javamelody-datasource-interceptor-lib"],
+)
+
+java_library(
+ name = "javamelody-datasource-interceptor-lib",
+ srcs = ["src/main/java/com/googlesource/gerrit/plugins/javamelody/MonitoringDataSourceInterceptor.java"],
+ deps = [
+ "//gerrit-plugin-api:lib-neverlink",
+ "@javamelody_lib//jar",
+ "@jrobin_lib//jar",
+ ],
+)
diff --git a/external_plugin_deps.bzl b/external_plugin_deps.bzl
new file mode 100644
index 0000000..d7a59a1
--- /dev/null
+++ b/external_plugin_deps.bzl
@@ -0,0 +1,14 @@
+load("//tools/bzl:maven_jar.bzl", "maven_jar")
+
+def external_plugin_deps():
+ maven_jar(
+ name = 'javamelody_lib',
+ artifact = 'net.bull.javamelody:javamelody-core:1.62.0',
+ sha1 = 'f1ee3fe3a023d07cd071dbd424a1b1d7bafbc59a',
+ )
+
+ maven_jar(
+ name = 'jrobin_lib',
+ artifact = 'org.jrobin:jrobin:1.5.9',
+ sha1 = 'bd9a84484c67de930fa841f23cd6a93108b05cd0',
+ )
diff --git a/src/main/resources/Documentation/build.md b/src/main/resources/Documentation/build.md
index 1202dfd..b09446a 100644
--- a/src/main/resources/Documentation/build.md
+++ b/src/main/resources/Documentation/build.md
@@ -1,98 +1,51 @@
Build
=====
-This plugin is built with Buck.
+This plugin is built with Bazel.
-Two build modes are supported: Standalone and in Gerrit tree. Standalone
-build mode is recommended, as this mode doesn't require local Gerrit
-tree to exist.
+Clone (or link) this plugin to the `plugins` directory of Gerrit's source tree.
-Build standalone
-----------------
-
-Clone bucklets library:
+Put the external dependency Bazel build file into the Gerrit /plugins directory,
+replacing the existing empty one.
```
- git clone https://gerrit.googlesource.com/bucklets
-
-```
-and link to bucklets directory:
-
-```
- cd javamelody && ln -s ../bucklets .
+ cd gerrit/plugins
+ rm external_plugin_deps.bzl
+ ln -s javamelody/external_plugin_deps.bzl .
```
-Add link to the .buckversion file:
+Then issue
```
- cd javamelody && ln -s bucklets/buckversion .buckversion
+ bazel build plugins/javamelody:javamelody
```
-Add link to the .watchmanconfig file:
+Note, that the plugin dependencies with arethe [database interception](database-monitoring.md)
+are built separately. To do that, issue this command:
```
- cd javamelody && ln -s bucklets/watchmanconfig .watchmanconfig
-```
-
-To build the plugin, issue the following commands:
-
-```
- buck build all
-```
-
-The output of the target is:
-
-```
- buck-out/gen/javamelody.jar
-```
-
-If [database interception](database-monitoring.md) should be activated,
-then the following artifacts must be used instead:
-
-```
- buck-out/gen/javamelody-nodep.jar
- buck-out/gen/javamelody-deps.jar
- buck-out/gen/javamelody-datasource-interceptor.jar
-```
-
-Build in Gerrit tree
---------------------
-
-Clone or link this plugin to the plugins directory of the Gerrit tree
-and issue the command:
-
-```
- buck build plugins/javamelody:javamelody
-```
-
-If [database interception](database-monitoring.md) should be activated,
-then the following targets must be used instead:
-
-```
- buck build plugins/javamelody:javamelody-nodep
- buck build plugins/javamelody:javamelody-deps
- buck build plugins/javamelody:javamelody-datasource-interceptor
+ bazel build plugins/javamelody:javamelody-deps_deploy.jar
```
The output from the former target is:
```
- buck-out/gen/plugins/javamelody/javamelody.jar
+ bazel-genfiles/plugins/javamelody/javamelody.jar
```
The output from the latter targets are:
```
- buck-out/gen/plugins/javamelody/javamelody-nodep.jar
- buck-out/gen/plugins/javamelody/javamelody-deps.jar
- buck-out/gen/plugins/javamelody/javamelody-datasource-interceptor.jar
+ bazel-bin/plugins/javamelody/javamelody-deps_deploy.jar
```
-This project can be imported into the Eclipse IDE:
+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:
```
./tools/eclipse/project.py
```
More information about Buck can be found in the [Gerrit
-documentation](../../../Documentation/dev-buck.html).
+documentation](../../../Documentation/dev-bazel.html).
diff --git a/src/main/resources/Documentation/database-monitoring.md b/src/main/resources/Documentation/database-monitoring.md
index 0da72f4..01827c6 100644
--- a/src/main/resources/Documentation/database-monitoring.md
+++ b/src/main/resources/Documentation/database-monitoring.md
@@ -21,40 +21,28 @@
dataSourceInterceptorClass = com.googlesource.gerrit.plugins.javamelody.MonitoringDataSourceInterceptor
```
-Compile the plugin without dependencies:
+Compile the plugin:
```
-buck build plugins/javamelody:javamelody-nodep
+bazel build plugins/javamelody:javamelody
```
Compile the plugin dependencies:
```
-buck build plugins/javamelody:javamelody-deps
+bazel build plugins/javamelody:javamelody-deps_deploy.jar
```
-Compile datasource interceptor:
+Deploy the plugin dependencies with datasource-interceptor to `$gerrit_site/lib`:
```
-buck build plugins/javamelody:javamelody-datasource-interceptor
-```
-
-Deploy the datasource-interceptor to `$gerrit_site/lib`:
-
-```
-cp buck-out/gen/plugins/javamelody/javamelody-datasource-interceptor.jar `$gerrit_site/lib`
-```
-
-Deploy the javamelody dependencies to `$gerrit_site/lib`:
-
-```
-cp buck-out/gen/plugins/javamelody/javamelody-deps.jar `$gerrit_site/lib`
+cp bazel-bin/plugins/javamelody/javamelody-deps_deploy.jar `$gerrit_site/lib`
```
Deploy the plugin without dependencies:
```
-cp buck-out/gen/plugins/javamelody/javamelody-nodep.jar `$gerrit_site/plugins`
+cp bazel-genfiles/plugins/javamelody/javamelody.jar `$gerrit_site/plugins`
```
Run Gerrit@Jetty and enjoy SQL statistics, a lá: