aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/DokkaBootstrapImpl.kt
blob: 8038089f6e67e9fc49f09cb28b3a83b94f33ad6a (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
package org.jetbrains.dokka

import java.io.File
import java.util.function.BiConsumer

fun parseSourceLinkDefinition(srcLink: String): SourceLinkDefinition {
    val (path, urlAndLine) = srcLink.split('=')
    return SourceLinkDefinition(File(path).absolutePath,
            urlAndLine.substringBefore("#"),
            urlAndLine.substringAfter("#", "").let { if (it.isEmpty()) null else "#" + it })
}

fun parseSourceRoot(sourceRoot: String): SourceRoot {
    val components = sourceRoot.split("::", limit = 2)
    return SourceRoot(components.last(), if (components.size == 1) listOf() else components[0].split(','))
}

class DokkaBootstrapImpl : DokkaBootstrap {

    class DokkaProxyLogger(val consumer: BiConsumer<String, String>) : DokkaLogger {
        override fun info(message: String) {
            consumer.accept("info", message)
        }

        override fun warn(message: String) {
            consumer.accept("warn", message)
        }

        override fun error(message: String) {
            consumer.accept("error", message)
        }
    }

    lateinit var generator: DokkaGenerator

    override fun configure(logger: BiConsumer<String, String>,
                           moduleName: String,
                           classpath: List<String>,
                           sources: List<String>,
                           samples: List<String>,
                           includes: List<String>,
                           outputDir: String,
                           format: String,
                           includeNonPublic: Boolean,
                           includeRootPackage: Boolean,
                           reportUndocumented: Boolean,
                           skipEmptyPackages: Boolean,
                           skipDeprecated: Boolean,
                           jdkVersion: Int,
                           generateIndexPages: Boolean,
                           sourceLinks: List<String>) {
        generator = DokkaGenerator(
                DokkaProxyLogger(logger),
                classpath,
                sources.map(::parseSourceRoot),
                samples,
                includes,
                moduleName,
                DocumentationOptions(
                        outputDir,
                        format,
                        includeNonPublic,
                        includeRootPackage,
                        reportUndocumented,
                        skipEmptyPackages,
                        skipDeprecated,
                        jdkVersion,
                        generateIndexPages,
                        sourceLinks.map(::parseSourceLinkDefinition)
                )
        )

    }

    override fun generate() = generator.generate()
}