-
Notifications
You must be signed in to change notification settings - Fork 391
/
GradleExternalDocumentationLinkBuilder.kt
86 lines (78 loc) · 3.02 KB
/
GradleExternalDocumentationLinkBuilder.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
/*
* Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
package org.jetbrains.dokka.gradle
import org.gradle.api.Project
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.Optional
import org.gradle.kotlin.dsl.property
import org.jetbrains.dokka.DokkaConfigurationBuilder
import org.jetbrains.dokka.ExternalDocumentationLink
import org.jetbrains.dokka.ExternalDocumentationLinkImpl
import java.net.URL
/**
* Configuration builder that allows creating links leading to externally hosted
* documentation of your dependencies.
*
* For instance, if you are using types from `kotlinx.serialization`, by default
* they will be unclickable in your documentation, as if unresolved. However,
* since API reference for `kotlinx.serialization` is also built by Dokka and is
* [published on kotlinlang.org](https://kotlinlang.org/api/kotlinx.serialization/),
* you can configure external documentation links for it, allowing Dokka to generate
* documentation links for used types, making them clickable and appear resolved.
*
* Example in Gradle Kotlin DSL:
*
* ```kotlin
* externalDocumentationLink {
* url.set(URI("https://kotlinlang.org/api/kotlinx.serialization/").toURL())
* packageListUrl.set(
* rootProject.projectDir.resolve("serialization.package.list").toURI().toURL()
* )
* }
* ```
*/
class GradleExternalDocumentationLinkBuilder(
@Transient @get:Internal internal val project: Project
) : DokkaConfigurationBuilder<ExternalDocumentationLinkImpl> {
/**
* Root URL of documentation to link with. **Must** contain a trailing slash.
*
* Dokka will do its best to automatically find `package-list` for the given URL, and link
* declarations together.
*
* It automatic resolution fails or if you want to use locally cached files instead,
* consider providing [packageListUrl].
*
* Example:
*
* ```kotlin
* java.net.URI("https://kotlinlang.org/api/kotlinx.serialization/").toURL()
* ```
*/
@Internal
val url: Property<URL> = project.objects.property()
@Input // URL is deprecated in Gradle inputs
internal fun getUrlString() = url.map(URL::toString)
/**
* Specifies the exact location of a `package-list` instead of relying on Dokka
* automatically resolving it. Can also be a locally cached file to avoid network calls.
*
* Example:
*
* ```kotlin
* rootProject.projectDir.resolve("serialization.package.list").toURI().toURL()
* ```
*/
@Internal
val packageListUrl: Property<URL> = project.objects.property()
@Input // URL is deprecated in Gradle inputs
@Optional
internal fun getPackageListUrlString() = packageListUrl.map(URL::toString)
override fun build(): ExternalDocumentationLinkImpl = ExternalDocumentationLink(
url = checkNotNull(url.get()) { "url not specified " },
packageListUrl = packageListUrl.orNull,
)
}