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-client" />
<orderEntry type="module" module-name="daemon-common" /> <orderEntry type="module" module-name="daemon-common" />
<orderEntry type="library" scope="TEST" name="kotlin-test" level="project" /> <orderEntry type="library" scope="TEST" name="kotlin-test" level="project" />
<orderEntry type="module" module-name="daemon" />
</component> </component>
</module> </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.CompilerMessageLocation
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.daemon.client.CompilerCallbackServicesFacadeServer import org.jetbrains.kotlin.daemon.client.CompilerCallbackServicesFacadeServer
import org.jetbrains.kotlin.daemon.common.JpsCompilerServicesFacade import org.jetbrains.kotlin.daemon.common.*
import org.jetbrains.kotlin.daemon.common.ReportCategory
import org.jetbrains.kotlin.daemon.common.SOCKET_ANY_FREE_PORT
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents
import org.jetbrains.kotlin.progress.CompilationCanceledStatus import org.jetbrains.kotlin.progress.CompilationCanceledStatus
import java.io.Serializable import java.io.Serializable
@@ -34,20 +32,26 @@ internal class JpsCompilerServicesFacadeImpl(
port), port),
JpsCompilerServicesFacade { JpsCompilerServicesFacade {
override fun report(category: ReportCategory, severity: Int, message: String?, attachment: Serializable?) { override fun report(category: Int, severity: Int, message: String?, attachment: Serializable?) {
when (category) { val reportCategory = ReportCategory.fromCode(category)
when (reportCategory) {
ReportCategory.OUTPUT_MESSAGE -> {
env.messageCollector.report(CompilerMessageSeverity.OUTPUT, message!!, CompilerMessageLocation.NO_LOCATION)
}
ReportCategory.COMPILER_MESSAGE -> { ReportCategory.COMPILER_MESSAGE -> {
val compilerMessageSeverity = CompilerMessageSeverity.values().firstOrNull { it.value == severity } val compilerMessageAttachment = attachment as? CompilerMessageAttachment
if (compilerMessageSeverity != null) { if (message != null && compilerMessageAttachment != null) {
val location = attachment as? CompilerMessageLocation ?: CompilerMessageLocation.NO_LOCATION val originalSeverity = compilerMessageAttachment.severity
env.messageCollector.report(compilerMessageSeverity, message!!, location) val originalLocation = compilerMessageAttachment.location
env.messageCollector.report(originalSeverity, message, originalLocation)
} }
else { else {
reportUnexpected(category, severity, message, attachment) reportUnexpected(category, severity, message, attachment)
} }
} }
ReportCategory.DAEMON_MESSAGE, ReportCategory.DAEMON_MESSAGE,
ReportCategory.INCREMENTAL_COMPILATION -> { ReportCategory.IC_MESSAGE -> {
if (message != null) { if (message != null) {
env.messageCollector.report(CompilerMessageSeverity.LOGGING, message, CompilerMessageLocation.NO_LOCATION) 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?) { private fun reportUnexpected(category: Int, severity: Int, message: String?, attachment: Serializable?) {
env.messageCollector.report(CompilerMessageSeverity.LOGGING, 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", "Unexpected message: category=$category; severity=$severity; message='$message'; attachment=$attachment",
CompilerMessageLocation.NO_LOCATION) CompilerMessageLocation.NO_LOCATION)
} }
@@ -28,6 +28,8 @@ import org.jetbrains.kotlin.jps.build.KotlinBuilder
import java.io.ByteArrayOutputStream import java.io.ByteArrayOutputStream
import java.io.File import java.io.File
import java.io.PrintStream import java.io.PrintStream
import java.io.Serializable
import java.rmi.server.UnicastRemoteObject
import java.util.* import java.util.*
class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() { class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
@@ -99,39 +101,30 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
} }
val res = withDaemon(environment, retryOnConnectionError = true) { daemon, sessionId -> val res = withDaemon(environment, retryOnConnectionError = true) { daemon, sessionId ->
val options = CompilationOptions(CompileService.CompilerMode.JPS_COMPILER, val compilerMode = CompileService.CompilerMode.JPS_COMPILER
targetPlatform, val verbose = compilerArgs.verbose
reportingFilters = getReportingFilters(compilerArgs.verbose)) val options = CompilationOptions(compilerMode, targetPlatform, reportCategories(verbose), reportSeverity(verbose), requestedCompilationResults = emptyArray())
daemon.compile(sessionId, compilerArgs, options, JpsCompilerServicesFacadeImpl(environment)) daemon.compile(sessionId, compilerArgs, options, JpsCompilerServicesFacadeImpl(environment), null)
} }
return res?.get()?.let { exitCodeFromProcessExitCode(it) } return res?.get()?.let { exitCodeFromProcessExitCode(it) }
} }
private fun getReportingFilters(verbose: Boolean): List<ReportingFilter> { private fun reportCategories(verbose: Boolean): Array<Int> =
val result = ArrayList<ReportingFilter>() if (!verbose) {
arrayOf(ReportCategory.COMPILER_MESSAGE.code)
val compilerMessagesSeverities = ArrayList<Int>().apply { }
add(CompilerMessageSeverity.ERROR.value) else {
add(CompilerMessageSeverity.EXCEPTION.value) ReportCategory.values().map { it.code }.toTypedArray()
add(CompilerMessageSeverity.WARNING.value)
add(CompilerMessageSeverity.INFO.value)
add(CompilerMessageSeverity.OUTPUT.value)
if (verbose) {
add(CompilerMessageSeverity.LOGGING.value)
} }
}
if (verbose) { private fun reportSeverity(verbose: Boolean): Int =
result.add(ReportingFilter(ReportCategory.DAEMON_MESSAGE, emptyList())) if (!verbose) {
} ReportSeverity.INFO.code
}
val compilerMessagesFilter = ReportingFilter(ReportCategory.COMPILER_MESSAGE, compilerMessagesSeverities) else {
result.add(compilerMessagesFilter) ReportSeverity.DEBUG.code
}
return result
}
private fun fallbackCompileStrategy( private fun fallbackCompileStrategy(
argsArray: Array<String>, argsArray: Array<String>,