1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-27 00:38:11 -07:00

Clean up the streams.

This commit is contained in:
Cedric Beust 2016-06-07 22:40:05 -08:00
parent 82b5c636d0
commit 1b065c8d50

View file

@ -94,17 +94,14 @@ class KotlinCompiler @Inject constructor(
val classLoader = ParentLastClassLoader(compilerJar) val classLoader = ParentLastClassLoader(compilerJar)
val compiler = classLoader.loadClass("org.jetbrains.kotlin.cli.common.CLICompiler") val compiler = classLoader.loadClass("org.jetbrains.kotlin.cli.common.CLICompiler")
val compilerMain = compiler.declaredMethods.filter {
it.name == "doMainNoExit" && it.parameterTypes.size == 2
}[0]
val kCompiler = classLoader.loadClass("org.jetbrains.kotlin.cli.jvm.K2JVMCompiler") val kCompiler = classLoader.loadClass("org.jetbrains.kotlin.cli.jvm.K2JVMCompiler")
// //
// In order to capture the error stream, I need to invoke CLICompiler.exec(), which // In order to capture the error stream, I need to invoke CLICompiler.exec(), which
// is the first method that accepts a PrintStream for the errors in parameter // is the first method that accepts a PrintStream for the errors in parameter
// //
val baos = ByteArrayOutputStream() ByteArrayOutputStream().use { baos ->
val ps = PrintStream(baos) PrintStream(baos).use { ps ->
val execMethod = compiler.declaredMethods.filter { val execMethod = compiler.declaredMethods.filter {
it.name == "exec" && it.parameterTypes.size == 2 it.name == "exec" && it.parameterTypes.size == 2
}[0] }[0]
@ -115,6 +112,8 @@ class KotlinCompiler @Inject constructor(
val nameMethod = exitCode.javaClass.getMethod("name") val nameMethod = exitCode.javaClass.getMethod("name")
val success = "OK" == nameMethod.invoke(exitCode).toString() val success = "OK" == nameMethod.invoke(exitCode).toString()
TaskResult(success, errorString) TaskResult(success, errorString)
}
}
} else { } else {
val exitCode = CLICompiler.doMainNoExit(K2JVMCompiler(), allArgs.toTypedArray()) val exitCode = CLICompiler.doMainNoExit(K2JVMCompiler(), allArgs.toTypedArray())
TaskResult(exitCode == ExitCode.OK) TaskResult(exitCode == ExitCode.OK)