Report messages from kapt using MessageCollector
This allows to print messages when daemon is used. System out is not copied to daemon client, because multiple compilations can occur in parallel.
This commit is contained in:
@@ -20,6 +20,9 @@ import com.intellij.mock.MockProject
|
||||
import com.intellij.openapi.extensions.Extensions
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.analyzer.AnalysisResult
|
||||
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageRenderer
|
||||
import org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector
|
||||
import org.jetbrains.kotlin.kapt3.Kapt3ConfigurationKeys.ANNOTATION_PROCESSOR_CLASSPATH
|
||||
import org.jetbrains.kotlin.kapt3.Kapt3ConfigurationKeys.APT_OPTIONS
|
||||
import org.jetbrains.kotlin.cli.jvm.config.JavaSourceRoot
|
||||
@@ -132,7 +135,10 @@ class Kapt3ComponentRegistrar : ComponentRegistrar {
|
||||
override fun registerProjectComponents(project: MockProject, configuration: CompilerConfiguration) {
|
||||
val isAptOnly = configuration.get(Kapt3ConfigurationKeys.APT_ONLY) == "true"
|
||||
val isVerbose = configuration.get(Kapt3ConfigurationKeys.VERBOSE_MODE) == "true"
|
||||
val logger = KaptLogger(isVerbose)
|
||||
val messageCollector = configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
|
||||
?: PrintingMessageCollector(System.err, MessageRenderer.PLAIN_FULL_PATHS, isVerbose)
|
||||
val logger = KaptLogger(isVerbose, messageCollector)
|
||||
|
||||
|
||||
val sourcesOutputDir = configuration.get(Kapt3ConfigurationKeys.SOURCE_OUTPUT_DIR)?.let(::File)
|
||||
val classFilesOutputDir = configuration.get(Kapt3ConfigurationKeys.CLASS_OUTPUT_DIR)?.let(::File)
|
||||
|
||||
@@ -16,14 +16,20 @@
|
||||
|
||||
package org.jetbrains.kotlin.kapt3.util
|
||||
|
||||
class KaptLogger(val isVerbose: Boolean) {
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.PrintWriter
|
||||
|
||||
class KaptLogger(val isVerbose: Boolean, val messageCollector: MessageCollector) {
|
||||
private companion object {
|
||||
val PREFIX = "[kapt] "
|
||||
}
|
||||
|
||||
fun info(message: String) {
|
||||
if (isVerbose) {
|
||||
println(PREFIX + message)
|
||||
messageCollector.report(CompilerMessageSeverity.INFO, PREFIX + message, CompilerMessageLocation.NO_LOCATION)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,11 +44,16 @@ class KaptLogger(val isVerbose: Boolean) {
|
||||
}
|
||||
|
||||
fun error(message: String) {
|
||||
System.err.println(PREFIX + message)
|
||||
messageCollector.report(CompilerMessageSeverity.ERROR, PREFIX + message, CompilerMessageLocation.NO_LOCATION)
|
||||
}
|
||||
|
||||
fun exception(e: Throwable) {
|
||||
System.err.println(PREFIX + "An exception occurred:")
|
||||
e.printStackTrace(System.err)
|
||||
val stacktrace = run {
|
||||
val byteArrayOutputStream = ByteArrayOutputStream()
|
||||
e.printStackTrace(PrintWriter(byteArrayOutputStream))
|
||||
byteArrayOutputStream.toString("UTF-8")
|
||||
}
|
||||
messageCollector.report(CompilerMessageSeverity.EXCEPTION, PREFIX + "An exception occurred: " + stacktrace, CompilerMessageLocation.NO_LOCATION)
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user