xref: /aosp_15_r20/external/dokka/runners/ant/src/main/kotlin/ant/dokka.kt (revision 1b2d298c530bf0473cc943e8414a5ff577a994bc)

<lambda>null1 package org.jetbrains.dokka.ant
2 
3 import org.apache.tools.ant.BuildException
4 import org.apache.tools.ant.Project
5 import org.apache.tools.ant.Task
6 import org.apache.tools.ant.types.Path
7 import org.apache.tools.ant.types.Reference
8 import org.jetbrains.dokka.*
9 import org.jetbrains.dokka.DokkaConfiguration.ExternalDocumentationLink
10 import java.io.File
11 
12 class AntLogger(val task: Task): DokkaLogger {
13     override fun info(message: String) = task.log(message, Project.MSG_INFO)
14     override fun warn(message: String) = task.log(message, Project.MSG_WARN)
15     override fun error(message: String) = task.log(message, Project.MSG_ERR)
16 }
17 
18 class AntSourceLinkDefinition(var path: String? = null, var url: String? = null, var lineSuffix: String? = null)
19 
20 class AntSourceRoot(var path: String? = null, var platforms: String? = null) {
toSourceRootnull21     fun toSourceRoot(): SourceRootImpl? = path?.let {
22         path ->
23         SourceRootImpl(path, platforms?.split(',').orEmpty())
24     }
25 }
26 
27 class AntPackageOptions(
28         override var prefix: String = "",
29         override var includeNonPublic: Boolean = false,
30         override var reportUndocumented: Boolean = true,
31         override var skipDeprecated: Boolean = false,
32         override var suppress: Boolean = false) : DokkaConfiguration.PackageOptions
33 
34 
35 class DokkaAntTask: Task() {
36     var moduleName: String? = null
37     var outputDir: String? = null
38     var outputFormat: String = "html"
39     var impliedPlatforms: String = ""
40     var jdkVersion: Int = 6
41 
42     var noStdlibLink: Boolean = false
43     var noJdkLink: Boolean = false
44 
45     var skipDeprecated: Boolean = false
46 
47     var cacheRoot: String? = null
48 
49     var languageVersion: String? = null
50     var apiVersion: String? = null
51 
52     var generateClassIndexPage: Boolean = true
53     var generatePackageIndexPage: Boolean = true
54     var outlineRoot: String = ""
55     var dacRoot: String = ""
56 
<lambda>null57     val compileClasspath: Path by lazy { Path(getProject()) }
<lambda>null58     val sourcePath: Path by lazy { Path(getProject()) }
<lambda>null59     val samplesPath: Path by lazy { Path(getProject()) }
<lambda>null60     val includesPath: Path by lazy { Path(getProject()) }
61 
62     val antSourceLinks: MutableList<AntSourceLinkDefinition> = arrayListOf()
63     val antSourceRoots: MutableList<AntSourceRoot> = arrayListOf()
64     val antPackageOptions: MutableList<AntPackageOptions> = arrayListOf()
65     val antExternalDocumentationLinks = mutableListOf<ExternalDocumentationLink.Builder>()
66 
setClasspathnull67     fun setClasspath(classpath: Path) {
68         compileClasspath.append(classpath)
69     }
70 
setClasspathRefnull71     fun setClasspathRef(ref: Reference) {
72         compileClasspath.createPath().refid = ref
73     }
74 
setSrcnull75     fun setSrc(src: Path) {
76         sourcePath.append(src)
77     }
78 
setSrcRefnull79     fun setSrcRef(ref: Reference) {
80         sourcePath.createPath().refid = ref
81     }
82 
setSamplesnull83     fun setSamples(samples: Path) {
84         samplesPath.append(samples)
85     }
86 
setSamplesRefnull87     fun setSamplesRef(ref: Reference) {
88         samplesPath.createPath().refid = ref
89     }
90 
setIncludenull91     fun setInclude(include: Path) {
92         includesPath.append(include)
93     }
94 
createSourceLinknull95     fun createSourceLink(): AntSourceLinkDefinition {
96         val def = AntSourceLinkDefinition()
97         antSourceLinks.add(def)
98         return def
99     }
100 
<lambda>null101     fun createSourceRoot(): AntSourceRoot = AntSourceRoot().apply { antSourceRoots.add(this) }
102 
<lambda>null103     fun createPackageOptions(): AntPackageOptions = AntPackageOptions().apply { antPackageOptions.add(this) }
104 
<lambda>null105     fun createExternalDocumentationLink() = ExternalDocumentationLink.Builder().apply { antExternalDocumentationLinks.add(this) }
106 
executenull107     override fun execute() {
108         if (sourcePath.list().isEmpty() && antSourceRoots.isEmpty()) {
109             throw BuildException("At least one source path needs to be specified")
110         }
111         if (moduleName == null) {
112             throw BuildException("Module name needs to be specified")
113         }
114         if (outputDir == null) {
115             throw BuildException("Output directory needs to be specified")
116         }
117         val sourceLinks = antSourceLinks.map {
118             val path = it.path ?: throw BuildException("'path' attribute of a <sourceLink> element is required")
119             val url = it.url ?: throw BuildException("'url' attribute of a <sourceLink> element is required")
120             SourceLinkDefinitionImpl(File(path).canonicalFile.absolutePath, url, it.lineSuffix)
121         }
122 
123         val generator = DokkaGenerator(
124                 AntLogger(this),
125                 compileClasspath.list().toList(),
126                 sourcePath.list().map { SourceRootImpl(it) } + antSourceRoots.mapNotNull { it.toSourceRoot() },
127                 samplesPath.list().toList(),
128                 includesPath.list().toList(),
129                 moduleName!!,
130                 DocumentationOptions(
131                         outputDir!!,
132                         outputFormat,
133                         skipDeprecated = skipDeprecated,
134                         sourceLinks = sourceLinks,
135                         jdkVersion = jdkVersion,
136                         impliedPlatforms = impliedPlatforms.split(','),
137                         perPackageOptions = antPackageOptions,
138                         externalDocumentationLinks = antExternalDocumentationLinks.map { it.build() },
139                         noStdlibLink = noStdlibLink,
140                         noJdkLink = noJdkLink,
141                         cacheRoot = cacheRoot,
142                         languageVersion = languageVersion,
143                         apiVersion = apiVersion,
144                         generatePackageIndexPage = generatePackageIndexPage,
145                         generateClassIndexPage = generateClassIndexPage,
146                         outlineRoot = outlineRoot,
147                         dacRoot = dacRoot
148                 )
149         )
150         generator.generate()
151     }
152 }