Skip to content

Commit

Permalink
Incorporate review feedback
Browse files Browse the repository at this point in the history
- improve how tests get access to Pkl distributions
  • Loading branch information
translatenix committed Mar 1, 2024
1 parent 85103c6 commit 06f94fd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ msgpack = { group = "org.msgpack", name = "msgpack-core", version.ref = "msgpack
nuValidator = { group = "nu.validator", name = "validator", version.ref = "nuValidator" }
# to be replaced with https://github.com/usethesource/capsule or https://github.com/lacuna/bifurcan
paguro = { group = "org.organicdesign", name = "Paguro", version.ref = "paguro" }
pklConfigJavaAll025 = { group = "org.pkl-lang", name = "pkl-config-java-all", version = "0.25.0" }
shadowPlugin = { group = "gradle.plugin.com.github.johnrengelman", name = "shadow", version.ref = "shadowPlugin" }
slf4jApi = { group = "org.slf4j", name = "slf4j-api", version.ref = "slf4j" }
slf4jSimple = { group = "org.slf4j", name = "slf4j-simple", version.ref = "slf4j" }
Expand Down
20 changes: 9 additions & 11 deletions pkl-executor/pkl-executor.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import de.undercouch.gradle.tasks.download.Download

plugins {
pklAllProjects
pklJavaLibrary
pklPublishLibrary
pklKotlinTest
}

val pklDistribution: Configuration by configurations.creating
val pklDistributionCurrent: Configuration by configurations.creating
val pklDistribution025: Configuration by configurations.creating

// Because pkl-executor doesn't depend on other Pkl modules
// (nor has overlapping dependencies that could cause a version conflict),
// clients are free to use different versions of pkl-executor and (say) pkl-config-java-all.
// (Pkl distributions used by EmbeddedExecutor are isolated via class loaders.)
dependencies {
pklDistribution(project(":pkl-config-java", "fatJar"))
pklDistributionCurrent(project(":pkl-config-java", "fatJar"))
@Suppress("UnstableApiUsage")
pklDistribution025(libs.pklConfigJavaAll025)

implementation(libs.slf4jApi)

Expand Down Expand Up @@ -51,17 +52,14 @@ sourceSets {
}
}

val downloadPkl025 by tasks.registering(Download::class) {
src("https://repo1.maven.org/maven2/org/pkl-lang/pkl-config-java-all/0.25.0/pkl-config-java-all-0.25.0.jar")
dest("build/download/pkl-config-java-all-0.25.0.jar")
doFirst { file("build/download").mkdirs() }
}

// this task could be folded into tasks.test by switching to IntelliJ's Gradle test runner
val prepareTest by tasks.registering {
// used by EmbeddedExecutorTest
dependsOn(downloadPkl025, pklDistribution)
dependsOn(pklDistributionCurrent, pklDistribution025)
}

tasks.test {
dependsOn(prepareTest)
systemProperty("pklDistributionCurrent", pklDistributionCurrent.singleFile)
systemProperty("pklDistribution025", pklDistribution025.singleFile)
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class EmbeddedExecutorTest {
ExecutionContext(executor1_1.value, ::convertToOptions1, "Options1, Executor1, Distribution1"),

// This context has a pkl-executor version that is lower than the distribution version.
// It can be enabled once there is a distribution that ships (at least) with pkl-executor's SPI classes.
//ExecutionContext(::convertToOptions1, executor1_2.value),
// It can be enabled once there is a distribution that includes pkl-executor.
//ExecutionContext(executor1_2.value, ::convertToOptions1, "Options1, Executor1, Distribution2"),

ExecutionContext(executor2_1.value, ::convertToOptions1, "Options1, Executor2, Distribution1"),
ExecutionContext(executor2_1.value, ::convertToOptions2, "Options2, Executor2, Distribution1"),
Expand Down Expand Up @@ -101,19 +101,28 @@ class EmbeddedExecutorTest {

// a Pkl distribution that supports ExecutorSpiOptions up to v1
private val pklDistribution1: Path by lazy {
FileTestUtils.rootProjectDir
.resolve("pkl-executor/build/download/pkl-config-java-all-0.25.0.jar").apply {
if (!exists()) throw AssertionError("Missing test fixture. Run `./gradlew :pkl-executor:prepareTest` to create it.")
val path = System.getProperty("pklDistribution025")?.toPath() ?:
// can get rid of this path by switching to IntelliJ's Gradle test runner
System.getProperty("user.home").toPath()
.resolve(".gradle/caches/modules-2/files-2.1/org.pkl-lang/pkl-config-java-all/" +
"0.25.0/e9451dda554f1659e49ff5bdd30accd26be7bf0f/pkl-config-java-all-0.25.0.jar")
path.apply {
if (!exists()) throw AssertionError("Missing test fixture. " +
"To fix this problem, run `./gradlew :pkl-executor:prepareTest`.")
}
}

// a Pkl distribution that supports ExecutorSpiOptions up to v2
private val pklDistribution2: Path by lazy {
val mavenVersion = Release.current().version().withBuild(null).toString().replaceFirst("dev", "SNAPSHOT")
FileTestUtils.rootProjectDir
.resolve("pkl-config-java/build/libs/pkl-config-java-all-$mavenVersion.jar").apply {
if (!exists()) throw AssertionError("Missing test fixture. Run `./gradlew :pkl-executor:prepareTest` to create it.")
}
val path = System.getProperty("pklDistributionCurrent")?.toPath() ?:
// can get rid of this path by switching to IntelliJ's Gradle test runner
FileTestUtils.rootProjectDir
.resolve("pkl-config-java/build/libs/pkl-config-java-all-" +
"${Release.current().version().withBuild(null).toString().replaceFirst("dev", "SNAPSHOT")}.jar")
path.apply {
if (!exists()) throw AssertionError("Missing test fixture. " +
"To fix this problem, run `./gradlew :pkl-executor:prepareTest`.")
}
}

private fun convertToOptions2(options: ExecutorOptions): ExecutorOptions2 =
Expand Down

0 comments on commit 06f94fd

Please sign in to comment.