Refactor JPS daemon client
This commit is contained in:
+7
-35
@@ -110,15 +110,10 @@ abstract class KotlinCompilerRunner<in Env : CompilerEnvironment> {
|
||||
|
||||
protected fun runCompiler(
|
||||
compilerClassName: String,
|
||||
arguments: CommonCompilerArguments,
|
||||
additionalArguments: String,
|
||||
compilerArgs: CommonCompilerArguments,
|
||||
environment: Env): ExitCode {
|
||||
return try {
|
||||
val argumentsList = ArgumentUtils.convertArgumentsToStringList(arguments)
|
||||
argumentsList.addAll(additionalArguments.split(" "))
|
||||
|
||||
val argsArray = argumentsList.toTypedArray()
|
||||
doRunCompiler(compilerClassName, argsArray, environment)
|
||||
compileWithDaemonOrFallback(compilerClassName, compilerArgs, environment)
|
||||
}
|
||||
catch (e: Throwable) {
|
||||
MessageCollectorUtil.reportException(environment.messageCollector, e)
|
||||
@@ -126,43 +121,20 @@ abstract class KotlinCompilerRunner<in Env : CompilerEnvironment> {
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract fun doRunCompiler(
|
||||
protected abstract fun compileWithDaemonOrFallback(
|
||||
compilerClassName: String,
|
||||
argsArray: Array<String>,
|
||||
compilerArgs: CommonCompilerArguments,
|
||||
environment: Env
|
||||
): ExitCode
|
||||
|
||||
/**
|
||||
* Returns null if could not connect to daemon
|
||||
*/
|
||||
protected open fun compileWithDaemon(
|
||||
protected abstract fun compileWithDaemon(
|
||||
compilerClassName: String,
|
||||
argsArray: Array<String>,
|
||||
compilerArgs: CommonCompilerArguments,
|
||||
environment: Env
|
||||
): ExitCode? {
|
||||
val compilerOut = ByteArrayOutputStream()
|
||||
val daemonOut = ByteArrayOutputStream()
|
||||
val services = CompilationServices(
|
||||
incrementalCompilationComponents = environment.services.get(IncrementalCompilationComponents::class.java),
|
||||
compilationCanceledStatus = environment.services.get(CompilationCanceledStatus::class.java))
|
||||
val targetPlatform = when (compilerClassName) {
|
||||
K2JVM_COMPILER -> CompileService.TargetPlatform.JVM
|
||||
K2JS_COMPILER -> CompileService.TargetPlatform.JS
|
||||
K2METADATA_COMPILER -> CompileService.TargetPlatform.METADATA
|
||||
else -> throw IllegalArgumentException("Unknown compiler type $compilerClassName")
|
||||
}
|
||||
|
||||
val res: Int = withDaemon(environment, retryOnConnectionError = true) { daemon, sessionId ->
|
||||
KotlinCompilerClient.incrementalCompile(daemon, sessionId, targetPlatform, argsArray, services, compilerOut, daemonOut)
|
||||
} ?: return null
|
||||
|
||||
val exitCode = exitCodeFromProcessExitCode(res)
|
||||
processCompilerOutput(environment, compilerOut, exitCode)
|
||||
BufferedReader(StringReader(daemonOut.toString())).forEachLine {
|
||||
environment.messageCollector.report(CompilerMessageSeverity.INFO, it, CompilerMessageLocation.NO_LOCATION)
|
||||
}
|
||||
return exitCode
|
||||
}
|
||||
): ExitCode?
|
||||
|
||||
protected fun <T> withDaemon(environment: Env, retryOnConnectionError: Boolean, fn: (CompileService, sessionId: Int)->T): T? {
|
||||
fun retryOrFalse(e: Exception): T? {
|
||||
|
||||
Reference in New Issue
Block a user