Merge "Create gradle task for kotlin compiler"
diff --git a/build.gradle b/build.gradle
index 4060a7a..934c650 100644
--- a/build.gradle
+++ b/build.gradle
@@ -136,7 +136,7 @@
     supportLibs 'com.android.support:support-v4:25.4.0'
     supportLibs 'junit:junit:4.12'
     supportLibs 'com.android.support.test.espresso:espresso-core:3.0.0'
-    debugTestResourcesKotlinCompileOnly 'org.jetbrains.kotlin:kotlin-stdlib:1.1.3'
+    debugTestResourcesKotlinCompileOnly 'org.jetbrains.kotlin:kotlin-stdlib:1.1.4-3'
 }
 
 protobuf {
@@ -588,17 +588,9 @@
     }
     def kotlinResourcesDir = file("src/test/debugTestResourcesKotlin")
     def kotlinHostJar = "debug_test_resources_kotlin.jar"
-    task "jar_debugTestResourcesKotlin"(type: Exec) {
-        if (OperatingSystem.current().isWindows()) {
-            executable file("third_party/kotlin/kotlinc/bin/kotlinc.bat")
-        } else {
-            executable file("third_party/kotlin/kotlinc/bin/kotlinc");
-        }
-        args "-include-runtime"
-        args "-nowarn"
-        args "-d"
-        args "build/test/${kotlinHostJar}"
-        args fileTree(dir: kotlinResourcesDir, include: '**/*.kt')
+    task "jar_debugTestResourcesKotlin"(type: kotlin.Kotlinc) {
+        source = fileTree(dir: kotlinResourcesDir, include: '**/*.kt')
+        destination = file("build/test/${kotlinHostJar}")
     }
     dependsOn downloadDeps
     dependsOn jar_debugTestResources
diff --git a/buildSrc/src/main/java/kotlin/Kotlinc.java b/buildSrc/src/main/java/kotlin/Kotlinc.java
new file mode 100644
index 0000000..261acc3
--- /dev/null
+++ b/buildSrc/src/main/java/kotlin/Kotlinc.java
@@ -0,0 +1,68 @@
+// Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+package kotlin;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import org.gradle.api.Action;
+import org.gradle.api.DefaultTask;
+import org.gradle.api.UncheckedIOException;
+import org.gradle.api.file.FileTree;
+import org.gradle.api.tasks.InputFiles;
+import org.gradle.api.tasks.OutputFile;
+import org.gradle.api.tasks.TaskAction;
+import org.gradle.process.ExecSpec;
+import utils.Utils;
+
+/**
+ * Gradle task to compile Kotlin source files.
+ */
+public class Kotlinc extends DefaultTask {
+
+  @InputFiles
+  private FileTree source;
+
+  @OutputFile
+  private File destination;
+
+  public FileTree getSource() {
+    return source;
+  }
+
+  public void setSource(FileTree source) {
+    this.source = source;
+  }
+
+  public File getDestination() {
+    return destination;
+  }
+
+  public void setDestination(File destination) {
+    this.destination = destination;
+  }
+
+  @TaskAction
+  public void compile() {
+    getProject().exec(new Action<ExecSpec>() {
+      @Override
+      public void execute(ExecSpec execSpec) {
+        try {
+          String kotlincExecName = Utils.toolsDir().equals("windows") ? "kotlinc.bat" : "kotlinc";
+          Path kotlincExecPath = Paths
+              .get("third_party", "kotlin", "kotlinc", "bin", kotlincExecName);
+          execSpec.setExecutable(kotlincExecPath.toFile());
+          execSpec.args("-include-runtime");
+          execSpec.args("-nowarn");
+          execSpec.args("-d", destination.getCanonicalPath());
+          execSpec.args(source.getFiles());
+        } catch (IOException e) {
+          throw new UncheckedIOException(e);
+        }
+      }
+    });
+  }
+}