Expose bouncycastle library in plugin API bazlets

Expose bouncycastle library in plugin API bazlets. This way plugins do
not need to extra fetch bouncycastle library in standalone build mode.

Add the bouncycastle to the PLUGIN_TEST_DEPS constant, so that the
plugins do not need to explicitly add them to the java_test rule.

Change-Id: I89900a4bfb75f2388b81a3ac455b4a21cc0e30bd
diff --git a/bouncycastle.bzl b/bouncycastle.bzl
new file mode 100644
index 0000000..f170d8a
--- /dev/null
+++ b/bouncycastle.bzl
@@ -0,0 +1,43 @@
+load("//tools:maven_jar.bzl", "maven_jar")
+
+"""Bazel rule for fetching [Bouncycastle](https://www.bouncycastle.org/)
+dependency
+"""
+
+# This should be the same version used in Gerrit.
+BC_VERS = "1.56"
+
+def bouncycastle_repos():
+  maven_jar(
+    name = "bouncycastle_bcprov",
+    artifact = "org.bouncycastle:bcprov-jdk15on:" + BC_VERS,
+    sha1 = "a153c6f9744a3e9dd6feab5e210e1c9861362ec7",
+  )
+  maven_jar(
+    name = "bouncycastle_bcpg",
+    artifact = "org.bouncycastle:bcpg-jdk15on:" + BC_VERS,
+    sha1 = "9c3f2e7072c8cc1152079b5c25291a9f462631f1",
+  )
+  maven_jar(
+    name = "bouncycastle_bcpkix",
+    artifact = "org.bouncycastle:bcpkix-jdk15on:" + BC_VERS,
+    sha1 = "4648af70268b6fdb24674fb1fd7c1fcc73db1231",
+  )
+  native.bind(
+    name = 'bcprov',
+    actual = '@bouncycastle_bcprov//jar')
+  native.bind(
+    name = 'bcprov-neverlink',
+    actual = '@bouncycastle_bcprov//jar:neverlink')
+  native.bind(
+    name = 'bcpg',
+    actual = '@bouncycastle_bcpg//jar')
+  native.bind(
+    name = 'bcpg-neverlink',
+    actual = '@bouncycastle_bcpg//jar:neverlink')
+  native.bind(
+    name = 'bcpkix',
+    actual = '@bouncycastle_bcpkix//jar')
+  native.bind(
+    name = 'bcpkix-neverlink',
+    actual = '@bouncycastle_bcpkix//jar:neverlink')
diff --git a/gerrit_api.bzl b/gerrit_api.bzl
index 6968e82..a20131e 100644
--- a/gerrit_api.bzl
+++ b/gerrit_api.bzl
@@ -1,4 +1,5 @@
 load("//tools:maven_jar.bzl", "maven_jar")
+load("//:bouncycastle.bzl", "bouncycastle_repos")
 
 """Bazel rule for building [Gerrit Code Review](https://www.gerritcodereview.com/)
 gerrit_api is rule for fetching Gerrit plugin API using Bazel.
@@ -7,6 +8,8 @@
 VER = "2.13.2"
 
 def gerrit_api():
+  bouncycastle_repos()
+
   maven_jar(
    name = 'gerrit_plugin_api',
    artifact = 'com.google.gerrit:gerrit-plugin-api:' + VER,
diff --git a/gerrit_api_maven_local.bzl b/gerrit_api_maven_local.bzl
index 2e26af9..1b9252a 100644
--- a/gerrit_api_maven_local.bzl
+++ b/gerrit_api_maven_local.bzl
@@ -1,4 +1,5 @@
 load("//tools:maven_jar.bzl", "maven_jar", "MAVEN_LOCAL")
+load("//:bouncycastle.bzl", "bouncycastle_repos")
 
 """Bazel rule for building [Gerrit Code Review](https://www.gerritcodereview.com/)
 gerrit_api is rule for fetching Gerrit plugin API using Bazel.
@@ -7,6 +8,8 @@
 VER = "2.14-SNAPSHOT"
 
 def gerrit_api_maven_local():
+  bouncycastle_repos()
+
   maven_jar(
    name = 'gerrit_plugin_api',
    artifact = 'com.google.gerrit:gerrit-plugin-api:' + VER,
diff --git a/tools/commons.bzl b/tools/commons.bzl
index e499cfb..cf31704 100644
--- a/tools/commons.bzl
+++ b/tools/commons.bzl
@@ -6,6 +6,9 @@
     "//external:gerrit-plugin-api",
 ]
 
-PLUGIN_TEST_DEPS=[
-    "//external:gerrit-acceptance-framework"
+PLUGIN_TEST_DEPS = [
+    "//external:bcpg",
+    "//external:bcpkix",
+    "//external:bcprov",
+    "//external:gerrit-acceptance-framework",
 ]