Skip to content

Commit cddd735

Browse files
authored
Add example to demonstrate how to configure a custom Dokka plugin (#3871)
#3869
1 parent e00d4bf commit cddd735

File tree

79 files changed

+3280
-12
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+3280
-12
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2014-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
package dokkabuild.utils
5+
6+
import org.gradle.api.file.DirectoryProperty
7+
import org.gradle.api.provider.ValueSource
8+
import org.gradle.api.provider.ValueSourceParameters
9+
import java.io.File
10+
import kotlin.io.path.isDirectory
11+
import kotlin.io.path.listDirectoryEntries
12+
import kotlin.io.path.name
13+
14+
/**
15+
* Fetch the example directories in `dokka/examples/gradle-v2` using a [ValueSource].
16+
*
17+
* A [ValueSource] is necessary to ensure that Gradle registers the directory values as Configuration Cache inputs,
18+
* but doesn't become overly sensitive to the contents of the directories.
19+
*/
20+
abstract class DokkaGradleExampleDirectoriesSource :
21+
ValueSource<List<File>, DokkaGradleExampleDirectoriesSource.Parameters> {
22+
23+
interface Parameters : ValueSourceParameters {
24+
/**
25+
* The directory containing the Dokka Gradle v2 examples: `dokka/examples/gradle-v2`
26+
*/
27+
val exampleGradleProjectsDir: DirectoryProperty
28+
}
29+
30+
override fun obtain(): List<File> {
31+
return parameters.exampleGradleProjectsDir.get().asFile.toPath()
32+
.listDirectoryEntries()
33+
.filter { it.isDirectory() && it.name.endsWith("-example") }
34+
.map { it.toFile() }
35+
}
36+
}

build-logic/src/main/kotlin/dokkabuild/utils/SystemPropertyAdder.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,16 @@ abstract class SystemPropertyAdder @Inject internal constructor(
153153
return task.inputs.property("SystemProperty input property $key", value)
154154
}
155155

156+
fun inputProperty(
157+
key: String,
158+
value: String,
159+
): TaskInputPropertyBuilder {
160+
task.jvmArgumentProviders.add(
161+
SystemPropertyArgumentProvider(key, value) { it }
162+
)
163+
return task.inputs.property("SystemProperty input property $key", value)
164+
}
165+
156166
@JvmName("inputBooleanProperty")
157167
fun inputProperty(
158168
key: String,
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/*
2+
* Copyright 2014-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
package dokkabuild.utils
5+
6+
/** Title case the first char of a string */
7+
fun String.uppercaseFirstChar(): String = replaceFirstChar(Char::uppercaseChar)

dokka-integration-tests/gradle/build.gradle.kts

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
@file:Suppress("UnstableApiUsage")
55

66
import dokkabuild.tasks.GitCheckoutTask
7+
import dokkabuild.utils.DokkaGradleExampleDirectoriesSource
78
import dokkabuild.utils.systemProperty
8-
import org.gradle.api.tasks.PathSensitivity.NAME_ONLY
9-
import org.gradle.api.tasks.PathSensitivity.RELATIVE
9+
import dokkabuild.utils.uppercaseFirstChar
10+
import org.gradle.api.tasks.PathSensitivity.*
1011

1112
plugins {
1213
id("dokkabuild.kotlin-jvm")
@@ -226,10 +227,10 @@ testing {
226227
}
227228
}
228229
val testExampleProjects by suites.registering(JvmTestSuite::class) {
229-
targets.configureEach {
230-
testTask.configure {
230+
val exampleGradleProjectsDir = projectDir.resolve("../../examples/gradle-v2")
231231

232-
val exampleGradleProjectsDir = projectDir.resolve("../../examples/gradle-v2")
232+
targets.configureEach {
233+
testTask {
233234
systemProperty
234235
.inputDirectory("exampleGradleProjectsDir", exampleGradleProjectsDir)
235236
.withPathSensitivity(RELATIVE)
@@ -244,5 +245,28 @@ testing {
244245
systemProperty("junit.jupiter.execution.parallel.mode.default", "CONCURRENT")
245246
}
246247
}
248+
249+
val exampleProjectDirs = providers.of(DokkaGradleExampleDirectoriesSource::class) {
250+
parameters.exampleGradleProjectsDir = exampleGradleProjectsDir
251+
}.get()
252+
253+
exampleProjectDirs.forEach { exampleProjectDir ->
254+
val exampleProjectName = exampleProjectDir.name
255+
val prettyName = exampleProjectName
256+
.split("-")
257+
.joinToString("") { it.uppercaseFirstChar() }
258+
259+
targets.register("test$prettyName") {
260+
testTask {
261+
description = "Only test $exampleProjectName"
262+
group = "verification - example projects"
263+
systemProperty.inputProperty("exampleProjectFilter", exampleProjectName)
264+
265+
systemProperty
266+
.inputDirectory("exampleGradleProjectDir $exampleProjectName", exampleProjectDir)
267+
.withPathSensitivity(NONE)
268+
}
269+
}
270+
}
247271
}
248272
}

dokka-integration-tests/gradle/src/testExampleProjects/expectedData/exampleProjects/custom-dokka-plugin-example/html/-demo -library/demo/-greeter/-greeter.html

Lines changed: 132 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dokka-integration-tests/gradle/src/testExampleProjects/expectedData/exampleProjects/custom-dokka-plugin-example/html/-demo -library/demo/-greeter/greet.html

Lines changed: 132 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)