From 823852cc6c875f658092a29fcd47c9c075c9b779 Mon Sep 17 00:00:00 2001 From: Evgeny Goldin Date: Sun, 15 Jan 2012 19:00:40 +0200 Subject: [PATCH] First Ant task + "buildToolsTest" Ant target added --- .../ant/KotlinBytecodeCompilerTask.java | 46 ++++++++++++++++ .../ant/KotlinJavaScriptCompilerTask.java | 16 ++++++ .../jetbrains/jet/buildtools/ant/tasks.xml | 12 +++++ build-tools/build.xml | 53 +++++++++++++++++++ .../core/KotlinBytecodeCompiler.java | 37 ++----------- .../jetbrains/jet/buildtools/core/Util.java | 30 +++++++++++ build-tools/test/Hello.kt | 3 ++ build.xml | 25 ++------- 8 files changed, 169 insertions(+), 53 deletions(-) create mode 100644 build-tools/ant/src/org/jetbrains/jet/buildtools/ant/KotlinBytecodeCompilerTask.java create mode 100644 build-tools/ant/src/org/jetbrains/jet/buildtools/ant/KotlinJavaScriptCompilerTask.java create mode 100644 build-tools/ant/src/org/jetbrains/jet/buildtools/ant/tasks.xml create mode 100644 build-tools/build.xml create mode 100644 build-tools/core/src/org/jetbrains/jet/buildtools/core/Util.java create mode 100644 build-tools/test/Hello.kt 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 new file mode 100644 index 00000000000..7c966878585 --- /dev/null +++ b/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/KotlinBytecodeCompilerTask.java @@ -0,0 +1,46 @@ +package org.jetbrains.jet.buildtools.ant; + +import static org.jetbrains.jet.buildtools.core.Util.*; +import org.apache.tools.ant.Task; +import org.jetbrains.jet.buildtools.core.KotlinBytecodeCompiler; + +import java.io.File; + + +/** + * Kotlin bytecode compiler Ant task. + * + * See + * http://evgeny-goldin.org/javadoc/ant/tutorial-writing-tasks.html + * http://evgeny-goldin.org/javadoc/ant/Tasks/javac.html - attribute names should be similar to {@code }. + */ +public class KotlinBytecodeCompilerTask extends Task { + + private File srcdir; + private File file; + private File destdir; + + public void setSrcdir ( File srcdir ) { this.srcdir = srcdir; } + public void setFile ( File file ) { this.file = file; } + public void setDestdir ( File destdir ) { this.destdir = destdir; } + + + @Override + public void execute() { + + if ( this.destdir == null ) { + throw new RuntimeException( "\"destdir\" attribute is not specified" ); + } + + if (( this.srcdir != null ) || ( this.file != null )) { + 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 ); + } + else { + throw new RuntimeException( String.format( "Operation is not supported" )); + } + } +} diff --git a/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/KotlinJavaScriptCompilerTask.java b/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/KotlinJavaScriptCompilerTask.java new file mode 100644 index 00000000000..0d7eaa4cce7 --- /dev/null +++ b/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/KotlinJavaScriptCompilerTask.java @@ -0,0 +1,16 @@ +package org.jetbrains.jet.buildtools.ant; + +import org.apache.tools.ant.Task; + + +/** + * Kotlin JavaScript compiler Ant task. + * http://evgeny-goldin.org/javadoc/ant/tutorial-writing-tasks.html + */ +public class KotlinJavaScriptCompilerTask extends Task { + + @Override + public void execute() { + log( "KotlinJavaScriptCompilerTask" ); + } +} diff --git a/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/tasks.xml b/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/tasks.xml new file mode 100644 index 00000000000..25a527811e6 --- /dev/null +++ b/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/tasks.xml @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/build-tools/build.xml b/build-tools/build.xml new file mode 100644 index 00000000000..73de8c83b1a --- /dev/null +++ b/build-tools/build.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 5ab862111c8..33aeabd5c9d 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 @@ -2,9 +2,6 @@ package org.jetbrains.jet.buildtools.core; import org.jetbrains.jet.cli.KotlinCompiler; -import java.io.File; -import java.io.IOException; - /** * Wrapper class for Kotlin bytecode compiler. @@ -12,36 +9,12 @@ import java.io.IOException; public class KotlinBytecodeCompiler { /** - * Compiles a single file. - * - * @param sourceFile source file to compile - * @param destinationDirectory destination directory to compile the file to + * Invokes Kotlin compiler with "-src" and "-output" options. + * @param source "-src" option to specify + * @param destination "-output" option to specify */ - public static void file ( File sourceFile, File destinationDirectory ) { - - String sourcePath = getPath( sourceFile ); - String destinationPath = getPath( destinationDirectory ); - - try { - KotlinCompiler.main( "-src", sourcePath, "-output", destinationPath ); - } - catch ( Exception e ) { - throw new RuntimeException( String.format( "Failed to compile [%s] to [%s]: %s", sourcePath, destinationPath, e ), e ); - } + public static void src ( String source, String destination ) { + KotlinCompiler.main( "-src", source, "-output", destination ); } - - /** - * {@code file.getCanonicalFile().getPath()} convenience wrapper. - * @param f file to get its canonical path. - * @return file's canonical path - */ - private static String getPath( File f ) { - try { - return f.getCanonicalFile().getPath(); - } - catch ( IOException e ) { - throw new RuntimeException( String.format( "Failed to resolve canonical file of [%s]: %s", f, e ), e ); - } - } } diff --git a/build-tools/core/src/org/jetbrains/jet/buildtools/core/Util.java b/build-tools/core/src/org/jetbrains/jet/buildtools/core/Util.java new file mode 100644 index 00000000000..f1fb49b858c --- /dev/null +++ b/build-tools/core/src/org/jetbrains/jet/buildtools/core/Util.java @@ -0,0 +1,30 @@ +package org.jetbrains.jet.buildtools.core; + +import java.io.File; +import java.io.IOException; + + +/** + * General convenient utilities. + */ +public final class Util { + + private Util () { + } + + + /** + * {@code file.getCanonicalFile().getPath()} convenience wrapper. + * @param f file to get its canonical path. + * @return file's canonical path + */ + public static String getPath( File f ) { + try { + return f.getCanonicalFile().getPath(); + } + catch ( IOException e ) { + throw new RuntimeException( String.format( "Failed to resolve canonical file of [%s]: %s", f, e ), e ); + } + } + +} diff --git a/build-tools/test/Hello.kt b/build-tools/test/Hello.kt new file mode 100644 index 00000000000..699426924dd --- /dev/null +++ b/build-tools/test/Hello.kt @@ -0,0 +1,3 @@ +fun main(args : Array) { + System.out?.println("Hello, world!") +} \ No newline at end of file diff --git a/build.xml b/build.xml index 19f07a6e888..fcf2fdf5c89 100644 --- a/build.xml +++ b/build.xml @@ -1,9 +1,12 @@ + + + @@ -24,15 +27,6 @@ - - - - - - - - - @@ -81,18 +75,7 @@ - - - - - - - - - - - - +