Improve messages printed by JPS plugin in Messages view

- Don't print "Loaded plugin: KotlinAndroidJpsPlugin" and "Using
  kotlin-home = ..." for every build. They are rarely useful; they can
  be found in the build log now
- Instead of potentially confusing for the user "Kotlin JPS plugin
  version ..." output simply "Kotlin version ...". Also add the version
  of the JRE, where the compiler is being run
- Do not treat messages reported with severity LOGGING as BuildMessage
  with kind PROGRESS. Such build messages are displayed to the user in
  the progress/status bar when IDEA Make process is running, but LOGGING
  messages never had this meaning. In particular, users could be
  confused by the progress bar message "Kotlin: Configuring the
  compilation environment" visible for a very long time during
  compilation. This message just happens to be the last LOGGING message
  reported by the compiler before the actual compilation; its presence
  there created an illusion that Kotlin spends most of the time
  configuring the compilation environment

 #KT-17387 Fixed
This commit is contained in:
Alexander Udalov
2017-04-06 19:40:50 +03:00
parent d8d3bafbe9
commit bb01ca038a
3 changed files with 30 additions and 22 deletions
@@ -732,13 +732,15 @@ class KotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() {
assertFilesExistInOutput(module, "foo/Bar.class")
val buildResult = BuildResult()
val canceledStatus = object: CanceledStatus {
val canceledStatus = object : CanceledStatus {
var checkFromIndex = 0
override fun isCanceled(): Boolean {
val messages = buildResult.getMessages(BuildMessage.Kind.INFO)
for (i in checkFromIndex..messages.size - 1) {
if (messages.get(i).messageText.startsWith("Kotlin JPS plugin version")) return true
if (messages[i].messageText.matches("kotlinc-jvm .+ \\(JRE .+\\)".toRegex())) {
return true
}
}
checkFromIndex = messages.size
@@ -749,8 +751,6 @@ class KotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() {
touch("src/Bar.kt").apply()
buildCustom(canceledStatus, TestProjectBuilderLogger(), buildResult)
assertCanceled(buildResult)
assertFilesNotExistInOutput(module, "foo/Bar.class")
}
fun testFileDoesNotExistWarning() {
@@ -21,7 +21,6 @@ import org.jetbrains.jps.api.GlobalOptions
import org.jetbrains.kotlin.cli.common.ExitCode
import org.jetbrains.kotlin.cli.common.KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY
import org.jetbrains.kotlin.cli.common.arguments.*
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.config.CompilerSettings
import org.jetbrains.kotlin.config.additionalArgumentsAsList
import org.jetbrains.kotlin.daemon.client.CompileServiceSession
@@ -104,7 +103,7 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
compilerArgs: CommonCompilerArguments,
environment: JpsCompilerEnvironment
): ExitCode {
environment.messageCollector.report(CompilerMessageSeverity.INFO, "Using kotlin-home = " + environment.kotlinPaths.homePath)
log.debug("Using kotlin-home = " + environment.kotlinPaths.homePath)
return if (isDaemonEnabled()) {
val daemonExitCode = compileWithDaemon(compilerClassName, compilerArgs, environment)
@@ -230,7 +230,9 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
return NOTHING_DONE
}
messageCollector.report(INFO, "Kotlin JPS plugin version " + KotlinCompilerVersion.VERSION)
messageCollector.report(
INFO, "Kotlin version " + KotlinCompilerVersion.VERSION + " (JRE " + System.getProperty("java.runtime.version") + ")"
)
val targetsWithoutOutputDir = targets.filter { it.outputDir == null }
if (targetsWithoutOutputDir.isNotEmpty()) {
@@ -258,7 +260,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
val start = System.nanoTime()
val outputItemCollector = doCompileModuleChunk(allCompiledFiles, chunk, commonArguments, context, dirtyFilesHolder,
environment, filesToCompile, incrementalCaches, messageCollector, project)
environment, filesToCompile, incrementalCaches, project)
statisticsLogger.registerStatistic(chunk, System.nanoTime() - start)
@@ -416,7 +418,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
allCompiledFiles: MutableSet<File>, chunk: ModuleChunk, commonArguments: CommonCompilerArguments, context: CompileContext,
dirtyFilesHolder: DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget>, environment: JpsCompilerEnvironment,
filesToCompile: MultiMap<ModuleBuildTarget, File>, incrementalCaches: Map<ModuleBuildTarget, IncrementalCacheImpl<*>>,
messageCollector: MessageCollectorAdapter, project: JpsProject
project: JpsProject
): OutputItemsCollector? {
if (JpsUtils.isJsKotlinModule(chunk.representativeTarget())) {
@@ -434,7 +436,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
val representativeTarget = chunk.representativeTarget()
fun concatenate(strings: Array<String>?, cp: List<String>) = arrayOf(*(strings ?: emptyArray()), *cp.toTypedArray())
fun concatenate(strings: Array<String>?, cp: List<String>) = arrayOf(*strings.orEmpty(), *cp.toTypedArray())
for (argumentProvider in ServiceLoader.load(KotlinJpsCompilerArgumentsProvider::class.java)) {
// appending to pluginOptions
@@ -444,7 +446,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
commonArguments.pluginClasspaths = concatenate(commonArguments.pluginClasspaths,
argumentProvider.getClasspath(representativeTarget, context))
messageCollector.report(INFO, "Plugin loaded: ${argumentProvider::class.java.simpleName}")
LOG.debug("Plugin loaded: ${argumentProvider::class.java.simpleName}")
}
return compileToJvm(allCompiledFiles, chunk, commonArguments, context, dirtyFilesHolder, environment, filesToCompile)
@@ -742,15 +744,22 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
if (severity == EXCEPTION) {
prefix = INTERNAL_ERROR_PREFIX
}
context.processMessage(CompilerMessage(
CompilerRunnerConstants.KOTLIN_COMPILER_NAME,
kind(severity),
prefix + message,
location?.path,
-1, -1, -1,
location?.line?.toLong() ?: -1,
location?.column?.toLong() ?: -1
))
val kind = kind(severity)
if (kind != null) {
context.processMessage(CompilerMessage(
CompilerRunnerConstants.KOTLIN_COMPILER_NAME,
kind,
prefix + message,
location?.path,
-1, -1, -1,
location?.line?.toLong() ?: -1,
location?.column?.toLong() ?: -1
))
}
else {
val path = if (location != null) "${location.path}:${location.line}:${location.column}: " else ""
KotlinBuilder.LOG.debug(path + message)
}
}
override fun clear() {
@@ -759,12 +768,12 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
override fun hasErrors(): Boolean = hasErrors
private fun kind(severity: CompilerMessageSeverity): BuildMessage.Kind {
private fun kind(severity: CompilerMessageSeverity): BuildMessage.Kind? {
return when (severity) {
INFO -> BuildMessage.Kind.INFO
ERROR, EXCEPTION -> BuildMessage.Kind.ERROR
WARNING, STRONG_WARNING -> BuildMessage.Kind.WARNING
LOGGING -> BuildMessage.Kind.PROGRESS
LOGGING -> null
else -> throw IllegalArgumentException("Unsupported severity: " + severity)
}
}