diff options
author | Ignat Beresnev <ignat.beresnev@jetbrains.com> | 2023-11-10 11:46:54 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-10 11:46:54 +0100 |
commit | 8e5c63d035ef44a269b8c43430f43f5c8eebfb63 (patch) | |
tree | 1b915207b2b9f61951ddbf0ff2e687efd053d555 /plugins/base/src/main/kotlin/resolvers/shared | |
parent | a44efd4ba0c2e4ab921ff75e0f53fc9335aa79db (diff) | |
download | dokka-8e5c63d035ef44a269b8c43430f43f5c8eebfb63.tar.gz dokka-8e5c63d035ef44a269b8c43430f43f5c8eebfb63.tar.bz2 dokka-8e5c63d035ef44a269b8c43430f43f5c8eebfb63.zip |
Restructure the project to utilize included builds (#3174)
* Refactor and simplify artifact publishing
* Update Gradle to 8.4
* Refactor and simplify convention plugins and build scripts
Fixes #3132
---------
Co-authored-by: Adam <897017+aSemy@users.noreply.github.com>
Co-authored-by: Oleg Yukhnevich <whyoleg@gmail.com>
Diffstat (limited to 'plugins/base/src/main/kotlin/resolvers/shared')
5 files changed, 0 insertions, 172 deletions
diff --git a/plugins/base/src/main/kotlin/resolvers/shared/ExternalDocumentation.kt b/plugins/base/src/main/kotlin/resolvers/shared/ExternalDocumentation.kt deleted file mode 100644 index db0c5492..00000000 --- a/plugins/base/src/main/kotlin/resolvers/shared/ExternalDocumentation.kt +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -package org.jetbrains.dokka.base.resolvers.shared - -import java.net.URL - -public data class ExternalDocumentation(val documentationURL: URL, val packageList: PackageList) diff --git a/plugins/base/src/main/kotlin/resolvers/shared/LinkFormat.kt b/plugins/base/src/main/kotlin/resolvers/shared/LinkFormat.kt deleted file mode 100644 index 4f0d4932..00000000 --- a/plugins/base/src/main/kotlin/resolvers/shared/LinkFormat.kt +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -package org.jetbrains.dokka.base.resolvers.shared - -public interface LinkFormat { - public val formatName: String - public val linkExtension: String -} diff --git a/plugins/base/src/main/kotlin/resolvers/shared/PackageList.kt b/plugins/base/src/main/kotlin/resolvers/shared/PackageList.kt deleted file mode 100644 index 8297f875..00000000 --- a/plugins/base/src/main/kotlin/resolvers/shared/PackageList.kt +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -package org.jetbrains.dokka.base.resolvers.shared - -import java.net.URL - -public typealias Module = String - -public data class PackageList( - val linkFormat: RecognizedLinkFormat, - val modules: Map<Module, Set<String>>, - val locations: Map<String, String>, - val url: URL -) { - val packages: Set<String> - get() = modules.values.flatten().toSet() - - public fun moduleFor(packageName: String): Module? { - return modules.asSequence() - .filter { it.value.contains(packageName) } - .firstOrNull()?.key - } - - public companion object { - public const val PACKAGE_LIST_NAME: String = "package-list" - public const val MODULE_DELIMITER: String = "module:" - public const val DOKKA_PARAM_PREFIX: String = "\$dokka" - public const val SINGLE_MODULE_NAME: String = "" - - public fun load(url: URL, jdkVersion: Int, offlineMode: Boolean = false): PackageList? { - if (offlineMode && url.protocol.toLowerCase() != "file") - return null - - val packageListStream = runCatching { url.readContent() }.onFailure { - println("Failed to download package-list from $url, this might suggest that remote resource is not available," + - " module is empty or dokka output got corrupted") - return null - }.getOrThrow() - - val (params, packages) = packageListStream - .bufferedReader() - .useLines { lines -> lines.partition { it.startsWith(DOKKA_PARAM_PREFIX) } } - - val paramsMap = splitParams(params) - val format = linkFormat(paramsMap["format"]?.singleOrNull(), jdkVersion) - val locations = splitLocations(paramsMap["location"].orEmpty()).filterKeys(String::isNotEmpty) - - val modulesMap = splitPackages(packages) - return PackageList(format, modulesMap, locations, url) - } - - private fun splitParams(params: List<String>) = params.asSequence() - .map { it.removePrefix("$DOKKA_PARAM_PREFIX.").split(":", limit = 2) } - .groupBy({ (key, _) -> key }, { (_, value) -> value }) - - private fun splitLocations(locations: List<String>) = locations.map { it.split("\u001f", limit = 2) } - .associate { (key, value) -> key to value } - - private fun splitPackages(packages: List<String>): Map<Module, Set<String>> = - packages.fold(("" to mutableMapOf<Module, Set<String>>())) { (lastModule, acc), el -> - val currentModule : String - when { - el.startsWith(MODULE_DELIMITER) -> currentModule = el.substringAfter(MODULE_DELIMITER) - el.isNotBlank() -> { - currentModule = lastModule - acc[currentModule] = acc.getOrDefault(lastModule, emptySet()) + el - } - else -> currentModule = lastModule - } - currentModule to acc - }.second - - private fun linkFormat(formatName: String?, jdkVersion: Int) = - formatName?.let { RecognizedLinkFormat.fromString(it) } - ?: when { - jdkVersion < 8 -> RecognizedLinkFormat.Javadoc1 // Covers JDK 1 - 7 - jdkVersion < 10 -> RecognizedLinkFormat.Javadoc8 // Covers JDK 8 - 9 - else -> RecognizedLinkFormat.Javadoc10 // Covers JDK 10+ - } - } -} diff --git a/plugins/base/src/main/kotlin/resolvers/shared/RecognizedLinkFormat.kt b/plugins/base/src/main/kotlin/resolvers/shared/RecognizedLinkFormat.kt deleted file mode 100644 index 4810c9e5..00000000 --- a/plugins/base/src/main/kotlin/resolvers/shared/RecognizedLinkFormat.kt +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -package org.jetbrains.dokka.base.resolvers.shared - -public enum class RecognizedLinkFormat( - override val formatName: String, - override val linkExtension: String -) : LinkFormat { - DokkaHtml("html-v1", "html"), - DokkaJavadoc("javadoc-v1", "html"), - DokkaGFM("gfm-v1", "md"), - DokkaJekyll("jekyll-v1", "html"), - Javadoc1("javadoc1", "html"), - Javadoc8("javadoc8", "html"), - Javadoc10("javadoc10", "html"), - DokkaOldHtml("html", "html"), - KotlinWebsite("kotlin-website", "html"), - KotlinWebsiteHtml("kotlin-website-html", "html"); - - public companion object { - private val values = values() - - public fun fromString(formatName: String): RecognizedLinkFormat? { - return values.firstOrNull { it.formatName == formatName } - } - } -} diff --git a/plugins/base/src/main/kotlin/resolvers/shared/utils.kt b/plugins/base/src/main/kotlin/resolvers/shared/utils.kt deleted file mode 100644 index a6d9afc6..00000000 --- a/plugins/base/src/main/kotlin/resolvers/shared/utils.kt +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -package org.jetbrains.dokka.base.resolvers.shared - -import java.io.InputStream -import java.net.HttpURLConnection -import java.net.URL -import java.net.URLConnection - -internal fun URL.readContent(timeout: Int = 10000, redirectsAllowed: Int = 16): InputStream { - fun URL.doOpenConnection(timeout: Int, redirectsAllowed: Int): URLConnection { - val connection = this.openConnection().apply { - connectTimeout = timeout - readTimeout = timeout - } - - when (connection) { - is HttpURLConnection -> return when (connection.responseCode) { - in 200..299 -> connection - - HttpURLConnection.HTTP_MOVED_PERM, - HttpURLConnection.HTTP_MOVED_TEMP, - HttpURLConnection.HTTP_SEE_OTHER -> { - if (redirectsAllowed > 0) { - val newUrl = connection.getHeaderField("Location") - URL(newUrl).doOpenConnection(timeout, redirectsAllowed - 1) - } else { - throw RuntimeException("Too many redirects") - } - } - - else -> throw RuntimeException("Unhandled HTTP code: ${connection.responseCode}") - } - - else -> return connection - } - } - return doOpenConnection(timeout, redirectsAllowed).getInputStream() -} |