Merge branch 'stable-2.13'

* stable-2.13:
  Use queue to hold Events during connection glitches
  Remove obsolete manifest entries
  Tidy up dependencies
  Build with plugin API 2.13.2

Change-Id: I32aa58836e0d4f1dc01e30ee7cbedf93aeef65ee
diff --git a/.buckconfig b/.buckconfig
deleted file mode 100644
index 5238f0d..0000000
--- a/.buckconfig
+++ /dev/null
@@ -1,13 +0,0 @@
-[alias]
-  rabbitmq = //:rabbitmq
-  plugin = //:rabbitmq
-
-[java]
-  src_roots = java, resources
-
-[project]
-  ignore = .git
-
-[cache]
-  mode = dir
-  dir = buck-out/cache
diff --git a/.gitignore b/.gitignore
index 73faeb9..5c795fd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,15 +1,6 @@
-work/
-buck-out/
-bucklets
-build/
-bin/
-target/
-.buckd/
-.buckversion
 .classpath
 .checkstyle
 .project
 .settings/
 .idea/
-.watchmanconfig
 *.iml
diff --git a/BUCK b/BUCK
deleted file mode 100644
index b80fa41..0000000
--- a/BUCK
+++ /dev/null
@@ -1,64 +0,0 @@
-include_defs('//bucklets/gerrit_plugin.bucklet')
-include_defs('//bucklets/maven_jar.bucklet')
-
-gerrit_plugin(
-  name = 'rabbitmq',
-  srcs = glob(['src/main/java/**/*.java']),
-  resources = glob(['src/main/resources/**/*']),
-  manifest_entries = [
-    'Gerrit-PluginName: rabbitmq',
-    'Gerrit-Module: com.googlesource.gerrit.plugins.rabbitmq.Module',
-    'Implementation-Title: Gerrit rabbitmq plugin',
-  ],
-  deps = [
-    ':amqp-client',
-    ':commons-codec',
-    ':commons-io',
-    ':guice-multibindings',
-  ],
-)
-
-java_library(
-  name = 'classpath',
-  deps = [':rabbitmq__plugin'],
-)
-
-maven_jar(
-  name = 'commons-codec',
-  id = 'commons-codec:commons-codec:1.4',
-  sha1 = '4216af16d38465bbab0f3dff8efa14204f7a399a',
-  license = 'Apache2.0',
-  exclude = ['META-INF/LICENSE.txt', 'META-INF/NOTICE.txt'],
-)
-
-maven_jar(
-  name = 'commons-io',
-  id = 'commons-io:commons-io:1.4',
-  sha1 = 'a8762d07e76cfde2395257a5da47ba7c1dbd3dce',
-  license = 'Apache2.0',
-)
-
-maven_jar(
-  name = 'amqp-client',
-  id = 'com.rabbitmq:amqp-client:3.5.2',
-  sha1 = '8d10edd29e08f78349bd1da9d18f81c9f8b90567',
-  license = 'MPL1.1',
-  exclude_java_sources = True,
-  visibility = [],
-)
-
-maven_jar(
-  name = 'guice-multibindings',
-  id = 'com.google.inject.extensions:guice-multibindings:4.0',
-  sha1 = 'f4509545b4470bbcc865aa500ad6fef2e97d28bf',
-  license = 'Apache2.0',
-  exclude_java_sources = True,
-  exclude = [
-    'META-INF/DEPENDENCIES',
-    'META-INF/LICENSE',
-    'META-INF/NOTICE',
-    'META-INF/maven/com.google.guava/guava/pom.properties',
-    'META-INF/maven/com.google.guava/guava/pom.xml',
-  ],
-  visibility = [],
-)
diff --git a/BUILD b/BUILD
new file mode 100644
index 0000000..3f40714
--- /dev/null
+++ b/BUILD
@@ -0,0 +1,20 @@
+load("//tools/bzl:plugin.bzl", "gerrit_plugin")
+
+gerrit_plugin(
+    name = "rabbitmq",
+    srcs = glob(["src/main/java/**/*.java"]),
+    resources = glob(["src/main/resources/**/*"]),
+    manifest_entries = [
+        "Gerrit-PluginName: rabbitmq",
+        "Gerrit-Module: com.googlesource.gerrit.plugins.rabbitmq.Module",
+        "Implementation-Title: Gerrit rabbitmq plugin",
+        "Implementation-URL: https://gerrit-review.googlesource.com/#/admin/projects/plugins/rabbitmq",
+    ],
+    deps = [
+        "@amqp_client//jar",
+        "@commons_codec//jar:neverlink",
+        "@commons_io//jar",
+        "@commons_lang//jar:neverlink",
+        "@gson//jar:neverlink",
+    ],
+)
diff --git a/README.md b/README.md
index 6b8c33f..b3b6665 100644
--- a/README.md
+++ b/README.md
@@ -1,12 +1,6 @@
 gerrit-rabbitmq-plugin: Gerrit event publish plugin via RabbitMQ
 =======================
 
-* Author: rinrinne a.k.a. rin_ne
-* Repository: http://github.com/rinrinne/gerrit-rabbitmq-plugin
-* Release: http://github.com/rinrinne/gerrit-rabbitmq-plugin/releases
-
-[![Build Status](https://travis-ci.org/rinrinne/gerrit-rabbitmq-plugin.png?branch=master)](https://travis-ci.org/rinrinne/gerrit-rabbitmq-plugin)
-
 Synopsis
 ----------------------
 
@@ -15,36 +9,25 @@
 This can publish gerrit events to message queue provided by RabbitMQ.
 Published events are the same as Gerrit stream evnets.
 
-This plugin works on Gerrit 2.8 - 2.10.
+This plugin works on Gerrit 2.8 - 2.13.
 
 Environments
 ---------------------
 
 * `linux`
-* `java-1.7`
-* `Buck`
-
-Build
----------------------
-
-Clone or link this plugin to the plugins directory of Gerrit's source
-tree, and issue the command:
-
-
-    buck build plugins/rabbitmq
-
-The output is created in
-
-    buck-out/gen/plugins/rabbitmq/rabbitmq.jar
+* `java-1.8`
+* `Bazel`
 
 Reference
 ---------------------
 
+* [Build]
 * [Configuration]
 * [Message Format]
 
-[Configuration]: https://github.com/rinrinne/gerrit-rabbitmq-plugin/blob/master/src/main/resources/Documentation/config.md
-[Message Format]: https://github.com/rinrinne/gerrit-rabbitmq-plugin/blob/master/src/main/resources/Documentation/message.md
+[Build]: src/main/resources/Documentation/build.md
+[Configuration]: src/main/resources/Documentation/config.md
+[Message Format]: src/main/resources/Documentation/message.md
 
 Minimum Configuration
 ---------------------
diff --git a/external_plugin_deps.bzl b/external_plugin_deps.bzl
new file mode 100644
index 0000000..70ed9e6
--- /dev/null
+++ b/external_plugin_deps.bzl
@@ -0,0 +1,8 @@
+load("//tools/bzl:maven_jar.bzl", "maven_jar")
+
+def external_plugin_deps():
+    maven_jar(
+        name = "amqp_client",
+        artifact = "com.rabbitmq:amqp-client:3.5.2",
+        sha1 = "8d10edd29e08f78349bd1da9d18f81c9f8b90567",
+    )
diff --git a/lib/BUCK b/lib/BUCK
deleted file mode 100644
index 07a8031..0000000
--- a/lib/BUCK
+++ /dev/null
@@ -1 +0,0 @@
-include_defs('//bucklets/maven_jar.bucklet')
diff --git a/lib/gerrit/BUCK b/lib/gerrit/BUCK
deleted file mode 100644
index 1ae48ff..0000000
--- a/lib/gerrit/BUCK
+++ /dev/null
@@ -1,13 +0,0 @@
-include_defs('//bucklets/maven_jar.bucklet')
-
-VER = '2.13.2'
-REPO = MAVEN_CENTRAL
-
-maven_jar(
-  name = 'plugin-api',
-  id = 'com.google.gerrit:gerrit-plugin-api:' + VER,
-  sha1 = '3cdeb17c2b0f945e71135ef6abe5a1db59b9d313',
-  license = 'Apache2.0',
-  attach_source = False,
-  repository = REPO,
-)
diff --git a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/config/AMQProperties.java b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/config/AMQProperties.java
index 5d1c553..ceaef0a 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/config/AMQProperties.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/config/AMQProperties.java
@@ -32,8 +32,8 @@
 
 public class AMQProperties {
 
-  public final static String EVENT_APPID = "gerrit";
-  public final static String CONTENT_TYPE_JSON = "application/json";
+  public static final String EVENT_APPID = "gerrit";
+  public static final String CONTENT_TYPE_JSON = "application/json";
 
   private static final Logger LOGGER = LoggerFactory.getLogger(AMQProperties.class);
 
diff --git a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/config/PluginProperties.java b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/config/PluginProperties.java
index 36ba106..09661ca 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/config/PluginProperties.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/config/PluginProperties.java
@@ -40,7 +40,7 @@
 
   private static final Logger LOGGER = LoggerFactory.getLogger(PluginProperties.class);
 
-  private final static int MINIMUM_CONNECTION_MONITOR_INTERVAL = 5000;
+  private static final int MINIMUM_CONNECTION_MONITOR_INTERVAL = 5000;
 
   private final Set<Section> sections;
   private final Path propertiesFile;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/config/Properties.java b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/config/Properties.java
index d81379b..635d3ad 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/config/Properties.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/config/Properties.java
@@ -8,12 +8,12 @@
 import java.util.Set;
 
 public interface Properties extends Cloneable {
-  public Config toConfig();
-  public boolean load();
-  public boolean load(Properties baseProperties);
-  public Path getPath();
-  public String getName();
-  public Set<Section> getSections();
-  public <T extends Section> T getSection(Class<T> clazz);
-  public AMQProperties getAMQProperties();
+  Config toConfig();
+  boolean load();
+  boolean load(Properties baseProperties);
+  Path getPath();
+  String getName();
+  Set<Section> getSections();
+  <T extends Section> T getSection(Class<T> clazz);
+  AMQProperties getAMQProperties();
 }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/config/internal/GerritFrontUrl.java b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/config/internal/GerritFrontUrl.java
index 233c156..9b7a84d 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/config/internal/GerritFrontUrl.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/config/internal/GerritFrontUrl.java
@@ -3,5 +3,5 @@
 import org.eclipse.jgit.lib.Config;
 
 public interface GerritFrontUrl {
-  public void setGerritFrontUrlFromConfig(Config config);
+  void setGerritFrontUrlFromConfig(Config config);
 }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/config/section/Sections.java b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/config/section/Sections.java
index 759ef03..ba6f220 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/config/section/Sections.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/config/section/Sections.java
@@ -27,11 +27,11 @@
 public final class Sections {
   private static final Logger LOGGER = LoggerFactory.getLogger(Sections.class);
 
-  public static final <T extends Section> String getName(T section) {
+  public static <T extends Section> String getName(T section) {
     return section.getClass().getSimpleName().toLowerCase();
   }
 
-  public static final <T extends Section> T initialize(T section) {
+  public static <T extends Section> T initialize(T section) {
     Field[] fs = section.getClass().getFields();
     for (Field f : fs) {
       try {
@@ -56,11 +56,11 @@
     return section;
   }
 
-  public static final <T extends Section> Config toConfig(T section) {
+  public static <T extends Section> Config toConfig(T section) {
     return toConfig(section, new Config());
   }
 
-  public static final <T extends Section> Config toConfig(T section, Config config) {
+  public static <T extends Section> Config toConfig(T section, Config config) {
     Field[] fs = section.getClass().getFields();
     for (Field f : fs) {
       try {
@@ -85,7 +85,7 @@
     return config;
   }
 
-  public static final <T extends Section> Section fromConfig(T section, Config... configs) {
+  public static <T extends Section> Section fromConfig(T section, Config... configs) {
     for (Config config : configs) {
       if (config != null) {
         Set<String> names = config.getNames(getName(section));
@@ -115,7 +115,7 @@
     return section;
   }
 
-  public static final <T extends Section> T normalize(T section) {
+  public static <T extends Section> T normalize(T section) {
     Field[] fs = section.getClass().getFields();
     for (Field f : fs) {
       try {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/message/MessagePublisher.java b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/message/MessagePublisher.java
index 81ad042..48465bc 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/message/MessagePublisher.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/message/MessagePublisher.java
@@ -41,7 +41,7 @@
 
   private static final Logger LOGGER = LoggerFactory.getLogger(MessagePublisher.class);
 
-  private final static int MONITOR_FIRSTTIME_DELAY = 15000;
+  private static final int MONITOR_FIRSTTIME_DELAY = 15000;
 
   private static final int MAX_EVENTS = 16384;
   private final Session session;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/message/Publisher.java b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/message/Publisher.java
index e6eaae3..b729dd3 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/message/Publisher.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/message/Publisher.java
@@ -6,13 +6,13 @@
 import com.googlesource.gerrit.plugins.rabbitmq.session.Session;
 
 public interface Publisher {
-  public void start();
-  public void stop();
-  public void enable();
-  public void disable();
-  public boolean isEnable();
-  public Session getSession();
-  public Properties getProperties();
-  public String getName();
-  public EventListener getEventListener();
+  void start();
+  void stop();
+  void enable();
+  void disable();
+  boolean isEnable();
+  Session getSession();
+  Properties getProperties();
+  String getName();
+  EventListener getEventListener();
 }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/session/Session.java b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/session/Session.java
index 6cd7e81..5aa03fb 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/session/Session.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/session/Session.java
@@ -14,8 +14,8 @@
 package com.googlesource.gerrit.plugins.rabbitmq.session;
 
 public interface Session {
-  public boolean isOpen();
-  public void connect();
-  public void disconnect();
-  public void publish(String message);
+  boolean isOpen();
+  void connect();
+  void disconnect();
+  void publish(String message);
 }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/session/type/AMQPSession.java b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/session/type/AMQPSession.java
index 6afec87..d5389dc 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/session/type/AMQPSession.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/session/type/AMQPSession.java
@@ -46,7 +46,7 @@
 
     private final Class<?> clazz;
 
-    public <T extends ShutdownNotifier> ShutdownListenerImpl(Class<T> clazz) {
+    <T extends ShutdownNotifier> ShutdownListenerImpl(Class<T> clazz) {
       this.clazz = clazz;
     }
 
diff --git a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/worker/EventWorker.java b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/worker/EventWorker.java
index 332b9cd..1a46663 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/worker/EventWorker.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/worker/EventWorker.java
@@ -3,8 +3,8 @@
 import com.googlesource.gerrit.plugins.rabbitmq.message.Publisher;
 
 public interface EventWorker {
-  public void addPublisher(Publisher publisher);
-  public void addPublisher(Publisher publisher, String userName);
-  public void removePublisher(Publisher publisher);
-  public void clear();
+  void addPublisher(Publisher publisher);
+  void addPublisher(Publisher publisher, String userName);
+  void removePublisher(Publisher publisher);
+  void clear();
 }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/worker/EventWorkerFactory.java b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/worker/EventWorkerFactory.java
index 92c36b9..46b9c7c 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/worker/EventWorkerFactory.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/worker/EventWorkerFactory.java
@@ -15,5 +15,5 @@
 package com.googlesource.gerrit.plugins.rabbitmq.worker;
 
 public interface EventWorkerFactory {
-  public EventWorker create();
+  EventWorker create();
 }
diff --git a/src/main/resources/Documentation/build.md b/src/main/resources/Documentation/build.md
index 38c3bb5..f6656f0 100644
--- a/src/main/resources/Documentation/build.md
+++ b/src/main/resources/Documentation/build.md
@@ -1,73 +1,37 @@
 Build
 =====
 
-This plugin is built with Buck.
+This @PLUGIN@ 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 it to rabbitmq directory:
-
-```
-  cd rabbitmq && 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 rabbitmq && ln -s bucklets/buckversion .buckversion
+  bazel build plugins/@PLUGIN@
 ```
 
-Add link to the .watchmanconfig file:
-
-```
-  cd rabbitmq && ln -s bucklets/watchmanconfig .watchmanconfig
-```
-
-To build the plugin, issue the following command:
-
-
-```
-  buck build plugin
-```
+in the root of Gerrit's source tree to build
 
 The output is created in
 
 ```
-  buck-out/gen/rabbitmq.jar
+  bazel-genfiles/plugins/@PLUGIN@/@PLUGIN@.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/rabbitmq
-```
-
-The output is created in
-
-```
-  buck-out/gen/plugins/rabbitmq/rabbitmq.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
 ```
-
-How to build the Gerrit Plugin API is described in the [Gerrit
-documentation](../../../Documentation/dev-buck.html#_extension_and_plugin_api_jar_files).