BuildTools: added ant task for Kotlin2Js compiler.
This commit is contained in:
Generated
+3
@@ -1,5 +1,8 @@
|
|||||||
<component name="libraryTable">
|
<component name="libraryTable">
|
||||||
<library name="ant-1.7">
|
<library name="ant-1.7">
|
||||||
|
<ANNOTATIONS>
|
||||||
|
<root url="file://$PROJECT_DIR$/annotations" />
|
||||||
|
</ANNOTATIONS>
|
||||||
<CLASSES>
|
<CLASSES>
|
||||||
<root url="jar://$PROJECT_DIR$/dependencies/ant-1.7/lib/ant.jar!/" />
|
<root url="jar://$PROJECT_DIR$/dependencies/ant-1.7/lib/ant.jar!/" />
|
||||||
</CLASSES>
|
</CLASSES>
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<root>
|
||||||
|
<item name='org.apache.tools.ant.types.Path org.apache.tools.ant.types.Path createPath()'>
|
||||||
|
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||||
|
</item>
|
||||||
|
</root>
|
||||||
@@ -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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,8 +7,8 @@
|
|||||||
name = "kotlinc"
|
name = "kotlinc"
|
||||||
classname = "org.jetbrains.jet.buildtools.ant.BytecodeCompilerTask"/>
|
classname = "org.jetbrains.jet.buildtools.ant.BytecodeCompilerTask"/>
|
||||||
<taskdef
|
<taskdef
|
||||||
name = "kotlinJSc"
|
name = "kotlin2js"
|
||||||
classname = "org.jetbrains.jet.buildtools.ant.JavaScriptCompilerTask"/>
|
classname = "org.jetbrains.jet.buildtools.ant.Kotlin2JsCompilerTask"/>
|
||||||
<typedef
|
<typedef
|
||||||
name = "withKotlin"
|
name = "withKotlin"
|
||||||
classname = "org.jetbrains.jet.buildtools.ant.KotlinCompilerAdapter"/>
|
classname = "org.jetbrains.jet.buildtools.ant.KotlinCompilerAdapter"/>
|
||||||
|
|||||||
@@ -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 {
|
|
||||||
}
|
|
||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.buildtools.core;
|
package org.jetbrains.jet.buildtools.core;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
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.
|
* @param f file to get its canonical path.
|
||||||
* @return file's canonical path
|
* @return file's canonical path
|
||||||
*/
|
*/
|
||||||
public static String getPath(File f) {
|
@NotNull
|
||||||
|
public static String getPath(@NotNull File f) {
|
||||||
try {
|
try {
|
||||||
return f.getCanonicalFile().getPath();
|
return f.getCanonicalPath();
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
throw new RuntimeException(String.format("Failed to resolve canonical file of [%s]: %s", f, e), e);
|
throw new RuntimeException(String.format("Failed to resolve canonical file of [%s]: %s", f, e), e);
|
||||||
|
|||||||
@@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
<property name="java.target" value="1.6"/>
|
<property name="java.target" value="1.6"/>
|
||||||
|
|
||||||
|
<property name="external.annotations.path" value="${basedir}/annotations"/>
|
||||||
|
|
||||||
<path id="classpath">
|
<path id="classpath">
|
||||||
<file file="${bootstrap.runtime}"/>
|
<file file="${bootstrap.runtime}"/>
|
||||||
<fileset dir="${idea.sdk}" includes="core/*.jar"/>
|
<fileset dir="${idea.sdk}" includes="core/*.jar"/>
|
||||||
@@ -436,6 +438,7 @@
|
|||||||
<target name="antTools">
|
<target name="antTools">
|
||||||
<cleandir dir="${output}/classes/buildTools"/>
|
<cleandir dir="${output}/classes/buildTools"/>
|
||||||
<javac2 destdir="${output}/classes/buildTools" debug="true" debuglevel="lines,vars,source" includeAntRuntime="false" source="${java.target}" target="${java.target}">
|
<javac2 destdir="${output}/classes/buildTools" debug="true" debuglevel="lines,vars,source" includeAntRuntime="false" source="${java.target}" target="${java.target}">
|
||||||
|
<withKotlin externalannotations="${external.annotations.path}"/>
|
||||||
<src>
|
<src>
|
||||||
<dirset dir="${basedir}/build-tools">
|
<dirset dir="${basedir}/build-tools">
|
||||||
<include name="core/src"/>
|
<include name="core/src"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user