Skip to content

Commit

Permalink
try to fix example projects CC
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-enko committed Nov 19, 2024
1 parent 4a5e488 commit 8c87761
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -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<List<File>, DokkaGradleExampleDirectoriesSource.Parameters> {

interface Parameters : ValueSourceParameters {
/**
* The directory containing the Dokka Gradle v2 examples: `dokka/examples/gradle-v2`
*/
val exampleGradleProjectsDir: DirectoryProperty
}

override fun obtain(): List<File> {
return parameters.exampleGradleProjectsDir.get().asFile.toPath()
.listDirectoryEntries()
.filter { it.isDirectory() && it.name.endsWith("-example") }
.map { it.toFile() }
}
}
47 changes: 22 additions & 25 deletions dokka-integration-tests/gradle/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -204,7 +202,6 @@ testing {

targets.configureEach {
testTask {

systemProperty
.inputDirectory("exampleGradleProjectsDir", exampleGradleProjectsDir)
.withPathSensitivity(RELATIVE)
Expand All @@ -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)
}
}
}
}
}

0 comments on commit 8c87761

Please sign in to comment.