Skip to content

Commit 9eb05a5

Browse files
committed
Fix suppressGeneratedFiles was unused
1 parent f98203a commit 9eb05a5

File tree

2 files changed

+140
-0
lines changed

2 files changed

+140
-0
lines changed

dokka-runners/dokka-gradle-plugin/src/main/kotlin/DokkaBasePlugin.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,15 @@ constructor(
202202
sourceSetScope.convention(sourceSetScopeConvention)
203203

204204
suppressGeneratedFiles.convention(true)
205+
suppressedFiles.from(
206+
suppressGeneratedFiles.map { suppressGenerated ->
207+
if (suppressGenerated) {
208+
layout.buildDirectory.dir("generated")
209+
} else {
210+
objects.fileCollection()
211+
}
212+
}
213+
)
205214

206215
sourceLinks.configureEach {
207216
localDirectory.convention(layout.projectDirectory)
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
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 org.jetbrains.dokka.gradle
5+
6+
import io.kotest.core.spec.style.FunSpec
7+
import io.kotest.matchers.paths.shouldExist
8+
import io.kotest.matchers.string.shouldContain
9+
import io.kotest.matchers.string.shouldNotContain
10+
import org.jetbrains.dokka.gradle.internal.DokkaConstants.DOKKA_VERSION
11+
import org.jetbrains.dokka.gradle.utils.*
12+
import java.nio.file.Path
13+
import kotlin.io.path.readText
14+
15+
class SuppressGeneratedFilesFunctionalTest : FunSpec({
16+
17+
context("suppressGeneratedFiles") {
18+
19+
test("when suppressGeneratedFiles is true, generated files should be suppressed") {
20+
val project = createProject(suppressGeneratedFiles = true)
21+
22+
project.runner
23+
.addArguments(
24+
":dokkaGeneratePublicationHtml",
25+
"--rerun-tasks",
26+
"--stacktrace",
27+
)
28+
.build {
29+
val htmlContent = project.projectDir
30+
.resolve("build/dokka/html/suppress-generated-files-true/[root]/index.html")
31+
.also(Path::shouldExist)
32+
.readText()
33+
htmlContent shouldContain "MyClass"
34+
htmlContent shouldNotContain "GeneratedClass"
35+
htmlContent shouldNotContain "GeneratedJavaClass"
36+
}
37+
}
38+
39+
test("when suppressGeneratedFiles is false, generated files should be documented") {
40+
val project = createProject(suppressGeneratedFiles = false)
41+
42+
project.runner
43+
.addArguments(
44+
":dokkaGeneratePublicationHtml",
45+
"--rerun-tasks",
46+
"--stacktrace",
47+
)
48+
.build {
49+
val htmlContent = project.projectDir
50+
.resolve("build/dokka/html/suppress-generated-files-false/[root]/index.html")
51+
.also(Path::shouldExist)
52+
.readText()
53+
htmlContent shouldContain "MyClass"
54+
htmlContent shouldContain "GeneratedClass"
55+
htmlContent shouldContain "GeneratedJavaClass"
56+
}
57+
}
58+
}
59+
})
60+
61+
private fun createProject(
62+
suppressGeneratedFiles: Boolean
63+
): GradleProjectTest = gradleKtsProjectTest("suppress-generated-files-$suppressGeneratedFiles") {
64+
buildGradleKts = """
65+
|plugins {
66+
| kotlin("jvm") version embeddedKotlinVersion
67+
| id("org.jetbrains.dokka") version "$DOKKA_VERSION"
68+
|}
69+
|
70+
|dokka {
71+
| dokkaSourceSets.configureEach {
72+
| suppressGeneratedFiles.set(${suppressGeneratedFiles})
73+
| // emulate generated sources added, for example by KSP
74+
| sourceRoots.from("build/generated")
75+
| }
76+
|}
77+
|""".trimMargin()
78+
79+
dir("src/main/kotlin") {
80+
createKotlinFile(
81+
"MyClass.kt",
82+
"""
83+
|/**
84+
| * A regular class that should be documented
85+
| */
86+
|class MyClass {
87+
| /**
88+
| * A function that should be documented
89+
| */
90+
| fun regularFunction() = "Hello"
91+
|}
92+
|""".trimMargin()
93+
)
94+
}
95+
96+
dir("build/generated/ksp/main") {
97+
createKotlinFile(
98+
"GeneratedClass.kt",
99+
"""
100+
|/**
101+
| * A generated class that should NOT be documented
102+
| */
103+
|class GeneratedClass {
104+
| /**
105+
| * A generated function that should NOT be documented
106+
| */
107+
| fun generatedFunction() = "Generated"
108+
|}
109+
|""".trimMargin()
110+
)
111+
}
112+
113+
dir("build/generated/apt/java/main") {
114+
createFile(
115+
"GeneratedJavaClass.java",
116+
"""
117+
|/**
118+
| * A generated Java class that should NOT be documented
119+
| */
120+
|public class GeneratedJavaClass {
121+
| /**
122+
| * A generated method that should NOT be documented
123+
| */
124+
| public String generatedMethod() {
125+
| return "Generated Java";
126+
| }
127+
|}
128+
|""".trimMargin()
129+
)
130+
}
131+
}

0 commit comments

Comments
 (0)