forked from Kotlin/dokka
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMultiModuleFunctionalTest.kt
272 lines (249 loc) · 11.9 KB
/
MultiModuleFunctionalTest.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
package org.jetbrains.dokka.gradle
import io.kotest.assertions.withClue
import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder
import io.kotest.matchers.collections.shouldNotContainAnyOf
import io.kotest.matchers.paths.shouldBeAFile
import io.kotest.matchers.paths.shouldExist
import io.kotest.matchers.string.shouldContain
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.json.decodeFromStream
import org.jetbrains.dokka.gradle.dokka_configuration.DokkaConfigurationKxs
import org.jetbrains.dokka.gradle.utils.*
import org.junit.jupiter.api.Test
class MultiModuleFunctionalTest {
private val project = gradleKtsProjectTest("multi-module-hello-goodbye") {
settingsGradleKts += """
|
|include(":subproject-hello")
|include(":subproject-goodbye")
""".trimMargin()
buildGradleKts = """
|import org.jetbrains.dokka.gradle.tasks.DokkaConfigurationTask
|import org.jetbrains.dokka.gradle.dokka_configuration.DokkaConfigurationKxs
|import org.jetbrains.dokka.*
|
|plugins {
| // Kotlin plugin shouldn't be necessary here, but without it Dokka errors
| // with ClassNotFound KotlinPluginExtension... very weird
| kotlin("jvm") version "1.7.20" apply false
| id("org.jetbrains.dokka2") version "2.0.0"
|}
|
|dependencies {
| dokka(project(":subproject-hello"))
| dokka(project(":subproject-goodbye"))
|}
|
|//tasks.withType<DokkaConfigurationTask>().configureEach {
|// sourceSets.add(
|// DokkaConfigurationKxs.DokkaSourceSetKxs(
|// displayName = "The Root Project",
|// sourceSetID = DokkaSourceSetID("moduleName", "main"),
|// classpath = emptyList(),
|// sourceRoots = setOf(file("src/main/kotlin")),
|// dependentSourceSets = emptySet(),
|// samples = emptySet(),
|// includes = emptySet(),
|// documentedVisibilities = DokkaConfiguration.Visibility.values().toSet(),
|// reportUndocumented = false,
|// skipEmptyPackages = true,
|// skipDeprecated = false,
|// jdkVersion = 8,
|// sourceLinks = emptySet(),
|// perPackageOptions = emptyList(),
|// externalDocumentationLinks = emptySet(),
|// languageVersion = null,
|// apiVersion = null,
|// noStdlibLink = false,
|// noJdkLink = false,
|// suppressedFiles = emptySet(),
|// analysisPlatform = org.jetbrains.dokka.Platform.DEFAULT,
|// )
|// )
|//}
""".trimMargin()
// createKotlinFile(
// "src/main/kotlin/Dummy.kt", """
// package com.project.dummy
//
// /** Dummy class - this is only here to trigger Dokka */
// class Dummy {
// val nothing: String = ""
// }
// """.trimIndent()
// )
createKtsFile(
"subproject-hello/build.gradle.kts",
"""
|//import org.jetbrains.dokka.gradle.tasks.DokkaConfigurationTask
|//import org.jetbrains.dokka.gradle.dokka_configuration.DokkaConfigurationKxs
|//import org.jetbrains.dokka.*
|
|plugins {
| kotlin("jvm") version "1.7.20"
| id("org.jetbrains.dokka2") version "2.0.0"
|}
|
|// TODO copy the DSL from the old plugin
|//tasks.withType<DokkaConfigurationTask>().configureEach {
| //dokkaSourceSets.create("Hello Subproject") {
| // sourceSetID = DokkaSourceSetID("moduleName", "main")
| // classpath = emptyList()
| // sourceRoots = setOf(file("src/main/kotlin"))
| // dependentSourceSets = emptySet()
| // samples = emptySet()
| // includes = emptySet()
| // documentedVisibilities = DokkaConfiguration.Visibility.values().toSet()
| // reportUndocumented = false
| // skipEmptyPackages = true
| // skipDeprecated = false
| // jdkVersion = 8
| // sourceLinks = emptySet()
| // perPackageOptions = emptyList()
| // externalDocumentationLinks = emptySet()
| // languageVersion = null
| // apiVersion = null
| // noStdlibLink = false
| // noJdkLink = false
| // suppressedFiles = emptySet()
| // analysisPlatform = org.jetbrains.dokka.Platform.DEFAULT
| //}
|//}
""".trimMargin()
)
createKotlinFile(
"subproject-hello/src/main/kotlin/Hello.kt", """
|package com.project.hello
|
|/** The Hello class */
|class Hello {
| /** prints `Hello` to the console */
| fun sayHello() = println("Hello")
|}
""".trimMargin()
)
createKtsFile(
"subproject-goodbye/build.gradle.kts",
"""
|
|//import org.jetbrains.dokka.gradle.tasks.DokkaConfigurationTask
|//import org.jetbrains.dokka.gradle.dokka_configuration.DokkaConfigurationKxs
|//import org.jetbrains.dokka.*
|
|plugins {
| kotlin("jvm") version "1.7.20"
| id("org.jetbrains.dokka2") version "2.0.0"
|}
|
|logger.lifecycle("with kotlin extension " + kotlin::class.toString())
|
|//tasks.withType<DokkaConfigurationTask>().configureEach {
| // dokkaSourceSets.create("Goodbye Subproject") {}
|// sourceSets.add(
|// DokkaConfigurationKxs.DokkaSourceSetKxs(
|// displayName = "My Subproject",
|// sourceSetID = DokkaSourceSetID("moduleName", "main"),
|// classpath = emptyList(),
|// sourceRoots = setOf(file("src/main/kotlin")),
|// dependentSourceSets = emptySet(),
|// samples = emptySet(),
|// includes = emptySet(),
|// documentedVisibilities = DokkaConfiguration.Visibility.values().toSet(),
|// reportUndocumented = false,
|// skipEmptyPackages = true,
|// skipDeprecated = false,
|// jdkVersion = 8,
|// sourceLinks = emptySet(),
|// perPackageOptions = emptyList(),
|// externalDocumentationLinks = emptySet(),
|// languageVersion = null,
|// apiVersion = null,
|// noStdlibLink = false,
|// noJdkLink = false,
|// suppressedFiles = emptySet(),
|// analysisPlatform = org.jetbrains.dokka.Platform.DEFAULT,
|// )
|// )
|//}
""".trimMargin()
)
createKotlinFile(
"subproject-goodbye/src/main/kotlin/Goodbye.kt", """
|package com.project.goodbye
|
|/** The Goodbye class */
|class Goodbye {
| /** prints a goodbye message to the console */
| fun sayHello() = println("Goodbye!")
|}
""".trimMargin()
)
}
// @Test
fun `expect subproject generates JavaDoc site`() {
val build = project.runner
.withArguments(":subproject:dokkaGenerate", "--stacktrace", "--info")
.forwardOutput()
.build()
build.output shouldContain "BUILD SUCCESSFUL"
build.output shouldContain "Generation completed successfully"
project.projectDir.resolve("subproject/build/dokka/html/com/project/hello/Hello.html").shouldBeAFile()
project.projectDir.resolve("subproject/build/dokka/html/index.html").shouldBeAFile()
project.projectDir.resolve("subproject/build/dokka/html/dokka_configuration.json").shouldBeAFile()
project.projectDir.resolve("subproject/build/dokka/html/element-list").shouldBeAFile()
project.projectDir.resolve("subproject/build/dokka/html/element-list").toFile().readText().shouldContain(
"""
${'$'}dokka.format:javadoc-v1
${'$'}dokka.linkExtension:html
com.project.hello
""".trimIndent()
)
}
@Test
fun `expect root project aggregates`() {
val build = project.runner
.withArguments("clean", ":dokkaGenerate", "--stacktrace", "--info")
.forwardOutput()
.build()
build.output shouldContain "BUILD SUCCESSFUL"
build.output shouldContain "Generation completed successfully"
// project.projectDir.toFile().walk().forEach { println(it) }
// project.projectDir.resolve("subproject/build/dokka-output/com/project/hello/Hello.html").shouldBeAFile()
// project.projectDir.resolve("subproject/build/dokka-output/index.html").shouldBeAFile()
// project.projectDir.resolve("subproject/build/dokka-config/dokka_configuration.json").shouldBeAFile()
// project.projectDir.resolve("subproject/build/dokka-output/element-list").shouldBeAFile()
// project.projectDir.resolve("subproject/build/dokka-output/element-list").toFile().readText().shouldContain(
// """
// ${'$'}dokka.format:javadoc-v1
// ${'$'}dokka.linkExtension:html
//
// com.project.hello
// """.trimIndent()
// )
val dokkaConfigurationFile = project.projectDir.resolve("build/dokka-config/html/dokka_configuration.json")
dokkaConfigurationFile.shouldExist()
dokkaConfigurationFile.shouldBeAFile()
@OptIn(ExperimentalSerializationApi::class)
val dokkaConfiguration = kotlinx.serialization.json.Json.decodeFromStream(
DokkaConfigurationKxs.serializer(),
dokkaConfigurationFile.toFile().inputStream(),
)
withClue("pluginsClasspath should not contain subproject jars") {
val pluginClasspathJars = dokkaConfiguration.pluginsClasspath.map { it.name }
pluginClasspathJars.shouldNotContainAnyOf(
"subproject-hello.jar",
"subproject-goodbye.jar",
)
pluginClasspathJars.shouldContainExactlyInAnyOrder(
"markdown-jvm-0.3.1.jar",
"kotlin-analysis-intellij-1.7.20.jar",
"dokka-base-1.7.20.jar",
"templating-plugin-1.7.20.jar",
"dokka-analysis-1.7.20.jar",
"kotlin-analysis-compiler-1.7.20.jar",
"kotlinx-html-jvm-0.8.0.jar",
"freemarker-2.3.31.jar"
)
}
}
}