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:
+13
-5
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.analyzer.AnalysisResult
|
||||
import org.jetbrains.kotlin.annotation.processing.RoundAnnotations
|
||||
import org.jetbrains.kotlin.annotation.processing.diagnostic.ErrorsAnnotationProcessing
|
||||
import org.jetbrains.kotlin.annotation.processing.impl.*
|
||||
import org.jetbrains.kotlin.cli.common.messages.*
|
||||
import org.jetbrains.kotlin.codegen.ClassBuilderMode
|
||||
import org.jetbrains.kotlin.codegen.state.IncompatibleClassTracker
|
||||
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper
|
||||
@@ -55,10 +56,11 @@ class ClasspathBasedAnnotationProcessingExtension(
|
||||
classesOutputDir: File,
|
||||
javaSourceRoots: List<File>,
|
||||
verboseOutput: Boolean,
|
||||
incrementalDataFile: File?
|
||||
incrementalDataFile: File?,
|
||||
messageCollector: MessageCollector?
|
||||
) : AbstractAnnotationProcessingExtension(generatedSourcesOutputDir,
|
||||
classesOutputDir, javaSourceRoots, verboseOutput,
|
||||
incrementalDataFile) {
|
||||
incrementalDataFile, messageCollector) {
|
||||
override fun loadAnnotationProcessors(): List<Processor> {
|
||||
val classLoader = URLClassLoader(annotationProcessingClasspath.map { it.toURI().toURL() }.toTypedArray())
|
||||
return ServiceLoader.load(Processor::class.java, classLoader).toList()
|
||||
@@ -70,17 +72,23 @@ abstract class AbstractAnnotationProcessingExtension(
|
||||
val classesOutputDir: File,
|
||||
val javaSourceRoots: List<File>,
|
||||
val verboseOutput: Boolean,
|
||||
val incrementalDataFile: File? = null
|
||||
val incrementalDataFile: File? = null,
|
||||
messageCollector: MessageCollector? = null
|
||||
) : AnalysisHandlerExtension {
|
||||
private companion object {
|
||||
val LINE_SEPARATOR = System.getProperty("line.separator") ?: "\n"
|
||||
}
|
||||
|
||||
private var annotationProcessingComplete = false
|
||||
private val messager = KotlinMessager()
|
||||
private val messager = run {
|
||||
val collector = messageCollector ?: PrintingMessageCollector(System.err, MessageRenderer.WITHOUT_PATHS, verboseOutput)
|
||||
KotlinMessager(collector)
|
||||
}
|
||||
|
||||
private inline fun log(message: () -> String) {
|
||||
if (verboseOutput) messager.printMessage(Diagnostic.Kind.OTHER, "Kapt: " + message())
|
||||
if (verboseOutput) {
|
||||
messager.printMessage(Diagnostic.Kind.OTHER, "Kapt: " + message())
|
||||
}
|
||||
}
|
||||
|
||||
private fun Int.count(noun: String) = if (this == 1) "$this $noun" else "$this ${noun}s"
|
||||
|
||||
+4
-1
@@ -37,6 +37,7 @@ import java.io.File
|
||||
|
||||
import org.jetbrains.kotlin.annotation.processing.AnnotationProcessingConfigurationKeys.ANNOTATION_PROCESSOR_CLASSPATH
|
||||
import org.jetbrains.kotlin.annotation.processing.AnnotationProcessingConfigurationKeys.APT_OPTIONS
|
||||
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
||||
|
||||
object AnnotationProcessingConfigurationKeys {
|
||||
val GENERATED_OUTPUT_DIR: CompilerConfigurationKey<String> =
|
||||
@@ -142,9 +143,11 @@ class AnnotationProcessingComponentRegistrar : ComponentRegistrar {
|
||||
// Annotations with the "SOURCE" retention will be written to class files
|
||||
project.putUserData(IS_KAPT2_ENABLED_KEY, true)
|
||||
|
||||
val messageCollector = configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
|
||||
|
||||
val annotationProcessingExtension = ClasspathBasedAnnotationProcessingExtension(
|
||||
classpath, apOptions, generatedOutputDirFile, classesOutputDir, javaRoots, verboseOutput,
|
||||
incrementalDataFile)
|
||||
incrementalDataFile, messageCollector)
|
||||
|
||||
project.registerService(JeElementRegistry::class.java, JeElementRegistry())
|
||||
|
||||
|
||||
+9
-6
@@ -16,6 +16,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.annotation.processing.impl
|
||||
|
||||
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 javax.annotation.processing.Messager
|
||||
import javax.lang.model.element.AnnotationMirror
|
||||
import javax.lang.model.element.AnnotationValue
|
||||
@@ -23,7 +26,7 @@ import javax.lang.model.element.Element
|
||||
import javax.tools.Diagnostic
|
||||
import javax.tools.Diagnostic.Kind
|
||||
|
||||
class KotlinMessager : Messager {
|
||||
class KotlinMessager(private val messageCollector: MessageCollector) : Messager {
|
||||
var errorCount: Int = 0
|
||||
private set
|
||||
|
||||
@@ -39,17 +42,17 @@ class KotlinMessager : Messager {
|
||||
}
|
||||
|
||||
override fun printMessage(kind: Diagnostic.Kind, msg: CharSequence, e: Element?, a: AnnotationMirror?, v: AnnotationValue?) {
|
||||
val output = when (kind) {
|
||||
val severity = when (kind) {
|
||||
Kind.ERROR -> {
|
||||
errorCount++
|
||||
System.err
|
||||
CompilerMessageSeverity.ERROR
|
||||
}
|
||||
Kind.WARNING, Kind.MANDATORY_WARNING -> {
|
||||
warningCount++
|
||||
System.err
|
||||
CompilerMessageSeverity.WARNING
|
||||
}
|
||||
else -> System.out
|
||||
else -> CompilerMessageSeverity.LOGGING
|
||||
}
|
||||
output.println(msg)
|
||||
messageCollector.report(severity, msg.toString(), CompilerMessageLocation.NO_LOCATION)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user