From e56e3d78c87206a46c15bc9640c0919b96601456 Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Mon, 10 Jul 2017 23:07:14 +0300 Subject: [PATCH] Use ANSI escape codes only with CLI tools Before this change jansi was used by the compiler, unless "kotlin.colors.enabled" is not set to false. This caused multiple issues in different build systems, where newer or older version of jansi could crash the JVM since it uses native code. The following short term solutions were discussed: * Set "kotlin.colors.enabled" to false where jansi is not needed (basically in any build system). * Set "kotlin.colors.enabled" to true where jansi is needed, and use it only when the system property is set to true. Escaped codes are only needed in CLI tools (kotlinc, REPL), so the second solution is preferred (less places to set the property). #KT-17031 fixed #KT-18874 fixed #KT-18927 fixed --- compiler/cli/src/org/jetbrains/kotlin/cli/common/CLITool.kt | 3 +++ .../kotlin/cli/common/messages/PlainTextMessageRenderer.java | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLITool.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLITool.kt index 7e964e92695..aa7139260d7 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLITool.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLITool.kt @@ -142,6 +142,9 @@ abstract class CLITool { if (System.getProperty("java.awt.headless") == null) { System.setProperty("java.awt.headless", "true") } + if (System.getProperty(PlainTextMessageRenderer.KOTLIN_COLORS_ENABLED_PROPERTY) == null) { + System.setProperty(PlainTextMessageRenderer.KOTLIN_COLORS_ENABLED_PROPERTY, "true") + } val exitCode = doMainNoExit(compiler, args) if (exitCode != ExitCode.OK) { System.exit(exitCode.code) 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 03edd893fd1..7471c8c1e03 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 @@ -30,12 +30,13 @@ import java.util.Set; import static org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.*; public abstract class PlainTextMessageRenderer implements MessageRenderer { + public static final String KOTLIN_COLORS_ENABLED_PROPERTY = "kotlin.colors.enabled"; public static final boolean COLOR_ENABLED; static { boolean colorEnabled = false; // TODO: investigate why ANSI escape codes on Windows only work in REPL for some reason - if (!SystemInfo.isWindows && !"false".equals(System.getProperty("kotlin.colors.enabled"))) { + if (!SystemInfo.isWindows && "true".equals(System.getProperty(KOTLIN_COLORS_ENABLED_PROPERTY))) { try { // AnsiConsole doesn't check isatty() for stderr (see https://github.com/fusesource/jansi/pull/35). colorEnabled = CLibrary.isatty(CLibrary.STDERR_FILENO) != 0;