diff --git a/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/BytecodeCompilerTask.java b/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/BytecodeCompilerTask.java new file mode 100644 index 00000000000..7094b6c0ba3 --- /dev/null +++ b/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/BytecodeCompilerTask.java @@ -0,0 +1,63 @@ +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.BytecodeCompiler; + +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 BytecodeCompilerTask extends Task { + + private final BytecodeCompiler compiler = new BytecodeCompiler(); + + private File srcdir; + private File file; + private File destdir; + private File destjar; + private boolean includeRuntime = true; + private boolean excludeStdlib = false; + + public void setSrcdir ( File srcdir ) { this.srcdir = srcdir; } + public void setFile ( File file ) { this.file = file; } + public void setDestdir ( File destdir ) { this.destdir = destdir; } + public void setDestjar ( File destjar ) { this.destjar = destjar; } + + public void setIncludeRuntime ( boolean includeRuntime ) { this.includeRuntime = includeRuntime; } + public void setExcludeStdlib ( boolean excludeStdlib ) { this.excludeStdlib = excludeStdlib; } + + + @Override + public void execute() { + + if (( this.srcdir != null ) || ( this.file != null )) { + + if (( this.destdir == null ) && ( this.destjar == null )) { + throw new RuntimeException( "\"destdir\" or \"destjar\" should be specified" ); + } + + String src = getPath( this.srcdir != null ? this.srcdir : this.file ); + String dest = getPath( this.destdir != null ? this.destdir : this.destjar ); + + log( String.format( "[%s] => [%s]", src, dest )); + + if ( this.destdir != null ) { + compiler.sourcesToDir( src, dest, this.includeRuntime, this.excludeStdlib ); + } + else { + compiler.sourcesToJar( src, dest, this.includeRuntime, this.excludeStdlib ); + } + + } + else { + throw new RuntimeException( "Operation is not supported yet" ); + } + } +} diff --git a/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/KotlinJavaScriptCompilerTask.java b/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/JavaScriptCompilerTask.java similarity index 70% rename from build-tools/ant/src/org/jetbrains/jet/buildtools/ant/KotlinJavaScriptCompilerTask.java rename to build-tools/ant/src/org/jetbrains/jet/buildtools/ant/JavaScriptCompilerTask.java index 0d7eaa4cce7..3435b1b1e43 100644 --- a/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/KotlinJavaScriptCompilerTask.java +++ b/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/JavaScriptCompilerTask.java @@ -7,10 +7,10 @@ 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 { +public class JavaScriptCompilerTask extends Task { @Override public void execute() { - log( "KotlinJavaScriptCompilerTask" ); + log( "JavaScriptCompilerTask" ); } } 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 deleted file mode 100644 index 6b7a3027942..00000000000 --- a/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/KotlinBytecodeCompilerTask.java +++ /dev/null @@ -1,46 +0,0 @@ -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( "[%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/antlib.xml b/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/antlib.xml index 25a527811e6..59309c0326f 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 @@ -5,8 +5,8 @@ + classname = "org.jetbrains.jet.buildtools.ant.BytecodeCompilerTask"/> + classname = "org.jetbrains.jet.buildtools.ant.JavaScriptCompilerTask"/> diff --git a/build-tools/core/src/org/jetbrains/jet/buildtools/core/BytecodeCompiler.java b/build-tools/core/src/org/jetbrains/jet/buildtools/core/BytecodeCompiler.java new file mode 100644 index 00000000000..6c1fb652671 --- /dev/null +++ b/build-tools/core/src/org/jetbrains/jet/buildtools/core/BytecodeCompiler.java @@ -0,0 +1,71 @@ +package org.jetbrains.jet.buildtools.core; + +import org.jetbrains.jet.compiler.CompileEnvironment; + + +/** + * Wrapper class for Kotlin bytecode compiler. + */ +public class BytecodeCompiler { + + private final CompileEnvironment ENV = createCompileEnvironment(); + + + public BytecodeCompiler () { + } + + + /** + * Creates and initializes new {@link CompileEnvironment} instance. + * @return new {@link CompileEnvironment} instance + */ + private CompileEnvironment createCompileEnvironment () { + + CompileEnvironment environment = new CompileEnvironment(); + environment.setJavaRuntime( CompileEnvironment.findRtJar( true )); + + if ( ! environment.initializeKotlinRuntime()) { + throw new RuntimeException( "No Kotlin runtime library found" ); + } + + return environment; + } + + + /** + * Retrieves compilation error message. + * @param source compilation source + * @return compilation error message + */ + private String compilationError ( String source ) { + return String.format( "[%s] compilation failed, see \"ERROR:\" messages above for more details.", source ); + } + + + /** + * {@code CompileEnvironment#compileBunchOfSources} wrapper. + * + * @param source compilation source (directory or file) + * @param destination compilation destination + */ + public void sourcesToDir ( String source, String destination, boolean includeRuntime, boolean excludeStdlib ) { + boolean success = ENV.compileBunchOfSources( source, null, destination, includeRuntime, ! excludeStdlib ); + if ( ! success ) { + throw new RuntimeException( compilationError( source )); + } + } + + + /** + * {@code CompileEnvironment#compileBunchOfSources} wrapper. + * + * @param source compilation source (directory or file) + * @param jar compilation destination jar + */ + public void sourcesToJar ( String source, String jar, boolean includeRuntime, boolean excludeStdlib ) { + boolean success = ENV.compileBunchOfSources( source, jar, null, includeRuntime, ! excludeStdlib ); + if ( ! success ) { + throw new RuntimeException( compilationError( source )); + } + } +} diff --git a/build-tools/core/src/org/jetbrains/jet/buildtools/core/KotlinJavaScriptCompiler.java b/build-tools/core/src/org/jetbrains/jet/buildtools/core/JavaScriptCompiler.java similarity index 72% rename from build-tools/core/src/org/jetbrains/jet/buildtools/core/KotlinJavaScriptCompiler.java rename to build-tools/core/src/org/jetbrains/jet/buildtools/core/JavaScriptCompiler.java index f4079188a08..4d3027f4c88 100644 --- a/build-tools/core/src/org/jetbrains/jet/buildtools/core/KotlinJavaScriptCompiler.java +++ b/build-tools/core/src/org/jetbrains/jet/buildtools/core/JavaScriptCompiler.java @@ -4,5 +4,5 @@ package org.jetbrains.jet.buildtools.core; /** * Wrapper class for Kotlin JavaScript compiler. */ -public class KotlinJavaScriptCompiler { +public class JavaScriptCompiler { } 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 deleted file mode 100644 index a5daafbed12..00000000000 --- a/build-tools/core/src/org/jetbrains/jet/buildtools/core/KotlinBytecodeCompiler.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.jetbrains.jet.buildtools.core; - -import org.jetbrains.jet.compiler.CompileEnvironment; - - -/** - * Wrapper class for Kotlin bytecode compiler. - */ -public class KotlinBytecodeCompiler { - - - 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 )); - } - } -}