diff --git a/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/KotlinBytecodeCompilerTask.java b/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/KotlinBytecodeCompilerTask.java index 7c966878585..6b7a3027942 100644 --- a/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/KotlinBytecodeCompilerTask.java +++ b/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/KotlinBytecodeCompilerTask.java @@ -36,8 +36,8 @@ public class KotlinBytecodeCompilerTask extends Task { String src = getPath( this.srcdir != null ? this.srcdir : this.file ); String dest = getPath( this.destdir ); - log( String.format( "Kotlin bytecode compiler: [%s] => [%s]", src, dest )); - KotlinBytecodeCompiler.src( src, dest ); + log( String.format( "[%s] => [%s]", src, dest )); + KotlinBytecodeCompiler.compileSources( src, dest ); } else { throw new RuntimeException( String.format( "Operation is not supported" )); diff --git a/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/tasks.xml b/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/antlib.xml similarity index 100% rename from build-tools/ant/src/org/jetbrains/jet/buildtools/ant/tasks.xml rename to build-tools/ant/src/org/jetbrains/jet/buildtools/ant/antlib.xml diff --git a/build-tools/build.xml b/build-tools/build.xml index 73de8c83b1a..6b72edbf829 100644 --- a/build-tools/build.xml +++ b/build-tools/build.xml @@ -1,5 +1,13 @@ + + + + + + + + @@ -32,22 +40,55 @@ + + + + + + + + + + + + + + ${java-out} + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - + + + + + diff --git a/build-tools/core/src/org/jetbrains/jet/buildtools/core/KotlinBytecodeCompiler.java b/build-tools/core/src/org/jetbrains/jet/buildtools/core/KotlinBytecodeCompiler.java index 33aeabd5c9d..a5daafbed12 100644 --- a/build-tools/core/src/org/jetbrains/jet/buildtools/core/KotlinBytecodeCompiler.java +++ b/build-tools/core/src/org/jetbrains/jet/buildtools/core/KotlinBytecodeCompiler.java @@ -1,6 +1,6 @@ package org.jetbrains.jet.buildtools.core; -import org.jetbrains.jet.cli.KotlinCompiler; +import org.jetbrains.jet.compiler.CompileEnvironment; /** @@ -8,13 +8,29 @@ import org.jetbrains.jet.cli.KotlinCompiler; */ public class KotlinBytecodeCompiler { - /** - * Invokes Kotlin compiler with "-src" and "-output" options. - * @param source "-src" option to specify - * @param destination "-output" option to specify - */ - public static void src ( String source, String destination ) { - KotlinCompiler.main( "-src", source, "-output", destination ); + + private static CompileEnvironment environment() { + CompileEnvironment environment = new CompileEnvironment(); + environment.setJavaRuntime(CompileEnvironment.findRtJar( true )); + + if ( ! environment.initializeKotlinRuntime()) { + throw new RuntimeException( "No Kotlin runtime library found" ); + } + + return environment; } + + /** + * {@code CompileEnvironment#compileBunchOfSources} wrapper. + * + * @param source compilation source + * @param destination compilation destination + */ + public static void compileSources ( String source, String destination ) { + boolean success = environment().compileBunchOfSources( source, null, destination, true, false ); + if ( ! success ) { + throw new RuntimeException( String.format( "[%s] compilation failed, see \"ERROR:\" messages above for more details.", source )); + } + } } diff --git a/build-tools/lib/ant-contrib-1.0b3.jar b/build-tools/lib/ant-contrib-1.0b3.jar new file mode 100644 index 00000000000..062537661a5 Binary files /dev/null and b/build-tools/lib/ant-contrib-1.0b3.jar differ diff --git a/build-tools/test/Hello.kt b/build-tools/test/hello/1/Hello.kt similarity index 100% rename from build-tools/test/Hello.kt rename to build-tools/test/hello/1/Hello.kt diff --git a/build-tools/test/hello/2/Hello.kt b/build-tools/test/hello/2/Hello.kt new file mode 100644 index 00000000000..83ed78ab4c4 --- /dev/null +++ b/build-tools/test/hello/2/Hello.kt @@ -0,0 +1,7 @@ +fun main(args : Array) { + if (args.size == 0) { + System.out?.println("Please provide a name as a command-line argument") + return + } + System.out?.println("Hello, ${args[0]}!") +} diff --git a/build-tools/test/hello/3/Hello.kt b/build-tools/test/hello/3/Hello.kt new file mode 100644 index 00000000000..efc6503f75b --- /dev/null +++ b/build-tools/test/hello/3/Hello.kt @@ -0,0 +1,4 @@ +fun main(args : Array) { + for (name in args) + System.out?.println("Hello, $name!") +} diff --git a/build-tools/test/hello/4/Hello.kt b/build-tools/test/hello/4/Hello.kt new file mode 100644 index 00000000000..0038a5e12c0 --- /dev/null +++ b/build-tools/test/hello/4/Hello.kt @@ -0,0 +1,9 @@ +fun main(args : Array) { + val language = if (args.size == 0) "EN" else args[0] + System.out?.println(when (language) { + "EN" -> "Hello!" + "FR" -> "Salut!" + "IT" -> "Ciao!" + else -> "Sorry, I can't greet you in $language yet" + }) +} diff --git a/build-tools/test/hello/5/Hello.kt b/build-tools/test/hello/5/Hello.kt new file mode 100644 index 00000000000..96a210ce6cf --- /dev/null +++ b/build-tools/test/hello/5/Hello.kt @@ -0,0 +1,9 @@ +class Greeter(val name : String) { + fun greet() { + System.out?.println("Hello, ${name}!"); + } +} + +fun main(args : Array) { + Greeter(args[0]).greet() +}