|
| 1 | +import org.gradle.api.Project |
| 2 | +import org.gradle.api.tasks.compile.JavaCompile |
| 3 | +import org.jetbrains.dokka.gradle.DokkaExtension |
| 4 | +import org.jetbrains.dokka.gradle.engine.parameters.DokkaSourceSetSpec |
| 5 | +import org.jetbrains.dokka.gradle.engine.parameters.VisibilityModifier |
| 6 | +import org.jetbrains.dokka.gradle.engine.plugins.DokkaHtmlPluginParameters |
| 7 | +import java.io.File |
| 8 | +import java.net.URI |
| 9 | +import java.time.Year |
| 10 | + |
| 11 | +/* |
| 12 | + * Copyright (c) 2025. ForteScarlet. |
| 13 | + * |
| 14 | + * This file is part of simbot-component-onebot. |
| 15 | + * |
| 16 | + * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms |
| 17 | + * of the GNU Lesser General Public License as published by the Free Software Foundation, |
| 18 | + * either version 3 of the License, or (at your option) any later version. |
| 19 | + * |
| 20 | + * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 21 | + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 22 | + * See the GNU Lesser General Public License for more details. |
| 23 | + * |
| 24 | + * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. |
| 25 | + * If not, see <https://www.gnu.org/licenses/>. |
| 26 | + */ |
| 27 | + |
| 28 | +fun DokkaExtension.configSourceSets(project: Project) { |
| 29 | + dokkaSourceSets.configureEach { |
| 30 | + skipEmptyPackages.set(true) |
| 31 | + suppressGeneratedFiles.set(false) |
| 32 | + documentedVisibilities( |
| 33 | + VisibilityModifier.Public, |
| 34 | + VisibilityModifier.Protected |
| 35 | + ) |
| 36 | + project.tasks.withType(JavaCompile::class.java).firstOrNull() |
| 37 | + ?.targetCompatibility?.toInt().also { |
| 38 | + logger.info("project {} found jdkVersionValue: {}", project, it) |
| 39 | + }?.also { |
| 40 | + jdkVersion.set(it) |
| 41 | + } |
| 42 | + |
| 43 | + configModuleMdInclude(project) |
| 44 | + |
| 45 | + perPackageOption { |
| 46 | + matchingRegex.set(".*internal.*") // will match all .internal packages and sub-packages |
| 47 | + suppress.set(true) |
| 48 | + } |
| 49 | + |
| 50 | + configSourceLink(project) |
| 51 | + |
| 52 | + configExternalDocumentations() |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +fun DokkaSourceSetSpec.configModuleMdInclude(project: Project) { |
| 57 | + val moduleFile = project.file("Module.md") |
| 58 | + if (moduleFile.exists() && moduleFile.length() > 0) { |
| 59 | + includes.from("Module.md") |
| 60 | + } |
| 61 | +} |
| 62 | + |
| 63 | +fun DokkaSourceSetSpec.configSourceLink(project: Project) { |
| 64 | + sourceLink { |
| 65 | + localDirectory.set(File(project.projectDir, "src")) |
| 66 | + val relativeTo = project.projectDir.relativeTo(project.rootProject.projectDir).toString() |
| 67 | + .replace('\\', '/') |
| 68 | + remoteUrl.set(URI.create("${P.HOMEPAGE}/tree/dev/main/$relativeTo/src")) |
| 69 | + remoteLineSuffix.set("#L") |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +fun DokkaSourceSetSpec.configExternalDocumentations() { |
| 74 | + fun externalDocumentation(name: String, docUrl: URI, suffix: String = "package-list") { |
| 75 | + externalDocumentationLinks.register(name) { |
| 76 | + url.set(docUrl) |
| 77 | + packageListUrl.set(docUrl.resolve(suffix)) |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + // kotlin-coroutines doc |
| 82 | + externalDocumentation( |
| 83 | + "kotlinx.coroutines", |
| 84 | + URI.create("https://kotlinlang.org/api/kotlinx.coroutines/") |
| 85 | + ) |
| 86 | + |
| 87 | + // kotlin-serialization doc |
| 88 | + externalDocumentation( |
| 89 | + "kotlinx.serialization", |
| 90 | + URI.create("https://kotlinlang.org/api/kotlinx.serialization/") |
| 91 | + ) |
| 92 | + |
| 93 | + // ktor |
| 94 | + externalDocumentation( |
| 95 | + "ktor", |
| 96 | + URI.create("https://api.ktor.io/") |
| 97 | + ) |
| 98 | + |
| 99 | + // SLF4J |
| 100 | + externalDocumentation( |
| 101 | + "slf4j", |
| 102 | + URI.create("https://www.slf4j.org/apidocs/"), |
| 103 | + "element-list" |
| 104 | + ) |
| 105 | +} |
| 106 | + |
| 107 | +fun DokkaHtmlPluginParameters.configHtmlCustoms(project: Project) { |
| 108 | + customAssets.from( |
| 109 | + project.rootProject.file(".simbot/dokka-assets/logo-icon.svg"), |
| 110 | + project.rootProject.file(".simbot/dokka-assets/logo-icon-light.svg"), |
| 111 | + ) |
| 112 | + |
| 113 | + customStyleSheets.from(project.rootProject.file(".simbot/dokka-assets/css/kdoc-style.css")) |
| 114 | + |
| 115 | + if (!isSimbotLocal()) { |
| 116 | + templatesDir.set(project.rootProject.file(".simbot/dokka-templates")) |
| 117 | + } |
| 118 | + |
| 119 | + val now = Year.now().value |
| 120 | + footerMessage.set( |
| 121 | + "© 2024-$now " + |
| 122 | + "<a href='https://github.com/simple-robot'>Simple Robot</a>. All rights reserved." |
| 123 | + ) |
| 124 | + |
| 125 | + separateInheritedMembers.set(true) |
| 126 | + mergeImplicitExpectActualDeclarations.set(true) |
| 127 | + homepageLink.set(P.HOMEPAGE) |
| 128 | +} |
0 commit comments