Merge branch 'stable-3.0' into stable-3.1

* stable-3.0:
  Set snapshot version to 3.0.11-SNAPSHOT
  Add repository rule to provide gerrit api version
  Update Gerrit API to 3.0.10
  Update Gerrit API to 2.16.21
  Update Gerrit API to 2.15.19
  Update Gerrit API to 2.14.21

Change-Id: Iad7329938dd192cb6c8f96b72ae217e67b8a43fe
diff --git a/gerrit_api.bzl b/gerrit_api.bzl
index b8a8e77..4a08627 100644
--- a/gerrit_api.bzl
+++ b/gerrit_api.bzl
@@ -1,4 +1,5 @@
 load("//:bouncycastle.bzl", "bouncycastle_repos")
+load("//:gerrit_api_version.bzl", "gerrit_api_version")
 load("//:rules_python.bzl", "rules_python_repos")
 load("//tools:maven_jar.bzl", "maven_jar")
 
@@ -9,6 +10,11 @@
 VER = "3.1.6"
 
 def gerrit_api():
+    gerrit_api_version(
+        name = "gerrit_api_version",
+        version = VER,
+    )
+
     bouncycastle_repos()
     rules_python_repos()
 
diff --git a/gerrit_api_maven_local.bzl b/gerrit_api_maven_local.bzl
index 494910f..7e9817b 100644
--- a/gerrit_api_maven_local.bzl
+++ b/gerrit_api_maven_local.bzl
@@ -1,4 +1,5 @@
 load("//:bouncycastle.bzl", "bouncycastle_repos")
+load("//:gerrit_api_version.bzl", "gerrit_api_version")
 load("//:rules_python.bzl", "rules_python_repos")
 load("//tools:maven_jar.bzl", "MAVEN_LOCAL", "maven_jar")
 
@@ -9,6 +10,11 @@
 VER = "3.1.7-SNAPSHOT"
 
 def gerrit_api_maven_local():
+    gerrit_api_version(
+        name = "gerrit_api_version",
+        version = VER,
+    )
+
     bouncycastle_repos()
     rules_python_repos()
 
diff --git a/gerrit_api_version.bzl b/gerrit_api_version.bzl
new file mode 100644
index 0000000..58fa01a
--- /dev/null
+++ b/gerrit_api_version.bzl
@@ -0,0 +1,27 @@
+# Copyright (C) 2020 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.
+
+def _gerrit_api_version_impl(ctx):
+    ctx.file("version.txt", "Gerrit-ApiVersion: " + ctx.attr.version, False)
+    ctx.file("BUILD.bazel", 'exports_files(["version.txt"])', False)
+
+gerrit_api_version = repository_rule(
+    implementation = _gerrit_api_version_impl,
+    local = True,
+    attrs = {
+        "version": attr.string(
+            mandatory = True,
+        ),
+    },
+)
diff --git a/gerrit_plugin.bzl b/gerrit_plugin.bzl
index f61e6ec..4021733 100644
--- a/gerrit_plugin.bzl
+++ b/gerrit_plugin.bzl
@@ -67,13 +67,17 @@
             "TZ=UTC",
             "export TZ",
             "GEN_VERSION=$$(cat $(location :%s__gen_stamp_info))" % name,
+            "API_VERSION=$$(cat $(location @gerrit_api_version//:version.txt))",
             "cd $$TMP",
             "unzip -q $$ROOT/$<",
-            "echo \"Implementation-Version: $$GEN_VERSION\n$$(cat META-INF/MANIFEST.MF)\" > META-INF/MANIFEST.MF",
+            "echo \"Implementation-Version: $$GEN_VERSION\n$$API_VERSION\n$$(cat META-INF/MANIFEST.MF)\" > META-INF/MANIFEST.MF",
             "find . -exec touch '{}' ';'",
             "zip -Xqr $$ROOT/$@ .",
         ]),
-        tools = [":%s__gen_stamp_info" % name],
+        tools = [
+            ":%s__gen_stamp_info" % name,
+            "@gerrit_api_version//:version.txt",
+        ],
         outs = ["%s%s.jar" % (name, target_suffix)],
         visibility = ["//visibility:public"],
     )