Skip to content

Commit d375df5

Browse files
committed
Update Dokka with a bit more configuration.
1 parent e3e7c79 commit d375df5

File tree

7 files changed

+275
-49
lines changed

7 files changed

+275
-49
lines changed

buildSrc/src/main/kotlin/dokka.kt

+62-40
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,21 @@
2121
package net.devrieze.gradle.ext
2222

2323
import org.gradle.api.Project
24+
import org.gradle.api.provider.Provider
25+
import org.gradle.kotlin.dsl.assign
2426
import org.gradle.kotlin.dsl.withType
27+
import org.jetbrains.dokka.Platform
28+
import org.jetbrains.dokka.gradle.AbstractDokkaLeafTask
2529
import org.jetbrains.dokka.gradle.DokkaTask
2630
import org.jetbrains.dokka.gradle.DokkaTaskPartial
2731
import org.jetbrains.dokka.gradle.GradleDokkaSourceSetBuilder
32+
import java.net.URL
2833

2934
fun Project.configureDokka(
3035
myModuleName: String = name,
3136
myModuleVersion: String? = property("xmlutil_version") as String?
3237
) {
33-
tasks.withType<DokkaTask> {
34-
moduleName.set(myModuleName)
35-
myModuleVersion.let { moduleVersion.set(it) }
36-
dokkaSourceSets.configureEach {
37-
this@configureDokka.configureDokkaSourceSet(this)
38-
}
39-
}
40-
tasks.withType<DokkaTaskPartial> {
38+
tasks.withType<AbstractDokkaLeafTask> {
4139
moduleName.set(myModuleName)
4240
myModuleVersion.let { moduleVersion.set(it) }
4341
dokkaSourceSets.configureEach {
@@ -48,38 +46,62 @@ fun Project.configureDokka(
4846

4947
private fun Project.configureDokkaSourceSet(
5048
sourceSet: GradleDokkaSourceSetBuilder
51-
) = with(sourceSet) {
52-
logger.lifecycle("Configuring dokka on sourceSet: $name = ${displayName.orNull}")
53-
if (name.startsWith("android")) {
54-
noAndroidSdkLink.set(false)
55-
noJdkLink.set(true)
56-
} else {
57-
noAndroidSdkLink.set(true)
58-
noJdkLink.set(false)
59-
}
60-
displayName.set(
61-
when (val dn = displayName.get()) {
62-
"jvm" -> "JVM"
63-
"android" -> "Android"
64-
"common" -> "Common"
65-
"js" -> "JS"
66-
else -> dn
67-
}
68-
)
69-
includeNonPublic.set(false)
70-
skipEmptyPackages.set(true)
71-
skipDeprecated.set(true)
72-
perPackageOption {
73-
matchingRegex.set(".*\\.(impl|internal)(|\\..*)")
74-
suppress.set(true)
75-
}
76-
if ("Main" in name) {
77-
val readme = project.file(project.relativePath("src/README.md"))
78-
if (readme.exists() && readme.canRead()) {
79-
includes.from(listOf(readme))
80-
logger.lifecycle("Adding $readme to sourceSet ${project.name}:${name}(${displayName.orNull})")
81-
} else {
82-
logger.warn("Missing $readme for project ${project.name}")
49+
) {
50+
if (!sourceSet.suppress.get()) {
51+
with(sourceSet) {
52+
if (name.startsWith("android")) {
53+
noAndroidSdkLink.set(false)
54+
noJdkLink.set(true)
55+
} else {
56+
noAndroidSdkLink.set(true)
57+
noJdkLink.set(false)
58+
}
59+
displayName.set(
60+
when (val dn = displayName.get()) {
61+
"jvm" -> "JVM"
62+
"android" -> "Android"
63+
"common" -> "Common"
64+
"js" -> "JS"
65+
"native" -> "Native"
66+
else -> dn
67+
}
68+
)
69+
logger.lifecycle("Configuring dokka on sourceSet: $name = ${displayName.orNull}")
70+
71+
includeNonPublic = false
72+
skipEmptyPackages = true
73+
skipDeprecated = true
74+
75+
for (sourceRoot in sourceSet.sourceRoots) {
76+
val relativeRoot = sourceRoot.relativeTo(rootProject.projectDir)
77+
logger.lifecycle("Adding source link for root: $relativeRoot")
78+
sourceLink {
79+
localDirectory = sourceRoot
80+
remoteUrl = URL("https://github.com/pdvrieze/xmlutil/tree/master/${relativeRoot}")
81+
}
82+
}
83+
84+
externalDocumentationLink {
85+
url.set(URL("https://kotlinlang.org/api/kotlinx.serialization/"))
86+
packageListUrl.set(
87+
rootProject.projectDir.resolve("serialization.package.list").toURL()
88+
)
89+
}
90+
91+
perPackageOption {
92+
matchingRegex.set(".*\\.(impl|internal)(|\\..*)")
93+
suppress.set(true)
94+
}
95+
logger.lifecycle("Dokka source set: '$name'")
96+
if ("Main" in name) {
97+
val readme = project.file(project.relativePath("src/README.md"))
98+
if (readme.exists() && readme.canRead()) {
99+
includes.from(listOf(readme))
100+
logger.lifecycle("Adding $readme to sourceSet :${project.name}:${name}(${displayName.orNull})")
101+
} else {
102+
logger.warn("Missing $readme for project ${project.name}")
103+
}
104+
}
83105
}
84106
}
85107
}

core/src/README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Module core
22
Core Xml wrapper that provides xmlpull parsing functionality. This module
33
is designed to wrap the actually present xml functionality in the platform.
4-
As such it is currently limited to JVM, Android and JS(browser) platforms.
4+
In addition, this module provides a platform independent implementation
5+
based upon the Android code.
56

67
# Package nl.adaptivity.js.util
78
Package with various extension functions to make working with DOM nodes
@@ -15,4 +16,4 @@ The access point to the package/module is (XmlStreaming)[nl.adaptivity.xml.XmlSt
1516

1617
# Package nl.adaptivity.xmlutil.util
1718
Package with various utility types that are generally allow for a more
18-
convenient way of using the library.
19+
convenient way of using the library.

core/src/commonMain/kotlin/nl/adaptivity/xmlutil/DomWriter.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import nl.adaptivity.xmlutil.util.impl.*
2727
import nl.adaptivity.xmlutil.dom.*
2828

2929
/**
30-
* Created by pdvrieze on 04/04/17.
30+
* Writer that uses the DOM for the underlying storage (rather than writing to some string).
3131
*/
3232
public class DomWriter constructor(
3333
current: Node?,

core/src/commonMain/kotlin/nl/adaptivity/xmlutil/XmlWriter.kt

+64-5
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import kotlin.jvm.JvmOverloads
3737
public interface XmlWriter : Closeable {
3838

3939
/**
40-
* The current depth into the tree.
40+
* The current depth into the tree. The initial depth is `0`
4141
*/
4242
public val depth: Int
4343

@@ -73,12 +73,21 @@ public interface XmlWriter : Closeable {
7373
namespaceAttr(namespacePrefix.toString(), namespaceUri.toString())
7474
}
7575

76+
/**
77+
* Write a namespace declaration attribute.
78+
*/
7679
public fun namespaceAttr(namespacePrefix: String, namespaceUri: String)
7780

81+
/**
82+
* Write a namespace declaration attribute.
83+
*/
7884
public fun namespaceAttr(namespace: Namespace) {
7985
namespaceAttr(namespace.prefix, namespace.namespaceURI)
8086
}
8187

88+
/**
89+
* Close the writer. After invoking this the writer is not writable.
90+
*/
8291
override fun close()
8392

8493
/**
@@ -87,11 +96,9 @@ public interface XmlWriter : Closeable {
8796
public fun flush()
8897

8998
/**
90-
* Write a start tag.
99+
* Write a start tag. This increases the current depth.
91100
* @param namespace The namespace to use for the tag.
92-
*
93101
* @param localName The local name for the tag.
94-
*
95102
* @param prefix The prefix to use, or `null` for the namespace to be assigned automatically
96103
*/
97104
public fun startTag(namespace: String?, localName: String, prefix: String?)
@@ -114,25 +121,71 @@ public interface XmlWriter : Closeable {
114121
*/
115122
public fun cdsect(text: String)
116123

124+
/**
125+
* Write an entity reference
126+
* @param text the name of the reference. Must be a valid reference name.
127+
*/
117128
public fun entityRef(text: String)
118129

130+
/**
131+
* Write a processing instruction with the given raw content. When using, prefer the version taking two arguments
132+
*/
119133
public fun processingInstruction(text: String)
120134

135+
/**
136+
* Write a processing instruction with the given target and data
137+
* @param target The (CNAME) target of the instruction
138+
* @param data The data to be used.
139+
*/
121140
public fun processingInstruction(target: String, data: String): Unit =
122141
processingInstruction("$target $data")
123142

143+
/**
144+
* Write ignorable whitespace.
145+
* @param text This text is expected to be only XML whitespace.
146+
*/
124147
public fun ignorableWhitespace(text: String)
125148

149+
/**
150+
* Write an attribute.
151+
* @param namespace The namespace of the attribute. `null` and `""` will both resolve to the empty namespace.
152+
* @param name The local name of the attribute (CName, must exclude the prefix).
153+
* @param prefix The prefix to use. Note that in XML for attributes the prefix is empty/null when the namespace is and vice versa.
154+
* @param value The value of the attribute
155+
*/
126156
public fun attribute(namespace: String?, name: String, prefix: String?, value: String)
127157

158+
/**
159+
* Write a document declaration (DTD).
160+
* @param The content of the DTD Declaration.
161+
*/
128162
public fun docdecl(text: String)
129163

164+
/**
165+
* Start the document. This causes an xml declaration to be generated with the relevant content.
166+
* @param version The XML version
167+
* @param encoding The encoding of the document
168+
* @param standalone A statement that the document is standalone (no externally defined entities...)
169+
*/
130170
public fun startDocument(version: String? = null, encoding: String? = null, standalone: Boolean? = null)
131171

172+
/**
173+
* Close the document. This will do checks, and update the state, but there is no actual content in an xml stream
174+
* that corresponds to it.
175+
*/
132176
public fun endDocument()
133177

178+
/**
179+
* Write a closing tag.
180+
* @param namespace The namespace for the tag to close
181+
* @param localName The local name
182+
* @param prefix The prefix
183+
*/
134184
public fun endTag(namespace: String?, localName: String, prefix: String?)
135185

186+
/**
187+
* A namespace context that provides access to known namespaces/prefixes at this point in the writer.
188+
*/
136189
public val namespaceContext: NamespaceContext
137190

138191
/**
@@ -146,7 +199,13 @@ public interface XmlWriter : Closeable {
146199
public fun getPrefix(namespaceUri: String?): String?
147200
}
148201

149-
202+
/**
203+
* Function that collects namespaces not present in the writer
204+
* @receiver The writer where namespace information is looked up from
205+
* @param reader The reader from which the namespace information is retrieved
206+
* @param missingNamespaces Map to which the "missing" namespace is added.
207+
*/
208+
@Deprecated("This function should be internal")
150209
public fun XmlWriter.addUndeclaredNamespaces(reader: XmlReader, missingNamespaces: MutableMap<String, String>) {
151210
undeclaredPrefixes(reader, missingNamespaces)
152211
}

core/src/commonMain/kotlin/nl/adaptivity/xmlutil/annotations.kt

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
package nl.adaptivity.xmlutil
2222

2323

24+
/**
25+
* Annotation to signify that the annotated code is internal to the XmlUtil module, and no API
26+
* stability is guaranteed.
27+
*/
2428
@Target(AnnotationTarget.CLASS, AnnotationTarget.PROPERTY, AnnotationTarget.FUNCTION, AnnotationTarget.TYPEALIAS, AnnotationTarget.CONSTRUCTOR, AnnotationTarget.PROPERTY_GETTER)
2529
@RequiresOptIn("This function is internal to the XmlUtil modules. No api stability is guaranteed", RequiresOptIn.Level.ERROR)
2630
public annotation class XmlUtilInternal

0 commit comments

Comments
 (0)