From e9fd8b7bc00491b50e4822acc82e5615ab0bde3b Mon Sep 17 00:00:00 2001 From: "sebastian.sellmair" Date: Fri, 5 Jun 2020 09:07:20 +0200 Subject: Implement `reportUndocumented` option to report undocumented code --- .idea/misc.xml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to '.idea/misc.xml') diff --git a/.idea/misc.xml b/.idea/misc.xml index e208459b..ff8249e4 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,9 @@ - + + + + \ No newline at end of file -- cgit From b1520f0a45e5102f77a43dd20746a3db047bbcf4 Mon Sep 17 00:00:00 2001 From: "sebastian.sellmair" Date: Tue, 16 Jun 2020 15:35:17 +0200 Subject: Implement default configurations --- .gitignore | 2 ++ .idea/compiler.xml | 23 ------------- .idea/misc.xml | 9 ----- core/src/main/kotlin/DokkaBootstrapImpl.kt | 24 ++++++++++--- core/src/main/kotlin/configuration.kt | 27 +++++++++++++-- runners/cli/src/main/kotlin/cli/main.kt | 27 +++++++-------- .../dokka/gradle/configurationImplementations.kt | 35 +++++++++---------- runners/maven-plugin/src/main/kotlin/DokkaMojo.kt | 39 +++++++++++----------- 8 files changed, 96 insertions(+), 90 deletions(-) delete mode 100644 .idea/compiler.xml delete mode 100644 .idea/misc.xml (limited to '.idea/misc.xml') diff --git a/.gitignore b/.gitignore index 78a59f54..13060d89 100644 --- a/.gitignore +++ b/.gitignore @@ -37,6 +37,8 @@ hs_err_pid* .idea/shelf .idea/jsLibraryMappings.xml .idea/modules.xml +.idea/misc.xml +.idea/compiler.xml # Sensitive or high-churn files: .idea/dataSources.ids diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index a6b0adf4..00000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index ff8249e4..00000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/core/src/main/kotlin/DokkaBootstrapImpl.kt b/core/src/main/kotlin/DokkaBootstrapImpl.kt index e0f014c8..32248163 100644 --- a/core/src/main/kotlin/DokkaBootstrapImpl.kt +++ b/core/src/main/kotlin/DokkaBootstrapImpl.kt @@ -11,12 +11,26 @@ import java.util.function.BiConsumer fun parsePerPackageOptions(args: List): List = args.map { it.split(",") }.map { val prefix = it.first() if (prefix == "") - throw IllegalArgumentException("Please do not register packageOptions with all match pattern, use global settings instead") + throw IllegalArgumentException( + "Please do not register packageOptions with all match pattern, use global settings instead" + ) + val args = it.subList(1, it.size) - val deprecated = args.find { it.endsWith("deprecated") }?.startsWith("+") ?: true - val reportUndocumented = args.find { it.endsWith("reportUndocumented") }?.startsWith("+") ?: true - val privateApi = args.find { it.endsWith("privateApi") }?.startsWith("+") ?: false - val suppress = args.find { it.endsWith("suppress") }?.startsWith("+") ?: false + + val deprecated = args.find { it.endsWith("deprecated") }?.startsWith("+") + ?: args.find { it.endsWith("skipDeprecated") }?.startsWith("+") + ?: DokkaDefaults.skipDeprecated + + val reportUndocumented = args.find { it.endsWith("reportUndocumented") }?.startsWith("+") + ?: DokkaDefaults.reportUndocumented + + val privateApi = args.find { it.endsWith("privateApi") }?.startsWith("+") + ?: args.find { it.endsWith("includeNonPublic") }?.startsWith("+") + ?: DokkaDefaults.includeNonPublic + + val suppress = args.find { it.endsWith("suppress") }?.startsWith("+") + ?:DokkaDefaults.suppress + PackageOptionsImpl( prefix, includeNonPublic = privateApi, diff --git a/core/src/main/kotlin/configuration.kt b/core/src/main/kotlin/configuration.kt index f5115435..b016f83d 100644 --- a/core/src/main/kotlin/configuration.kt +++ b/core/src/main/kotlin/configuration.kt @@ -3,6 +3,25 @@ package org.jetbrains.dokka import java.io.File import java.net.URL +object DokkaDefaults { + const val outputDir = "./dokka" + const val format: String = "html" + val cacheRoot: String? = null + const val offlineMode: Boolean = false + const val failOnWarning: Boolean = false + + const val includeNonPublic: Boolean = false + const val includeRootPackage: Boolean = false + const val reportUndocumented: Boolean = false + const val skipEmptyPackages: Boolean = false + const val skipDeprecated: Boolean = false + const val jdkVersion: Int = 8 + const val noStdlibLink: Boolean = false + const val noJdkLink: Boolean = false + val analysisPlatform: Platform = Platform.DEFAULT + const val suppress: Boolean = false +} + enum class Platform(val key: String) { jvm("jvm"), js("js"), @@ -29,11 +48,11 @@ interface DokkaConfiguration { val format: String val cacheRoot: String? val offlineMode: Boolean + val failOnWarning: Boolean val passesConfigurations: List val modules: List val pluginsClasspath: List val pluginsConfiguration: Map - val failOnWarning: Boolean interface PassConfiguration { val moduleName: String @@ -89,8 +108,10 @@ interface DokkaConfiguration { val url: URL val packageListUrl: URL - open class Builder(open var url: URL? = null, - open var packageListUrl: URL? = null) { + 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) }) diff --git a/runners/cli/src/main/kotlin/cli/main.kt b/runners/cli/src/main/kotlin/cli/main.kt index 515f9bb0..f0df08e0 100644 --- a/runners/cli/src/main/kotlin/cli/main.kt +++ b/runners/cli/src/main/kotlin/cli/main.kt @@ -3,6 +3,7 @@ package org.jetbrains.dokka import com.google.gson.Gson import kotlinx.cli.* import org.jetbrains.dokka.DokkaConfiguration.ExternalDocumentationLink +import org.jetbrains.dokka.DokkaConfiguration.PassConfiguration.* import org.jetbrains.dokka.utilities.DokkaConsoleLogger import org.jetbrains.kotlin.utils.addToStdlib.cast import java.io.* @@ -18,12 +19,12 @@ class GlobalArguments(args: Array) : DokkaConfiguration { val json: String? by parser.argument(ArgType.String, description = "Json file name").optional() override val outputDir by parser.option(ArgType.String, description = "Output directory path") - .default("./dokka") + .default(DokkaDefaults.outputDir) override val format by parser.option( ArgType.String, description = "Output format (html, gfm, jekyll)" - ).default("html") + ).default(DokkaDefaults.format) override val cacheRoot by parser.option( ArgType.String, @@ -50,12 +51,12 @@ class GlobalArguments(args: Array) : DokkaConfiguration { override val offlineMode by parser.option( ArgType.Boolean, "Offline mode (do not download package lists from the Internet)" - ).default(false) + ).default(DokkaDefaults.offlineMode) override val failOnWarning by parser.option( ArgType.Boolean, "Throw an exception if the generation exited with warnings" - ).default(false) + ).default(DokkaDefaults.failOnWarning) val globalPackageOptions by parser.option( ArgType.String, @@ -160,26 +161,26 @@ fun passArguments(args: Array): DokkaConfiguration.PassConfiguration { ).delimiter(";") val includeNonPublic: Boolean by parser.option(ArgType.Boolean, description = "Include non public") - .default(false) + .default(DokkaDefaults.includeNonPublic) val includeRootPackage by parser.option(ArgType.Boolean, description = "Include non public") - .default(false) + .default(DokkaDefaults.includeRootPackage) val reportUndocumented by parser.option(ArgType.Boolean, description = "Report undocumented members") - .default(false) + .default(DokkaDefaults.reportUndocumented) val skipEmptyPackages by parser.option( ArgType.Boolean, description = "Do not create index pages for empty packages" - ).default(false) + ).default(DokkaDefaults.skipEmptyPackages) val skipDeprecated by parser.option(ArgType.Boolean, description = "Do not output deprecated members") - .default(false) + .default(DokkaDefaults.skipDeprecated) val jdkVersion by parser.option( ArgType.Int, description = "Version of JDK to use for linking to JDK JavaDoc" - ).default(8) + ).default(DokkaDefaults.jdkVersion) val languageVersion by parser.option( ArgType.String, @@ -192,10 +193,10 @@ fun passArguments(args: Array): DokkaConfiguration.PassConfiguration { ) val noStdlibLink by parser.option(ArgType.Boolean, description = "Disable documentation link to stdlib") - .default(false) + .default(DokkaDefaults.noStdlibLink) val noJdkLink by parser.option(ArgType.Boolean, description = "Disable documentation link to JDK") - .default(false) + .default(DokkaDefaults.noJdkLink) val suppressedFiles by parser.option( ArgType.String, @@ -205,7 +206,7 @@ fun passArguments(args: Array): DokkaConfiguration.PassConfiguration { val analysisPlatform: Platform by parser.option( ArgTypePlatform, description = "Platform for analysis" - ).default(Platform.DEFAULT) + ).default(DokkaDefaults.analysisPlatform) val perPackageOptions by parser.option( ArgType.String, diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/configurationImplementations.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/configurationImplementations.kt index 152fa910..f4e7730e 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/configurationImplementations.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/configurationImplementations.kt @@ -7,6 +7,7 @@ import org.gradle.api.tasks.Optional import org.gradle.util.ConfigureUtil import org.jetbrains.dokka.DokkaConfiguration import org.jetbrains.dokka.DokkaConfiguration.* +import org.jetbrains.dokka.DokkaDefaults import org.jetbrains.dokka.Platform import java.io.File import java.io.Serializable @@ -33,22 +34,22 @@ open class GradlePassConfigurationImpl(@Transient val name: String = ""): PassCo @Input override var dependentSourceSets: MutableList = mutableListOf() @Input override var samples: List = emptyList() @Input override var includes: List = emptyList() - @Input override var includeNonPublic: Boolean = false - @Input override var includeRootPackage: Boolean = false - @Input override var reportUndocumented: Boolean = false - @Input override var skipEmptyPackages: Boolean = false - @Input override var skipDeprecated: Boolean = false - @Input override var jdkVersion: Int = 8 + @Input override var includeNonPublic: Boolean = DokkaDefaults.includeNonPublic + @Input override var includeRootPackage: Boolean = DokkaDefaults.includeRootPackage + @Input override var reportUndocumented: Boolean = DokkaDefaults.reportUndocumented + @Input override var skipEmptyPackages: Boolean = DokkaDefaults.skipEmptyPackages + @Input override var skipDeprecated: Boolean = DokkaDefaults.skipDeprecated + @Input override var jdkVersion: Int = DokkaDefaults.jdkVersion @Input override var sourceLinks: MutableList = mutableListOf() @Input override var perPackageOptions: MutableList = mutableListOf() @Input override var externalDocumentationLinks: MutableList = mutableListOf() @Input @Optional override var languageVersion: String? = null @Input @Optional override var apiVersion: String? = null - @Input override var noStdlibLink: Boolean = false - @Input override var noJdkLink: Boolean = false + @Input override var noStdlibLink: Boolean = DokkaDefaults.noStdlibLink + @Input override var noJdkLink: Boolean = DokkaDefaults.noJdkLink @Input var noAndroidSdkLink: Boolean = false @Input override var suppressedFiles: List = emptyList() - @Input override var analysisPlatform: Platform = Platform.DEFAULT + @Input override var analysisPlatform: Platform = DokkaDefaults.analysisPlatform @Input @Optional var platform: String? = null @Transient var collectKotlinTasks: (() -> List?)? = null @@ -124,22 +125,22 @@ class GradleDokkaModuleDescription: DokkaModuleDescription { class GradleDokkaConfigurationImpl: DokkaConfiguration { override var outputDir: String = "" - override var format: String = "html" - override var cacheRoot: String? = null - override var offlineMode: Boolean = false + override var format: String = DokkaDefaults.format + override var cacheRoot: String? = DokkaDefaults.cacheRoot + override var offlineMode: Boolean = DokkaDefaults.offlineMode + override var failOnWarning: Boolean = DokkaDefaults.failOnWarning override var passesConfigurations: List = emptyList() override var pluginsClasspath: List = emptyList() override var pluginsConfiguration: Map = mutableMapOf() override var modules: List = emptyList() - override var failOnWarning: Boolean = false } class GradlePackageOptionsImpl: PackageOptions, Serializable { override var prefix: String = "" - override var includeNonPublic: Boolean = false - override var reportUndocumented: Boolean = true - override var skipDeprecated: Boolean = true - override var suppress: Boolean = false + override var includeNonPublic: Boolean = DokkaDefaults.includeNonPublic + override var reportUndocumented: Boolean = DokkaDefaults.reportUndocumented + override var skipDeprecated: Boolean = DokkaDefaults.skipDeprecated + override var suppress: Boolean = DokkaDefaults.suppress } internal fun GradlePassConfigurationImpl.copy(): GradlePassConfigurationImpl { diff --git a/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt b/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt index 5a739d5e..1ef04772 100644 --- a/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt +++ b/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt @@ -29,6 +29,7 @@ import org.eclipse.aether.transport.file.FileTransporterFactory import org.eclipse.aether.transport.http.HttpTransporterFactory import org.eclipse.aether.util.graph.visitor.PreorderNodeListGenerator import org.jetbrains.dokka.* +import org.jetbrains.dokka.DokkaConfiguration.PackageOptions import java.io.File import java.net.URL @@ -69,16 +70,16 @@ abstract class AbstractDokkaMojo : AbstractMojo() { override var prefix: String = "" @Parameter - override var includeNonPublic: Boolean = false + override var includeNonPublic: Boolean = DokkaDefaults.includeNonPublic @Parameter - override var reportUndocumented: Boolean = true + override var reportUndocumented: Boolean = DokkaDefaults.reportUndocumented @Parameter - override var skipDeprecated: Boolean = false + override var skipDeprecated: Boolean = DokkaDefaults.skipDeprecated @Parameter - override var suppress: Boolean = false + override var suppress: Boolean = DokkaDefaults.suppress } @Parameter(required = true, defaultValue = "\${project.sourceSet}") @@ -90,7 +91,6 @@ abstract class AbstractDokkaMojo : AbstractMojo() { @Parameter var sourceRoots: List = emptyList() - @Parameter var dependentSourceSets: List = emptyList() @@ -112,17 +112,17 @@ abstract class AbstractDokkaMojo : AbstractMojo() { @Parameter(required = false, defaultValue = "false") var skip: Boolean = false - @Parameter(required = false, defaultValue = "6") - var jdkVersion: Int = 8 + @Parameter(required = false, defaultValue = "${DokkaDefaults.jdkVersion}") + var jdkVersion: Int = DokkaDefaults.jdkVersion @Parameter - var skipDeprecated: Boolean = false + var skipDeprecated: Boolean = DokkaDefaults.skipDeprecated @Parameter - var skipEmptyPackages: Boolean = true + var skipEmptyPackages: Boolean = DokkaDefaults.skipEmptyPackages @Parameter - var reportUndocumented: Boolean = true + var reportUndocumented: Boolean = DokkaDefaults.reportUndocumented @Parameter var impliedPlatforms: List = emptyList() @@ -133,11 +133,11 @@ abstract class AbstractDokkaMojo : AbstractMojo() { @Parameter var externalDocumentationLinks: List = emptyList() - @Parameter(defaultValue = "false") - var noStdlibLink: Boolean = false + @Parameter(defaultValue = "${DokkaDefaults.noStdlibLink}") + var noStdlibLink: Boolean = DokkaDefaults.noStdlibLink - @Parameter(defaultValue = "false") - var noJdkLink: Boolean = false + @Parameter(defaultValue = "${DokkaDefaults.noJdkLink}") + var noJdkLink: Boolean = DokkaDefaults.noJdkLink @Parameter var cacheRoot: String? = null @@ -145,8 +145,8 @@ abstract class AbstractDokkaMojo : AbstractMojo() { @Parameter(defaultValue = "JVM") var displayName: String = "JVM" - @Parameter(defaultValue = "false") - var offlineMode: Boolean = false + @Parameter(defaultValue = "${DokkaDefaults.offlineMode}") + var offlineMode: Boolean = DokkaDefaults.offlineMode @Parameter var languageVersion: String? = null @@ -155,20 +155,19 @@ abstract class AbstractDokkaMojo : AbstractMojo() { var apiVersion: String? = null @Parameter - var includeRootPackage: Boolean = false + var includeRootPackage: Boolean = DokkaDefaults.includeRootPackage @Parameter var suppressedFiles: List = emptyList() - @Parameter var platform: String = "" @Parameter - var includeNonPublic: Boolean = false + var includeNonPublic: Boolean = DokkaDefaults.includeNonPublic @Parameter - var failOnWarning: Boolean = false + var failOnWarning: Boolean = DokkaDefaults.failOnWarning @Parameter var dokkaPlugins: List = emptyList() -- cgit From 3940153fd08e0c0596ac289766d9ef2877b56591 Mon Sep 17 00:00:00 2001 From: Andrzej Ratajczak Date: Fri, 13 Mar 2020 10:46:33 +0100 Subject: First version of javadoc output generation --- .idea/compiler.xml | 0 .idea/misc.xml | 0 .../documentation/DocumentableToPageTranslator.kt | 3 +- plugins/base/frontend/build.gradle.kts | 1 + plugins/base/src/main/kotlin/DokkaBase.kt | 12 +- .../base/src/test/kotlin/basic/DokkaBasicTests.kt | 5 +- plugins/base/src/test/kotlin/enums/EnumsTest.kt | 2 +- plugins/base/src/test/kotlin/markdown/KDocTest.kt | 2 +- plugins/build.gradle.kts | 1 + plugins/javadoc/build.gradle.kts | 19 + .../javadoc/JavadocDocumentableToPageTranslator.kt | 18 + .../main/kotlin/javadoc/JavadocLocationProvider.kt | 103 + .../src/main/kotlin/javadoc/JavadocPageCreator.kt | 92 + .../src/main/kotlin/javadoc/JavadocPlugin.kt | 29 + .../src/main/kotlin/javadoc/JavadocRenderer.kt | 28 + .../main/kotlin/javadoc/KorteJavadocRenderer.kt | 193 + .../kotlin/javadoc/pages/JavadocContentNodes.kt | 163 + .../main/kotlin/javadoc/pages/JavadocPageNodes.kt | 328 + .../main/kotlin/javadoc/pages/OverviewSummary.kt | 161 + .../main/kotlin/javadoc/pages/htmlGeneration.kt | 391 + .../main/kotlin/javadoc/pages/htmlPreprocessors.kt | 63 + .../javadoc/src/main/kotlin/javadoc/pages/pages.kt | 17 + .../org.jetbrains.dokka.plugability.DokkaPlugin | 1 + .../static_res/jquery/external/jquery/jquery.js | 10364 +++++++++++++++++ .../jquery/images/ui-bg_glass_55_fbf9ee_1x400.png | Bin 0 -> 335 bytes .../jquery/images/ui-bg_glass_65_dadada_1x400.png | Bin 0 -> 262 bytes .../jquery/images/ui-bg_glass_75_dadada_1x400.png | Bin 0 -> 262 bytes .../jquery/images/ui-bg_glass_75_e6e6e6_1x400.png | Bin 0 -> 262 bytes .../jquery/images/ui-bg_glass_95_fef1ec_1x400.png | Bin 0 -> 332 bytes .../ui-bg_highlight-soft_75_cccccc_1x100.png | Bin 0 -> 280 bytes .../jquery/images/ui-icons_222222_256x240.png | Bin 0 -> 6922 bytes .../jquery/images/ui-icons_2e83ff_256x240.png | Bin 0 -> 4549 bytes .../jquery/images/ui-icons_454545_256x240.png | Bin 0 -> 6992 bytes .../jquery/images/ui-icons_888888_256x240.png | Bin 0 -> 6999 bytes .../jquery/images/ui-icons_cd0a0a_256x240.png | Bin 0 -> 4549 bytes .../resources/static_res/jquery/jquery-3.3.1.js | 10364 +++++++++++++++++ .../static_res/jquery/jquery-migrate-3.0.1.js | 628 + .../main/resources/static_res/jquery/jquery-ui.css | 582 + .../main/resources/static_res/jquery/jquery-ui.js | 2659 +++++ .../resources/static_res/jquery/jquery-ui.min.css | 7 + .../resources/static_res/jquery/jquery-ui.min.js | 6 + .../static_res/jquery/jquery-ui.structure.css | 156 + .../static_res/jquery/jquery-ui.structure.min.css | 5 + .../jquery/jszip-utils/dist/jszip-utils-ie.js | 56 + .../jquery/jszip-utils/dist/jszip-utils-ie.min.js | 10 + .../jquery/jszip-utils/dist/jszip-utils.js | 118 + .../jquery/jszip-utils/dist/jszip-utils.min.js | 10 + .../static_res/jquery/jszip/dist/jszip.js | 11623 +++++++++++++++++++ .../static_res/jquery/jszip/dist/jszip.min.js | 15 + .../resources/static_res/package-search-index.js | 1 + .../main/resources/static_res/resources/glass.png | Bin 0 -> 499 bytes .../src/main/resources/static_res/resources/x.png | Bin 0 -> 394 bytes .../src/main/resources/static_res/stylesheet.css | 906 ++ .../javadoc/src/main/resources/views/class.korte | 2 + .../src/main/resources/views/components/base.korte | 27 + .../resources/views/components/bottomNavbar.korte | 20 + .../src/main/resources/views/components/head.korte | 19 + .../resources/views/components/indexPage.korte | 10 + .../resources/views/components/indexTable.korte | 12 + .../main/resources/views/components/navList.korte | 25 + .../resources/views/components/pageStart.korte | 38 + .../main/resources/views/components/subNav.korte | 30 + .../resources/views/components/topNavbar.korte | 24 + .../src/main/resources/views/listPage.korte | 13 + .../javadoc/src/main/resources/views/tabPage.korte | 4 + .../src/main/resources/views/treePage.korte | 48 + .../javadoc/src/test/kotlin/javadoc/JavadocTest.kt | 70 + .../test/main/java/adaptation/Adaptation.kt | 50 + plugins/kotlin-as-java/build.gradle.kts | 4 - settings.gradle.kts | 1 + .../main/kotlin/testApi/testRunner/TestRunner.kt | 4 +- 71 files changed, 39526 insertions(+), 17 deletions(-) create mode 100644 .idea/compiler.xml create mode 100644 .idea/misc.xml create mode 100644 plugins/javadoc/build.gradle.kts create mode 100644 plugins/javadoc/src/main/kotlin/javadoc/JavadocDocumentableToPageTranslator.kt create mode 100644 plugins/javadoc/src/main/kotlin/javadoc/JavadocLocationProvider.kt create mode 100644 plugins/javadoc/src/main/kotlin/javadoc/JavadocPageCreator.kt create mode 100644 plugins/javadoc/src/main/kotlin/javadoc/JavadocPlugin.kt create mode 100644 plugins/javadoc/src/main/kotlin/javadoc/JavadocRenderer.kt create mode 100644 plugins/javadoc/src/main/kotlin/javadoc/KorteJavadocRenderer.kt create mode 100644 plugins/javadoc/src/main/kotlin/javadoc/pages/JavadocContentNodes.kt create mode 100644 plugins/javadoc/src/main/kotlin/javadoc/pages/JavadocPageNodes.kt create mode 100644 plugins/javadoc/src/main/kotlin/javadoc/pages/OverviewSummary.kt create mode 100644 plugins/javadoc/src/main/kotlin/javadoc/pages/htmlGeneration.kt create mode 100644 plugins/javadoc/src/main/kotlin/javadoc/pages/htmlPreprocessors.kt create mode 100644 plugins/javadoc/src/main/kotlin/javadoc/pages/pages.kt create mode 100644 plugins/javadoc/src/main/resources/META-INF/services/org.jetbrains.dokka.plugability.DokkaPlugin create mode 100644 plugins/javadoc/src/main/resources/static_res/jquery/external/jquery/jquery.js create mode 100644 plugins/javadoc/src/main/resources/static_res/jquery/images/ui-bg_glass_55_fbf9ee_1x400.png create mode 100644 plugins/javadoc/src/main/resources/static_res/jquery/images/ui-bg_glass_65_dadada_1x400.png create mode 100644 plugins/javadoc/src/main/resources/static_res/jquery/images/ui-bg_glass_75_dadada_1x400.png create mode 100644 plugins/javadoc/src/main/resources/static_res/jquery/images/ui-bg_glass_75_e6e6e6_1x400.png create mode 100644 plugins/javadoc/src/main/resources/static_res/jquery/images/ui-bg_glass_95_fef1ec_1x400.png create mode 100644 plugins/javadoc/src/main/resources/static_res/jquery/images/ui-bg_highlight-soft_75_cccccc_1x100.png create mode 100644 plugins/javadoc/src/main/resources/static_res/jquery/images/ui-icons_222222_256x240.png create mode 100644 plugins/javadoc/src/main/resources/static_res/jquery/images/ui-icons_2e83ff_256x240.png create mode 100644 plugins/javadoc/src/main/resources/static_res/jquery/images/ui-icons_454545_256x240.png create mode 100644 plugins/javadoc/src/main/resources/static_res/jquery/images/ui-icons_888888_256x240.png create mode 100644 plugins/javadoc/src/main/resources/static_res/jquery/images/ui-icons_cd0a0a_256x240.png create mode 100644 plugins/javadoc/src/main/resources/static_res/jquery/jquery-3.3.1.js create mode 100644 plugins/javadoc/src/main/resources/static_res/jquery/jquery-migrate-3.0.1.js create mode 100644 plugins/javadoc/src/main/resources/static_res/jquery/jquery-ui.css create mode 100644 plugins/javadoc/src/main/resources/static_res/jquery/jquery-ui.js create mode 100644 plugins/javadoc/src/main/resources/static_res/jquery/jquery-ui.min.css create mode 100644 plugins/javadoc/src/main/resources/static_res/jquery/jquery-ui.min.js create mode 100644 plugins/javadoc/src/main/resources/static_res/jquery/jquery-ui.structure.css create mode 100644 plugins/javadoc/src/main/resources/static_res/jquery/jquery-ui.structure.min.css create mode 100644 plugins/javadoc/src/main/resources/static_res/jquery/jszip-utils/dist/jszip-utils-ie.js create mode 100644 plugins/javadoc/src/main/resources/static_res/jquery/jszip-utils/dist/jszip-utils-ie.min.js create mode 100644 plugins/javadoc/src/main/resources/static_res/jquery/jszip-utils/dist/jszip-utils.js create mode 100644 plugins/javadoc/src/main/resources/static_res/jquery/jszip-utils/dist/jszip-utils.min.js create mode 100644 plugins/javadoc/src/main/resources/static_res/jquery/jszip/dist/jszip.js create mode 100644 plugins/javadoc/src/main/resources/static_res/jquery/jszip/dist/jszip.min.js create mode 100644 plugins/javadoc/src/main/resources/static_res/package-search-index.js create mode 100644 plugins/javadoc/src/main/resources/static_res/resources/glass.png create mode 100644 plugins/javadoc/src/main/resources/static_res/resources/x.png create mode 100644 plugins/javadoc/src/main/resources/static_res/stylesheet.css create mode 100644 plugins/javadoc/src/main/resources/views/class.korte create mode 100644 plugins/javadoc/src/main/resources/views/components/base.korte create mode 100644 plugins/javadoc/src/main/resources/views/components/bottomNavbar.korte create mode 100644 plugins/javadoc/src/main/resources/views/components/head.korte create mode 100644 plugins/javadoc/src/main/resources/views/components/indexPage.korte create mode 100644 plugins/javadoc/src/main/resources/views/components/indexTable.korte create mode 100644 plugins/javadoc/src/main/resources/views/components/navList.korte create mode 100644 plugins/javadoc/src/main/resources/views/components/pageStart.korte create mode 100644 plugins/javadoc/src/main/resources/views/components/subNav.korte create mode 100644 plugins/javadoc/src/main/resources/views/components/topNavbar.korte create mode 100644 plugins/javadoc/src/main/resources/views/listPage.korte create mode 100644 plugins/javadoc/src/main/resources/views/tabPage.korte create mode 100644 plugins/javadoc/src/main/resources/views/treePage.korte create mode 100644 plugins/javadoc/src/test/kotlin/javadoc/JavadocTest.kt create mode 100644 plugins/javadoc/src/test/resources/javadoc/test/main/java/adaptation/Adaptation.kt (limited to '.idea/misc.xml') diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 00000000..e69de29b diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..e69de29b diff --git a/core/src/main/kotlin/transformers/documentation/DocumentableToPageTranslator.kt b/core/src/main/kotlin/transformers/documentation/DocumentableToPageTranslator.kt index 83456f01..a4daba63 100644 --- a/core/src/main/kotlin/transformers/documentation/DocumentableToPageTranslator.kt +++ b/core/src/main/kotlin/transformers/documentation/DocumentableToPageTranslator.kt @@ -2,7 +2,8 @@ package org.jetbrains.dokka.transformers.documentation import org.jetbrains.dokka.model.DModule import org.jetbrains.dokka.pages.ModulePageNode +import org.jetbrains.dokka.pages.RootPageNode interface DocumentableToPageTranslator { - operator fun invoke(module: DModule): ModulePageNode + operator fun invoke(module: DModule): RootPageNode } \ No newline at end of file diff --git a/plugins/base/frontend/build.gradle.kts b/plugins/base/frontend/build.gradle.kts index c1654f99..990b7828 100644 --- a/plugins/base/frontend/build.gradle.kts +++ b/plugins/base/frontend/build.gradle.kts @@ -7,6 +7,7 @@ tasks { inputs.dir("$projectDir/src/main/") inputs.files("$projectDir/package.json", "$projectDir/webpack.config.js") outputs.dir("$projectDir/dist/") + outputs.cacheIf { true } } register("generateFrontendFiles") { diff --git a/plugins/base/src/main/kotlin/DokkaBase.kt b/plugins/base/src/main/kotlin/DokkaBase.kt index af04d435..46c92c15 100644 --- a/plugins/base/src/main/kotlin/DokkaBase.kt +++ b/plugins/base/src/main/kotlin/DokkaBase.kt @@ -130,7 +130,7 @@ class DokkaBase : DokkaPlugin() { } val rootCreator by extending { - htmlPreprocessors with RootCreator + htmlPreprocessors with RootCreator applyIf { format == "html" } } val defaultSamplesTransformer by extending { @@ -153,19 +153,19 @@ class DokkaBase : DokkaPlugin() { } val navigationPageInstaller by extending { - htmlPreprocessors with NavigationPageInstaller order { after(rootCreator) } + htmlPreprocessors with NavigationPageInstaller order { after(rootCreator) } applyIf { format == "html" } } val searchPageInstaller by extending { - htmlPreprocessors with SearchPageInstaller order { after(rootCreator) } + htmlPreprocessors with SearchPageInstaller order { after(rootCreator) } applyIf { format == "html" } } val resourceInstaller by extending { - htmlPreprocessors with ResourceInstaller order { after(rootCreator) } + htmlPreprocessors with ResourceInstaller order { after(rootCreator) } applyIf { format == "html" } } val styleAndScriptsAppender by extending { - htmlPreprocessors with StyleAndScriptsAppender order { after(rootCreator) } + htmlPreprocessors with StyleAndScriptsAppender order { after(rootCreator) } applyIf { format == "html" } } val packageListCreator by extending { @@ -175,7 +175,7 @@ class DokkaBase : DokkaPlugin() { "html", "html" ) - } order { after(rootCreator) } + } order { after(rootCreator) } applyIf { format == "html" } } val sourcesetDependencyAppender by extending { diff --git a/plugins/base/src/test/kotlin/basic/DokkaBasicTests.kt b/plugins/base/src/test/kotlin/basic/DokkaBasicTests.kt index c1044e09..c9f4b156 100644 --- a/plugins/base/src/test/kotlin/basic/DokkaBasicTests.kt +++ b/plugins/base/src/test/kotlin/basic/DokkaBasicTests.kt @@ -31,8 +31,9 @@ class DokkaBasicTests : AbstractCoreTest() { configuration ) { pagesGenerationStage = { - println(it.dri) - assertTrue(it.getClasslikeToMemberMap().filterKeys { it.name == "Test" }.entries.firstOrNull()?.value?.size == 2) + val root = it as ModulePageNode + println(root.dri) + assertTrue(root.getClasslikeToMemberMap().filterKeys { root.name == "Test" }.entries.firstOrNull()?.value?.size == 2) } } } diff --git a/plugins/base/src/test/kotlin/enums/EnumsTest.kt b/plugins/base/src/test/kotlin/enums/EnumsTest.kt index a8b78baa..125e37e2 100644 --- a/plugins/base/src/test/kotlin/enums/EnumsTest.kt +++ b/plugins/base/src/test/kotlin/enums/EnumsTest.kt @@ -231,7 +231,7 @@ class EnumsTest : AbstractCoreTest() { } - fun ModulePageNode.getClasslikeToMemberMap() = + fun RootPageNode.getClasslikeToMemberMap() = this.parentMap.filterValues { it is ClasslikePageNode }.entries.groupBy({ it.value }) { it.key } private fun ContentGroup.constructorSignature(): String = diff --git a/plugins/base/src/test/kotlin/markdown/KDocTest.kt b/plugins/base/src/test/kotlin/markdown/KDocTest.kt index f9d717b0..218f7244 100644 --- a/plugins/base/src/test/kotlin/markdown/KDocTest.kt +++ b/plugins/base/src/test/kotlin/markdown/KDocTest.kt @@ -39,7 +39,7 @@ abstract class KDocTest : AbstractCoreTest() { pagesGenerationStage = { assertEquals( expectedDocumentationNode, - actualDocumentationNode(it) + actualDocumentationNode(it as ModulePageNode) ) } } diff --git a/plugins/build.gradle.kts b/plugins/build.gradle.kts index e65f78ac..d681cf2a 100644 --- a/plugins/build.gradle.kts +++ b/plugins/build.gradle.kts @@ -1,6 +1,7 @@ subprojects { apply { plugin("maven-publish") + plugin("com.jfrog.bintray") } dependencies { diff --git a/plugins/javadoc/build.gradle.kts b/plugins/javadoc/build.gradle.kts new file mode 100644 index 00000000..4414b1dd --- /dev/null +++ b/plugins/javadoc/build.gradle.kts @@ -0,0 +1,19 @@ +import org.jetbrains.configureBintrayPublication +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +publishing { + publications { + register("javadocPlugin") { + artifactId = "javadoc-plugin" + from(components["java"]) + } + } +} + +dependencies { + implementation("com.soywiz.korlibs.korte:korte-jvm:1.10.3") + implementation("org.jetbrains.kotlinx:kotlinx-html-jvm:0.6.10") + implementation(project(":plugins:base")) +} + +configureBintrayPublication("javadocPlugin") diff --git a/plugins/javadoc/src/main/kotlin/javadoc/JavadocDocumentableToPageTranslator.kt b/plugins/javadoc/src/main/kotlin/javadoc/JavadocDocumentableToPageTranslator.kt new file mode 100644 index 00000000..840bdc55 --- /dev/null +++ b/plugins/javadoc/src/main/kotlin/javadoc/JavadocDocumentableToPageTranslator.kt @@ -0,0 +1,18 @@ +package javadoc + +import org.jetbrains.dokka.base.signatures.SignatureProvider +import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter +import org.jetbrains.dokka.model.DModule +import org.jetbrains.dokka.pages.ModulePageNode +import org.jetbrains.dokka.pages.RootPageNode +import org.jetbrains.dokka.transformers.documentation.DocumentableToPageTranslator +import org.jetbrains.dokka.utilities.DokkaLogger + +class JavadocDocumentableToPageTranslator( + private val commentsToContentConverter: CommentsToContentConverter, + private val signatureProvider: SignatureProvider, + private val logger: DokkaLogger +) : DocumentableToPageTranslator { + override fun invoke(module: DModule): RootPageNode = + JavadocPageCreator(commentsToContentConverter, signatureProvider, logger).pageForModule(module) +} \ No newline at end of file diff --git a/plugins/javadoc/src/main/kotlin/javadoc/JavadocLocationProvider.kt b/plugins/javadoc/src/main/kotlin/javadoc/JavadocLocationProvider.kt new file mode 100644 index 00000000..520486f6 --- /dev/null +++ b/plugins/javadoc/src/main/kotlin/javadoc/JavadocLocationProvider.kt @@ -0,0 +1,103 @@ +package javadoc + +import javadoc.pages.* +import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.base.DokkaBase +import org.jetbrains.dokka.base.resolvers.local.LocationProvider +import org.jetbrains.dokka.links.DRI +import org.jetbrains.dokka.model.SourceSetData +import org.jetbrains.dokka.pages.ContentPage +import org.jetbrains.dokka.pages.PageNode +import org.jetbrains.dokka.pages.RootPageNode +import org.jetbrains.dokka.plugability.DokkaContext +import org.jetbrains.dokka.plugability.plugin +import org.jetbrains.dokka.plugability.query +import java.nio.file.Paths +import java.util.* + +class JavadocLocationProvider(pageRoot: RootPageNode, private val context: DokkaContext) : LocationProvider { + private val externalLocationProviderFactories = + context.plugin().query { externalLocationProviderFactory } + private val externalLocationProvider = + externalLocationProviderFactories.asSequence().map { it.getExternalLocationProvider("javadoc10") } + .filterNotNull().take(1).firstOrNull() + private val externalDocumentationLinks by lazy { + context.configuration.passesConfigurations + .filter { passConfig -> passConfig.analysisPlatform == Platform.jvm } + .flatMap { it.externalDocumentationLinks } + .distinct() + } + + private val pathIndex = IdentityHashMap>().apply { + fun registerPath(page: PageNode, prefix: List = emptyList()) { + val newPrefix = prefix + page.takeIf { it is JavadocPackagePageNode }?.name.orEmpty() + val path = (prefix + when (page) { + is AllClassesPage -> listOf("allclasses") + is TreeViewPage -> if (page.classes == null) + listOf("overview-tree") + else + listOf("package-tree") + is ContentPage -> if (page.dri.isNotEmpty() && page.dri.first().classNames != null) + listOfNotNull(page.dri.first().classNames) + else if (page is JavadocPackagePageNode) + listOf(page.name, "package-summary") + else + listOf("index") + else -> emptyList() + }).filterNot { it.isEmpty() } + + put(page, path) + page.children.forEach { registerPath(it, newPrefix) } + + } + put(pageRoot, listOf("index")) + pageRoot.children.forEach { registerPath(it) } + } + + private val nodeIndex = IdentityHashMap().apply { + fun registerNode(node: PageNode) { + if (node is ContentPage) put(node.dri.first(), node) + + node.children.forEach(::registerNode) + } + registerNode(pageRoot) + } + + private operator fun IdentityHashMap>.get(dri: DRI) = this[nodeIndex[dri]] + + override fun resolve(dri: DRI, sourceSets: List, context: PageNode?): String = + context?.let { resolve(it, skipExtension = false) } ?: nodeIndex[dri]?.let { + resolve(it, skipExtension = true) + } ?: with(externalLocationProvider!!) { + dri.toLocation() + } + + override fun resolve(node: PageNode, context: PageNode?, skipExtension: Boolean): String = + pathIndex[node]?.joinToString("/")?.let { + if (skipExtension) it.removeSuffix(".html") else it + } ?: run { + throw IllegalStateException("Path for ${node::class.java.canonicalName}:${node.name} not found") + } + + fun resolve(link: LinkJavadocListEntry, dir: String = "", skipExtension: Boolean = true) = pathIndex[link.dri.first()]?.let { + when (link.kind) { + JavadocContentKind.Class -> it + JavadocContentKind.OverviewSummary -> it.dropLast(1) + "index" + JavadocContentKind.PackageSummary -> it.dropLast(1) + "package-summary" + JavadocContentKind.AllClasses -> it.dropLast(1) + "allclasses" + JavadocContentKind.OverviewTree -> it.dropLast(1) + "overview-tree" + JavadocContentKind.PackageTree -> it.dropLast(1) + "package-tree" + else -> it + } + }?.joinToString("/")?.let {if (skipExtension) "$it.html" else it}?.let { + Paths.get(dir).relativize(Paths.get(it)).toString() + } ?: run {throw IllegalStateException("Page for ${link.name} not found")} + + override fun resolveRoot(node: PageNode): String { + TODO("Not yet implemented") + } + + override fun ancestors(node: PageNode): List { + TODO("Not yet implemented") + } +} \ No newline at end of file diff --git a/plugins/javadoc/src/main/kotlin/javadoc/JavadocPageCreator.kt b/plugins/javadoc/src/main/kotlin/javadoc/JavadocPageCreator.kt new file mode 100644 index 00000000..f5ca4bb3 --- /dev/null +++ b/plugins/javadoc/src/main/kotlin/javadoc/JavadocPageCreator.kt @@ -0,0 +1,92 @@ +package javadoc + +import javadoc.pages.* +import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.base.signatures.SignatureProvider +import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter +import org.jetbrains.dokka.model.* +import org.jetbrains.dokka.pages.ContentKind +import org.jetbrains.dokka.utilities.DokkaLogger + +open class JavadocPageCreator( + commentsToContentConverter: CommentsToContentConverter, + signatureProvider: SignatureProvider, + val logger: DokkaLogger +) { + fun pageForModule(m: DModule): JavadocModulePageNode = + JavadocModulePageNode( + m.name.ifEmpty { "root" }, + contentForModule(m), + m.packages.map { pageForPackage(it) }, + setOf(m.dri) + ) + + fun pageForPackage(p: DPackage) = + JavadocPackagePageNode(p.name, contentForPackage(p), setOf(p.dri), p, + p.classlikes.map { pageForClasslike(it) } // TODO: nested classlikes + ).also { + it + } + + fun pageForClasslike(c: DClasslike): JavadocClasslikePageNode { + val constructors = when (c) { + is DClass -> c.constructors + is DEnum -> c.constructors + else -> emptyList() + } + + return JavadocClasslikePageNode(c.name.orEmpty(), contentForClasslike(c), setOf(c.dri), c, emptyList()) + } + + fun contentForModule(m: DModule): JavadocContentNode = + JavadocContentGroup( + setOf(m.dri), + JavadocContentKind.OverviewSummary, + m.sourceSets.filter { it.platform == Platform.jvm }.toSet() + ) { + title(m.name, "0.0.1", dri = setOf(m.dri), kind = ContentKind.Main) + list("Packages", "Package", setOf(m.dri), ContentKind.Packages, m.packages.map { p -> + val doc = p.documentation.entries.find { (k, _) -> k.platform == Platform.jvm }?.value?.let { + it.children.joinToString("\n") { it.root.toString() } + }.orEmpty() + RowJavadocListEntry( + LinkJavadocListEntry(p.name, setOf(p.dri), JavadocContentKind.PackageSummary, sourceSets), + doc + ) + }) + } + + fun contentForPackage(p: DPackage): JavadocContentNode = + JavadocContentGroup( + setOf(p.dri), + JavadocContentKind.PackageSummary, + p.sourceSets.filter { it.platform == Platform.jvm }.toSet() + ) { + title(p.name, "0.0.1", dri = setOf(p.dri), kind = ContentKind.Packages) + list("Packages", "Package", setOf(p.dri), ContentKind.Packages, p.classlikes.map { c -> + val doc = c.documentation.entries.find { (k, _) -> k.platform == Platform.jvm }?.value?.let { + it.children.joinToString("\n") { it.root.toString() } + }.orEmpty() + RowJavadocListEntry( + LinkJavadocListEntry(c.name.orEmpty(), setOf(c.dri), JavadocContentKind.Class, sourceSets), + doc + ) + }) + } + + fun contentForClasslike(c: DClasslike): JavadocContentNode = + JavadocContentGroup( + setOf(c.dri), + JavadocContentKind.Class, + c.sourceSets.filter { it.platform == Platform.jvm }.toSet() + ) { + title( + c.name.orEmpty(), + "0.0.1", + parent = c.dri.packageName, + dri = setOf(c.dri), + kind = JavadocContentKind.Class + ) + } +} + diff --git a/plugins/javadoc/src/main/kotlin/javadoc/JavadocPlugin.kt b/plugins/javadoc/src/main/kotlin/javadoc/JavadocPlugin.kt new file mode 100644 index 00000000..f58faa49 --- /dev/null +++ b/plugins/javadoc/src/main/kotlin/javadoc/JavadocPlugin.kt @@ -0,0 +1,29 @@ +package org.jetbrains.dokka.javadoc + +import javadoc.JavadocDocumentableToPageTranslator +import javadoc.KorteJavadocRenderer +import org.jetbrains.dokka.CoreExtensions +import org.jetbrains.dokka.base.DokkaBase +import org.jetbrains.dokka.plugability.DokkaPlugin +import org.jetbrains.dokka.plugability.querySingle + +class JavadocPlugin : DokkaPlugin() { + val dokkaJavadocPlugin by extending { + val dokkaBasePlugin = plugin() + CoreExtensions.renderer providing { ctx -> + KorteJavadocRenderer(dokkaBasePlugin.querySingle { outputWriter }, ctx, "views") + } applyIf { format == "javadoc" } + } + + val pageTranslator by extending { + val dokkaBasePlugin = plugin() + CoreExtensions.documentableToPageTranslator providing { ctx -> + JavadocDocumentableToPageTranslator( + dokkaBasePlugin.querySingle { commentsToContentConverter }, + dokkaBasePlugin.querySingle { signatureProvider }, + ctx.logger + ) + } + } +} + diff --git a/plugins/javadoc/src/main/kotlin/javadoc/JavadocRenderer.kt b/plugins/javadoc/src/main/kotlin/javadoc/JavadocRenderer.kt new file mode 100644 index 00000000..588d89ba --- /dev/null +++ b/plugins/javadoc/src/main/kotlin/javadoc/JavadocRenderer.kt @@ -0,0 +1,28 @@ +package org.jetbrains.dokka.javadoc + +//class JavadocRenderer(val outputWriter: OutputWriter, val context: DokkaContext) : Renderer { +// override fun render(root: RootPageNode) { +// val rootIndex = (root as RootIndexPage) +// val instructions = (rootIndex.strategy as RenderingStrategy.Callback).instructions +// outputWriter.writeHtml("index", instructions(this, rootIndex)) // TODO get version +// rootIndex.children.forEach { renderPages(it) } +// } +// +// private fun renderPages(node: PageNode, dir: String = "") { +// val path = if (node is JavadocPageNode) node.fullPath else "$dir/${node.name}" +// if (node is RendererSpecificPage) { +// when (val strategy = node.strategy) { +// is RenderingStrategy.Copy -> outputWriter.writeResources(strategy.from, "") +// is RenderingStrategy.Write -> outputWriter.writeHtml(path, strategy.text) +// is RenderingStrategy.Callback -> outputWriter.writeHtml(path, strategy.instructions(this, node)) +// RenderingStrategy.DoNothing -> Unit +// } +// } +//// else +//// throw IllegalStateException("${node.name} was not expected here") +// +// node.children.forEach { renderPages(it, path) } +// } +// +// private fun OutputWriter.writeHtml(path: String, text: String) = write(path, text, ".html") +//} \ No newline at end of file diff --git a/plugins/javadoc/src/main/kotlin/javadoc/KorteJavadocRenderer.kt b/plugins/javadoc/src/main/kotlin/javadoc/KorteJavadocRenderer.kt new file mode 100644 index 00000000..ad83968e --- /dev/null +++ b/plugins/javadoc/src/main/kotlin/javadoc/KorteJavadocRenderer.kt @@ -0,0 +1,193 @@ +package javadoc + +import com.soywiz.korte.* +import javadoc.pages.* +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import kotlinx.coroutines.runBlocking +import org.jetbrains.dokka.base.renderers.OutputWriter +import org.jetbrains.dokka.links.DRI +import org.jetbrains.dokka.pages.PageNode +import org.jetbrains.dokka.pages.RendererSpecificPage +import org.jetbrains.dokka.pages.RenderingStrategy +import org.jetbrains.dokka.pages.RootPageNode +import org.jetbrains.dokka.plugability.DokkaContext +import org.jetbrains.dokka.renderers.Renderer +import java.nio.file.Path +import java.nio.file.Paths +import java.time.LocalDate + +class KorteJavadocRenderer(val outputWriter: OutputWriter, val context: DokkaContext, val resourceDir: String) : + Renderer { + private lateinit var locationProvider: JavadocLocationProvider + + override fun render(root: RootPageNode) = root.let { preprocessors.fold(root) { r, t -> t.invoke(r) } }.let { r -> + locationProvider = JavadocLocationProvider(r, context) + runBlocking(Dispatchers.IO) { + renderModulePageNode(r as JavadocModulePageNode) + } + } + + private fun templateForNode(node: JavadocPageNode) = when (node) { + is JavadocClasslikePageNode -> "class.korte" + is JavadocPackagePageNode -> "tabPage.korte" + is JavadocModulePageNode -> "tabPage.korte" + is AllClassesPage -> "listPage.korte" + is TreeViewPage -> "treePage.korte" + else -> "" + } + + private fun CoroutineScope.renderNode(node: PageNode, path: String = "") { + if (node is JavadocPageNode) { + renderJavadocNode(node) + } else if (node is RendererSpecificPage) { + renderSpecificPage(node, path) + } + } + + private fun CoroutineScope.renderModulePageNode(node: JavadocModulePageNode) { + val link = "." + val name = "index" + val pathToRoot = "" + + val contentMap = mapOf( + "docName" to "docName", // todo docname + "pathToRoot" to pathToRoot + ) + node.contentMap + writeFromTemplate(outputWriter, "$link/$name".toNormalized(), "tabPage.korte", contentMap.toList()) + node.children.forEach { renderNode(it, link) } + } + + private fun CoroutineScope.renderJavadocNode(node: JavadocPageNode) { + val link = locationProvider.resolve(node, skipExtension = true) + val dir = Paths.get(link).parent?.let { it.toNormalized() }.orEmpty() + val pathToRoot = dir.split("/").joinToString("/") { ".." }.let { + if (it.isNotEmpty()) "$it/" else it + } + + val contentMap = mapOf( + "docName" to "docName", // todo docname + "pathToRoot" to pathToRoot, + "dir" to dir + ) + node.contentMap +// DokkaConsoleLogger.info("${node::class.java.canonicalName}::${node.name} - $link") + writeFromTemplate(outputWriter, link, templateForNode(node), contentMap.toList()) + node.children.forEach { renderNode(it, link.toNormalized()) } + } + + fun CoroutineScope.renderSpecificPage(node: RendererSpecificPage, path: String) = launch { + when (val strategy = node.strategy) { + is RenderingStrategy.Copy -> outputWriter.writeResources(strategy.from, "") + is RenderingStrategy.Write -> outputWriter.writeHtml(path, strategy.text) + is RenderingStrategy.Callback -> outputWriter.writeResources( + path, + strategy.instructions(this@KorteJavadocRenderer, node) + ) + RenderingStrategy.DoNothing -> Unit + } + } + + fun Pair.pairToTag() = "\n${first}\n${second}" + + fun LinkJavadocListEntry.toLinkTag(parent: String? = null) = + createLinkTag(locationProvider.resolve(dri.first(), sourceSets.toList()).let { + if (parent != null) it.relativizePath(parent) + else it + }, name) + + fun DRI.toLink(context: PageNode? = null) = locationProvider.resolve(this, emptyList(), context) + + fun createLinkTag(address: String, name: String) = + address.let { if (it.endsWith(".html")) it else "$it.html" }.let { + """$name""" + } + + private fun String.parent() = Paths.get(this).parent.toNormalized() + private fun Path.toNormalized() = this.normalize().toFile().toString() + private fun String.toNormalized() = Paths.get(this).toNormalized() + private fun String.relativizePath(parent: String) = Paths.get(parent).relativize(Paths.get(this)).toNormalized() + + private suspend fun OutputWriter.writeHtml(path: String, text: String) = write(path, text, ".html") + private fun CoroutineScope.writeFromTemplate( + writer: OutputWriter, + path: String, + template: String, + args: List> + ) = + launch { + val tmp = templateRenderer.render(template, *(args.toTypedArray())) + writer.writeHtml( + path, + tmp + ) + } + + fun getTemplateConfig() = TemplateConfig().also { config -> + listOf( + TeFunction("curDate") { LocalDate.now() }, + TeFunction("jQueryVersion") { "3.1" }, + TeFunction("jQueryMigrateVersion") { "1.2.1" }, + TeFunction("rowColor") { args -> if ((args.first() as Int) % 2 == 0) "altColor" else "rowColor" }, + TeFunction("h1Title") { args -> if ((args.first() as? String) == "package") "title=\"Package\" " else "" }, + TeFunction("createTabRow") { args -> + val (link, doc) = args.first() as RowJavadocListEntry + val dir = args[1] as String? + (createLinkTag(locationProvider.resolve(link, dir.orEmpty()), link.name) to doc).pairToTag().trim() + }, + TeFunction("createListRow") { args -> + val link = args.first() as LinkJavadocListEntry + val dir = args[1] as String? +// link.toLinkTag(dir) + createLinkTag(locationProvider.resolve(link, dir.orEmpty()), link.name) + }, + TeFunction("createPackageHierarchy") { args -> + val list = args.first() as List + list.mapIndexed { i, p -> + val content = if (i + 1 == list.size) "" else ", " + val name = p.name + "
  • $name$content
  • " + }.joinToString("\n") + }, + TeFunction("renderInheritanceGraph") { args -> + val node = args.first() as TreeViewPage.InheritanceNode + + fun drawRec(node: TreeViewPage.InheritanceNode): String = + "
  • " + node.dri.let { dri -> + listOfNotNull( + dri.packageName, + dri.classNames + ).joinToString(".") + node.interfaces.takeUnless { node.isInterface || it.isEmpty() } + ?.let { + " implements " + it.joinToString(", ") { n -> + listOfNotNull( + n.packageName, + createLinkTag(n.toLink(), n.classNames.orEmpty()) + ).joinToString(".") + } + }.orEmpty() + } + node.children.filterNot { it.isInterface }.takeUnless { it.isEmpty() }?.let { + "
      " + it.joinToString("\n", transform = ::drawRec) + "
    " + }.orEmpty() + "
  • " + + drawRec(node) + }, + Filter("length") { subject.dynamicLength() } + ).forEach { + when (it) { + is TeFunction -> config.register(it) + is Filter -> config.register(it) + is Tag -> config.register(it) + } + } + } + + val config = getTemplateConfig() + val templateRenderer = Templates(ResourceTemplateProvider(resourceDir), config = config, cache = true) + + class ResourceTemplateProvider(val basePath: String) : TemplateProvider { + override suspend fun get(template: String): String = + javaClass.classLoader.getResourceAsStream("$basePath/$template")?.bufferedReader()?.lines()?.toArray() + ?.joinToString("\n") ?: throw IllegalStateException("Template not found: $basePath/$template") + } +} \ No newline at end of file diff --git a/plugins/javadoc/src/main/kotlin/javadoc/pages/JavadocContentNodes.kt b/plugins/javadoc/src/main/kotlin/javadoc/pages/JavadocContentNodes.kt new file mode 100644 index 00000000..df026be3 --- /dev/null +++ b/plugins/javadoc/src/main/kotlin/javadoc/pages/JavadocContentNodes.kt @@ -0,0 +1,163 @@ +package javadoc.pages + +import org.jetbrains.dokka.links.DRI +import org.jetbrains.dokka.model.SourceSetData +import org.jetbrains.dokka.model.properties.PropertyContainer +import org.jetbrains.dokka.pages.* + +enum class JavadocContentKind : Kind { + AllClasses, OverviewSummary, PackageSummary, Class, OverviewTree, PackageTree +} + +abstract class JavadocContentNode( + dri: Set, + kind: Kind, + override val sourceSets: Set +) : ContentNode { + abstract val contentMap: Map + override val dci: DCI = DCI(dri, kind) + override val style: Set