CompilerAdapter for <javac> task + test for compiler attribute
No test for the typedef <withKotlin/> because Ant 1.7 doesn't seem to support typedef inside <javac>
This commit is contained in:
@@ -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<String> strings = new ArrayList<String>();
|
||||
strings.addAll(Arrays.asList(basicArgs));
|
||||
strings.addAll(Arrays.asList(extraJavaArgs));
|
||||
return runJava(logName, strings.toArray(new String[strings.size()]));
|
||||
}
|
||||
|
||||
private static String getAntHome() {
|
||||
|
||||
@@ -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
|
||||
@@ -0,0 +1,13 @@
|
||||
<project name="Ant Task Test" default="build">
|
||||
|
||||
<target name="build">
|
||||
<delete dir="${temp}/classes" failonerror="false"/>
|
||||
<mkdir dir="${temp}/classes"/>
|
||||
<javac destdir="${temp}/classes" compiler="org.jetbrains.jet.buildtools.ant.KotlinCompilerAdapter">
|
||||
<src path="${test.data}/root1"/>
|
||||
</javac>
|
||||
<jar destfile="${temp}/hello.jar">
|
||||
<fileset dir="${temp}/classes"/>
|
||||
</jar>
|
||||
</target>
|
||||
</project>
|
||||
@@ -0,0 +1,3 @@
|
||||
OUT Hello, a!
|
||||
OUT Java
|
||||
Return code: 0
|
||||
@@ -0,0 +1,7 @@
|
||||
package hello
|
||||
|
||||
fun main(args : Array<String>) {
|
||||
for (s in arrayList("a"))
|
||||
println("Hello, $s!")
|
||||
j.Java().f();
|
||||
}
|
||||
@@ -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[] {});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user