mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 16:28:12 -07:00
Clean up the streams.
This commit is contained in:
parent
82b5c636d0
commit
1b065c8d50
1 changed files with 13 additions and 14 deletions
|
@ -94,27 +94,26 @@ 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]
|
||||||
val exitCode = execMethod.invoke(kCompiler.newInstance(), ps, allArgs.toTypedArray())
|
val exitCode = execMethod.invoke(kCompiler.newInstance(), ps, allArgs.toTypedArray())
|
||||||
val errorString = baos.toString(Charset.defaultCharset().toString())
|
val errorString = baos.toString(Charset.defaultCharset().toString())
|
||||||
|
|
||||||
// The return value is an enum
|
// The return value is an enum
|
||||||
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)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue