From 7ac96163acb7bdbb23c4e8d063ab0de497f6157b Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Fri, 27 Jan 2017 16:40:12 +0300 Subject: [PATCH] Introduce CompilerMessageSeverity.STRONG_WARNING This is a severity for mandatory warnings, i.e. those which should be reported in any case, even if there are compilation errors --- .../messages/CompilerMessageSeverity.java | 30 +++++++++++++++++-- .../messages/GroupingMessageCollector.java | 2 +- .../messages/PlainTextMessageRenderer.java | 8 +++-- .../common/messages/XmlMessageRenderer.java | 7 +++-- .../CompileServicesFacadeMessageCollector.kt | 4 +-- .../kotlin/jps/build/KotlinBuilder.kt | 17 +++++++---- .../jetbrains/kotlin/gradle/tasks/Tasks.kt | 6 ++-- .../processing/impl/KotlinMessager.kt | 8 +++-- 8 files changed, 60 insertions(+), 22 deletions(-) diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/messages/CompilerMessageSeverity.java b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/messages/CompilerMessageSeverity.java index cf49c63311b..d2b9a00d56a 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/messages/CompilerMessageSeverity.java +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/messages/CompilerMessageSeverity.java @@ -16,13 +16,16 @@ package org.jetbrains.kotlin.cli.common.messages; +import org.jetbrains.annotations.NotNull; + import java.util.EnumSet; public enum CompilerMessageSeverity { - INFO, - ERROR, - WARNING, EXCEPTION, + ERROR, + STRONG_WARNING, + WARNING, + INFO, LOGGING, OUTPUT; @@ -32,4 +35,25 @@ public enum CompilerMessageSeverity { public boolean isError() { return ERRORS.contains(this); } + + @NotNull + public String getPresentableName() { + switch (this) { + case EXCEPTION: + return "exception"; + case ERROR: + return "error"; + case STRONG_WARNING: + case WARNING: + return "warning"; + case INFO: + return "info"; + case LOGGING: + return "logging"; + case OUTPUT: + return "output"; + default: + throw new UnsupportedOperationException("Unknown severity: " + this); + } + } } diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/messages/GroupingMessageCollector.java b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/messages/GroupingMessageCollector.java index 793c0b358d3..d2259d82b8e 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/messages/GroupingMessageCollector.java +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/messages/GroupingMessageCollector.java @@ -68,7 +68,7 @@ public class GroupingMessageCollector implements MessageCollector { for (String path : sortedKeys()) { for (Message message : groupedMessages.get(path)) { - if (!hasErrors || message.severity.isError()) { + if (!hasErrors || message.severity.isError() || message.severity == CompilerMessageSeverity.STRONG_WARNING) { delegate.report(message.severity, message.message, message.location); } } diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/PlainTextMessageRenderer.java b/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/PlainTextMessageRenderer.java index 20b767d776e..60df45690c4 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/PlainTextMessageRenderer.java +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/PlainTextMessageRenderer.java @@ -49,7 +49,7 @@ public abstract class PlainTextMessageRenderer implements MessageRenderer { private static final String LINE_SEPARATOR = LineSeparator.getSystemLineSeparator().getSeparatorString(); - private static final Set IMPORTANT_MESSAGE_SEVERITIES = EnumSet.of(EXCEPTION, ERROR, WARNING); + private static final Set IMPORTANT_MESSAGE_SEVERITIES = EnumSet.of(EXCEPTION, ERROR, STRONG_WARNING, WARNING); @Override public String renderPreamble() { @@ -83,7 +83,7 @@ public abstract class PlainTextMessageRenderer implements MessageRenderer { Ansi ansi = Ansi.ansi() .bold() .fg(severityColor(severity)) - .a(severity.name().toLowerCase()) + .a(severity.getPresentableName()) .a(": ") .reset(); @@ -102,7 +102,7 @@ public abstract class PlainTextMessageRenderer implements MessageRenderer { } } else { - result.append(severity.name().toLowerCase()); + result.append(severity.getPresentableName()); result.append(": "); result.append(decapitalizeIfNeeded(message)); } @@ -141,6 +141,8 @@ public abstract class PlainTextMessageRenderer implements MessageRenderer { return Ansi.Color.RED; case ERROR: return Ansi.Color.RED; + case STRONG_WARNING: + return Ansi.Color.YELLOW; case WARNING: return Ansi.Color.YELLOW; case INFO: diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/XmlMessageRenderer.java b/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/XmlMessageRenderer.java index 95c0722688d..e4251b1058d 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/XmlMessageRenderer.java +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/XmlMessageRenderer.java @@ -28,7 +28,8 @@ public class XmlMessageRenderer implements MessageRenderer { @Override public String render(@NotNull CompilerMessageSeverity severity, @NotNull String message, @NotNull CompilerMessageLocation location) { StringBuilder out = new StringBuilder(); - out.append("<").append(severity.toString()); + String tagName = severity.getPresentableName(); + out.append("<").append(tagName); if (location.getPath() != null) { out.append(" path=\"").append(e(location.getPath())).append("\""); out.append(" line=\"").append(location.getLine()).append("\""); @@ -38,11 +39,11 @@ public class XmlMessageRenderer implements MessageRenderer { out.append(e(message)); - out.append("\n"); + out.append("\n"); return out.toString(); } - private String e(String str) { + private static String e(String str) { return StringUtil.escapeXml(str); } diff --git a/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/CompileServicesFacadeMessageCollector.kt b/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/CompileServicesFacadeMessageCollector.kt index 98301df12d3..bdc4b25ca61 100644 --- a/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/CompileServicesFacadeMessageCollector.kt +++ b/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/CompileServicesFacadeMessageCollector.kt @@ -46,7 +46,7 @@ internal class CompileServicesFacadeMessageCollector( else -> { val reportSeverity = when (severity) { CompilerMessageSeverity.ERROR -> ReportSeverity.ERROR - CompilerMessageSeverity.WARNING -> ReportSeverity.WARNING + CompilerMessageSeverity.WARNING, CompilerMessageSeverity.STRONG_WARNING -> ReportSeverity.WARNING CompilerMessageSeverity.INFO -> ReportSeverity.INFO else -> ReportSeverity.DEBUG } @@ -57,7 +57,7 @@ internal class CompileServicesFacadeMessageCollector( } } - hasErrors = hasErrors || severity == CompilerMessageSeverity.ERROR || severity == CompilerMessageSeverity.EXCEPTION + hasErrors = hasErrors || severity.isError } override fun hasErrors(): Boolean = hasErrors diff --git a/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt b/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt index f8d8c1c097d..7c64ef1e7b3 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt @@ -37,14 +37,20 @@ import org.jetbrains.jps.model.JpsProject import org.jetbrains.jps.model.java.JpsJavaClasspathKind import org.jetbrains.jps.model.java.JpsJavaExtensionService import org.jetbrains.jps.model.module.JpsModule -import org.jetbrains.kotlin.build.* +import org.jetbrains.kotlin.build.GeneratedFile +import org.jetbrains.kotlin.build.GeneratedJvmClass +import org.jetbrains.kotlin.build.JvmBuildMetaInfo +import org.jetbrains.kotlin.build.isModuleMappingFile import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments 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.cli.common.messages.MessageCollector import org.jetbrains.kotlin.cli.common.messages.OutputMessageUtil -import org.jetbrains.kotlin.compilerRunner.* +import org.jetbrains.kotlin.compilerRunner.JpsCompilerEnvironment +import org.jetbrains.kotlin.compilerRunner.JpsKotlinCompilerRunner +import org.jetbrains.kotlin.compilerRunner.OutputItemsCollector +import org.jetbrains.kotlin.compilerRunner.OutputItemsCollectorImpl import org.jetbrains.kotlin.config.* import org.jetbrains.kotlin.config.CompilerRunnerConstants.INTERNAL_ERROR_PREFIX import org.jetbrains.kotlin.daemon.common.isDaemonEnabled @@ -58,8 +64,9 @@ import org.jetbrains.kotlin.modules.TargetId import org.jetbrains.kotlin.preloading.ClassCondition import org.jetbrains.kotlin.progress.CompilationCanceledException import org.jetbrains.kotlin.progress.CompilationCanceledStatus -import org.jetbrains.kotlin.build.JvmBuildMetaInfo -import org.jetbrains.kotlin.utils.* +import org.jetbrains.kotlin.utils.JsLibraryUtils +import org.jetbrains.kotlin.utils.PathUtil +import org.jetbrains.kotlin.utils.keysToMap import org.jetbrains.org.objectweb.asm.ClassReader import java.io.File import java.util.* @@ -766,7 +773,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) { return when (severity) { INFO -> BuildMessage.Kind.INFO ERROR, EXCEPTION -> BuildMessage.Kind.ERROR - WARNING -> BuildMessage.Kind.WARNING + WARNING, STRONG_WARNING -> BuildMessage.Kind.WARNING LOGGING -> BuildMessage.Kind.PROGRESS else -> throw IllegalArgumentException("Unsupported severity: " + severity) } diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt index a4fd5973226..f5060773ddd 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt @@ -382,7 +382,7 @@ internal class GradleMessageCollector(val logger: Logger) : MessageCollector { "e" } CompilerMessageSeverity.INFO -> "i" - CompilerMessageSeverity.WARNING -> "w" + CompilerMessageSeverity.WARNING, CompilerMessageSeverity.STRONG_WARNING -> "w" else -> throw IllegalArgumentException("Unknown CompilerMessageSeverity: $severity") }) append(": ") @@ -404,8 +404,8 @@ internal class GradleMessageCollector(val logger: Logger) : MessageCollector { in CompilerMessageSeverity.VERBOSE -> logger.debug(text) in CompilerMessageSeverity.ERRORS -> logger.error(text) CompilerMessageSeverity.INFO -> logger.info(text) - CompilerMessageSeverity.WARNING -> logger.warn(text) + CompilerMessageSeverity.WARNING, CompilerMessageSeverity.STRONG_WARNING -> logger.warn(text) else -> throw IllegalArgumentException("Unknown CompilerMessageSeverity: $severity") } } -} \ No newline at end of file +} diff --git a/plugins/annotation-processing/src/org/jetbrains/kotlin/annotation/processing/impl/KotlinMessager.kt b/plugins/annotation-processing/src/org/jetbrains/kotlin/annotation/processing/impl/KotlinMessager.kt index 198abed9565..41bb5ebf7eb 100644 --- a/plugins/annotation-processing/src/org/jetbrains/kotlin/annotation/processing/impl/KotlinMessager.kt +++ b/plugins/annotation-processing/src/org/jetbrains/kotlin/annotation/processing/impl/KotlinMessager.kt @@ -47,12 +47,16 @@ class KotlinMessager(private val messageCollector: MessageCollector) : Messager errorCount++ CompilerMessageSeverity.ERROR } - Kind.WARNING, Kind.MANDATORY_WARNING -> { + Kind.WARNING -> { warningCount++ CompilerMessageSeverity.WARNING } + Kind.MANDATORY_WARNING -> { + warningCount++ + CompilerMessageSeverity.STRONG_WARNING + } else -> CompilerMessageSeverity.LOGGING } messageCollector.report(severity, msg.toString(), CompilerMessageLocation.NO_LOCATION) } -} \ No newline at end of file +}