diff --git a/.idea/libraries/ant_1_7.xml b/.idea/libraries/ant_1_7.xml index c2543e21bb4..88ad8f660fc 100644 --- a/.idea/libraries/ant_1_7.xml +++ b/.idea/libraries/ant_1_7.xml @@ -1,5 +1,8 @@ + + + diff --git a/annotations/org/apache/tools/ant/types/annotations.xml b/annotations/org/apache/tools/ant/types/annotations.xml new file mode 100644 index 00000000000..7d0d1cbb5db --- /dev/null +++ b/annotations/org/apache/tools/ant/types/annotations.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/JavaScriptCompilerTask.java b/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/JavaScriptCompilerTask.java deleted file mode 100644 index 59adfd03ad4..00000000000 --- a/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/JavaScriptCompilerTask.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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.Task; - - -/** - * Kotlin JavaScript compiler Ant task. - * http://evgeny-goldin.org/javadoc/ant/tutorial-writing-tasks.html - */ -public class JavaScriptCompilerTask extends Task { - - @Override - public void execute() { - log("JavaScriptCompilerTask"); - } -} diff --git a/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/Kotlin2JsCompilerTask.kt b/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/Kotlin2JsCompilerTask.kt new file mode 100644 index 00000000000..9dd9b96da24 --- /dev/null +++ b/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/Kotlin2JsCompilerTask.kt @@ -0,0 +1,99 @@ +/* + * 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.Task +import org.apache.tools.ant.types.Path +import org.apache.tools.ant.types.Reference +import org.jetbrains.jet.buildtools.core.Util +import org.jetbrains.jet.cli.common.arguments.K2JSCompilerArguments +import org.jetbrains.jet.cli.common.messages.MessageCollectorPlainTextToStream +import org.jetbrains.jet.cli.js.K2JSCompiler +import java.io.File +import org.apache.tools.ant.BuildException +import org.jetbrains.jet.cli.common.ExitCode +import java.util.Arrays + +/** + * Kotlin JavaScript compiler Ant task. + * http://evgeny-goldin.org/javadoc/ant/tutorial-writing-tasks.html + */ +public class Kotlin2JsCompilerTask : Task() { + public var src: Path? = null + public var output: File? = null + public var library: Path? = null + public var outputPrefix: File? = null + public var outputPostfix: File? = null + public var sourcemap: Boolean = false + + /** + * {@link K2JsArgumentConstants.CALL} (default) if need generate a main function call (main function will be auto detected) + * {@link K2JsArgumentConstants.NO_CALL} otherwise. + */ + public var main: String? = null + + public fun createSrc(): Path { + val srcPath = src + if (srcPath == null) { + val t = Path(getProject()) + src = t + return t + } + + return srcPath.createPath() + } + + public fun setSrcRef(ref: Reference) { + createSrc().setRefid(ref) + } + + public fun createLibrary(): Path { + val libraryPath = library + if (libraryPath == null) { + val t = Path(getProject()) + library = t + return t + } + + return libraryPath.createPath() + } + + override fun execute(): Unit { + val arguments = K2JSCompilerArguments() + + val sourcePaths = src ?: throw BuildException("\"src\" should be specified") + arguments.sourceFiles = Util.getPaths(sourcePaths.list()) + + val outputFile = output ?: throw BuildException("\"output\" should be specified") + arguments.outputFile = outputFile.canonicalPath + + arguments.outputPrefix = outputPrefix?.canonicalPath + arguments.outputPostfix = outputPostfix?.canonicalPath + + arguments.main = main + arguments.sourcemap = sourcemap + + log("Compiling [${arguments.sourceFiles?.makeString(",")}] => [${arguments.outputFile}]"); + + val compiler = K2JSCompiler() + val exitCode = compiler.exec(MessageCollectorPlainTextToStream.PLAIN_TEXT_TO_SYSTEM_ERR, arguments) + + if (exitCode != ExitCode.OK) { + throw BuildException("Compilation finished with exit code $exitCode") + } + } +} 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 2443203af4e..99b545c88d6 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 @@ -7,8 +7,8 @@ name = "kotlinc" classname = "org.jetbrains.jet.buildtools.ant.BytecodeCompilerTask"/> + name = "kotlin2js" + classname = "org.jetbrains.jet.buildtools.ant.Kotlin2JsCompilerTask"/> diff --git a/build-tools/core/src/org/jetbrains/jet/buildtools/core/JavaScriptCompiler.java b/build-tools/core/src/org/jetbrains/jet/buildtools/core/JavaScriptCompiler.java deleted file mode 100644 index fdf32979150..00000000000 --- a/build-tools/core/src/org/jetbrains/jet/buildtools/core/JavaScriptCompiler.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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.core; - - -/** - * Wrapper class for Kotlin JavaScript compiler. - */ -public class JavaScriptCompiler { -} 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 index 55456eb97b5..79a35190372 100644 --- a/build-tools/core/src/org/jetbrains/jet/buildtools/core/Util.java +++ b/build-tools/core/src/org/jetbrains/jet/buildtools/core/Util.java @@ -16,6 +16,8 @@ package org.jetbrains.jet.buildtools.core; +import org.jetbrains.annotations.NotNull; + import java.io.File; import java.io.IOException; @@ -30,14 +32,15 @@ public final class Util { /** - * {@code file.getCanonicalFile().getPath()} convenience wrapper. + * {@code file.getCanonicalPath()} convenience wrapper. * * @param f file to get its canonical path. * @return file's canonical path */ - public static String getPath(File f) { + @NotNull + public static String getPath(@NotNull File f) { try { - return f.getCanonicalFile().getPath(); + return f.getCanonicalPath(); } catch (IOException e) { throw new RuntimeException(String.format("Failed to resolve canonical file of [%s]: %s", f, e), e); diff --git a/build.xml b/build.xml index 47b91300883..85bbfbd611d 100644 --- a/build.xml +++ b/build.xml @@ -22,6 +22,8 @@ + + @@ -436,6 +438,7 @@ +