Jarjar the third-party dependencies of the Jacoco test runner, except on Windows. This way, we don't need a new release to make coverage collection happen.

This is the fifth try on commit 823091f7516abf7d854021edc765daf1467f1647 . This time, it's disabled on Windows because two bugs (#2306 and #2342) collude to make it impossible to run Java binaries during the build on Windows and jarjar is a Java binary.

Tested by building //src:bazel on a Windows machine with --output_base=<something with a $ sign in it>. I also verified that the genrule gets run by adding an "exit 1" at its beginning.

Fifth time is the charm! Hopefully we don't get to seven.

--
PiperOrigin-RevId: 144818587
MOS_MIGRATED_REVID=144818587
diff --git a/src/java_tools/junitrunner/java/com/google/testing/coverage/BUILD b/src/java_tools/junitrunner/java/com/google/testing/coverage/BUILD
index 319f13b..3a57a5b 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/coverage/BUILD
+++ b/src/java_tools/junitrunner/java/com/google/testing/coverage/BUILD
@@ -22,7 +22,7 @@
 filegroup(
     name = "embedded_tools",
     srcs = [
-        "JacocoCoverage_deploy.jar",
+        "JacocoCoverage_jarjar_deploy.jar",
     ],
 )
 
@@ -68,3 +68,34 @@
         "//third_party:apache_commons_lang",
     ],
 )
+
+genrule(
+    name = "Jacoco_jarjar",
+    srcs = [
+        ":JacocoCoverage_deploy.jar",
+        ":JacocoCoverage.jarjar",
+    ],
+    outs = ["JacocoCoverage_jarjar_deploy.jar"],
+    cmd = "\n".join([
+        # Bazel 0.4.3 contains two bugs: a quoting bug in the Java cmd.exe
+        # wrapper script that makes it unable to handle $ signs in paths (#2306)
+        # and one that makes it occasionally put $ signs in the output base
+        # (#2342).
+        #
+        # These two collude to make it impossible to run built Java binaries on
+        # Windows if the output base happens to contain a $ sign.
+        #
+        # Thus, don't call jarjar when on Windows. This makes Java coverage not
+        # work if the code under test uses libraries the test runner also does
+        # (e.g. ASM).
+        #
+        # TODO(lberki): Remove this once a Bazel version with a fix to either of
+        # these bugs is out.
+        "if [[ $$(uname -a) =~ MSYS ]]; then",
+        "  cp \"$(location :JacocoCoverage_deploy.jar)\" \"$@\";",
+        "else",
+        "  \"$(location //third_party/java/jarjar:jarjar_bin)\" process \"$(location :JacocoCoverage.jarjar)\" \"$(location :JacocoCoverage_deploy.jar)\" \"$@\"",
+        "fi",
+    ]),
+    tools = ["//third_party/java/jarjar:jarjar_bin"],
+)