Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[gradle] Avoid usage of "findProperty" to support project isolation. #5120

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ package org.jetbrains.compose.desktop.application.internal
import org.gradle.api.Project
import org.gradle.api.provider.Provider
import org.gradle.api.provider.ProviderFactory
import org.jetbrains.compose.internal.utils.findLocalOrGlobalProperty
import org.jetbrains.compose.internal.utils.toBooleanProvider
import org.jetbrains.compose.internal.utils.valueOrNull
import org.jetbrains.kotlin.gradle.plugin.extraProperties

internal object ComposeProperties {
internal const val VERBOSE = "compose.desktop.verbose"
Expand Down Expand Up @@ -59,7 +61,6 @@ internal object ComposeProperties {
providers.valueOrNull(DISABLE_MULTIMODULE_RESOURCES).toBooleanProvider(false)

//providers.valueOrNull works only with root gradle.properties
fun dontSyncResources(project: Project): Provider<Boolean> = project.provider {
project.findProperty(SYNC_RESOURCES_PROPERTY)?.toString().equals("false", true)
}
fun dontSyncResources(project: Project): Provider<Boolean> =
project.findLocalOrGlobalProperty(SYNC_RESOURCES_PROPERTY).map { it == "false" }
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.gradle.api.tasks.Copy
import org.jetbrains.compose.desktop.application.tasks.AbstractJPackageTask
import org.jetbrains.compose.internal.utils.OS
import org.jetbrains.compose.internal.utils.currentOS
import org.jetbrains.compose.internal.utils.findLocalOrGlobalProperty
import org.jetbrains.compose.internal.utils.ioFile
import java.io.File

Expand All @@ -32,7 +33,8 @@ internal fun JvmApplicationContext.configureWix() {
return
}

if (project.findProperty(DOWNLOAD_WIX_PROPERTY) == "false") return
val disableWixDownload = project.findLocalOrGlobalProperty(DOWNLOAD_WIX_PROPERTY).map { it == "false" }
if (disableWixDownload.get()) return

val root = project.rootProject
val wixDir = project.gradle.gradleUserHomeDir.resolve("compose-jb")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package org.jetbrains.compose.experimental.internal

import org.gradle.api.Project
import org.jetbrains.compose.internal.utils.findLocalOrGlobalProperty
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget

Expand Down Expand Up @@ -74,7 +75,8 @@ private fun checkTarget(project: Project, target: KotlinTarget): CheckResult {
it.id.displayName.contains(SKIKO_ARTIFACT_PREFIX)
}
if (containsSkikoArtifact) {
if (project.findProperty(targetType.gradlePropertyName) != "true") {
val targetIsDisabled = project.findLocalOrGlobalProperty(targetType.gradlePropertyName).map { it != "true" }
if (targetIsDisabled.get()) {
return CheckResult.Fail(targetType)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@

package org.jetbrains.compose.internal.utils

import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import org.gradle.api.provider.ProviderFactory
import org.jetbrains.kotlin.gradle.plugin.extraProperties

internal inline fun <reified T> ObjectFactory.new(vararg params: Any): T =
newInstance(T::class.java, *params)
Expand Down Expand Up @@ -45,3 +47,8 @@ private fun Provider<String?>.forUseAtConfigurationTimeSafe(): Provider<String?>

internal fun Provider<String?>.toBooleanProvider(defaultValue: Boolean): Provider<Boolean> =
orElse(defaultValue.toString()).map { "true" == it }

internal fun Project.findLocalOrGlobalProperty(name: String, default: String = ""): Provider<String> = provider {
if (extraProperties.has(name)) extraProperties.get(name).toString()
else providers.gradleProperty(name).getOrElse(default)
}
Loading