in executors/src/main/kotlin/JavaRunnerExecutor.kt [15:52]
fun main(args: Array<String>) {
val defaultOutputStream = System.out
try {
System.setOut(PrintStream(standardOutputStream))
System.setErr(PrintStream(errorOutputStream))
val outputObj = RunOutput()
val className: String
if (args.isNotEmpty()) {
className = args[0]
try {
val mainMethod = Class.forName(className)
.getMethod("main", Array<String>::class.java)
mainMethod.invoke(null, args.copyOfRange(1, args.size) as Any)
}
catch (e: InvocationTargetException) {
outputObj.exception = e.cause
}
catch (e: NoSuchMethodException) {
System.err.println(NO_MAIN_METHOD)
}
catch (e: ClassNotFoundException) {
System.err.println(NO_MAIN_METHOD)
}
}
else {
System.err.println(NO_MAIN_METHOD)
}
System.out.flush()
System.err.flush()
outputObj.text = synchronized(outputStream) { outputStream.toString() }
.replace("</errStream><errStream>".toRegex(), "")
.replace("</outStream><outStream>".toRegex(), "")
defaultOutputStream.print(mapper.writeValueAsString(outputObj))
}
catch (e: Throwable) {
defaultOutputStream.println(mapper.writeValueAsString(RunOutput(exception = e)))
}
}