Invoke bower install in the account plugin

The account plugin relies on bower to install the required
JS libraries and package them with the plugin jar.

Change-Id: Id4973a9685ae92205657bec160eba9507c2112c4
diff --git a/jenkins/gerrit-bazel-build-account-plugin.sh b/jenkins/gerrit-bazel-build-account-plugin.sh
new file mode 100644
index 0000000..c7b7e71
--- /dev/null
+++ b/jenkins/gerrit-bazel-build-account-plugin.sh
@@ -0,0 +1,41 @@
+#!/bin/bash -e
+
+git checkout -f gerrit/stable-2.16
+rm -rf plugins/account
+git read-tree -u --prefix=plugins/account origin/stable-2.16
+
+if [ -f plugins/account/external_plugin_deps.bzl ]
+then
+  cp -f plugins/account/external_plugin_deps.bzl plugins/
+fi
+
+TARGETS=$(echo "plugins/account:account" | sed -e 's/account/account/g')
+TEST_TARGET=$(grep -2 junit_tests plugins/account/BUILD | grep -o 'name = "[^"]*"' | cut -d '"' -f 2)
+
+. set-java.sh 8
+
+pushd plugins/account
+npm install bower
+./node_modules/bower/bin/bower install
+cp -Rf bower_components/jquery/dist/*js src/main/resources/static/js/.
+cp -Rf bower_components/bootstrap/dist/js/*js src/main/resources/static/js/.
+cp -Rf bower_components/bootstrap/dist/css/*css src/main/resources/static/css/.
+cp -Rf bower_components/angular/*js src/main/resources/static/js/.
+popd
+
+bazel build --spawn_strategy=standalone --genrule_strategy=standalone $TARGETS
+
+if [ "$TEST_TARGET" != "" ]
+then
+    bazel test --test_env DOCKER_HOST=$DOCKER_HOST plugins/account:$TEST_TARGET
+fi
+
+for JAR in $(find bazel-genfiles/plugins/account -name account*.jar)
+do
+    PLUGIN_VERSION=$(git describe  --always origin/stable-2.16)
+    echo -e "Implementation-Version: $PLUGIN_VERSION" > MANIFEST.MF
+    jar ufm $JAR MANIFEST.MF && rm MANIFEST.MF
+    DEST_JAR=bazel-genfiles/plugins/account/$(basename $JAR)
+    [ "$JAR" -ef "$DEST_JAR" ] || mv $JAR $DEST_JAR
+    echo "$PLUGIN_VERSION" > bazel-genfiles/plugins/account/$(basename $JAR-version)
+done
diff --git a/jenkins/gerrit-bazel-plugin-account.yaml b/jenkins/gerrit-bazel-plugin-account.yaml
index 2b9402f..cadb03c 100644
--- a/jenkins/gerrit-bazel-plugin-account.yaml
+++ b/jenkins/gerrit-bazel-plugin-account.yaml
@@ -1,7 +1,24 @@
+- job-template:
+    name: 'plugin-account-bazel-{branch}'
+    description: "Plugin account {branch} branch build with Bazel\n"
+    defaults: plugin-template
+    node: bazel-debian
+    class: plugins
+    project-name: plugins%2Faccount
+    builders:
+      - shell:
+         !include-raw: gerrit-bazel-build-account-plugin.sh
+      - shell:
+         !include-raw: gerrit-bazel-get-project-info.sh
+    publishers:
+      - archive:
+         artifacts: >
+           bazel-genfiles/plugins/account/account.jar*,bazel-genfiles/plugins/account/account.json
+
 - project:
     name: account
     jobs:
-      - 'plugin-{name}-bazel-{branch}':
+      - 'plugin-account-bazel-{branch}':
           branch:
             - master
             - stable-2.16