From a1881a72511fee97bcb5a30f4eb5e42ca689ee5b Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Mon, 29 Oct 2018 20:59:13 +0300 Subject: [PATCH] Avoid catching exceptions from workers in GradleKotlinCompilerRunner Exceptions were catched in `KotlinCompilerRunner.runCompiler`. When the method from superclass is not used in `GradleKotlinCompilerRunner`, the superclass does not make much sense anymore, so I turned it into util object. Original commit: a41c2d759a480aea85c3e5e3f7b6719bb0a7a72b --- .../compilerRunner/JpsKotlinCompilerRunner.kt | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/jps/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinCompilerRunner.kt b/jps/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinCompilerRunner.kt index ad01c5fbd7d..4d8cc2b9566 100644 --- a/jps/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinCompilerRunner.kt +++ b/jps/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinCompilerRunner.kt @@ -21,6 +21,7 @@ import org.jetbrains.jps.api.GlobalOptions import org.jetbrains.kotlin.cli.common.ExitCode import org.jetbrains.kotlin.cli.common.KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY import org.jetbrains.kotlin.cli.common.arguments.* +import org.jetbrains.kotlin.cli.common.messages.MessageCollectorUtil import org.jetbrains.kotlin.config.CompilerSettings import org.jetbrains.kotlin.config.IncrementalCompilation import org.jetbrains.kotlin.config.additionalArgumentsAsList @@ -32,8 +33,8 @@ import java.io.ByteArrayOutputStream import java.io.File import java.io.PrintStream -class JpsKotlinCompilerRunner : KotlinCompilerRunner() { - override val log: KotlinLogger = JpsKotlinLogger(KotlinBuilder.LOG) +class JpsKotlinCompilerRunner { + private val log: KotlinLogger = JpsKotlinLogger(KotlinBuilder.LOG) private var compilerSettings: CompilerSettings? = null @@ -153,7 +154,7 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner() { } } - override fun compileWithDaemonOrFallback( + private fun compileWithDaemonOrFallback( compilerClassName: String, compilerArgs: CommonCompilerArguments, environment: JpsCompilerEnvironment @@ -166,6 +167,15 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner() { ) } + private fun runCompiler(compilerClassName: String, compilerArgs: CommonCompilerArguments, environment: JpsCompilerEnvironment) { + try { + compileWithDaemonOrFallback(compilerClassName, compilerArgs, environment) + } catch (e: Throwable) { + MessageCollectorUtil.reportException(environment.messageCollector, e) + reportInternalCompilerError(environment.messageCollector) + } + } + private fun compileWithDaemon( compilerClassName: String, compilerArgs: CommonCompilerArguments, @@ -311,7 +321,7 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner() { } private fun getReturnCodeFromObject(rc: Any?): String = when { - rc == null -> INTERNAL_ERROR + rc == null -> ExitCode.INTERNAL_ERROR.toString() ExitCode::class.java.name == rc::class.java.name -> rc.toString() else -> throw IllegalStateException("Unexpected return: " + rc) } @@ -333,7 +343,7 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner() { environment.withProgressReporter { progress -> progress.progress("connecting to daemon") - newDaemonConnection( + KotlinCompilerRunnerUtils.newDaemonConnection( compilerId, clientFlagFile, sessionFlagFile,