Bazel: Hoist PolyGerrit UI into the plugin final artifact

Ship the PolyGerrit UI into the plugin final artifact:

static/checks-pg.js
static/checks-pg.html

and expose it through WebUiPlugin during the load phase of the plugin.

Change-Id: I80a2af3619b580b32f1365948021bb80a4cbb3d1
diff --git a/BUILD b/BUILD
index 6808f81..48b9093 100644
--- a/BUILD
+++ b/BUILD
@@ -18,5 +18,6 @@
         "Gerrit-Module: com.google.gerrit.plugins.checks.Module",
         "Gerrit-HttpModule: com.google.gerrit.plugins.checks.api.HttpModule",
     ],
+    resource_jars = ["//plugins/checks/gr-checks:gr-checks-static"],
     resources = glob(["src/main/resources/**/*"]),
 )
diff --git a/gr-checks/BUILD b/gr-checks/BUILD
index 39ab4b3..ca089ef 100644
--- a/gr-checks/BUILD
+++ b/gr-checks/BUILD
@@ -6,6 +6,7 @@
 package(default_visibility = [":visibility"])
 
 load("//tools/bzl:js.bzl", "polygerrit_plugin")
+load("//tools/bzl:genrule2.bzl", "genrule2")
 
 polygerrit_plugin(
     name = "gr-checks",
@@ -17,3 +18,15 @@
     externs = ["externs.js"],
     plugin_name = "checks-pg",
 )
+
+genrule2(
+    name = "gr-checks-static",
+    srcs = [":gr-checks"],
+    outs = ["gr-checks-static.jar"],
+    cmd = " && ".join([
+        "mkdir $$TMP/static",
+        "cp -r $(locations :gr-checks) $$TMP/static",
+        "cd $$TMP",
+        "zip -Drq $$ROOT/$@ -g .",
+    ]),
+)
diff --git a/java/com/google/gerrit/plugins/checks/api/HttpModule.java b/java/com/google/gerrit/plugins/checks/api/HttpModule.java
index 3c34503..12c0a51 100644
--- a/java/com/google/gerrit/plugins/checks/api/HttpModule.java
+++ b/java/com/google/gerrit/plugins/checks/api/HttpModule.java
@@ -14,6 +14,9 @@
 
 package com.google.gerrit.plugins.checks.api;
 
+import com.google.gerrit.extensions.registration.DynamicSet;
+import com.google.gerrit.extensions.webui.JavaScriptPlugin;
+import com.google.gerrit.extensions.webui.WebUiPlugin;
 import com.google.inject.servlet.ServletModule;
 
 public class HttpModule extends ServletModule {
@@ -22,5 +25,7 @@
   protected void configureServlets() {
     serveRegex("^/checkers/(.*)$").with(CheckersRestApiServlet.class);
     serveRegex("^/checks.pending/(.*)$").with(PendingChecksRestApiServlet.class);
+
+    DynamicSet.bind(binder(), WebUiPlugin.class).toInstance(new JavaScriptPlugin("checks-pg.html"));
   }
 }