diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLICompiler.java b/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLICompiler.java index cd5895afb5d..4714d47f405 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLICompiler.java +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLICompiler.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -130,16 +130,23 @@ public abstract class CLICompiler { MessageCollector collector = new PrintingMessageCollector(errStream, messageRenderer, arguments.verbose); try { - AnsiConsole.systemInstall(); + if (PlainTextMessageRenderer.COLOR_ENABLED) { + AnsiConsole.systemInstall(); + } + errStream.print(messageRenderer.renderPreamble()); return exec(collector, services, arguments); } finally { errStream.print(messageRenderer.renderConclusion()); - AnsiConsole.systemUninstall(); + + if (PlainTextMessageRenderer.COLOR_ENABLED) { + AnsiConsole.systemUninstall(); + } } } + @SuppressWarnings("WeakerAccess") // Used in maven (see KotlinCompileMojoBase.java) @NotNull public ExitCode exec(@NotNull MessageCollector messageCollector, @NotNull Services services, @NotNull A arguments) { printVersionIfNeeded(messageCollector, arguments); @@ -213,7 +220,7 @@ public abstract class CLICompiler { @NotNull Disposable rootDisposable ); - protected void printVersionIfNeeded(@NotNull MessageCollector messageCollector, @NotNull A arguments) { + private void printVersionIfNeeded(@NotNull MessageCollector messageCollector, @NotNull A arguments) { if (!arguments.version) return; messageCollector.report(CompilerMessageSeverity.INFO, @@ -234,6 +241,7 @@ public abstract class CLICompiler { } } + @SuppressWarnings("UseOfSystemOutOrSystemErr") @NotNull public static ExitCode doMainNoExit(@NotNull CLICompiler compiler, @NotNull String[] args) { try { 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 059ba87fc0d..7c4fdb23f18 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 @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,11 +30,14 @@ import java.util.Set; import static org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.*; public abstract class PlainTextMessageRenderer implements MessageRenderer { + + private static final String KOTLIN_COLORS_ENABLED_PROPERTY = "kotlin.colors.enabled"; + // AnsiConsole doesn't check isatty() for stderr (see https://github.com/fusesource/jansi/pull/35). // TODO: investigate why ANSI escape codes on Windows only work in REPL for some reason - private static final boolean COLOR_ENABLED = + public static final boolean COLOR_ENABLED = !SystemInfo.isWindows && - !"false".equals(System.getProperty("kotlin.colors.enabled")) && + !"false".equals(System.getProperty(KOTLIN_COLORS_ENABLED_PROPERTY)) && CLibrary.isatty(CLibrary.STDERR_FILENO) != 0; private static final String LINE_SEPARATOR = LineSeparator.getSystemLineSeparator().getSeparatorString();