[Build] Fix configuration cache undeclared system property read issues

#KT-44611 In Progress
This commit is contained in:
Alexander Likhachev
2021-04-27 02:23:19 +03:00
parent f0a6d9f33f
commit cc183e96a4
4 changed files with 13 additions and 5 deletions
+3
View File
@@ -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
+1 -1
View File
@@ -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 {
+1 -1
View File
@@ -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"))
}
@@ -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