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:
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -9,4 +9,7 @@
|
||||
<taskdef
|
||||
name = "kotlinJSc"
|
||||
classname = "org.jetbrains.jet.buildtools.ant.JavaScriptCompilerTask"/>
|
||||
<typedef
|
||||
name = "withKotlin"
|
||||
classname = "org.jetbrains.jet.buildtools.ant.KotlinCompilerAdapter"/>
|
||||
</antlib>
|
||||
|
||||
@@ -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