[Gradle] Read system properties at configuration time using Gradle providers
The change is a step to fully support Gradle configuration cache. Relates to #KT-43605 Relates to #KT-44611
This commit is contained in:
@@ -16,8 +16,48 @@
|
||||
|
||||
package org.jetbrains.kotlin.cli.common
|
||||
|
||||
val KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY = "kotlin.environment.keepalive"
|
||||
import com.intellij.util.LineSeparator
|
||||
import java.util.*
|
||||
|
||||
enum class CompilerSystemProperties(val property: String) {
|
||||
COMPILE_DAEMON_ENABLED_PROPERTY("kotlin.daemon.enabled"),
|
||||
COMPILE_DAEMON_JVM_OPTIONS_PROPERTY("kotlin.daemon.jvm.options"),
|
||||
COMPILE_DAEMON_OPTIONS_PROPERTY("kotlin.daemon.options"),
|
||||
COMPILE_DAEMON_CLIENT_OPTIONS_PROPERTY("kotlin.daemon.client.options"),
|
||||
COMPILE_DAEMON_CLIENT_ALIVE_PATH_PROPERTY("kotlin.daemon.client.alive.path"),
|
||||
COMPILE_DAEMON_LOG_PATH_PROPERTY("kotlin.daemon.log.path"),
|
||||
COMPILE_DAEMON_REPORT_PERF_PROPERTY("kotlin.daemon.perf"),
|
||||
COMPILE_DAEMON_VERBOSE_REPORT_PROPERTY("kotlin.daemon.verbose"),
|
||||
COMPILE_DAEMON_STARTUP_TIMEOUT_PROPERTY("kotlin.daemon.startup.timeout"),
|
||||
JAVA_RMI_SERVER_HOSTNAME("java.rmi.server.hostname"),
|
||||
DAEMON_RMI_SOCKET_BACKLOG_SIZE_PROPERTY("kotlin.daemon.socket.backlog.size"),
|
||||
DAEMON_RMI_SOCKET_CONNECT_ATTEMPTS_PROPERTY("kotlin.daemon.socket.connect.attempts"),
|
||||
DAEMON_RMI_SOCKET_CONNECT_INTERVAL_PROPERTY("kotlin.daemon.socket.connect.interval"),
|
||||
KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY("kotlin.environment.keepalive"),
|
||||
COMPILE_DAEMON_CUSTOM_RUN_FILES_PATH_FOR_TESTS("kotlin.daemon.custom.run.files.path.for.tests"),
|
||||
KOTLIN_COLORS_ENABLED_PROPERTY("kotlin.colors.enabled"),
|
||||
OS_NAME("os.name")
|
||||
;
|
||||
|
||||
var value
|
||||
get() = systemPropertyGetter(property)
|
||||
set(value) {
|
||||
systemPropertySetter(property, value!!)
|
||||
}
|
||||
|
||||
companion object {
|
||||
var systemPropertyGetter: (String) -> String? = {
|
||||
System.getProperty(it)
|
||||
}
|
||||
|
||||
var systemPropertySetter: (String, String) -> String? = { key, value ->
|
||||
System.setProperty(key, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val isWindows: Boolean
|
||||
get() = CompilerSystemProperties.OS_NAME.value!!.toLowerCase(Locale.ENGLISH).startsWith("windows")
|
||||
|
||||
fun String?.toBooleanLenient(): Boolean? = when (this?.toLowerCase()) {
|
||||
null -> false
|
||||
|
||||
@@ -205,8 +205,8 @@ abstract class CLITool<A : CommonToolArguments> {
|
||||
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")
|
||||
if (CompilerSystemProperties.KOTLIN_COLORS_ENABLED_PROPERTY.value == null) {
|
||||
CompilerSystemProperties.KOTLIN_COLORS_ENABLED_PROPERTY.value = "true"
|
||||
}
|
||||
|
||||
setupIdeaStandaloneExecution()
|
||||
|
||||
+4
-5
@@ -16,13 +16,13 @@
|
||||
|
||||
package org.jetbrains.kotlin.cli.common.messages;
|
||||
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.util.LineSeparator;
|
||||
import kotlin.text.StringsKt;
|
||||
import org.fusesource.jansi.Ansi;
|
||||
import org.fusesource.jansi.internal.CLibrary;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.cli.common.CompilerSystemProperties;
|
||||
import org.jetbrains.kotlin.cli.common.PropertiesKt;
|
||||
import org.jetbrains.kotlin.util.capitalizeDecapitalize.CapitalizeDecapitalizeKt;
|
||||
|
||||
import java.util.EnumSet;
|
||||
@@ -31,13 +31,12 @@ 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 && "true".equals(System.getProperty(KOTLIN_COLORS_ENABLED_PROPERTY))) {
|
||||
if (!PropertiesKt.isWindows() && "true".equals(CompilerSystemProperties.KOTLIN_COLORS_ENABLED_PROPERTY.getValue())) {
|
||||
try {
|
||||
// AnsiConsole doesn't check isatty() for stderr (see https://github.com/fusesource/jansi/pull/35).
|
||||
colorEnabled = CLibrary.isatty(CLibrary.STDERR_FILENO) != 0;
|
||||
@@ -49,7 +48,7 @@ public abstract class PlainTextMessageRenderer implements MessageRenderer {
|
||||
COLOR_ENABLED = colorEnabled;
|
||||
}
|
||||
|
||||
private static final String LINE_SEPARATOR = LineSeparator.getSystemLineSeparator().getSeparatorString();
|
||||
private static final String LINE_SEPARATOR = System.lineSeparator();
|
||||
|
||||
private static final Set<CompilerMessageSeverity> IMPORTANT_MESSAGE_SEVERITIES = EnumSet.of(EXCEPTION, ERROR, STRONG_WARNING, WARNING);
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ import org.jetbrains.kotlin.asJava.finder.JavaElementFinder
|
||||
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
|
||||
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
||||
import org.jetbrains.kotlin.cli.common.CliModuleVisibilityManagerImpl
|
||||
import org.jetbrains.kotlin.cli.common.KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY
|
||||
import org.jetbrains.kotlin.cli.common.CompilerSystemProperties
|
||||
import org.jetbrains.kotlin.cli.common.config.ContentRoot
|
||||
import org.jetbrains.kotlin.cli.common.config.KotlinSourceRoot
|
||||
import org.jetbrains.kotlin.cli.common.config.kotlinSourceRoots
|
||||
@@ -498,7 +498,7 @@ class KotlinCoreEnvironment private constructor(
|
||||
}
|
||||
// Disposing of the environment is unsafe in production then parallel builds are enabled, but turning it off universally
|
||||
// breaks a lot of tests, therefore it is disabled for production and enabled for tests
|
||||
if (System.getProperty(KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY).toBooleanLenient() != true) {
|
||||
if (CompilerSystemProperties.KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY.value.toBooleanLenient() != true) {
|
||||
// JPS may run many instances of the compiler in parallel (there's an option for compiling independent modules in parallel in IntelliJ)
|
||||
// All projects share the same ApplicationEnvironment, and when the last project is disposed, the ApplicationEnvironment is disposed as well
|
||||
@Suppress("ObjectLiteralToLambda") // Disposer tree depends on identity of disposables.
|
||||
|
||||
Reference in New Issue
Block a user