diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/Properties.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/Properties.kt index 309a41e0e0d..457c48aecee 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/Properties.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/Properties.kt @@ -36,7 +36,12 @@ enum class CompilerSystemProperties(val property: String) { 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") + OS_NAME("os.name"), + TMP_DIR("java.io.tmpdir"), + USER_HOME("user.home"), + JAVA_VERSION("java.specification.version"), + JAVA_HOME("java.home"), + JAVA_CLASS_PATH("java.class.path"), ; var value @@ -45,6 +50,9 @@ enum class CompilerSystemProperties(val property: String) { (systemPropertySetter ?: System::setProperty)(property, value!!) } + val safeValue + get() = value ?: error("No value for $property system property") + fun clear(): String? = (systemPropertyCleaner ?: System::clearProperty)(property) companion object { diff --git a/compiler/daemon/daemon-client-new/src/org/jetbrains/kotlin/daemon/client/experimental/KotlinCompilerClient.kt b/compiler/daemon/daemon-client-new/src/org/jetbrains/kotlin/daemon/client/experimental/KotlinCompilerClient.kt index 3d7b73f38cc..1aada5c88db 100644 --- a/compiler/daemon/daemon-client-new/src/org/jetbrains/kotlin/daemon/client/experimental/KotlinCompilerClient.kt +++ b/compiler/daemon/daemon-client-new/src/org/jetbrains/kotlin/daemon/client/experimental/KotlinCompilerClient.kt @@ -360,7 +360,7 @@ class KotlinCompilerClient : KotlinCompilerDaemonClient { } private fun detectCompilerClasspath(): List? = - System.getProperty("java.class.path") + CompilerSystemProperties.JAVA_CLASS_PATH.value ?.split(File.pathSeparator) ?.map { File(it).parentFile } ?.distinct() @@ -454,7 +454,7 @@ class KotlinCompilerClient : KotlinCompilerDaemonClient { daemonOptions: DaemonOptions, reportingTargets: DaemonReportingTargets ): Boolean { - val javaExecutable = File(File(System.getProperty("java.home"), "bin"), "java") + val javaExecutable = File(File(CompilerSystemProperties.JAVA_HOME.safeValue, "bin"), "java") val serverHostname = CompilerSystemProperties.JAVA_RMI_SERVER_HOSTNAME.value ?: error("${CompilerSystemProperties.JAVA_RMI_SERVER_HOSTNAME.property} is not set!") val platformSpecificOptions = listOf( // hide daemon window diff --git a/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/KotlinCompilerClient.kt b/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/KotlinCompilerClient.kt index e2f0dbd4592..4ec95bfacf3 100644 --- a/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/KotlinCompilerClient.kt +++ b/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/KotlinCompilerClient.kt @@ -299,7 +299,7 @@ object KotlinCompilerClient { } fun detectCompilerClasspath(): List? = - System.getProperty("java.class.path") + CompilerSystemProperties.JAVA_CLASS_PATH.value ?.split(File.pathSeparator) ?.map { File(it).parentFile } ?.distinct() @@ -368,13 +368,13 @@ object KotlinCompilerClient { private fun startDaemon(compilerId: CompilerId, daemonJVMOptions: DaemonJVMOptions, daemonOptions: DaemonOptions, reportingTargets: DaemonReportingTargets): Boolean { - val javaExecutable = File(File(System.getProperty("java.home"), "bin"), "java") + val javaExecutable = File(File(CompilerSystemProperties.JAVA_HOME.safeValue, "bin"), "java") val serverHostname = CompilerSystemProperties.JAVA_RMI_SERVER_HOSTNAME.value ?: error("${CompilerSystemProperties.JAVA_RMI_SERVER_HOSTNAME.property} is not set!") val platformSpecificOptions = listOf( // hide daemon window "-Djava.awt.headless=true", "-D$${CompilerSystemProperties.JAVA_RMI_SERVER_HOSTNAME.property}=$serverHostname") - val javaVersion = System.getProperty("java.specification.version")?.toIntOrNull() + val javaVersion = CompilerSystemProperties.JAVA_VERSION.value?.toIntOrNull() val javaIllegalAccessWorkaround = if (javaVersion != null && javaVersion >= 16) listOf("--illegal-access=permit") diff --git a/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/FileSystemUtils.kt b/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/FileSystemUtils.kt index bd2f3bc400f..5c17387c796 100644 --- a/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/FileSystemUtils.kt +++ b/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/FileSystemUtils.kt @@ -16,6 +16,7 @@ package org.jetbrains.kotlin.daemon.common +import org.jetbrains.kotlin.cli.common.CompilerSystemProperties import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly import java.io.File @@ -26,7 +27,7 @@ enum class OSKind { Unknown; companion object { - val current: OSKind = System.getProperty("os.name").toLowerCaseAsciiOnly().let { + val current: OSKind = CompilerSystemProperties.OS_NAME.safeValue.toLowerCaseAsciiOnly().let { when { // partly taken from http://www.code4copy.com/java/post/detecting-os-type-in-java it.startsWith("windows") -> Windows @@ -57,8 +58,8 @@ private fun String?.orDefault(v: String): String = object FileSystem { - val userHomePath: String get() = System.getProperty("user.home") - val tempPath: String get() = System.getProperty("java.io.tmpdir") + val userHomePath: String get() = CompilerSystemProperties.USER_HOME.safeValue + val tempPath: String get() = CompilerSystemProperties.TMP_DIR.safeValue val logFilesPath: String get() = tempPath