/
TestDokkaConfigurationBuilder.kt
210 lines (193 loc) · 8.06 KB
/
TestDokkaConfigurationBuilder.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
package testApi.testRunner
import org.intellij.markdown.MarkdownElementTypes
import org.jetbrains.dokka.*
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.model.*
import org.jetbrains.dokka.model.doc.CustomDocTag
import org.jetbrains.dokka.model.doc.Description
import org.jetbrains.dokka.model.doc.DocumentationNode
import org.jetbrains.dokka.model.doc.Text
import org.jetbrains.dokka.model.properties.PropertyContainer
import java.io.File
fun dokkaConfiguration(block: TestDokkaConfigurationBuilder.() -> Unit): DokkaConfigurationImpl =
TestDokkaConfigurationBuilder().apply(block).build()
@DslMarker
annotation class DokkaConfigurationDsl
@DokkaConfigurationDsl
class TestDokkaConfigurationBuilder {
var moduleName: String = "root"
set(value) {
check(lazySourceSets.isEmpty()) { "Cannot set moduleName after adding source sets" }
field = value
}
var moduleVersion: String = "1.0-SNAPSHOT"
var outputDir: File = File("out")
var format: String = "html"
var offlineMode: Boolean = false
var cacheRoot: String? = null
var pluginsClasspath: List<File> = emptyList()
var pluginsConfigurations: MutableList<PluginConfigurationImpl> = mutableListOf()
var failOnWarning: Boolean = false
var modules: List<DokkaModuleDescriptionImpl> = emptyList()
var suppressObviousFunctions: Boolean = DokkaDefaults.suppressObviousFunctions
var includes: List<File> = emptyList()
var suppressInheritedMembers: Boolean = DokkaDefaults.suppressInheritedMembers
var delayTemplateSubstitution: Boolean = DokkaDefaults.delayTemplateSubstitution
private val lazySourceSets = mutableListOf<Lazy<DokkaSourceSetImpl>>()
fun build() = DokkaConfigurationImpl(
moduleName = moduleName,
moduleVersion = moduleVersion,
outputDir = outputDir,
cacheRoot = cacheRoot?.let(::File),
offlineMode = offlineMode,
sourceSets = lazySourceSets.map { it.value }.toList(),
pluginsClasspath = pluginsClasspath,
pluginsConfiguration = pluginsConfigurations,
modules = modules,
failOnWarning = failOnWarning,
suppressObviousFunctions = suppressObviousFunctions,
includes = includes.toSet(),
suppressInheritedMembers = suppressInheritedMembers,
delayTemplateSubstitution = delayTemplateSubstitution,
finalizeCoroutines = false
)
fun sourceSets(block: SourceSetsBuilder.() -> Unit) {
lazySourceSets.addAll(SourceSetsBuilder(moduleName).apply(block))
}
fun sourceSet(block: DokkaSourceSetBuilder.() -> Unit): Lazy<DokkaSourceSetImpl> {
val lazySourceSet = lazy { DokkaSourceSetBuilder(moduleName).apply(block).build() }
lazySourceSets.add(lazySourceSet)
return lazySourceSet
}
fun unattachedSourceSet(block: DokkaSourceSetBuilder.() -> Unit): DokkaSourceSetImpl {
return DokkaSourceSetBuilder(moduleName).apply(block).build()
}
}
@DokkaConfigurationDsl
class SourceSetsBuilder(val moduleName: String) : ArrayList<Lazy<DokkaSourceSetImpl>>() {
fun sourceSet(block: DokkaSourceSetBuilder.() -> Unit): Lazy<DokkaConfiguration.DokkaSourceSet> =
lazy { DokkaSourceSetBuilder(moduleName).apply(block).build() }.apply(::add)
}
@DokkaConfigurationDsl
class DokkaSourceSetBuilder(
private val moduleName: String,
var name: String = "main",
var displayName: String = "JVM",
var classpath: List<String> = emptyList(),
var sourceRoots: List<String> = emptyList(),
var dependentSourceSets: Set<DokkaSourceSetID> = emptySet(),
var samples: List<String> = emptyList(),
var includes: List<String> = emptyList(),
@Deprecated(message = "Use [documentedVisibilities] property for a more flexible control over documented visibilities")
var includeNonPublic: Boolean = false,
var documentedVisibilities: Set<DokkaConfiguration.Visibility> = DokkaDefaults.documentedVisibilities,
var reportUndocumented: Boolean = false,
var skipEmptyPackages: Boolean = false,
var skipDeprecated: Boolean = false,
var jdkVersion: Int = 8,
var languageVersion: String? = null,
var apiVersion: String? = null,
var noStdlibLink: Boolean = false,
var noJdkLink: Boolean = false,
var suppressedFiles: List<String> = emptyList(),
var analysisPlatform: String = "jvm",
var perPackageOptions: List<PackageOptionsImpl> = emptyList(),
var externalDocumentationLinks: List<ExternalDocumentationLinkImpl> = emptyList(),
var sourceLinks: List<SourceLinkDefinitionImpl> = emptyList()
) {
fun build() = DokkaSourceSetImpl(
displayName = displayName,
sourceSetID = DokkaSourceSetID(moduleName, name),
classpath = classpath.map(::File),
sourceRoots = sourceRoots.map(::File).toSet(),
dependentSourceSets = dependentSourceSets,
samples = samples.map(::File).toSet(),
includes = includes.map(::File).toSet(),
includeNonPublic = includeNonPublic,
documentedVisibilities = documentedVisibilities,
reportUndocumented = reportUndocumented,
skipEmptyPackages = skipEmptyPackages,
skipDeprecated = skipDeprecated,
jdkVersion = jdkVersion,
sourceLinks = sourceLinks.toSet(),
perPackageOptions = perPackageOptions.toList(),
externalDocumentationLinks = externalDocumentationLinks.toSet(),
languageVersion = languageVersion,
apiVersion = apiVersion,
noStdlibLink = noStdlibLink,
noJdkLink = noJdkLink,
suppressedFiles = suppressedFiles.map(::File).toSet(),
analysisPlatform = Platform.fromString(analysisPlatform)
)
}
val defaultSourceSet = DokkaSourceSetImpl(
displayName = "DEFAULT",
sourceSetID = DokkaSourceSetID("DEFAULT", "DEFAULT"),
classpath = emptyList(),
sourceRoots = emptySet(),
dependentSourceSets = emptySet(),
samples = emptySet(),
includes = emptySet(),
includeNonPublic = false,
documentedVisibilities = DokkaDefaults.documentedVisibilities,
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 = Platform.DEFAULT
)
fun sourceSet(name: String): DokkaConfiguration.DokkaSourceSet {
return defaultSourceSet.copy(
displayName = name,
sourceSetID = defaultSourceSet.sourceSetID.copy(sourceSetName = name)
)
}
fun dModule(
name: String,
packages: List<DPackage> = emptyList(),
documentation: SourceSetDependent<DocumentationNode> = emptyMap(),
expectPresentInSet: DokkaConfiguration.DokkaSourceSet? = null,
sourceSets: Set<DokkaConfiguration.DokkaSourceSet> = emptySet(),
extra: PropertyContainer<DModule> = PropertyContainer.empty()
): DModule = DModule(
name = name,
packages = packages,
documentation = documentation,
expectPresentInSet = expectPresentInSet,
sourceSets = sourceSets,
extra = extra
)
fun dPackage(
dri: DRI,
functions: List<DFunction> = emptyList(),
properties: List<DProperty> = emptyList(),
classlikes: List<DClasslike> = emptyList(),
typealiases: List<DTypeAlias> = emptyList(),
documentation: SourceSetDependent<DocumentationNode> = emptyMap(),
expectPresentInSet: DokkaConfiguration.DokkaSourceSet? = null,
sourceSets: Set<DokkaConfiguration.DokkaSourceSet> = emptySet(),
extra: PropertyContainer<DPackage> = PropertyContainer.empty()
): DPackage = DPackage(
dri = dri,
functions = functions,
properties = properties,
classlikes = classlikes,
typealiases = typealiases,
documentation = documentation,
expectPresentInSet = expectPresentInSet,
sourceSets = sourceSets,
extra = extra
)
fun documentationNode(vararg texts: String): DocumentationNode {
return DocumentationNode(
texts.toList()
.map { Description(CustomDocTag(listOf(Text(it)), name = MarkdownElementTypes.MARKDOWN_FILE.name)) })
}