Refactor messages sending

Original commit: 16352ff2e5
This commit is contained in:
Alexey Tsvetkov
2017-01-12 16:16:56 +03:00
parent 8571c2086e
commit 9594031126
3 changed files with 43 additions and 38 deletions
+1
View File
@@ -20,5 +20,6 @@
<orderEntry type="module" module-name="daemon-client" />
<orderEntry type="module" module-name="daemon-common" />
<orderEntry type="library" scope="TEST" name="kotlin-test" level="project" />
<orderEntry type="module" module-name="daemon" />
</component>
</module>
@@ -19,9 +19,7 @@ package org.jetbrains.kotlin.compilerRunner
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.daemon.client.CompilerCallbackServicesFacadeServer
import org.jetbrains.kotlin.daemon.common.JpsCompilerServicesFacade
import org.jetbrains.kotlin.daemon.common.ReportCategory
import org.jetbrains.kotlin.daemon.common.SOCKET_ANY_FREE_PORT
import org.jetbrains.kotlin.daemon.common.*
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents
import org.jetbrains.kotlin.progress.CompilationCanceledStatus
import java.io.Serializable
@@ -34,20 +32,26 @@ internal class JpsCompilerServicesFacadeImpl(
port),
JpsCompilerServicesFacade {
override fun report(category: ReportCategory, severity: Int, message: String?, attachment: Serializable?) {
when (category) {
override fun report(category: Int, severity: Int, message: String?, attachment: Serializable?) {
val reportCategory = ReportCategory.fromCode(category)
when (reportCategory) {
ReportCategory.OUTPUT_MESSAGE -> {
env.messageCollector.report(CompilerMessageSeverity.OUTPUT, message!!, CompilerMessageLocation.NO_LOCATION)
}
ReportCategory.COMPILER_MESSAGE -> {
val compilerMessageSeverity = CompilerMessageSeverity.values().firstOrNull { it.value == severity }
if (compilerMessageSeverity != null) {
val location = attachment as? CompilerMessageLocation ?: CompilerMessageLocation.NO_LOCATION
env.messageCollector.report(compilerMessageSeverity, message!!, location)
val compilerMessageAttachment = attachment as? CompilerMessageAttachment
if (message != null && compilerMessageAttachment != null) {
val originalSeverity = compilerMessageAttachment.severity
val originalLocation = compilerMessageAttachment.location
env.messageCollector.report(originalSeverity, message, originalLocation)
}
else {
reportUnexpected(category, severity, message, attachment)
}
}
ReportCategory.DAEMON_MESSAGE,
ReportCategory.INCREMENTAL_COMPILATION -> {
ReportCategory.IC_MESSAGE -> {
if (message != null) {
env.messageCollector.report(CompilerMessageSeverity.LOGGING, message, CompilerMessageLocation.NO_LOCATION)
}
@@ -61,8 +65,15 @@ internal class JpsCompilerServicesFacadeImpl(
}
}
private fun reportUnexpected(category: ReportCategory, severity: Int, message: String?, attachment: Serializable?) {
env.messageCollector.report(CompilerMessageSeverity.LOGGING,
private fun reportUnexpected(category: Int, severity: Int, message: String?, attachment: Serializable?) {
val compilerMessageSeverity = when (ReportSeverity.fromCode(severity)) {
ReportSeverity.ERROR -> CompilerMessageSeverity.ERROR
ReportSeverity.WARNING -> CompilerMessageSeverity.WARNING
ReportSeverity.INFO -> CompilerMessageSeverity.INFO
else -> CompilerMessageSeverity.LOGGING
}
env.messageCollector.report(compilerMessageSeverity,
"Unexpected message: category=$category; severity=$severity; message='$message'; attachment=$attachment",
CompilerMessageLocation.NO_LOCATION)
}
@@ -28,6 +28,8 @@ import org.jetbrains.kotlin.jps.build.KotlinBuilder
import java.io.ByteArrayOutputStream
import java.io.File
import java.io.PrintStream
import java.io.Serializable
import java.rmi.server.UnicastRemoteObject
import java.util.*
class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
@@ -99,39 +101,30 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
}
val res = withDaemon(environment, retryOnConnectionError = true) { daemon, sessionId ->
val options = CompilationOptions(CompileService.CompilerMode.JPS_COMPILER,
targetPlatform,
reportingFilters = getReportingFilters(compilerArgs.verbose))
daemon.compile(sessionId, compilerArgs, options, JpsCompilerServicesFacadeImpl(environment))
val compilerMode = CompileService.CompilerMode.JPS_COMPILER
val verbose = compilerArgs.verbose
val options = CompilationOptions(compilerMode, targetPlatform, reportCategories(verbose), reportSeverity(verbose), requestedCompilationResults = emptyArray())
daemon.compile(sessionId, compilerArgs, options, JpsCompilerServicesFacadeImpl(environment), null)
}
return res?.get()?.let { exitCodeFromProcessExitCode(it) }
}
private fun getReportingFilters(verbose: Boolean): List<ReportingFilter> {
val result = ArrayList<ReportingFilter>()
val compilerMessagesSeverities = ArrayList<Int>().apply {
add(CompilerMessageSeverity.ERROR.value)
add(CompilerMessageSeverity.EXCEPTION.value)
add(CompilerMessageSeverity.WARNING.value)
add(CompilerMessageSeverity.INFO.value)
add(CompilerMessageSeverity.OUTPUT.value)
if (verbose) {
add(CompilerMessageSeverity.LOGGING.value)
private fun reportCategories(verbose: Boolean): Array<Int> =
if (!verbose) {
arrayOf(ReportCategory.COMPILER_MESSAGE.code)
}
else {
ReportCategory.values().map { it.code }.toTypedArray()
}
}
if (verbose) {
result.add(ReportingFilter(ReportCategory.DAEMON_MESSAGE, emptyList()))
}
val compilerMessagesFilter = ReportingFilter(ReportCategory.COMPILER_MESSAGE, compilerMessagesSeverities)
result.add(compilerMessagesFilter)
return result
}
private fun reportSeverity(verbose: Boolean): Int =
if (!verbose) {
ReportSeverity.INFO.code
}
else {
ReportSeverity.DEBUG.code
}
private fun fallbackCompileStrategy(
argsArray: Array<String>,