aboutsummaryrefslogtreecommitdiff
path: root/integration/src/main/kotlin/org/jetbrains/dokka/configuration.kt
blob: 12efd252b801b3e8c01ff66b39b3d9000ab5eed0 (plain)
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
package org.jetbrains.dokka

import ru.yole.jkid.CustomSerializer
import ru.yole.jkid.ValueSerializer
import ru.yole.jkid.deserialization.JKidException
import java.io.Serializable
import java.net.URL


class UrlSerializer : ValueSerializer<URL?> {
    override fun fromJsonValue(jsonValue: Any?): URL? {
        if (jsonValue !is String?)
            throw JKidException("Expected string representation of URL, got: $jsonValue")
        return jsonValue?.let { URL(jsonValue) }
    }

    override fun toJsonValue(value: URL?): Any? = value?.toExternalForm()
}

enum class Platform(val key: String) {
    jvm("jvm"),
    js("js"),
    native("native"),
    common("common");


    companion object {
        val DEFAULT = jvm

        fun fromString(key: String): Platform {
            return when (key.toLowerCase()) {
                jvm.key -> jvm
                js.key -> js
                native.key -> native
                common.key -> common
                else -> TODO("write normal exception")
            }
        }
    }

}

interface DokkaConfiguration {
    val outputDir: String
    val format: String
    val generateIndexPages: Boolean
    val cacheRoot: String?
    val passesConfigurations: List<PassConfiguration>
    val impliedPlatforms: List<String>

    interface PassConfiguration {
        val moduleName: String
        val classpath: List<String>
        val sourceRoots: List<SourceRoot>
        val samples: List<String>
        val includes: List<String>
        val includeNonPublic: Boolean
        val includeRootPackage: Boolean
        val reportUndocumented: Boolean
        val skipEmptyPackages: Boolean
        val skipDeprecated: Boolean
        val jdkVersion: Int
        val sourceLinks: List<SourceLinkDefinition>
        val perPackageOptions: List<PackageOptions>
        val externalDocumentationLinks: List<DokkaConfiguration.ExternalDocumentationLink>
        val languageVersion: String?
        val apiVersion: String?
        val noStdlibLink: Boolean
        val noJdkLink: Boolean
        val suppressedFiles: List<String>
        val collectInheritedExtensionsFromLibraries: Boolean
        val analysisPlatform: Platform
        val targets: List<String>
        val sinceKotlin: String
    }

    interface SourceRoot {
        val path: String
    }

    interface SourceLinkDefinition {
        val path: String
        val url: String
        val lineSuffix: String?
    }

    interface PackageOptions {
        val prefix: String
        val includeNonPublic: Boolean
        val reportUndocumented: Boolean
        val skipDeprecated: Boolean
        val suppress: Boolean
    }

    interface ExternalDocumentationLink {
        @CustomSerializer(UrlSerializer::class) val url: URL
        @CustomSerializer(UrlSerializer::class) val packageListUrl: URL

        open class Builder(open var url: URL? = null,
                           open var packageListUrl: URL? = null) {

            constructor(root: String, packageList: String? = null) : this(URL(root), packageList?.let { URL(it) })

            fun build(): DokkaConfiguration.ExternalDocumentationLink =
                    if (packageListUrl != null && url != null)
                        ExternalDocumentationLinkImpl(url!!, packageListUrl!!)
                    else if (url != null)
                        ExternalDocumentationLinkImpl(url!!, URL(url!!, "package-list"))
                    else
                        throw IllegalArgumentException("url or url && packageListUrl must not be null for external documentation link")
        }
    }
}

data class SerializeOnlyDokkaConfiguration(
    override val outputDir: String,
    override val format: String,
    override val generateIndexPages: Boolean,
    override val cacheRoot: String?,
    override val impliedPlatforms: List<String>,
    override val passesConfigurations: List<DokkaConfiguration.PassConfiguration>
) : DokkaConfiguration


data class ExternalDocumentationLinkImpl(@CustomSerializer(UrlSerializer::class) override val url: URL,
                                         @CustomSerializer(UrlSerializer::class) override val packageListUrl: URL) : Serializable, DokkaConfiguration.ExternalDocumentationLink