From b7d88430e01816600a092e0e0cc21b91e8f9378b Mon Sep 17 00:00:00 2001 From: hfhbd <22521688+hfhbd@users.noreply.github.com> Date: Sun, 29 Sep 2024 15:47:55 +0200 Subject: [PATCH 1/3] Gradle plugin: Replace findProperty with Isolated Project compatible api gradleProperty Signed-off-by: hfhbd <22521688+hfhbd@users.noreply.github.com> --- .../src/main/kotlin/dev/sigstore/sign/SigstoreSignExtension.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sigstore-gradle/sigstore-gradle-sign-base-plugin/src/main/kotlin/dev/sigstore/sign/SigstoreSignExtension.kt b/sigstore-gradle/sigstore-gradle-sign-base-plugin/src/main/kotlin/dev/sigstore/sign/SigstoreSignExtension.kt index 22fd84b7..115cdf93 100644 --- a/sigstore-gradle/sigstore-gradle-sign-base-plugin/src/main/kotlin/dev/sigstore/sign/SigstoreSignExtension.kt +++ b/sigstore-gradle/sigstore-gradle-sign-base-plugin/src/main/kotlin/dev/sigstore/sign/SigstoreSignExtension.kt @@ -84,7 +84,7 @@ abstract class SigstoreSignExtension(private val project: Project) { } val removeSigstoreAsc = - project.findProperty("dev.sigstore.sign.remove.sigstore.json.asc")?.toString()?.toBoolean() != false + project.providers.gradleProperty("dev.sigstore.sign.remove.sigstore.json.asc").map { it.toBoolean() }.orNull != false val publicationName = publication.name From 005fe0479a85e77430c9b0f313f970aa81dbef49 Mon Sep 17 00:00:00 2001 From: hfhbd <22521688+hfhbd@users.noreply.github.com> Date: Wed, 23 Oct 2024 10:39:22 +0200 Subject: [PATCH 2/3] Add test Signed-off-by: hfhbd <22521688+hfhbd@users.noreply.github.com> --- .../kotlin/dev/sigstore/gradle/OidcDslTest.kt | 1 + .../dev/sigstore/gradle/SigstoreSignTest.kt | 1 + .../sigstore/gradle/RemoveSigstoreAscTest.kt | 3 +- .../gradle/SigstorePublishSignTest.kt | 1 + .../dev/sigstore/testkit/BaseGradleTest.kt | 29 ++++++++++++++++--- .../dev/sigstore/testkit/TestedGradle.kt | 3 +- 6 files changed, 32 insertions(+), 6 deletions(-) diff --git a/sigstore-gradle/sigstore-gradle-sign-base-plugin/src/test/kotlin/dev/sigstore/gradle/OidcDslTest.kt b/sigstore-gradle/sigstore-gradle-sign-base-plugin/src/test/kotlin/dev/sigstore/gradle/OidcDslTest.kt index 0a183c3c..0567fd4c 100644 --- a/sigstore-gradle/sigstore-gradle-sign-base-plugin/src/test/kotlin/dev/sigstore/gradle/OidcDslTest.kt +++ b/sigstore-gradle/sigstore-gradle-sign-base-plugin/src/test/kotlin/dev/sigstore/gradle/OidcDslTest.kt @@ -46,6 +46,7 @@ class OidcDslTest: BaseGradleTest() { """.trimIndent() ) enableConfigurationCache(gradle) + enableProjectIsolation(gradle) prepare(gradle.version, "printConfig", "-s") .build() } diff --git a/sigstore-gradle/sigstore-gradle-sign-base-plugin/src/test/kotlin/dev/sigstore/gradle/SigstoreSignTest.kt b/sigstore-gradle/sigstore-gradle-sign-base-plugin/src/test/kotlin/dev/sigstore/gradle/SigstoreSignTest.kt index 77978f96..e7eb9299 100644 --- a/sigstore-gradle/sigstore-gradle-sign-base-plugin/src/test/kotlin/dev/sigstore/gradle/SigstoreSignTest.kt +++ b/sigstore-gradle/sigstore-gradle-sign-base-plugin/src/test/kotlin/dev/sigstore/gradle/SigstoreSignTest.kt @@ -55,6 +55,7 @@ class SigstoreSignTest: BaseGradleTest() { """.trimIndent() ) enableConfigurationCache(case.gradle) + enableProjectIsolation(case.gradle) prepare(case.gradle.version, "signFile", "-s") .build() assertThat(projectDir.resolve("build/helloProps.txt.sigstore.json")) diff --git a/sigstore-gradle/sigstore-gradle-sign-plugin/src/test/kotlin/dev/sigstore/gradle/RemoveSigstoreAscTest.kt b/sigstore-gradle/sigstore-gradle-sign-plugin/src/test/kotlin/dev/sigstore/gradle/RemoveSigstoreAscTest.kt index bb648c53..b63b51fd 100644 --- a/sigstore-gradle/sigstore-gradle-sign-plugin/src/test/kotlin/dev/sigstore/gradle/RemoveSigstoreAscTest.kt +++ b/sigstore-gradle/sigstore-gradle-sign-plugin/src/test/kotlin/dev/sigstore/gradle/RemoveSigstoreAscTest.kt @@ -41,7 +41,7 @@ class RemoveSigstoreAscTest : BaseGradleTest() { // Gradle < 8.1 + configuration cache=on which is incompatible with signing plugin. listOf( TestedGradleAndSigstoreJava( - TestedGradle(GradleVersion.version("8.1"), ConfigurationCache.OFF), + TestedGradle(GradleVersion.version("8.1"), ConfigurationCache.OFF, ProjectIsolation.OFF), SIGSTORE_JAVA_CURRENT_VERSION ) ) @@ -147,6 +147,7 @@ class RemoveSigstoreAscTest : BaseGradleTest() { """.trimIndent() ) enableConfigurationCache(case.gradle) + enableProjectIsolation(case.gradle) } private fun SoftAssertions.assertSignatures(name: String, expectSigstoreAsc: Boolean = false) { diff --git a/sigstore-gradle/sigstore-gradle-sign-plugin/src/test/kotlin/dev/sigstore/gradle/SigstorePublishSignTest.kt b/sigstore-gradle/sigstore-gradle-sign-plugin/src/test/kotlin/dev/sigstore/gradle/SigstorePublishSignTest.kt index d6552cb5..85597c69 100644 --- a/sigstore-gradle/sigstore-gradle-sign-plugin/src/test/kotlin/dev/sigstore/gradle/SigstorePublishSignTest.kt +++ b/sigstore-gradle/sigstore-gradle-sign-plugin/src/test/kotlin/dev/sigstore/gradle/SigstorePublishSignTest.kt @@ -65,6 +65,7 @@ class SigstorePublishSignTest : BaseGradleTest() { """.trimIndent() ) enableConfigurationCache(case.gradle) + enableProjectIsolation(case.gradle) prepare(case.gradle.version, "publishAllPublicationsToTmpRepository", "-s") .build() diff --git a/sigstore-testkit/src/main/kotlin/dev/sigstore/testkit/BaseGradleTest.kt b/sigstore-testkit/src/main/kotlin/dev/sigstore/testkit/BaseGradleTest.kt index b761b1d2..06781f27 100644 --- a/sigstore-testkit/src/main/kotlin/dev/sigstore/testkit/BaseGradleTest.kt +++ b/sigstore-testkit/src/main/kotlin/dev/sigstore/testkit/BaseGradleTest.kt @@ -29,11 +29,15 @@ import org.junit.jupiter.params.provider.Arguments import org.junit.jupiter.params.provider.Arguments.arguments import java.io.File import java.nio.file.Path +import kotlin.io.path.appendText open class BaseGradleTest { enum class ConfigurationCache { ON, OFF } + enum class ProjectIsolation { + ON, OFF + } // to debug these tests, add .withDebug(true) before running a test in debug mode protected val gradleRunner = GradleRunner.create().withPluginClasspath() @@ -63,16 +67,16 @@ open class BaseGradleTest { if (!isCI) { // Execute a single combination only when running locally return listOf( - TestedGradle(gradleVersions().first(), ConfigurationCache.ON) + TestedGradle(gradleVersions().first(), ConfigurationCache.ON, ProjectIsolation.ON) ) } return buildList { addAll( - gradleVersions().map { TestedGradle(it, ConfigurationCache.ON) } + gradleVersions().map { TestedGradle(it, ConfigurationCache.ON, ProjectIsolation.ON) } ) // Test the first and the last version without configuration cache - add(TestedGradle(gradleVersions().first(), ConfigurationCache.OFF)) - add(TestedGradle(gradleVersions().last(), ConfigurationCache.OFF)) + add(TestedGradle(gradleVersions().first(), ConfigurationCache.OFF, ProjectIsolation.OFF)) + add(TestedGradle(gradleVersions().last(), ConfigurationCache.OFF, ProjectIsolation.OFF)) } } @@ -202,6 +206,23 @@ open class BaseGradleTest { ) } + protected fun enableProjectIsolation( + gradle: TestedGradle, + ) { + if (gradle.projectIsolation != ProjectIsolation.ON) { + return + } + require(gradle.configurationCache == ConfigurationCache.ON) { + "Project isolation requires Configuration Cache." + } + projectDir.resolve("gradle.properties").appendText( + """ + + org.gradle.unsafe.isolated-projects=true + """.trimIndent() + ) + } + protected fun assertSoftly(body: SoftAssertions.() -> Unit) = SoftAssertions.assertSoftly(body) diff --git a/sigstore-testkit/src/main/kotlin/dev/sigstore/testkit/TestedGradle.kt b/sigstore-testkit/src/main/kotlin/dev/sigstore/testkit/TestedGradle.kt index b6ee684b..8990fae7 100644 --- a/sigstore-testkit/src/main/kotlin/dev/sigstore/testkit/TestedGradle.kt +++ b/sigstore-testkit/src/main/kotlin/dev/sigstore/testkit/TestedGradle.kt @@ -23,5 +23,6 @@ import org.gradle.util.GradleVersion */ data class TestedGradle( val version: GradleVersion, - val configurationCache: BaseGradleTest.ConfigurationCache + val configurationCache: BaseGradleTest.ConfigurationCache, + val projectIsolation: BaseGradleTest.ProjectIsolation, ) From 9144e2382e9b2bdafadbfa5e3191b9cf03574238 Mon Sep 17 00:00:00 2001 From: Philip Wedemann <22521688+hfhbd@users.noreply.github.com> Date: Wed, 23 Oct 2024 12:35:11 +0200 Subject: [PATCH 3/3] Update sigstore-gradle/sigstore-gradle-sign-base-plugin/src/main/kotlin/dev/sigstore/sign/SigstoreSignExtension.kt Co-authored-by: Vladimir Sitnikov Signed-off-by: Philip Wedemann <22521688+hfhbd@users.noreply.github.com> --- .../src/main/kotlin/dev/sigstore/sign/SigstoreSignExtension.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sigstore-gradle/sigstore-gradle-sign-base-plugin/src/main/kotlin/dev/sigstore/sign/SigstoreSignExtension.kt b/sigstore-gradle/sigstore-gradle-sign-base-plugin/src/main/kotlin/dev/sigstore/sign/SigstoreSignExtension.kt index 115cdf93..e2fb43fc 100644 --- a/sigstore-gradle/sigstore-gradle-sign-base-plugin/src/main/kotlin/dev/sigstore/sign/SigstoreSignExtension.kt +++ b/sigstore-gradle/sigstore-gradle-sign-base-plugin/src/main/kotlin/dev/sigstore/sign/SigstoreSignExtension.kt @@ -84,7 +84,7 @@ abstract class SigstoreSignExtension(private val project: Project) { } val removeSigstoreAsc = - project.providers.gradleProperty("dev.sigstore.sign.remove.sigstore.json.asc").map { it.toBoolean() }.orNull != false + project.providers.gradleProperty("dev.sigstore.sign.remove.sigstore.json.asc").orNull?.toBoolean() != false val publicationName = publication.name