diff --git a/build-logic/src/main/kotlin/dokkabuild/utils/DokkaGradleExampleDirectoriesSource.kt b/build-logic/src/main/kotlin/dokkabuild/utils/DokkaGradleExampleDirectoriesSource.kt new file mode 100644 index 0000000000..79e1b1e3dd --- /dev/null +++ b/build-logic/src/main/kotlin/dokkabuild/utils/DokkaGradleExampleDirectoriesSource.kt @@ -0,0 +1,36 @@ +/* + * Copyright 2014-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. + */ +package dokkabuild.utils + +import org.gradle.api.file.DirectoryProperty +import org.gradle.api.provider.ValueSource +import org.gradle.api.provider.ValueSourceParameters +import java.io.File +import kotlin.io.path.isDirectory +import kotlin.io.path.listDirectoryEntries +import kotlin.io.path.name + +/** + * Fetch the example directories in `dokka/examples/gradle-v2` using a [ValueSource]. + * + * A [ValueSource] is necessary to ensure that Gradle registers the directory values as Configuration Cache inputs, + * but doesn't become overly sensitive to the contents of the directories. + */ +abstract class DokkaGradleExampleDirectoriesSource : + ValueSource, DokkaGradleExampleDirectoriesSource.Parameters> { + + interface Parameters : ValueSourceParameters { + /** + * The directory containing the Dokka Gradle v2 examples: `dokka/examples/gradle-v2` + */ + val exampleGradleProjectsDir: DirectoryProperty + } + + override fun obtain(): List { + return parameters.exampleGradleProjectsDir.get().asFile.toPath() + .listDirectoryEntries() + .filter { it.isDirectory() && it.name.endsWith("-example") } + .map { it.toFile() } + } +} diff --git a/dokka-integration-tests/gradle/build.gradle.kts b/dokka-integration-tests/gradle/build.gradle.kts index b7b302d758..0288a1236c 100644 --- a/dokka-integration-tests/gradle/build.gradle.kts +++ b/dokka-integration-tests/gradle/build.gradle.kts @@ -4,12 +4,10 @@ @file:Suppress("UnstableApiUsage") import dokkabuild.tasks.GitCheckoutTask +import dokkabuild.utils.DokkaGradleExampleDirectoriesSource import dokkabuild.utils.systemProperty import dokkabuild.utils.uppercaseFirstChar -import org.gradle.api.tasks.PathSensitivity.NAME_ONLY -import org.gradle.api.tasks.PathSensitivity.RELATIVE -import kotlin.io.path.listDirectoryEntries -import kotlin.io.path.name +import org.gradle.api.tasks.PathSensitivity.* plugins { id("dokkabuild.kotlin-jvm") @@ -204,7 +202,6 @@ testing { targets.configureEach { testTask { - systemProperty .inputDirectory("exampleGradleProjectsDir", exampleGradleProjectsDir) .withPathSensitivity(RELATIVE) @@ -220,27 +217,27 @@ testing { } } - // Register specific Gradle test runs for each example so the examples can be tested individually. - exampleGradleProjectsDir.toPath() - .listDirectoryEntries() - .map { it.name } - .filter { - it.endsWith("-example") - // note: avoid checks like `isDirectory()` to prevent Gradle registering the files as CC inputs. - } - .forEach { exampleProjectName -> - val prettyName = exampleProjectName - .removeSuffix("-example") - .split("-") - .joinToString("") { it.uppercaseFirstChar() } - - targets.register("testExample$prettyName") { - testTask { - description = "Only test $exampleProjectName" - group = "verification - example projects" - systemProperty.inputProperty("exampleProjectFilter", exampleProjectName) - } + val exampleProjectDirs = providers.of(DokkaGradleExampleDirectoriesSource::class) { + parameters.exampleGradleProjectsDir = exampleGradleProjectsDir + }.get() + + exampleProjectDirs.forEach { exampleProjectDir -> + val exampleProjectName = exampleProjectDir.name + val prettyName = exampleProjectName + .split("-") + .joinToString("") { it.uppercaseFirstChar() } + + targets.register("test$prettyName") { + testTask { + description = "Only test $exampleProjectName" + group = "verification - example projects" + systemProperty.inputProperty("exampleProjectFilter", exampleProjectName) + + systemProperty + .inputDirectory("exampleGradleProjectDir $exampleProjectName", exampleProjectDir) + .withPathSensitivity(NONE) } } + } } }