First Ant task + "buildToolsTest" Ant target added
This commit is contained in:
@@ -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 <javac>}.
|
||||
*/
|
||||
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" ));
|
||||
}
|
||||
}
|
||||
}
|
||||
+16
@@ -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" );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
|
||||
<!-- http://evgeny-goldin.org/javadoc/ant/Types/antlib.html -->
|
||||
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
|
||||
|
||||
<antlib>
|
||||
<taskdef
|
||||
name = "kotlinc"
|
||||
classname = "org.jetbrains.jet.buildtools.ant.KotlinBytecodeCompilerTask"/>
|
||||
<taskdef
|
||||
name = "kotlinJSc"
|
||||
classname = "org.jetbrains.jet.buildtools.ant.KotlinJavaScriptCompilerTask"/>
|
||||
</antlib>
|
||||
@@ -0,0 +1,53 @@
|
||||
<project name="build-tools" default="buildToolsJar">
|
||||
|
||||
<path id="sourcepath.buildTools">
|
||||
<dirset dir="${basedir}/build-tools">
|
||||
<include name="core/src"/>
|
||||
<include name="ant/src"/>
|
||||
<include name="maven/src"/>
|
||||
<include name="gradle/src"/>
|
||||
</dirset>
|
||||
</path>
|
||||
|
||||
<path id="classpath.buildTools">
|
||||
<path refid="classpath.kotlin"/>
|
||||
<fileset dir="${idea.sdk}/ant/lib" includes="*.jar"/>
|
||||
</path>
|
||||
|
||||
<path id="dist.jars">
|
||||
<fileset dir="${idea.sdk}" includes="*.jar"/>
|
||||
<fileset dir="${basedir}/lib" includes="*.jar"/>
|
||||
<fileset dir="${output}" includes="*.jar"/>
|
||||
</path>
|
||||
|
||||
<target name="buildToolsJar" depends="compile">
|
||||
<mkdir dir ="${output}/classes/buildTools"/>
|
||||
<javac destdir="${output}/classes/buildTools" debug="true" debuglevel="lines,vars,source">
|
||||
<src refid="sourcepath.buildTools"/>
|
||||
<classpath refid="classpath.buildTools"/>
|
||||
</javac>
|
||||
<jar destfile="${output}/kotlin-build-tools.jar">
|
||||
<fileset dir="${output}/classes/buildTools"/>
|
||||
<fileset dir="${basedir}/build-tools/ant/src" includes="**/*.xml"/>
|
||||
</jar>
|
||||
</target>
|
||||
|
||||
<target name="buildToolsTest" depends="jarRT, jar, buildToolsJar">
|
||||
<taskdef resource = "org/jetbrains/jet/buildtools/ant/tasks.xml"
|
||||
classpathref = "dist.jars"/>
|
||||
|
||||
<kotlinc file = "${basedir}/build-tools/test/Hello.kt"
|
||||
destdir = "${output}/build-tools-test"/>
|
||||
<java classpathref = "dist.jars"
|
||||
classname = "namespace">
|
||||
<classpath path = "${output}/build-tools-test"/>
|
||||
</java>
|
||||
|
||||
<kotlinc srcdir = "${basedir}/build-tools/test"
|
||||
destdir = "${output}/build-tools-test"/>
|
||||
<java classpathref = "dist.jars"
|
||||
classname = "namespace">
|
||||
<classpath path = "${output}/build-tools-test"/>
|
||||
</java>
|
||||
</target>
|
||||
</project>
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fun main(args : Array<String>) {
|
||||
System.out?.println("Hello, world!")
|
||||
}
|
||||
@@ -1,9 +1,12 @@
|
||||
<project name="Kotlin" default="dist">
|
||||
|
||||
<property name="output" value="${basedir}/dist"/>
|
||||
<property name="build.number" value="snapshot"/>
|
||||
<property name="output.name" value="kotlin-${build.number}"/>
|
||||
<property name="idea.sdk" value="${basedir}/ideaSDK"/>
|
||||
|
||||
<import file="build-tools/build.xml" optional="false"/>
|
||||
|
||||
<path id="classpath">
|
||||
<fileset dir="${idea.sdk}" includes="*.jar"/>
|
||||
<fileset dir="${basedir}/lib" includes="*.jar"/>
|
||||
@@ -24,15 +27,6 @@
|
||||
</dirset>
|
||||
</path>
|
||||
|
||||
<path id="buildToolsSourcepath">
|
||||
<dirset dir="${basedir}/build-tools">
|
||||
<include name="core/src"/>
|
||||
<include name="ant/src"/>
|
||||
<include name="maven/src"/>
|
||||
<include name="gradle/src"/>
|
||||
</dirset>
|
||||
</path>
|
||||
|
||||
<target name="compileRT">
|
||||
<mkdir dir="${output}/classes/runtime"/>
|
||||
<javac destdir="${output}/classes/runtime" debug="true" debuglevel="lines,vars,source">
|
||||
@@ -81,18 +75,7 @@
|
||||
<delete dir="${output}"/>
|
||||
</target>
|
||||
|
||||
<target name="buildTools" depends="compile">
|
||||
<mkdir dir="${output}/classes/buildTools"/>
|
||||
<javac destdir="${output}/classes/buildTools" debug="true" debuglevel="lines,vars,source">
|
||||
<src refid="buildToolsSourcepath"/>
|
||||
<classpath refid="classpath.kotlin"/>
|
||||
</javac>
|
||||
<jar destfile="${output}/kotlin-build-tools.jar">
|
||||
<fileset dir="${output}/classes/buildTools"/>
|
||||
</jar>
|
||||
</target>
|
||||
|
||||
<target name="dist" depends="clean,jarRT,jar,buildTools">
|
||||
<target name="dist" depends="clean,jarRT,jar,buildToolsJar">
|
||||
<echo file="${output}/build.txt" message="${build.number}"/>
|
||||
<zip destfile="${output}/${output.name}.zip">
|
||||
<zipfileset prefix="kotlinc" file="${output}/build.txt"/>
|
||||
|
||||
Reference in New Issue
Block a user