Ant task - attribute names changed: output, jar, src.
This commit is contained in:
+16
-11
@@ -12,30 +12,35 @@ To define an Ant's {{*<kotlinc>*}} task you need to define a {{*KOTLIN_HOME*}} e
|
||||
</taskdef>
|
||||
{code}
|
||||
|
||||
|
||||
Alternatively, you can copy all jar files from Kotlin distribution to Ant's {{"lib"}} folder.
|
||||
|
||||
|
||||
h2. {{*<kotlinc>*}} attributes
|
||||
|
||||
|
||||
|| {align:center}Name{align} || {align:center}Description{align} || {align:center}Required{align} || {align:center}Default Value{align} ||
|
||||
| {align:center}{{*file*}}{align} | Kotlin source file to compile | {{"file"}}, {{"srcdir"}}, or {{"module"}} needs to be specified | |
|
||||
| {align:center}{{*srcdir*}}{align} | Kotlin source directory to compile | {{"file"}}, {{"srcdir"}}, or {{"module"}} needs to be specified | |
|
||||
| {align:center}{{*module*}}{align} | Kotlin [module|http://confluence.jetbrains.net/display/Kotlin/Modules+and+Compilation] to compile, can only be used with {{*"destjar"*}}.| {{"file"}}, {{"srcdir"}}, or {{"module"}} needs to be specified | |
|
||||
| {align:center}{{*destdir*}}{align} | Destination directory | {{"destdir"}} or {{"destjar"}} needs to be specified | |
|
||||
| {align:center}{{*destjar*}}{align} | Destination jar file | {{"destdir"}} or {{"destjar"}} needs to be specified | |
|
||||
| {align:center}{{*src*}}{align} | Kotlin source file or directory to compile | {{"src"}} or {{"module"}} needs to be specified | |
|
||||
| {align:center}{{*module*}}{align} | Kotlin [module|http://confluence.jetbrains.net/display/Kotlin/Modules+and+Compilation] to compile | {{"src"}} or {{"module"}} needs to be specified | |
|
||||
| {align:center}{{*output*}}{align} | Destination directory | If {{"src"}} is used - {{"output"}} or {{"jar"}} needs to be specified | |
|
||||
| {align:center}{{*jar*}}{align} | Destination jar file | If {{"src"}} is used - {{"output"}} or {{"jar"}} needs to be specified
|
||||
If {{"module"}} is used - only {{"jar"}} can be specified or it can be omitted | {align:center}{{"moduleName.jar"}}{align} |
|
||||
| {align:center}{{*stdlib*}}{align} | Path to {{"kotlin-runtime.jar"}} | {align:center}{{false}}{align} | {align:center}{{""}}{align} |
|
||||
| {align:center}{{*includeRuntime*}}{align} | Whether Kotlin runtime library is included in compilation | {align:center}{{false}}{align} | {align:center}{{true}}{align} |
|
||||
| {align:center}{{*includeRuntime*}}{align} | If {{"jar"}} is used - whether Kotlin runtime library is included | {align:center}{{false}}{align} | {align:center}{{true}}{align} |
|
||||
|
||||
|
||||
h2. Examples
|
||||
|
||||
|
||||
{code}
|
||||
<kotlinc file = "test/longer-examples/Bottles.kt" destdir = "dist"/>
|
||||
<kotlinc srcdir = "test/longer-examples" destdir = "dist"/>
|
||||
<kotlinc src = "test/longer-examples/Bottles.kt" output = "dist"/>
|
||||
<kotlinc src = "test/longer-examples" output = "dist"/>
|
||||
|
||||
<kotlinc file = "test/longer-examples/Bottles.kt" destjar = "dist.jar"/>
|
||||
<kotlinc srcdir = "test/longer-examples" destjar = "dist.jar"/>
|
||||
<kotlinc src = "test/longer-examples/Bottles.kt" jar = "dist.jar"/>
|
||||
<kotlinc src = "test/longer-examples" jar = "dist.jar"/>
|
||||
|
||||
<kotlinc module = "test/modules/smoke/Smoke.kts" destjar = "dist.jar"/>
|
||||
<kotlinc module = "test/modules/smoke/Smoke.kts" jar = "dist.jar"/>
|
||||
<kotlinc module = "test/modules/smoke/Smoke.kts"/>
|
||||
{code}
|
||||
|
||||
{{"Smoke.kts"}}:
|
||||
|
||||
@@ -16,62 +16,57 @@ import java.io.File;
|
||||
*/
|
||||
public class BytecodeCompilerTask extends Task {
|
||||
|
||||
private boolean includeRuntime = true;
|
||||
private String stdlib;
|
||||
|
||||
private File output;
|
||||
private File jar;
|
||||
private File stdlib;
|
||||
private File src;
|
||||
private File module;
|
||||
private File srcdir;
|
||||
private File file;
|
||||
private File destdir;
|
||||
private File destjar;
|
||||
|
||||
|
||||
public void setStdlib ( String stdlib ) { this.stdlib = stdlib; }
|
||||
public void setModule ( File module ) { this.module = module; }
|
||||
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; }
|
||||
private boolean includeRuntime = true;
|
||||
|
||||
public void setOutput ( File output ) { this.output = output; }
|
||||
public void setJar ( File jar ) { this.jar = jar; }
|
||||
public void setStdlib ( File stdlib ) { this.stdlib = stdlib; }
|
||||
public void setSrc ( File src ) { this.src = src; }
|
||||
public void setModule ( File module ) { this.module = module; }
|
||||
public void setIncludeRuntime ( boolean includeRuntime ) { this.includeRuntime = includeRuntime; }
|
||||
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
|
||||
final BytecodeCompiler compiler = new BytecodeCompiler( this.stdlib );
|
||||
final BytecodeCompiler compiler = new BytecodeCompiler( this.stdlib != null ? getPath( this.stdlib ) : null );
|
||||
|
||||
if (( this.srcdir != null ) || ( this.file != null )) {
|
||||
if ( this.src != null ) {
|
||||
|
||||
if (( this.destdir == null ) && ( this.destjar == null )) {
|
||||
throw new RuntimeException( "\"destdir\" or \"destjar\" should be specified" );
|
||||
if (( this.output == null ) && ( this.jar == null )) {
|
||||
throw new RuntimeException( "\"output\" or \"jar\" should be specified" );
|
||||
}
|
||||
|
||||
String src = getPath( this.srcdir != null ? this.srcdir : this.file );
|
||||
String dest = getPath( this.destdir != null ? this.destdir : this.destjar );
|
||||
String source = getPath( this.src );
|
||||
String destination = getPath( this.output != null ? this.output : this.jar );
|
||||
|
||||
log( String.format( "[%s] => [%s]", src, dest ));
|
||||
log( String.format( "[%s] => [%s]", source, destination ));
|
||||
|
||||
if ( this.destdir != null ) {
|
||||
compiler.sourcesToDir( src, dest );
|
||||
if ( this.output != null ) {
|
||||
compiler.sourcesToDir( source, destination );
|
||||
}
|
||||
else {
|
||||
compiler.sourcesToJar( src, dest, this.includeRuntime );
|
||||
compiler.sourcesToJar( source, destination, this.includeRuntime );
|
||||
}
|
||||
}
|
||||
else if ( this.module != null ) {
|
||||
|
||||
if ( this.destdir != null ) {
|
||||
if ( this.output != null ) {
|
||||
throw new RuntimeException( "Module compilation is only supported for jar destination" );
|
||||
}
|
||||
|
||||
String modulePath = getPath( this.module );
|
||||
String jarPath = ( this.destjar != null ? getPath( this.destjar ) : null );
|
||||
String jarPath = ( this.jar != null ? getPath( this.jar ) : null );
|
||||
|
||||
compiler.moduleToJar( modulePath, jarPath, this.includeRuntime );
|
||||
}
|
||||
else {
|
||||
throw new RuntimeException( "This operation is not supported" );
|
||||
throw new RuntimeException( "\"src\" or \"module\" should be specified" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+21
-52
@@ -74,32 +74,19 @@
|
||||
|
||||
<!-- Runs <kotlinc> create a *.class files in directory -->
|
||||
<macrodef name="kotlinc-dir">
|
||||
<attribute name="file" default=""/>
|
||||
<attribute name="srcdir" default=""/>
|
||||
<attribute name="includeRuntime" default="true"/>
|
||||
<attribute name="stdlib" default=""/>
|
||||
<attribute name="src"/>
|
||||
<attribute name="stdlib" default=""/>
|
||||
|
||||
<sequential>
|
||||
|
||||
<cleanup/>
|
||||
|
||||
<if>
|
||||
<equals arg1="@{file}" arg2=""/>
|
||||
<then>
|
||||
<kotlinc srcdir = "@{srcdir}" destdir = "${tests-dir}" includeRuntime = "@{includeRuntime}" stdlib = "@{stdlib}"/>
|
||||
</then>
|
||||
<else>
|
||||
<kotlinc file = "@{file}" destdir = "${tests-dir}" includeRuntime = "@{includeRuntime}" stdlib = "@{stdlib}"/>
|
||||
</else>
|
||||
</if>
|
||||
<kotlinc src = "@{src}" output = "${tests-dir}" stdlib = "@{stdlib}"/>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
|
||||
|
||||
<!-- Runs <kotlinc> to create a *.class files in a jar -->
|
||||
<macrodef name="kotlinc-jar">
|
||||
<attribute name="file" default=""/>
|
||||
<attribute name="srcdir" default=""/>
|
||||
<attribute name="src" default=""/>
|
||||
<attribute name="module" default=""/>
|
||||
<attribute name="includeRuntime" default="true"/>
|
||||
<attribute name="stdlib" default=""/>
|
||||
@@ -108,30 +95,12 @@
|
||||
<cleanup/>
|
||||
|
||||
<if>
|
||||
<not>
|
||||
<equals arg1="@{file}" arg2=""/>
|
||||
</not>
|
||||
<equals arg1="@{module}" arg2=""/>
|
||||
<then>
|
||||
<kotlinc file = "@{file}" destjar = "${tests-jar}" includeRuntime = "@{includeRuntime}" stdlib = "@{stdlib}"/>
|
||||
<kotlinc src = "@{src}" jar = "${tests-jar}" includeRuntime = "@{includeRuntime}" stdlib = "@{stdlib}"/>
|
||||
</then>
|
||||
<elseif>
|
||||
<not>
|
||||
<equals arg1="@{srcdir}" arg2=""/>
|
||||
</not>
|
||||
<then>
|
||||
<kotlinc srcdir = "@{srcdir}" destjar = "${tests-jar}" includeRuntime = "@{includeRuntime}" stdlib = "@{stdlib}"/>
|
||||
</then>
|
||||
</elseif>
|
||||
<elseif>
|
||||
<not>
|
||||
<equals arg1="@{module}" arg2=""/>
|
||||
</not>
|
||||
<then>
|
||||
<kotlinc module = "@{module}" destjar = "${tests-jar}" includeRuntime = "@{includeRuntime}" stdlib = "@{stdlib}"/>
|
||||
</then>
|
||||
</elseif>
|
||||
<else>
|
||||
<fail message="One of 'file', 'srcdir', or 'module' should be specified"/>
|
||||
<kotlinc module = "@{module}" jar = "${tests-jar}" includeRuntime = "@{includeRuntime}" stdlib = "@{stdlib}"/>
|
||||
</else>
|
||||
</if>
|
||||
</sequential>
|
||||
@@ -203,16 +172,16 @@
|
||||
<attribute name="args" default=""/>
|
||||
<attribute name="out"/>
|
||||
<sequential>
|
||||
<kotlinc-dir file = "@{root}/Hello.kt"/>
|
||||
<kotlinc-dir src = "@{root}/Hello.kt"/>
|
||||
<run-java args = "@{args}" out = "@{out}"/>
|
||||
|
||||
<kotlinc-dir srcdir = "@{root}"/>
|
||||
<kotlinc-dir src = "@{root}"/>
|
||||
<run-java args = "@{args}" out = "@{out}"/>
|
||||
|
||||
<kotlinc-jar file = "@{root}/Hello.kt"/>
|
||||
<kotlinc-jar src = "@{root}/Hello.kt"/>
|
||||
<run-java args = "@{args}" out = "@{out}" run-jar="true"/>
|
||||
|
||||
<kotlinc-jar srcdir = "@{root}"/>
|
||||
<kotlinc-jar src = "@{root}"/>
|
||||
<run-java args = "@{args}" out = "@{out}" run-jar="true"/>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
@@ -234,14 +203,14 @@
|
||||
<!-- Compiles, runs and verifies the output of web demo longer examples -->
|
||||
<macrodef name="longer-examples-tests">
|
||||
<sequential>
|
||||
<kotlinc-dir srcdir = "${basedir}/build-tools/test/longer-examples"/>
|
||||
<kotlinc-dir src = "${basedir}/build-tools/test/longer-examples"/>
|
||||
|
||||
<run-java classname = "bottles.namespace" equals="false" out="12 bottles of beer on the wall, 12 bottles of beer."/>
|
||||
<run-java classname = "maze.namespace" equals="false" out="O ~OOOOOOOOOOOOOO"/>
|
||||
<run-java classname = "life.namespace" equals="false" out="*** ** ** ***"/>
|
||||
<run-java classname = "html.namespace" equals="false" out="<a href="http://jetbrains.com/kotlin">"/>
|
||||
|
||||
<kotlinc-jar srcdir = "${basedir}/build-tools/test/longer-examples"/>
|
||||
<kotlinc-jar src = "${basedir}/build-tools/test/longer-examples"/>
|
||||
|
||||
<run-java classname = "bottles.namespace" equals="false" run-jar="true" out="12 bottles of beer on the wall, 12 bottles of beer."/>
|
||||
<run-java classname = "maze.namespace" equals="false" run-jar="true" out="O ~OOOOOOOOOOOOOO"/>
|
||||
@@ -255,13 +224,13 @@
|
||||
<!-- Currently disabled, see "buildToolsTest" -->
|
||||
<macrodef name="testlib-tests">
|
||||
<sequential>
|
||||
<kotlinc-dir file = "${basedir}/testlib/test/CollectionTest.kt"/>
|
||||
<kotlinc-dir file = "${basedir}/testlib/test/Test.kt"/>
|
||||
<kotlinc-dir srcdir = "${basedir}/testlib/test"/>
|
||||
<kotlinc-dir src = "${basedir}/testlib/test/CollectionTest.kt"/>
|
||||
<kotlinc-dir src = "${basedir}/testlib/test/Test.kt"/>
|
||||
<kotlinc-dir src = "${basedir}/testlib/test"/>
|
||||
|
||||
<kotlinc-jar file = "${basedir}/testlib/test/CollectionTest.kt"/>
|
||||
<kotlinc-jar file = "${basedir}/testlib/test/Test.kt"/>
|
||||
<kotlinc-jar srcdir = "${basedir}/testlib/test"/>
|
||||
<kotlinc-jar src = "${basedir}/testlib/test/CollectionTest.kt"/>
|
||||
<kotlinc-jar src = "${basedir}/testlib/test/Test.kt"/>
|
||||
<kotlinc-jar src = "${basedir}/testlib/test"/>
|
||||
<kotlinc-jar module = "${basedir}/build-tools/test/modules/Testlib.kts"/>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
@@ -283,7 +252,7 @@
|
||||
<trycatch property="error-message" reference="bar">
|
||||
<try>
|
||||
<!-- Should fail -->
|
||||
<kotlinc-dir srcdir = "${basedir}/build-tools/test/compilation-fail"/>
|
||||
<kotlinc-dir src = "${basedir}/build-tools/test/compilation-fail"/>
|
||||
</try>
|
||||
<catch>
|
||||
<var name="failed" value="true"/>
|
||||
@@ -301,7 +270,7 @@
|
||||
<trycatch property="error-message" reference="bar">
|
||||
<try>
|
||||
<!-- Should fail -->
|
||||
<kotlinc-jar srcdir = "${basedir}/build-tools/test/compilation-fail"/>
|
||||
<kotlinc-jar src = "${basedir}/build-tools/test/compilation-fail"/>
|
||||
</try>
|
||||
<catch>
|
||||
<var name="failed" value="true"/>
|
||||
|
||||
@@ -11,6 +11,10 @@ public class BytecodeCompiler {
|
||||
private final CompileEnvironment ENV;
|
||||
|
||||
|
||||
/**
|
||||
* Initializes an instance of this bytecode compiler.
|
||||
* @param stdlib "stdlib" compiler argument, path to "kotlin-runtime.jar", allowed to be <code>null</code> or empty.
|
||||
*/
|
||||
public BytecodeCompiler ( String stdlib ) {
|
||||
ENV = new CompileEnvironment();
|
||||
if (( stdlib != null ) && ( stdlib.trim().length() > 0 )) {
|
||||
|
||||
Reference in New Issue
Block a user