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/tools/jdk/BUILD b/tools/jdk/BUILD
index 5e5fc19..220815f 100644
--- a/tools/jdk/BUILD
+++ b/tools/jdk/BUILD
@@ -1,5 +1,25 @@
 package(default_visibility = ["//visibility:public"])
 
+config_setting(
+    name = "jdk7",
+    values = {"define": "JAVA_VERSION=1.7"},
+)
+
+genrule(
+    name = "BUILD-jdk7",
+    srcs = [":BUILD"],
+    outs = ["BUILD.jdk7"],
+    cmd = "sed 's/_version = \"8\"/_version = \"7\"/' $< > $@",
+)
+
+filegroup(
+    name = "BUILD-jdk",
+    srcs = select({
+        ":jdk7": [":BUILD-jdk7"],
+        "//conditions:default": [":BUILD"],
+    }),
+)
+
 filegroup(
     name = "jni_header",
     srcs = ["//external:jni_header"],
@@ -112,7 +132,7 @@
 filegroup(
     name = "srcs",
     srcs = [
-        "BUILD",  # Tools are build from the workspace for tests.
+        "BUILD-jdk",  # Tools are build from the workspace for tests.
         "proguard_whitelister.py",
         "proguard_whitelister_test.py",
         "proguard_whitelister_test_input.cfg",