diff --git a/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/KotlinCompilerAdapter.java b/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/KotlinCompilerAdapter.java
new file mode 100644
index 00000000000..932a9a2dc8b
--- /dev/null
+++ b/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/KotlinCompilerAdapter.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2010-2013 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jetbrains.jet.buildtools.ant;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.taskdefs.Javac;
+import org.apache.tools.ant.taskdefs.compilers.DefaultCompilerAdapter;
+import org.apache.tools.ant.taskdefs.compilers.Javac13;
+
+public class KotlinCompilerAdapter extends DefaultCompilerAdapter {
+ @Override
+ public boolean execute() throws BuildException {
+ Javac javac = getJavac();
+
+ BytecodeCompilerTask kotlinTask = new BytecodeCompilerTask();
+ kotlinTask.setOutput(javac.getDestdir());
+ kotlinTask.setClasspath(javac.getClasspath());
+ kotlinTask.setSrc(javac.getSrcdir());
+
+ kotlinTask.execute();
+
+ javac.log("Running javac...");
+
+ Javac13 javac13 = new Javac13();
+ javac13.setJavac(javac);
+ return javac13.execute();
+ }
+}
diff --git a/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/antlib.xml b/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/antlib.xml
index 59309c0326f..2443203af4e 100644
--- a/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/antlib.xml
+++ b/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/antlib.xml
@@ -9,4 +9,7 @@
+
diff --git a/compiler/integration-tests/src/org/jetbrains/kotlin/AntTaskTest.java b/compiler/integration-tests/src/org/jetbrains/kotlin/AntTaskTest.java
index 11dd8049ea4..57db3821af6 100644
--- a/compiler/integration-tests/src/org/jetbrains/kotlin/AntTaskTest.java
+++ b/compiler/integration-tests/src/org/jetbrains/kotlin/AntTaskTest.java
@@ -19,15 +19,18 @@ package org.jetbrains.kotlin;
import org.junit.Test;
import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
import static junit.framework.Assert.assertEquals;
public class AntTaskTest extends KotlinIntegrationTestBase {
- private void doAntTest() throws Exception {
+ private void doAntTest(String... extraJavaArgs) throws Exception {
String jar = tmpdir.getTmpDir().getAbsolutePath() + File.separator + "hello.jar";
String runtime = new File("dist/kotlinc/lib/kotlin-runtime.jar").getAbsolutePath();
- assertEquals("compilation failed", 0, runAnt("build.log", "build.xml"));
+ assertEquals("compilation failed", 0, runAnt("build.log", "build.xml", extraJavaArgs));
runJava("hello.run", "-cp", jar + File.pathSeparator + runtime, "Hello.HelloPackage");
}
@@ -41,18 +44,29 @@ public class AntTaskTest extends KotlinIntegrationTestBase {
doAntTest();
}
+ @Test
+ public void javacCompiler() throws Exception {
+ doAntTest("-cp", getCompilerLib() + "/kotlin-ant.jar");
+ }
+
@Override
protected String normalizeOutput(String content) {
return super.normalizeOutput(content)
.replaceAll("Total time: .+\n", "Total time: [time]\n");
}
- private int runAnt(String logName, String scriptName) throws Exception {
- return runJava(logName, "-jar", getAntHome() + File.separator + "lib" + File.separator + "ant-launcher.jar",
- "-Dkotlin.lib=" + getCompilerLib(),
- "-Dtest.data=" + testDataDir,
- "-Dtemp=" + tmpdir.getTmpDir(),
- "-f", scriptName);
+ private int runAnt(String logName, String scriptName, String... extraJavaArgs) throws Exception {
+ String[] basicArgs = {
+ "-jar", getAntHome() + File.separator + "lib" + File.separator + "ant-launcher.jar",
+ "-Dkotlin.lib=" + getCompilerLib(),
+ "-Dtest.data=" + testDataDir,
+ "-Dtemp=" + tmpdir.getTmpDir(),
+ "-f", scriptName
+ };
+ List strings = new ArrayList();
+ strings.addAll(Arrays.asList(basicArgs));
+ strings.addAll(Arrays.asList(extraJavaArgs));
+ return runJava(logName, strings.toArray(new String[strings.size()]));
}
private static String getAntHome() {
diff --git a/compiler/integration-tests/testData/javacCompiler/build.log.expected b/compiler/integration-tests/testData/javacCompiler/build.log.expected
new file mode 100644
index 00000000000..1b19712aa36
--- /dev/null
+++ b/compiler/integration-tests/testData/javacCompiler/build.log.expected
@@ -0,0 +1,12 @@
+OUT Buildfile: build.xml
+OUT
+OUT build:
+OUT [mkdir] Created dir: [Temp]/classes
+OUT [javac] Compiling 1 source file to [Temp]/classes
+OUT [javac] Compiling [[[TestData]/root1]] => [[Temp]/classes]
+OUT [javac] Running javac...
+OUT [jar] Building jar: [Temp]/hello.jar
+OUT
+OUT BUILD SUCCESSFUL
+OUT Total time: [time]
+Return code: 0
diff --git a/compiler/integration-tests/testData/javacCompiler/build.xml b/compiler/integration-tests/testData/javacCompiler/build.xml
new file mode 100644
index 00000000000..c7bceadc551
--- /dev/null
+++ b/compiler/integration-tests/testData/javacCompiler/build.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/compiler/integration-tests/testData/javacCompiler/hello.run.expected b/compiler/integration-tests/testData/javacCompiler/hello.run.expected
new file mode 100644
index 00000000000..a3346aed731
--- /dev/null
+++ b/compiler/integration-tests/testData/javacCompiler/hello.run.expected
@@ -0,0 +1,3 @@
+OUT Hello, a!
+OUT Java
+Return code: 0
diff --git a/compiler/integration-tests/testData/javacCompiler/root1/hello.kt b/compiler/integration-tests/testData/javacCompiler/root1/hello.kt
new file mode 100644
index 00000000000..e2007e5880e
--- /dev/null
+++ b/compiler/integration-tests/testData/javacCompiler/root1/hello.kt
@@ -0,0 +1,7 @@
+package hello
+
+fun main(args : Array) {
+ for (s in arrayList("a"))
+ println("Hello, $s!")
+ j.Java().f();
+}
diff --git a/compiler/integration-tests/testData/javacCompiler/root1/j/Java.java b/compiler/integration-tests/testData/javacCompiler/root1/j/Java.java
new file mode 100644
index 00000000000..1c2d8c763e7
--- /dev/null
+++ b/compiler/integration-tests/testData/javacCompiler/root1/j/Java.java
@@ -0,0 +1,14 @@
+package j;
+
+import java.lang.String;
+import java.lang.System;
+
+public class Java {
+ public void f() {
+ System.out.println("Java");
+ }
+
+ public static void main(String[] args) {
+ hello.HelloPackage.main(new String[] {});
+ }
+}
\ No newline at end of file