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 plugin: Replace findProperty with Isolated Project compatible … #811

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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 @@ -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").orNull?.toBoolean() != false

val publicationName = publication.name

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class OidcDslTest: BaseGradleTest() {
""".trimIndent()
)
enableConfigurationCache(gradle)
enableProjectIsolation(gradle)
prepare(gradle.version, "printConfig", "-s")
.build()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
)
Expand Down Expand Up @@ -147,6 +147,7 @@ class RemoveSigstoreAscTest : BaseGradleTest() {
""".trimIndent()
)
enableConfigurationCache(case.gradle)
enableProjectIsolation(case.gradle)
}

private fun SoftAssertions.assertSignatures(name: String, expectSigstoreAsc: Boolean = false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class SigstorePublishSignTest : BaseGradleTest() {
""".trimIndent()
)
enableConfigurationCache(case.gradle)
enableProjectIsolation(case.gradle)
prepare(case.gradle.version, "publishAllPublicationsToTmpRepository", "-s")
.build()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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))
}
}

Expand Down Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Loading