Add support for Bazel in Gerrit tree build

Change-Id: If0862c12fc1fb058434e608cee7797c407cb23c3
diff --git a/BUILD b/BUILD
new file mode 100644
index 0000000..a7a7bad
--- /dev/null
+++ b/BUILD
@@ -0,0 +1,31 @@
+load("//tools/bzl:junit.bzl", "junit_tests")
+load(
+    "//tools/bzl:plugin.bzl",
+    "gerrit_plugin",
+    "PLUGIN_DEPS",
+    "PLUGIN_TEST_DEPS",
+)
+
+gerrit_plugin(
+    name = "sync-events",
+    srcs = glob(["src/main/java/**/*.java"]),
+    resources = glob(["src/main/resources/**/*"]),
+    manifest_entries = [
+        "Gerrit-PluginName: sync-events",
+        "Gerrit-Module: com.ericsson.gerrit.plugins.syncevents.Module",
+        "Gerrit-HttpModule: com.ericsson.gerrit.plugins.syncevents.HttpModule",
+        "Implementation-Title: sync-events plugin",
+        "Implementation-URL: https://gerrit-review.googlesource.com/#/admin/projects/plugins/sync-events",
+    ],
+)
+
+junit_tests(
+    name = "sync_events_tests",
+    srcs = glob(["src/test/java/**/*.java"]),
+    tags = ["sync-events"],
+    deps = PLUGIN_DEPS + PLUGIN_TEST_DEPS + [
+        ":sync-events__plugin",
+        "@mockito//jar",
+        "@wiremock//jar",
+    ],
+)
diff --git a/external_plugin_deps.bzl b/external_plugin_deps.bzl
new file mode 100644
index 0000000..6c723ba
--- /dev/null
+++ b/external_plugin_deps.bzl
@@ -0,0 +1,33 @@
+load("//tools/bzl:maven_jar.bzl", "maven_jar")
+
+def external_plugin_deps():
+  maven_jar(
+    name = 'wiremock',
+    artifact = 'com.github.tomakehurst:wiremock:1.58:standalone',
+    sha1 = '21c8386a95c5dc54a9c55839c5a95083e42412ae',
+    attach_source = False,
+  )
+
+  maven_jar(
+    name = 'mockito',
+    artifact = 'org.mockito:mockito-core:2.5.0',
+    sha1 = 'be28d46a52c7f2563580adeca350145e9ce916f8',
+    deps = [
+      '@byte_buddy//jar',
+      '@objenesis//jar',
+    ],
+  )
+
+  maven_jar(
+    name = 'byte_buddy',
+    artifact = 'net.bytebuddy:byte-buddy:1.5.12',
+    sha1 = 'b1ba1d15f102b36ed43b826488114678d6d413da',
+    attach_source = False,
+  )
+
+  maven_jar(
+    name = 'objenesis',
+    artifact = 'org.objenesis:objenesis:2.4',
+    sha1 = '2916b6c96b50c5b3ec4452ed99401db745aabb27',
+    attach_source = False,
+  )
diff --git a/src/main/resources/Documentation/build.md b/src/main/resources/Documentation/build.md
index 3babed2..3f0527b 100644
--- a/src/main/resources/Documentation/build.md
+++ b/src/main/resources/Documentation/build.md
@@ -1,92 +1,39 @@
 Build
 =====
 
-This plugin is built with Buck.
+Build
+=====
 
-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.
+This plugin is built with Bazel.
 
-Build standalone
-----------------
+Clone (or link) this plugin to the `plugins` directory of Gerrit's source tree.
 
-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 it to @PLUGIN@ directory:
-
-```
-  cd @PLUGIN@ && ln -s ../bucklets .
+  cd gerrit/plugins
+  rm external_plugin_deps.bzl
+  ln -s @PLUGIN@/external_plugin_deps.bzl .
 ```
 
-Add link to the .buckversion file:
+Then issue
 
 ```
-  cd @PLUGIN@ && ln -s bucklets/buckversion .buckversion
+  bazel build plugins/@PLUGIN@
 ```
 
-Add link to the .watchmanconfig file:
+in the root of Gerrit's source tree to build
+
+The output is created in
 
 ```
-  cd @PLUGIN@ && ln -s bucklets/watchmanconfig .watchmanconfig
+  bazel-genfiles/plugins/@PLUGIN@/@PLUGIN@.jar
 ```
 
-To build the plugin, issue the following command:
-
-```
-  buck build plugin
-```
-
-The output is created in:
-
-```
-  buck-out/gen/@PLUGIN@.jar
-```
-
-This project can be imported into the Eclipse IDE:
-
-```
-  ./bucklets/tools/eclipse.py
-```
-
-To execute the tests run:
-
-```
-  buck test
-```
-
-To build plugin sources run:
-
-```
-  buck build src
-```
-
-The output is created in:
-
-```
-  buck-out/gen/@PLUGIN@-sources.jar
-```
-
-Build in Gerrit tree
---------------------
-
-Clone or link this plugin to the plugins directory of Gerrit's source
-tree, and issue the command:
-
-```
-  buck build plugins/@PLUGIN@
-```
-
-The output is created in:
-
-```
-  buck-out/gen/plugins/@PLUGIN@/@PLUGIN@.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
@@ -95,11 +42,11 @@
 To execute the tests run:
 
 ```
-  buck test --include @PLUGIN@
+  bazel test plugins/@PLUGIN@:sync_events_tests
 ```
 
 How to build the Gerrit Plugin API is described in the [Gerrit
-documentation](../../../Documentation/dev-buck.html#_extension_and_plugin_api_jar_files).
+documentation](../../../Documentation/dev-bazel.html#_extension_and_plugin_api_jar_files).
 
 [Back to @PLUGIN@ documentation index][index]