From cc183e96a4d234a505a09377a45b2a4f44a89a02 Mon Sep 17 00:00:00 2001 From: Alexander Likhachev Date: Tue, 27 Apr 2021 02:23:19 +0300 Subject: [PATCH] [Build] Fix configuration cache undeclared system property read issues #KT-44611 In Progress --- buildSrc/src/main/kotlin/CommonUtil.kt | 3 +++ compiler/tests-java8/build.gradle.kts | 2 +- compiler/tests-spec/build.gradle.kts | 2 +- .../kotlin-build-gradle-plugin/src/BuildProperties.kt | 11 ++++++++--- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/buildSrc/src/main/kotlin/CommonUtil.kt b/buildSrc/src/main/kotlin/CommonUtil.kt index 72c8f9630c2..fde7467fbfb 100644 --- a/buildSrc/src/main/kotlin/CommonUtil.kt +++ b/buildSrc/src/main/kotlin/CommonUtil.kt @@ -81,3 +81,6 @@ fun Task.singleOutputFile(): File = when (this) { is ProGuardTask -> project.file(outJarFiles.single()!!) else -> outputs.files.singleFile } + +val Project.isIdeaActive + get() = providers.systemProperty("idea.active").forUseAtConfigurationTime().isPresent \ No newline at end of file diff --git a/compiler/tests-java8/build.gradle.kts b/compiler/tests-java8/build.gradle.kts index a6246fcb905..52a43201b33 100644 --- a/compiler/tests-java8/build.gradle.kts +++ b/compiler/tests-java8/build.gradle.kts @@ -14,7 +14,7 @@ dependencies { testRuntimeOnly(toolsJar()) testRuntime(intellijDep()) testRuntimeOnly(intellijPluginDep("java")) - if (System.getProperty("idea.active") != null) testRuntimeOnly(files("${rootProject.projectDir}/dist/kotlinc/lib/kotlin-reflect.jar")) + if (isIdeaActive) testRuntimeOnly(files("${rootProject.projectDir}/dist/kotlinc/lib/kotlin-reflect.jar")) } sourceSets { diff --git a/compiler/tests-spec/build.gradle.kts b/compiler/tests-spec/build.gradle.kts index b045fa034c8..06171f21a4f 100644 --- a/compiler/tests-spec/build.gradle.kts +++ b/compiler/tests-spec/build.gradle.kts @@ -19,7 +19,7 @@ dependencies { testCompileOnly(intellijCoreDep()) { includeJars("intellij-core") } testRuntimeOnly(intellijPluginDep("java")) compile("org.jsoup:jsoup:1.10.3") - if (System.getProperty("idea.active") != null) testRuntimeOnly(files("${rootProject.projectDir}/dist/kotlinc/lib/kotlin-reflect.jar")) + if (isIdeaActive) testRuntimeOnly(files("${rootProject.projectDir}/dist/kotlinc/lib/kotlin-reflect.jar")) testRuntime(project(":kotlin-reflect")) } diff --git a/dependencies/kotlin-build-gradle-plugin/src/BuildProperties.kt b/dependencies/kotlin-build-gradle-plugin/src/BuildProperties.kt index 8b1218ab9e0..8164ee015a7 100644 --- a/dependencies/kotlin-build-gradle-plugin/src/BuildProperties.kt +++ b/dependencies/kotlin-build-gradle-plugin/src/BuildProperties.kt @@ -13,6 +13,7 @@ import java.util.* interface PropertiesProvider { val rootProjectDir: File fun getProperty(key: String): Any? + fun getSystemProperty(key: String): String? } class KotlinBuildProperties( @@ -46,16 +47,16 @@ class KotlinBuildProperties( val isInIdeaSync: Boolean = run { // "idea.sync.active" was introduced in 2019.1 - System.getProperty("idea.sync.active")?.toBoolean() == true || let { + propertiesProvider.getSystemProperty("idea.sync.active")?.toBoolean() == true || let { // before 2019.1 there is "idea.active" that was true only on sync, // but since 2019.1 "idea.active" present in task execution too. // So let's check Idea version - val majorIdeaVersion = System.getProperty("idea.version") + val majorIdeaVersion = propertiesProvider.getSystemProperty("idea.version") ?.split(".") ?.getOrNull(0) val isBeforeIdea2019 = majorIdeaVersion == null || majorIdeaVersion.toInt() < 2019 - isBeforeIdea2019 && System.getProperty("idea.active")?.toBoolean() == true + isBeforeIdea2019 && propertiesProvider.getSystemProperty("idea.active")?.toBoolean() == true } } @@ -133,6 +134,8 @@ class ProjectProperties(val project: Project) : PropertiesProvider { get() = project.rootProject.projectDir.let { if (it.name == "buildSrc") it.parentFile else it } override fun getProperty(key: String): Any? = project.findProperty(key) + + override fun getSystemProperty(key: String) = project.providers.systemProperty(key).forUseAtConfigurationTime().orNull } val Project.kotlinBuildProperties: KotlinBuildProperties @@ -149,6 +152,8 @@ class SettingsProperties(val settings: Settings) : PropertiesProvider { val obj = (settings as DynamicObjectAware).asDynamicObject return if (obj.hasProperty(key)) obj.getProperty(key) else null } + + override fun getSystemProperty(key: String) = settings.providers.systemProperty(key).forUseAtConfigurationTime().orNull } fun getKotlinBuildPropertiesForSettings(settings: Any) = (settings as Settings).kotlinBuildProperties