Refactor JDK 7 build to use the vendored version of it

Along the path, fix the build for JDK 7 and get rid of
most ugliness in the JDK 7 build. Now simply setting
JAVA_VERSION to 1.7 will build a JDK 7 compatible version.

Fixes #1159.

--
Change-Id: I9599283844a57d9e053f12d37445907f22a9232e
Reviewed-on: https://bazel-review.googlesource.com/#/c/3452
MOS_MIGRATED_REVID=120332747
diff --git a/scripts/bootstrap/bootstrap.sh b/scripts/bootstrap/bootstrap.sh
index 1394b62..8732d98 100755
--- a/scripts/bootstrap/bootstrap.sh
+++ b/scripts/bootstrap/bootstrap.sh
@@ -30,10 +30,17 @@
 
 : ${JAVA_VERSION:="1.8"}
 
-: ${BAZEL_ARGS:=--java_toolchain=//src/java_tools/buildjar:bootstrap_toolchain \
-      --strategy=Javac=worker --worker_quit_after_build \
-      --genrule_strategy=standalone --spawn_strategy=standalone \
-      "${EXTRA_BAZEL_ARGS:-}"}
+if [ "${JAVA_VERSION}" = "1.7" ]; then
+  : ${BAZEL_ARGS:=--java_toolchain=//src/java_tools/buildjar:bootstrap_toolchain_jdk7 \
+        --define JAVA_VERSION=1.7 \
+        --genrule_strategy=standalone --spawn_strategy=standalone \
+        "${EXTRA_BAZEL_ARGS:-}"}
+else
+  : ${BAZEL_ARGS:=--java_toolchain=//src/java_tools/buildjar:bootstrap_toolchain \
+        --strategy=Javac=worker --worker_quit_after_build \
+        --genrule_strategy=standalone --spawn_strategy=standalone \
+        "${EXTRA_BAZEL_ARGS:-}"}
+fi
 
 if [ -z "${BAZEL-}" ]; then
   function bazel_build() {
@@ -82,6 +89,7 @@
       ${EXTRA_BAZEL_ARGS-} \
       --strategy=Javac=worker --worker_quit_after_build \
       --fetch --nostamp \
+      --define "JAVA_VERSION=${JAVA_VERSION}" \
       --javacopt="-source ${JAVA_VERSION} -target ${JAVA_VERSION}" \
       ${BAZEL_TARGET} || return $?
   if [ -n "${BAZEL_SUM}" ]; then