rebase "fix usage java tools" pr (#134)

Fixes to make docker remote execution work. Some docker tests disabled.
diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml
index 6f16d3a..45b7c06 100644
--- a/.bazelci/presubmit.yml
+++ b/.bazelci/presubmit.yml
@@ -6,6 +6,18 @@
   ubuntu1604:
     test_targets:
     - "//:all_tests"
+  rbe_ubuntu1604:
+    test_targets:
+    - "--"
+    - "//src/test/kotlin/io/bazel/kotlin/builder:builder_tests"
+    # KotlinJvmDaggerExampleTest and KotlinJvmKaptAssertionTest are not remote
+    # execution compatible, do not run them for now.
+    - "//src/test/kotlin/io/bazel/kotlin:KotlinJvmFriendsVisibilityTest"
+    - "//src/test/kotlin/io/bazel/kotlin:KotlinJvmBasicAssertionTest"
+    test_flags:
+    # Override the default worker strategy for remote builds (worker strategy
+    # cannot be used with remote builds)
+    - "--strategy=KotlinCompile=remote"
   macos:
     test_targets:
     - "//:all_tests"
diff --git a/WORKSPACE b/WORKSPACE
index c79c711..e709ffb 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -27,6 +27,16 @@
     url = "https://github.com/hsyed/bazel-deps/releases/download/v0.1.0/parseproject_deploy.jar",
 )
 
+http_archive(
+    name = "bazel_toolchains",
+    sha256 = "cefb6ccf86ca592baaa029bcef04148593c0efe8f734542f10293ea58f170715",
+    strip_prefix = "bazel-toolchains-cdea5b8675914d0a354d89f108de5d28e54e0edc",
+    urls = [
+        "https://mirror.bazel.build/github.com/bazelbuild/bazel-toolchains/archive/cdea5b8675914d0a354d89f108de5d28e54e0edc.tar.gz",
+        "https://github.com/bazelbuild/bazel-toolchains/archive/cdea5b8675914d0a354d89f108de5d28e54e0edc.tar.gz",
+    ],
+)
+
 load("//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains")
 
 kotlin_repositories()
diff --git a/examples/dagger/BUILD b/examples/dagger/BUILD
index 58048fd..0714c2c 100644
--- a/examples/dagger/BUILD
+++ b/examples/dagger/BUILD
@@ -43,15 +43,14 @@
     cmd = """
 cat << EOF > TeaPot.kt
 package tea
-
 object TeaPot {
     fun isEmpty() = true
 }
 EOF
-external/local_jdk/bin/jar -cf $@ TeaPot.kt
+$(JAVABASE)/bin/jar -cf $@ TeaPot.kt
 rm TeaPot.kt
 """,
-    tools = ["@local_jdk//:jdk"],
+    toolchains = ["@bazel_tools//tools/jdk:current_host_java_runtime"],
 )
 
 kt_jvm_library(
diff --git a/kotlin/internal/jvm/impl.bzl b/kotlin/internal/jvm/impl.bzl
index 094c57f..22c7194 100644
--- a/kotlin/internal/jvm/impl.bzl
+++ b/kotlin/internal/jvm/impl.bzl
@@ -47,6 +47,7 @@
     classpath = ":".join(["${RUNPATH}%s" % (j.short_path) for j in rjars.to_list()])
     jvm_flags = " ".join([ctx.expand_location(f, ctx.attr.data) for f in jvm_flags])
     template = ctx.attr._java_stub_template.files.to_list()[0]
+    javabin = "JAVABIN=" + str(ctx.attr._java_runtime[java_common.JavaRuntimeInfo].java_executable_exec_path)
 
     ctx.actions.expand_template(
         template = template,
@@ -54,7 +55,7 @@
         substitutions = {
             "%classpath%": classpath,
             "%java_start_class%": main_class,
-            "%javabin%": "JAVABIN=${RUNPATH}" + ctx.executable._java.short_path,
+            "%javabin%": javabin,
             "%jvm_flags%": jvm_flags,
             "%set_jacoco_metadata%": "",
             "%workspace_prefix%": ctx.workspace_name + "/",
@@ -141,7 +142,7 @@
         depset(
             order = "default",
             transitive = [providers.java.transitive_runtime_jars],
-            direct = [ctx.executable._java],
+            direct = ctx.files._java_runtime,
         ),
     )
 
@@ -160,6 +161,6 @@
         depset(
             order = "default",
             transitive = [runtime_jars],
-            direct = [ctx.executable._java],
+            direct = ctx.files._java_runtime,
         ),
     )
diff --git a/kotlin/internal/jvm/jvm.bzl b/kotlin/internal/jvm/jvm.bzl
index 7b8c19d..2224653 100644
--- a/kotlin/internal/jvm/jvm.bzl
+++ b/kotlin/internal/jvm/jvm.bzl
@@ -124,11 +124,8 @@
         default = Label("@bazel_tools//tools/zip:zipper"),
         allow_files = True,
     ),
-    "_java": attr.label(
-        executable = True,
-        cfg = "host",
-        default = Label("@bazel_tools//tools/jdk:java"),
-        allow_files = True,
+    "_java_runtime": attr.label(
+        default = Label("@bazel_tools//tools/jdk:current_java_runtime"),
     ),
     "_java_stub_template": attr.label(
         cfg = "host",
diff --git a/src/test/kotlin/io/bazel/kotlin/builder/BUILD b/src/test/kotlin/io/bazel/kotlin/builder/BUILD
index 9a554b2..9c94869 100644
--- a/src/test/kotlin/io/bazel/kotlin/builder/BUILD
+++ b/src/test/kotlin/io/bazel/kotlin/builder/BUILD
@@ -69,12 +69,12 @@
     srcs = ["tasks/jvm/KotlinBuilderJvmKaptTest.java"],
     data = [
         "//third_party/jvm/com/google/auto/value:auto_value",
-    ]
+    ],
 )
 
 kt_rules_test(
     name = "KotlinBuilderJsTest",
-    srcs = ["tasks/js/KotlinBuilderJsTest.java"]
+    srcs = ["tasks/js/KotlinBuilderJsTest.java"],
 )
 
 test_suite(
@@ -82,8 +82,8 @@
     tests = [
         ":JdepsParserTest",
         ":KotlinBuilderJsTest",
-        ":KotlinBuilderJvmKaptTest",
         ":KotlinBuilderJvmBasicTest",
+        ":KotlinBuilderJvmKaptTest",
         ":SourceJarCreatorTest",
     ],
     visibility = ["//visibility:public"],