diff --git a/compiler/compiler-runner/src/org/jetbrains/kotlin/compilerRunner/CompilerEnvironment.kt b/compiler/compiler-runner/src/org/jetbrains/kotlin/compilerRunner/CompilerEnvironment.kt index ea8a8117539..6aa919cf3a9 100644 --- a/compiler/compiler-runner/src/org/jetbrains/kotlin/compilerRunner/CompilerEnvironment.kt +++ b/compiler/compiler-runner/src/org/jetbrains/kotlin/compilerRunner/CompilerEnvironment.kt @@ -16,8 +16,13 @@ package org.jetbrains.kotlin.compilerRunner +import org.jetbrains.kotlin.cli.common.messages.MessageCollector import org.jetbrains.kotlin.config.Services import org.jetbrains.kotlin.utils.KotlinPaths -open class CompilerEnvironment(val services: Services) +open class CompilerEnvironment( + val services: Services, + val messageCollector: MessageCollector, + open val outputItemsCollector: OutputItemsCollector +) diff --git a/compiler/compiler-runner/src/org/jetbrains/kotlin/compilerRunner/KotlinCompilerRunner.kt b/compiler/compiler-runner/src/org/jetbrains/kotlin/compilerRunner/KotlinCompilerRunner.kt index 7dd8f376eb3..a34e6f71dec 100644 --- a/compiler/compiler-runner/src/org/jetbrains/kotlin/compilerRunner/KotlinCompilerRunner.kt +++ b/compiler/compiler-runner/src/org/jetbrains/kotlin/compilerRunner/KotlinCompilerRunner.kt @@ -53,10 +53,10 @@ abstract class KotlinCompilerRunner { class DaemonConnection(val daemon: CompileService?, val sessionId: Int = CompileService.NO_SESSION) - protected abstract fun getDaemonConnection(environment: Env, messageCollector: MessageCollector): DaemonConnection + protected abstract fun getDaemonConnection(environment: Env): DaemonConnection @Synchronized - protected fun newDaemonConnection(compilerPath: File, messageCollector: MessageCollector, flagFile: File): DaemonConnection { + protected fun newDaemonConnection(compilerPath: File, flagFile: File, environment: Env): DaemonConnection { val compilerId = CompilerId.makeCompilerId(compilerPath) val daemonOptions = configureDaemonOptions() val daemonJVMOptions = configureDaemonJVMOptions(inheritMemoryLimits = true, inheritAdditionalProperties = true) @@ -71,9 +71,9 @@ abstract class KotlinCompilerRunner { } for (msg in daemonReportMessages) { - messageCollector.report(CompilerMessageSeverity.INFO, + environment.messageCollector.report(CompilerMessageSeverity.INFO, (if (msg.category == DaemonReportCategory.EXCEPTION && connection.daemon == null) "Falling back to compilation without daemon due to error: " else "") + msg.message, - CompilerMessageLocation.NO_LOCATION) + CompilerMessageLocation.NO_LOCATION) } fun reportTotalAndThreadPerf(message: String, daemonOptions: DaemonOptions, messageCollector: MessageCollector, profiler: Profiler) { @@ -86,21 +86,20 @@ abstract class KotlinCompilerRunner { } } - reportTotalAndThreadPerf("Daemon connect", daemonOptions, messageCollector, profiler) + reportTotalAndThreadPerf("Daemon connect", daemonOptions, environment.messageCollector, profiler) return connection } protected fun processCompilerOutput( - messageCollector: MessageCollector, - collector: OutputItemsCollector, + environment: Env, stream: ByteArrayOutputStream, exitCode: ExitCode ) { val reader = BufferedReader(StringReader(stream.toString())) - CompilerOutputParser.parseCompilerMessagesFromReader(messageCollector, reader, collector) + CompilerOutputParser.parseCompilerMessagesFromReader(environment.messageCollector, reader, environment.outputItemsCollector) if (ExitCode.INTERNAL_ERROR == exitCode) { - reportInternalCompilerError(messageCollector) + reportInternalCompilerError(environment.messageCollector) } } @@ -113,28 +112,24 @@ abstract class KotlinCompilerRunner { compilerClassName: String, arguments: CommonCompilerArguments, additionalArguments: String, - messageCollector: MessageCollector, - collector: OutputItemsCollector, environment: Env): ExitCode { return try { val argumentsList = ArgumentUtils.convertArgumentsToStringList(arguments) argumentsList.addAll(additionalArguments.split(" ")) val argsArray = argumentsList.toTypedArray() - doRunCompiler(compilerClassName, argsArray, environment, messageCollector, collector) + doRunCompiler(compilerClassName, argsArray, environment) } catch (e: Throwable) { - MessageCollectorUtil.reportException(messageCollector, e) - reportInternalCompilerError(messageCollector) + MessageCollectorUtil.reportException(environment.messageCollector, e) + reportInternalCompilerError(environment.messageCollector) } } protected abstract fun doRunCompiler( compilerClassName: String, argsArray: Array, - environment: Env, - messageCollector: MessageCollector, - collector: OutputItemsCollector + environment: Env ): ExitCode /** @@ -144,12 +139,10 @@ abstract class KotlinCompilerRunner { compilerClassName: String, argsArray: Array, environment: Env, - messageCollector: MessageCollector, - collector: OutputItemsCollector, retryOnConnectionError: Boolean = true ): ExitCode? { log.debug("Try to connect to daemon") - val connection = getDaemonConnection(environment, messageCollector) + val connection = getDaemonConnection(environment) if (connection.daemon != null) { log.info("Connected to daemon") @@ -170,7 +163,7 @@ abstract class KotlinCompilerRunner { fun retryOrFalse(e: Exception): ExitCode? { if (retryOnConnectionError) { log.debug("retrying once on daemon connection error: ${e.message}") - return compileWithDaemon(compilerClassName, argsArray, environment, messageCollector, collector, retryOnConnectionError = false) + return compileWithDaemon(compilerClassName, argsArray, environment, retryOnConnectionError = false) } log.info("daemon connection error: ${e.message}") return null @@ -187,9 +180,9 @@ abstract class KotlinCompilerRunner { } val exitCode = exitCodeFromProcessExitCode(res) - processCompilerOutput(messageCollector, collector, compilerOut, exitCode) + processCompilerOutput(environment, compilerOut, exitCode) BufferedReader(StringReader(daemonOut.toString())).forEachLine { - messageCollector.report(CompilerMessageSeverity.INFO, it, CompilerMessageLocation.NO_LOCATION) + environment.messageCollector.report(CompilerMessageSeverity.INFO, it, CompilerMessageLocation.NO_LOCATION) } return exitCode } diff --git a/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/CompilerRunnerUtil.java b/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/CompilerRunnerUtil.java index ab4343f24ee..56996120bba 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/CompilerRunnerUtil.java +++ b/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/CompilerRunnerUtil.java @@ -74,10 +74,9 @@ public class CompilerRunnerUtil { @NotNull String compilerClassName, @NotNull String[] arguments, @NotNull JpsCompilerEnvironment environment, - @NotNull MessageCollector messageCollector, @NotNull PrintStream out ) throws Exception { - File libPath = getLibPath(environment.getKotlinPaths(), messageCollector); + File libPath = getLibPath(environment.getKotlinPaths(), environment.getMessageCollector()); if (libPath == null) return null; ClassLoader classLoader = getOrCreateClassLoader(environment, libPath); diff --git a/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsCompilerEnvironment.kt b/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsCompilerEnvironment.kt index dd35f5e1ad0..6e9ce4b2bd0 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsCompilerEnvironment.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsCompilerEnvironment.kt @@ -27,8 +27,10 @@ import org.jetbrains.kotlin.utils.PathUtil class JpsCompilerEnvironment( val kotlinPaths: KotlinPaths, services: Services, - val classesToLoadByParent: ClassCondition -) : CompilerEnvironment(services) { + val classesToLoadByParent: ClassCondition, + messageCollector: MessageCollector, + override val outputItemsCollector: OutputItemsCollectorImpl +) : CompilerEnvironment(services, messageCollector, outputItemsCollector) { fun success(): Boolean { return kotlinPaths.homePath.exists() } diff --git a/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinCompilerRunner.kt b/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinCompilerRunner.kt index ad0760629b2..2cfb0394f2d 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinCompilerRunner.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinCompilerRunner.kt @@ -44,24 +44,20 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner() { commonArguments: CommonCompilerArguments, k2jvmArguments: K2JVMCompilerArguments, compilerSettings: CompilerSettings, - messageCollector: MessageCollector, environment: JpsCompilerEnvironment, - moduleFile: File, - collector: OutputItemsCollector + moduleFile: File ) { val arguments = mergeBeans(commonArguments, k2jvmArguments) setupK2JvmArguments(moduleFile, arguments) - runCompiler(K2JVM_COMPILER, arguments, compilerSettings.additionalArguments, messageCollector, collector, environment) + runCompiler(K2JVM_COMPILER, arguments, compilerSettings.additionalArguments, environment) } fun runK2JsCompiler( commonArguments: CommonCompilerArguments, k2jsArguments: K2JSCompilerArguments, compilerSettings: CompilerSettings, - messageCollector: MessageCollector, environment: JpsCompilerEnvironment, - collector: OutputItemsCollector, sourceFiles: Collection, libraryFiles: List, outputFile: File @@ -69,27 +65,25 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner() { val arguments = mergeBeans(commonArguments, k2jsArguments) setupK2JsArguments(outputFile, sourceFiles, libraryFiles, arguments) - runCompiler(K2JS_COMPILER, arguments, compilerSettings.additionalArguments, messageCollector, collector, environment) + runCompiler(K2JS_COMPILER, arguments, compilerSettings.additionalArguments, environment) } - override fun doRunCompiler(compilerClassName: String, argsArray: Array, environment: JpsCompilerEnvironment, messageCollector: MessageCollector, collector: OutputItemsCollector): ExitCode { - messageCollector.report(CompilerMessageSeverity.INFO, "Using kotlin-home = " + environment.kotlinPaths.homePath, CompilerMessageLocation.NO_LOCATION) + override fun doRunCompiler(compilerClassName: String, argsArray: Array, environment: JpsCompilerEnvironment): ExitCode { + environment.messageCollector.report(CompilerMessageSeverity.INFO, "Using kotlin-home = " + environment.kotlinPaths.homePath, CompilerMessageLocation.NO_LOCATION) return if (isDaemonEnabled()) { - val daemonExitCode = compileWithDaemon(compilerClassName, argsArray, environment, messageCollector, collector) - daemonExitCode ?: fallbackCompileStrategy(argsArray, collector, compilerClassName, environment, messageCollector) + val daemonExitCode = compileWithDaemon(compilerClassName, argsArray, environment) + daemonExitCode ?: fallbackCompileStrategy(argsArray, compilerClassName, environment) } else { - fallbackCompileStrategy(argsArray, collector, compilerClassName, environment, messageCollector) + fallbackCompileStrategy(argsArray, compilerClassName, environment) } } private fun fallbackCompileStrategy( argsArray: Array, - collector: OutputItemsCollector, compilerClassName: String, - environment: JpsCompilerEnvironment, - messageCollector: MessageCollector + environment: JpsCompilerEnvironment ): ExitCode { // otherwise fallback to in-process log.info("Compile in-process") @@ -103,12 +97,12 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner() { if (System.getProperty(GlobalOptions.COMPILE_PARALLEL_OPTION, "false").toBoolean()) System.setProperty(KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY, "true") - val rc = CompilerRunnerUtil.invokeExecMethod(compilerClassName, argsArray, environment, messageCollector, out) + val rc = CompilerRunnerUtil.invokeExecMethod(compilerClassName, argsArray, environment, out) // exec() returns an ExitCode object, class of which is loaded with a different class loader, // so we take it's contents through reflection val exitCode = ExitCode.valueOf(getReturnCodeFromObject(rc)) - processCompilerOutput(messageCollector, collector, stream, exitCode) + processCompilerOutput(environment, stream, exitCode) return exitCode } @@ -140,14 +134,14 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner() { } @Synchronized - override fun getDaemonConnection(environment: JpsCompilerEnvironment, messageCollector: MessageCollector): DaemonConnection { + override fun getDaemonConnection(environment: JpsCompilerEnvironment): DaemonConnection { if (jpsDaemonConnection == null) { - val libPath = CompilerRunnerUtil.getLibPath(environment.kotlinPaths, messageCollector) + val libPath = CompilerRunnerUtil.getLibPath(environment.kotlinPaths, environment.messageCollector) val compilerPath = File(libPath, "kotlin-compiler.jar") val flagFile = File.createTempFile("kotlin-compiler-jps-session-", "-is-running").apply { deleteOnExit() } - newDaemonConnection(compilerPath, messageCollector, flagFile) + newDaemonConnection(compilerPath, flagFile, environment) } return jpsDaemonConnection!! } diff --git a/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt b/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt index 1b7a2106aac..239a0b8f472 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt @@ -205,7 +205,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) { val project = projectDescriptor.project val lookupTracker = getLookupTracker(project) val incrementalCaches = getIncrementalCaches(chunk, context) - val environment = createCompileEnvironment(incrementalCaches, lookupTracker, context) + val environment = createCompileEnvironment(incrementalCaches, lookupTracker, context, messageCollector) if (!environment.success()) { environment.reportErrorsTo(messageCollector) return ABORT @@ -238,7 +238,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) { LOG.info("Compiled successfully") } - val generatedFiles = getGeneratedFiles(chunk, outputItemCollector) + val generatedFiles = getGeneratedFiles(chunk, environment.outputItemsCollector) registerOutputItems(outputConsumer, generatedFiles) saveVersions(context, chunk) @@ -368,11 +368,11 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) { dirtyFilesHolder: DirtyFilesHolder, environment: JpsCompilerEnvironment, filesToCompile: MultiMap, incrementalCaches: Map>, messageCollector: MessageCollectorAdapter, project: JpsProject - ): OutputItemsCollectorImpl? { + ): OutputItemsCollector? { if (JpsUtils.isJsKotlinModule(chunk.representativeTarget())) { LOG.debug("Compiling to JS ${filesToCompile.values().size} files in ${filesToCompile.keySet().joinToString { it.presentableName }}") - return compileToJs(chunk, commonArguments, environment, messageCollector, project) + return compileToJs(chunk, commonArguments, environment, project) } if (IncrementalCompilation.isEnabled()) { @@ -402,13 +402,14 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) { ) } - return compileToJvm(allCompiledFiles, chunk, commonArguments, context, dirtyFilesHolder, environment, filesToCompile, messageCollector) + return compileToJvm(allCompiledFiles, chunk, commonArguments, context, dirtyFilesHolder, environment, filesToCompile) } private fun createCompileEnvironment( incrementalCaches: Map, lookupTracker: LookupTracker, - context: CompileContext + context: CompileContext, + messageCollector: MessageCollectorAdapter ): JpsCompilerEnvironment { val compilerServices = with(Services.Builder()) { register(IncrementalCompilationComponents::class.java, @@ -433,7 +434,9 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) { || className == "org.jetbrains.kotlin.progress.CompilationCanceledStatus" || className == "org.jetbrains.kotlin.progress.CompilationCanceledException" || className == "org.jetbrains.kotlin.modules.TargetId" - } + }, + messageCollector, + OutputItemsCollectorImpl() ) } @@ -585,16 +588,13 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) { private fun compileToJs(chunk: ModuleChunk, commonArguments: CommonCompilerArguments, environment: JpsCompilerEnvironment, - messageCollector: MessageCollectorAdapter, project: JpsProject - ): OutputItemsCollectorImpl? { - val outputItemCollector = OutputItemsCollectorImpl() - + ): OutputItemsCollector? { val representativeTarget = chunk.representativeTarget() if (chunk.modules.size > 1) { // We do not support circular dependencies, but if they are present, we do our best should not break the build, // so we simply yield a warning and report NOTHING_DONE - messageCollector.report( + environment.messageCollector.report( WARNING, "Circular dependencies are not supported. The following JS modules depend on each other: " + chunk.modules.map { it.name }.joinToString(", ") + ". " @@ -619,8 +619,8 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) { val k2JsArguments = JpsKotlinCompilerSettings.getK2JsCompilerArguments(representativeModule) val compilerRunner = JpsKotlinCompilerRunner() - compilerRunner.runK2JsCompiler(commonArguments, k2JsArguments, compilerSettings, messageCollector, environment, outputItemCollector, sourceFiles, libraryFiles, outputFile) - return outputItemCollector + compilerRunner.runK2JsCompiler(commonArguments, k2JsArguments, compilerSettings, environment, sourceFiles, libraryFiles, outputFile) + return environment.outputItemsCollector } private fun copyJsLibraryFilesIfNeeded(chunk: ModuleChunk, project: JpsProject) { @@ -642,12 +642,10 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) { context: CompileContext, dirtyFilesHolder: DirtyFilesHolder, environment: JpsCompilerEnvironment, - filesToCompile: MultiMap, messageCollector: MessageCollectorAdapter - ): OutputItemsCollectorImpl? { - val outputItemCollector = OutputItemsCollectorImpl() - + filesToCompile: MultiMap + ): OutputItemsCollector? { if (chunk.modules.size > 1) { - messageCollector.report( + environment.messageCollector.report( WARNING, "Circular dependencies are only partially supported. The following modules depend on each other: " + chunk.modules.map { it.name }.joinToString(", ") + ". " @@ -686,10 +684,10 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) { + " in " + filesToCompile.keySet().joinToString { it.presentableName }) val compilerRunner = JpsKotlinCompilerRunner() - compilerRunner.runK2JvmCompiler(commonArguments, k2JvmArguments, compilerSettings, messageCollector, environment, moduleFile, outputItemCollector) + compilerRunner.runK2JvmCompiler(commonArguments, k2JvmArguments, compilerSettings, environment, moduleFile) moduleFile.delete() - return outputItemCollector + return environment.outputItemsCollector } class MessageCollectorAdapter(private val context: CompileContext) : MessageCollector { diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleCompilerEnvironment.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleCompilerEnvironment.kt index 1e9a062071c..7fcf9a1d396 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleCompilerEnvironment.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleCompilerEnvironment.kt @@ -1,12 +1,15 @@ package org.jetbrains.kotlin.compilerRunner +import org.jetbrains.kotlin.cli.common.messages.MessageCollector import org.jetbrains.kotlin.config.Services import java.io.File import java.net.URL internal class GradleCompilerEnvironment( - val compilerJar: File -) : CompilerEnvironment(Services.EMPTY) { + val compilerJar: File, + messageCollector: MessageCollector, + outputItemsCollector: OutputItemsCollector +) : CompilerEnvironment(Services.EMPTY, messageCollector, outputItemsCollector) { val compilerClasspath: List get() = listOf(compilerJar).filterNotNull() diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleKotlinCompilerRunner.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleKotlinCompilerRunner.kt index 81dd0579ff8..da6259381e0 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleKotlinCompilerRunner.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleKotlinCompilerRunner.kt @@ -55,13 +55,11 @@ internal class GradleCompilerRunner(private val project: Project) : KotlinCompil sourcesToCompile: List, javaSourceRoots: Iterable, args: K2JVMCompilerArguments, - messageCollector: MessageCollector, - outputItemsCollector: OutputItemsCollector, - kotlinCompilerJar: File + environment: GradleCompilerEnvironment ): ExitCode { val outputDir = args.destinationAsFile log.debug("Removing all kotlin classes in $outputDir") - log.info("Using kotlin compiler jar: $kotlinCompilerJar") + log.info("Using kotlin compiler jar: ${environment.compilerJar}") // we're free to delete all classes since only we know about that directory outputDir.deleteRecursively() @@ -79,7 +77,7 @@ internal class GradleCompilerRunner(private val project: Project) : KotlinCompil val additionalArguments = "" try { - return runCompiler(K2JVM_COMPILER, args, additionalArguments, messageCollector, outputItemsCollector, GradleCompilerEnvironment(kotlinCompilerJar)) + return runCompiler(K2JVM_COMPILER, args, additionalArguments, environment) } finally { moduleFile.delete() @@ -89,15 +87,13 @@ internal class GradleCompilerRunner(private val project: Project) : KotlinCompil fun runJsCompiler( kotlinSources: List, args: K2JSCompilerArguments, - messageCollector: MessageCollector, - outputItemsCollector: OutputItemsCollector, - kotlinCompilerJar: File + environment: GradleCompilerEnvironment ): ExitCode { val additionalArguments = kotlinSources.joinToString(separator = " ") { it.absolutePath } - return runCompiler(K2JS_COMPILER, args, additionalArguments, messageCollector, outputItemsCollector, GradleCompilerEnvironment(kotlinCompilerJar)) + return runCompiler(K2JS_COMPILER, args, additionalArguments, environment) } - override fun doRunCompiler(compilerClassName: String, argsArray: Array, environment: GradleCompilerEnvironment, messageCollector: MessageCollector, collector: OutputItemsCollector): ExitCode { + override fun doRunCompiler(compilerClassName: String, argsArray: Array, environment: GradleCompilerEnvironment): ExitCode { with (project.logger) { kotlinDebug { "Kotlin compiler class: $compilerClassName" } kotlinDebug { "Kotlin compiler jar: ${environment.compilerJar}" } @@ -106,7 +102,7 @@ internal class GradleCompilerRunner(private val project: Project) : KotlinCompil val executionStrategy = System.getProperty(KOTLIN_COMPILER_EXECUTION_STRATEGY_PROPERTY) ?: DAEMON_EXECUTION_STRATEGY if (executionStrategy == DAEMON_EXECUTION_STRATEGY) { - val daemonExitCode = compileWithDaemon(compilerClassName, argsArray, environment, messageCollector, collector) + val daemonExitCode = compileWithDaemon(compilerClassName, argsArray, environment) if (daemonExitCode != null) { return daemonExitCode @@ -118,15 +114,15 @@ internal class GradleCompilerRunner(private val project: Project) : KotlinCompil val isGradleDaemonUsed = System.getProperty("org.gradle.daemon")?.let(String::toBoolean) return if (executionStrategy == IN_PROCESS_EXECUTION_STRATEGY || isGradleDaemonUsed == false) { - compileInProcess(argsArray, collector, compilerClassName, environment, messageCollector) + compileInProcess(argsArray, compilerClassName, environment) } else { compileOutOfProcess(argsArray, compilerClassName, environment) } } - override fun compileWithDaemon(compilerClassName: String, argsArray: Array, environment: GradleCompilerEnvironment, messageCollector: MessageCollector, collector: OutputItemsCollector, retryOnConnectionError: Boolean): ExitCode? { - val exitCode = super.compileWithDaemon(compilerClassName, argsArray, environment, messageCollector, collector, retryOnConnectionError) + override fun compileWithDaemon(compilerClassName: String, argsArray: Array, environment: GradleCompilerEnvironment, retryOnConnectionError: Boolean): ExitCode? { + val exitCode = super.compileWithDaemon(compilerClassName, argsArray, environment, retryOnConnectionError) exitCode?.let { logFinish(DAEMON_EXECUTION_STRATEGY) } @@ -162,10 +158,8 @@ internal class GradleCompilerRunner(private val project: Project) : KotlinCompil private fun compileInProcess( argsArray: Array, - collector: OutputItemsCollector, compilerClassName: String, - environment: GradleCompilerEnvironment, - messageCollector: MessageCollector + environment: GradleCompilerEnvironment ): ExitCode { val stream = ByteArrayOutputStream() val out = PrintStream(stream) @@ -184,7 +178,7 @@ internal class GradleCompilerRunner(private val project: Project) : KotlinCompil val res = exec.invoke(compiler.newInstance(), out, emptyServices, argsArray) val exitCode = ExitCode.valueOf(res.toString()) - processCompilerOutput(messageCollector, collector, stream, exitCode) + processCompilerOutput(environment, stream, exitCode) logFinish(IN_PROCESS_EXECUTION_STRATEGY) return exitCode } @@ -194,8 +188,8 @@ internal class GradleCompilerRunner(private val project: Project) : KotlinCompil } @Synchronized - override fun getDaemonConnection(environment: GradleCompilerEnvironment, messageCollector: MessageCollector): DaemonConnection { - return newDaemonConnection(environment.compilerJar, messageCollector, flagFile) + override fun getDaemonConnection(environment: GradleCompilerEnvironment): DaemonConnection { + return newDaemonConnection(environment.compilerJar, flagFile, environment) } } diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt index c2435448c8d..87e88cd0863 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt @@ -39,6 +39,7 @@ import org.jetbrains.kotlin.cli.common.messages.MessageCollector import org.jetbrains.kotlin.cli.js.K2JSCompiler import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler import org.jetbrains.kotlin.compilerRunner.ArgumentUtils +import org.jetbrains.kotlin.compilerRunner.GradleCompilerEnvironment import org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner import org.jetbrains.kotlin.compilerRunner.OutputItemsCollectorImpl import org.jetbrains.kotlin.gradle.dsl.* @@ -209,8 +210,8 @@ open class KotlinCompile : AbstractKotlinCompile(), Kotl if (!incremental) { anyClassesCompiled = true val compilerRunner = GradleCompilerRunner(project) - val exitCode = compilerRunner.runJvmCompiler(sourceRoots.kotlinSourceFiles, sourceRoots.javaSourceRoots, args, messageCollector, - outputItemCollector, compilerJar) + val environment = GradleCompilerEnvironment(compilerJar, messageCollector, outputItemCollector) + val exitCode = compilerRunner.runJvmCompiler(sourceRoots.kotlinSourceFiles, sourceRoots.javaSourceRoots, args, environment) processCompilerExitCode(exitCode) return } @@ -376,7 +377,8 @@ open class Kotlin2JsCompile() : AbstractKotlinCompile(), val outputItemCollector = OutputItemsCollectorImpl() val compilerRunner = GradleCompilerRunner(project) - val exitCode = compilerRunner.runJsCompiler(sourceRoots.kotlinSourceFiles, args, messageCollector, outputItemCollector, compilerJar) + val environment = GradleCompilerEnvironment(compilerJar, messageCollector, outputItemCollector) + val exitCode = compilerRunner.runJsCompiler(sourceRoots.kotlinSourceFiles, args, environment) when (exitCode) { ExitCode.OK -> {