From 6d0f74346faed9bab293463a877677bb5a301871 Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov <654232+AlexeyTsvetkov@users.noreply.github.com> Date: Tue, 3 Aug 2021 18:24:12 +0300 Subject: [PATCH] Allow using relative path, when specifying signing keychain (#988) --- .../validation/ValidatedMacOSSigningSettings.kt | 15 ++++++++++----- .../application/tasks/AbstractJPackageTask.kt | 3 ++- .../application/macSign/build.gradle | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/validation/ValidatedMacOSSigningSettings.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/validation/ValidatedMacOSSigningSettings.kt index 0f2c01b7b1..3ca82fb6a1 100644 --- a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/validation/ValidatedMacOSSigningSettings.kt +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/validation/ValidatedMacOSSigningSettings.kt @@ -5,6 +5,7 @@ package org.jetbrains.compose.desktop.application.internal.validation +import org.gradle.api.Project import org.gradle.api.provider.Provider import org.jetbrains.compose.desktop.application.dsl.MacOSSigningSettings import org.jetbrains.compose.desktop.application.internal.ComposeProperties @@ -31,7 +32,8 @@ internal data class ValidatedMacOSSigningSettings( } internal fun MacOSSigningSettings.validate( - bundleIDProvider: Provider + bundleIDProvider: Provider, + project: Project ): ValidatedMacOSSigningSettings { check(currentOS == OS.MacOS) { ERR_WRONG_OS } @@ -41,10 +43,13 @@ internal fun MacOSSigningSettings.validate( ?: error(ERR_UNKNOWN_PREFIX) val signIdentity = this.identity.orNull ?: error(ERR_UNKNOWN_SIGN_ID) - val keychainFile = this.keychain.orNull?.let { File(it) } - if (keychainFile != null) { - check(keychainFile.exists()) { - "$ERR_PREFIX keychain is not an existing file: ${keychainFile.absolutePath}" + val keychainPath = this.keychain.orNull + val keychainFile = + listOf(project.file(keychainPath), project.rootProject.file(keychainPath)) + .firstOrNull { it.exists() } + if (keychainPath != null) { + check(keychainFile != null && keychainFile.exists()) { + "$ERR_PREFIX could not find the specified keychain: $keychainPath" } } diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractJPackageTask.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractJPackageTask.kt index 5be642a196..55c9584ca8 100644 --- a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractJPackageTask.kt +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractJPackageTask.kt @@ -178,7 +178,8 @@ abstract class AbstractJPackageTask @Inject constructor( private val macSigner: MacSigner? by lazy { val nonValidatedSettings = nonValidatedMacSigningSettings if (currentOS == OS.MacOS && nonValidatedSettings?.sign?.get() == true) { - val validatedSettings = nonValidatedSettings.validate(nonValidatedMacBundleID) + val validatedSettings = + nonValidatedSettings.validate(nonValidatedMacBundleID, project) MacSigner(validatedSettings, runExternalTool) } else null } diff --git a/gradle-plugins/compose/src/test/test-projects/application/macSign/build.gradle b/gradle-plugins/compose/src/test/test-projects/application/macSign/build.gradle index 2e13dd5860..92fce3f186 100644 --- a/gradle-plugins/compose/src/test/test-projects/application/macSign/build.gradle +++ b/gradle-plugins/compose/src/test/test-projects/application/macSign/build.gradle @@ -29,7 +29,7 @@ compose.desktop { signing { sign.set(true) identity.set("Compose Test") - keychain.set(project.file("compose.test.keychain").absolutePath) + keychain.set("compose.test.keychain") } } }