Refactoring: pass MessageCollector, OutputItemsCollector in CompilerEnvironment
This commit is contained in:
+5
-2
@@ -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<File>
|
||||
get() = listOf(compilerJar).filterNotNull()
|
||||
|
||||
|
||||
+14
-20
@@ -55,13 +55,11 @@ internal class GradleCompilerRunner(private val project: Project) : KotlinCompil
|
||||
sourcesToCompile: List<File>,
|
||||
javaSourceRoots: Iterable<File>,
|
||||
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<File>,
|
||||
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<String>, environment: GradleCompilerEnvironment, messageCollector: MessageCollector, collector: OutputItemsCollector): ExitCode {
|
||||
override fun doRunCompiler(compilerClassName: String, argsArray: Array<String>, 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<String>, 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<String>, 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<String>,
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-3
@@ -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<K2JVMCompilerArguments>(), 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<K2JSCompilerArguments>(),
|
||||
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 -> {
|
||||
|
||||
Reference in New Issue
Block a user