Merge branch 'stable-2.13'

* stable-2.13:
  Implement rate limits per account for fetch requests

Change-Id: I06eff5786ba383f15a3f934d34319b0c48e82751
diff --git a/.buckconfig b/.buckconfig
deleted file mode 100644
index 8301d1b..0000000
--- a/.buckconfig
+++ /dev/null
@@ -1,14 +0,0 @@
-[alias]
-  quota = //:quota
-  plugin = //:quota
-
-[java]
-  src_roots = java, resources
-
-[project]
-  ignore = .git
-
-[cache]
-  mode = dir
-  dir = buck-out/cache
-
diff --git a/BUCK b/BUCK
deleted file mode 100644
index 4d527fb..0000000
--- a/BUCK
+++ /dev/null
@@ -1,30 +0,0 @@
-include_defs('//bucklets/gerrit_plugin.bucklet')
-
-gerrit_plugin(
-  name = 'quota',
-  srcs = glob(['src/main/java/**/*.java']),
-  resources = glob(['src/main/resources/**/*']),
-  manifest_entries = [
-    'Gerrit-PluginName: quota',
-    'Gerrit-Module: com.googlesource.gerrit.plugins.quota.Module',
-  ],
-  provided_deps = [
-    '//lib/commons:lang',
-  ]
-)
-
-TEST_DEPS = GERRIT_PLUGIN_API + GERRIT_TESTS + [
-  ':quota__plugin'
-]
-
-java_library(
-  name = 'classpath',
-  deps = TEST_DEPS,
-)
-
-java_test(
-  name = 'quota_tests',
-  srcs = glob(['src/test/java/**/*.java']),
-  labels = ['quota'],
-  deps = TEST_DEPS,
-)
diff --git a/BUILD b/BUILD
new file mode 100644
index 0000000..e4fda3a
--- /dev/null
+++ b/BUILD
@@ -0,0 +1,26 @@
+load("//tools/bzl:junit.bzl", "junit_tests")
+load(
+    "//tools/bzl:plugin.bzl",
+    "gerrit_plugin",
+    "PLUGIN_DEPS",
+    "PLUGIN_TEST_DEPS",
+)
+
+gerrit_plugin(
+    name = "quota",
+    srcs = glob(["src/main/java/**/*.java"]),
+    resources = glob(["src/main/resources/**/*"]),
+    manifest_entries = [
+        "Gerrit-PluginName: quota",
+        "Gerrit-Module: com.googlesource.gerrit.plugins.quota.Module",
+    ],
+)
+
+junit_tests(
+    name = "quota_tests",
+    srcs = glob(["src/test/java/**/*.java"]),
+    tags = ["quota"],
+    deps = PLUGIN_DEPS + PLUGIN_TEST_DEPS + [
+        ":quota__plugin",
+    ],
+)
diff --git a/lib/commons/BUCK b/lib/commons/BUCK
deleted file mode 100644
index be9dfe5..0000000
--- a/lib/commons/BUCK
+++ /dev/null
@@ -1,11 +0,0 @@
-include_defs('//bucklets/maven_jar.bucklet')
-
-maven_jar(
-  name = 'lang',
-  id = 'commons-lang:commons-lang:2.5',
-  sha1 = 'b0236b252e86419eef20c31a44579d2aee2f0a69',
-  exclude = ['META-INF/LICENSE.txt', 'META-INF/NOTICE.txt'],
-  attach_source = False,
-  license = 'Apache2.0',
-)
-
diff --git a/lib/gerrit/BUCK b/lib/gerrit/BUCK
deleted file mode 100644
index 19326f3..0000000
--- a/lib/gerrit/BUCK
+++ /dev/null
@@ -1,22 +0,0 @@
-include_defs('//bucklets/maven_jar.bucklet')
-
-VER = '2.13-SNAPSHOT'
-REPO = MAVEN_LOCAL
-
-maven_jar(
-  name = 'plugin-api',
-  id = 'com.google.gerrit:gerrit-plugin-api:' + VER,
-  sha1 = '78df190269b0d5a4bc4f61ab3a66a49252b779eb',
-  attach_source = False,
-  repository = REPO,
-  license = 'Apache2.0',
-)
-
-maven_jar(
-  name = 'acceptance-framework',
-  id = 'com.google.gerrit:gerrit-acceptance-framework:' + VER,
-  sha1 ='76eceefa7e31c6945513c36c4d106066d1df3e63',
-  license = 'Apache2.0',
-  attach_source = False,
-  repository = REPO,
-)
diff --git a/pom.xml b/pom.xml
deleted file mode 100644
index 0c61ba6..0000000
--- a/pom.xml
+++ /dev/null
@@ -1,109 +0,0 @@
-<!--
-Copyright (C) 2014 The Android Open Source Project
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
-http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0"
-  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-  <modelVersion>4.0.0</modelVersion>
-
-  <groupId>com.googlesource.gerrit.plugins.quota</groupId>
-  <artifactId>quota</artifactId>
-  <packaging>jar</packaging>
-  <version>2.13-SNAPSHOT</version>
-  <name>quota</name>
-
-  <properties>
-    <Gerrit-ApiType>plugin</Gerrit-ApiType>
-    <Gerrit-ApiVersion>${project.version}</Gerrit-ApiVersion>
-  </properties>
-
-  <build>
-    <plugins>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-jar-plugin</artifactId>
-        <version>2.4</version>
-        <configuration>
-          <archive>
-            <manifestEntries>
-              <Gerrit-PluginName>quota</Gerrit-PluginName>
-              <Gerrit-Module>com.googlesource.gerrit.plugins.quota.Module</Gerrit-Module>
-
-              <Implementation-Vendor>Gerrit Code Review</Implementation-Vendor>
-              <Implementation-URL>http://code.google.com/p/gerrit/</Implementation-URL>
-
-              <Implementation-Title>${Gerrit-ApiType} ${project.artifactId}</Implementation-Title>
-              <Implementation-Version>${project.version}</Implementation-Version>
-
-              <Gerrit-ApiType>${Gerrit-ApiType}</Gerrit-ApiType>
-              <Gerrit-ApiVersion>${Gerrit-ApiVersion}</Gerrit-ApiVersion>
-            </manifestEntries>
-          </archive>
-        </configuration>
-      </plugin>
-
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-compiler-plugin</artifactId>
-        <version>2.3.2</version>
-        <configuration>
-          <source>1.7</source>
-          <target>1.7</target>
-          <encoding>UTF-8</encoding>
-        </configuration>
-      </plugin>
-    </plugins>
-  </build>
-
-  <dependencies>
-    <dependency>
-      <groupId>com.google.gerrit</groupId>
-      <artifactId>gerrit-${Gerrit-ApiType}-api</artifactId>
-      <version>${Gerrit-ApiVersion}</version>
-      <scope>provided</scope>
-    </dependency>
-    <dependency>
-      <groupId>junit</groupId>
-      <artifactId>junit</artifactId>
-      <version>4.11</version>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.easymock</groupId>
-      <artifactId>easymock</artifactId>
-      <version>3.4</version>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>log4j</groupId>
-      <artifactId>log4j</artifactId>
-      <version>1.2.17</version>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.slf4j</groupId>
-      <artifactId>slf4j-log4j12</artifactId>
-      <version>1.7.7</version>
-      <scope>test</scope>
-    </dependency>
-  </dependencies>
-
-  <repositories>
-    <repository>
-      <id>gerrit-api-repository</id>
-      <url>https://gerrit-api.storage.googleapis.com/snapshot/</url>
-    </repository>
-  </repositories>
-</project>
diff --git a/src/main/resources/Documentation/build.md b/src/main/resources/Documentation/build.md
index e22de10..5ff0924 100644
--- a/src/main/resources/Documentation/build.md
+++ b/src/main/resources/Documentation/build.md
@@ -1,102 +1,35 @@
 Build
 =====
 
-This plugin can be built with Buck or Maven.
+This plugin is built with Bazel.
 
-Buck
+Bazel
 ----
 
-Two build modes are supported: Standalone and in Gerrit tree.
-The standalone build mode is recommended, as this mode doesn't require
-the Gerrit tree to exist locally.
+Clone (or link) this plugin to the `plugins` directory of Gerrit's source tree.
 
-
-### Build standalone
-
-Clone bucklets library:
+Build the plugin from Gerrit's root directory:
 
 ```
-  git clone https://gerrit.googlesource.com/bucklets
-
-```
-and link it to quota plugin directory:
-
-```
-  cd quota && ln -s ../bucklets .
-```
-
-Add link to the .buckversion file:
-
-```
-  cd quota && ln -s bucklets/buckversion .buckversion
-```
-
-Add link to the .watchmanconfig file:
-```
-  cd server-config && ln -s bucklets/watchmanconfig .watchmanconfig
-```
-
-To build the plugin, issue the following command:
-
-
-```
-  buck build plugin
+  bazel build plugins/quota
 ```
 
 The output is created in
 
 ```
-  buck-out/gen/quota.jar
+  bazel-genfiles/plugins/quota/quota.jar
 ```
 
-Test are executed with
-
-```
-  buck test
-```
-
-This project can be imported into the Eclipse IDE:
-
-```
-  ./bucklets/tools/eclipse.py
-```
-
-### 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/quota
-```
-
-The output is created in
-
-```
-  buck-out/gen/plugins/quota/quota.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's
+`tools/bzl/plugins.bzl` and execute:
 
 ```
   ./tools/eclipse/project.py
 ```
 
-Test are executed with
+To execute the tests run:
 
 ```
-  buck test --include quota-plugin
-```
-
-Maven
------
-
-Note that the Maven build is provided for compatibility reasons, but
-it is considered to be deprecated and will be removed in a future
-version of this plugin.
-
-To build with Maven, run
-
-```
-mvn clean package
+  bazel test plugins/quota:quota_tests
 ```
diff --git a/src/test/java/com/googlesource/gerrit/plugins/quota/PublisherExceptionTest.java b/src/test/java/com/googlesource/gerrit/plugins/quota/PublisherExceptionTest.java
index 291b4dd..8018a86 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/quota/PublisherExceptionTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/quota/PublisherExceptionTest.java
@@ -57,7 +57,7 @@
 
   @Before
   public void setupLogging() {
-    captor = EasyMock.newCapture();
+    captor = new Capture();
     appender = createMock(Appender.class);
     appender.doAppend(capture(captor));
     expectLastCall().anyTimes();