diff --git a/ant/src/org/jetbrains/kotlin/ant/KotlinCompilerAdapter.java b/ant/src/org/jetbrains/kotlin/ant/KotlinCompilerAdapter.java index e3b941b1cc6..46afaa32e2c 100644 --- a/ant/src/org/jetbrains/kotlin/ant/KotlinCompilerAdapter.java +++ b/ant/src/org/jetbrains/kotlin/ant/KotlinCompilerAdapter.java @@ -56,6 +56,7 @@ public class KotlinCompilerAdapter extends Javac13 { Javac javac = getJavac(); Kotlin2JvmTask kotlinc = new Kotlin2JvmTask(); + kotlinc.setFailOnError(javac.getFailonerror()); kotlinc.setOutput(javac.getDestdir()); Path classpath = javac.getClasspath(); @@ -70,6 +71,10 @@ public class KotlinCompilerAdapter extends Javac13 { kotlinc.setExternalAnnotations(externalAnnotations); kotlinc.execute(); + if (!Integer.valueOf(0).equals(kotlinc.getExitCode())) { + // Don't run javac if failOnError = false and there were errors on Kotlin sources + return false; + } javac.log("Running javac..."); diff --git a/ant/src/org/jetbrains/kotlin/ant/KotlinCompilerBaseTask.kt b/ant/src/org/jetbrains/kotlin/ant/KotlinCompilerBaseTask.kt index 9341d39dcaa..172f7c53faf 100644 --- a/ant/src/org/jetbrains/kotlin/ant/KotlinCompilerBaseTask.kt +++ b/ant/src/org/jetbrains/kotlin/ant/KotlinCompilerBaseTask.kt @@ -16,16 +16,16 @@ package org.jetbrains.kotlin.ant +import org.apache.tools.ant.AntClassLoader +import org.apache.tools.ant.BuildException import org.apache.tools.ant.Task +import org.apache.tools.ant.types.Commandline import org.apache.tools.ant.types.Path import org.apache.tools.ant.types.Reference -import java.io.File -import org.apache.tools.ant.BuildException -import org.apache.tools.ant.types.Commandline -import java.io.PrintStream -import org.apache.tools.ant.AntClassLoader -import java.lang.ref.SoftReference import org.jetbrains.kotlin.preloading.ClassPreloadingUtils +import java.io.File +import java.io.PrintStream +import java.lang.ref.SoftReference import java.net.JarURLConnection object CompilerClassLoaderHolder { @@ -66,11 +66,14 @@ public abstract class KotlinCompilerBaseTask : Task() { public var nowarn: Boolean = false public var verbose: Boolean = false public var printVersion: Boolean = false + public var failOnError: Boolean = false public var noStdlib: Boolean = false public val additionalArguments: MutableList = arrayListOf() + internal var exitCode: Int? = null + public fun createSrc(): Path { val srcPath = src if (srcPath == null) { @@ -118,10 +121,10 @@ public abstract class KotlinCompilerBaseTask : Task() { log("Compiling ${src!!.list().toList()} => [${output!!.canonicalPath}]"); - val exitCode = exec(compiler, System.err, args.copyToArray()) + val result = exec(compiler, System.err, args.toTypedArray()) + exitCode = (result as Enum<*>).ordinal() - // TODO: support failOnError attribute of javac - if ((exitCode as Enum<*>).ordinal() != 0) { + if (failOnError && exitCode != 0) { throw BuildException("Compile failed; see the compiler error output for details.") } } diff --git a/compiler/testData/integration/ant/jvm/doNotFailOnError/IncorrectJavaCode.java b/compiler/testData/integration/ant/jvm/doNotFailOnError/IncorrectJavaCode.java new file mode 100644 index 00000000000..5ffd5ec6ef1 --- /dev/null +++ b/compiler/testData/integration/ant/jvm/doNotFailOnError/IncorrectJavaCode.java @@ -0,0 +1,3 @@ +package hello; + +public class IncorrectJavaCode { diff --git a/compiler/testData/integration/ant/jvm/doNotFailOnError/build.log.expected b/compiler/testData/integration/ant/jvm/doNotFailOnError/build.log.expected new file mode 100644 index 00000000000..1d5b4f29ebd --- /dev/null +++ b/compiler/testData/integration/ant/jvm/doNotFailOnError/build.log.expected @@ -0,0 +1,21 @@ +OUT: +Buildfile: [TestData]/build.xml + +build: + [javac] Compiling 2 source files to [Temp] + [javac] Compiling [[TestData]] => [[Temp]] + [javac] ERROR: [TestData]/incorrectKotlinCode.kt: (4, 1) Parameter name expected + [javac] ERROR: [TestData]/incorrectKotlinCode.kt: (4, 1) Expecting comma or ')' + [javac] ERROR: [TestData]/incorrectKotlinCode.kt: (4, 1) Expecting ')' + [kotlinc] Compiling [[TestData]] => [[Temp]] + [kotlinc] ERROR: [TestData]/incorrectKotlinCode.kt: (4, 1) Parameter name expected + [kotlinc] ERROR: [TestData]/incorrectKotlinCode.kt: (4, 1) Expecting comma or ')' + [kotlinc] ERROR: [TestData]/incorrectKotlinCode.kt: (4, 1) Expecting ')' + +BUILD SUCCESSFUL +Total time: [time] + +ERR: + [javac] Compile failed; see the compiler error output for details. + +Return code: 0 diff --git a/compiler/testData/integration/ant/jvm/doNotFailOnError/build.xml b/compiler/testData/integration/ant/jvm/doNotFailOnError/build.xml new file mode 100644 index 00000000000..8faf3e5e599 --- /dev/null +++ b/compiler/testData/integration/ant/jvm/doNotFailOnError/build.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/compiler/testData/integration/ant/jvm/doNotFailOnError/hello.run.expected b/compiler/testData/integration/ant/jvm/doNotFailOnError/hello.run.expected new file mode 100644 index 00000000000..a9dec07cd07 --- /dev/null +++ b/compiler/testData/integration/ant/jvm/doNotFailOnError/hello.run.expected @@ -0,0 +1,12 @@ + +ERR: +Exception in thread "main" java.lang.NoClassDefFoundError: hello/HelloPackage +Caused by: java.lang.ClassNotFoundException: hello.HelloPackage + at java.net.URLClassLoader$1.run(URLClassLoader.java:202) + at java.security.AccessController.doPrivileged(Native Method) + at java.net.URLClassLoader.findClass(URLClassLoader.java:190) + at java.lang.ClassLoader.loadClass(ClassLoader.java:306) + at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) + at java.lang.ClassLoader.loadClass(ClassLoader.java:247) + +Return code: 1 diff --git a/compiler/testData/integration/ant/jvm/doNotFailOnError/incorrectKotlinCode.kt b/compiler/testData/integration/ant/jvm/doNotFailOnError/incorrectKotlinCode.kt new file mode 100644 index 00000000000..9c3a348d482 --- /dev/null +++ b/compiler/testData/integration/ant/jvm/doNotFailOnError/incorrectKotlinCode.kt @@ -0,0 +1,3 @@ +package hello + +fun main( diff --git a/compiler/tests/org/jetbrains/kotlin/integration/AntTaskJvmTest.java b/compiler/tests/org/jetbrains/kotlin/integration/AntTaskJvmTest.java index 236db6c4946..8ac3eb7daa0 100644 --- a/compiler/tests/org/jetbrains/kotlin/integration/AntTaskJvmTest.java +++ b/compiler/tests/org/jetbrains/kotlin/integration/AntTaskJvmTest.java @@ -71,6 +71,11 @@ public class AntTaskJvmTest extends AntTaskBaseTest { doJvmAntTest(); } + @Test + public void doNotFailOnError() throws Exception { + doJvmAntTest(); + } + @Test public void jvmClasspath() throws Exception { doJvmAntTest();