diff options
author | Błażej Kardyś <bkardys@virtuslab.com> | 2021-01-05 17:59:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-05 17:59:38 +0100 |
commit | 1618e552c136e25d86bf0708e0d760841c77c139 (patch) | |
tree | c608ce91b020bb0ecbfe75d0f456a0eae84b4c51 /plugins/all-modules-page/src/main/kotlin/templates/ExternalModuleLinkResolver.kt | |
parent | ef98e4b6505c3fdd192b1d5057c718079d27b972 (diff) | |
download | dokka-1618e552c136e25d86bf0708e0d760841c77c139.tar.gz dokka-1618e552c136e25d86bf0708e0d760841c77c139.tar.bz2 dokka-1618e552c136e25d86bf0708e0d760841c77c139.zip |
Versioning (#1654)
* Adding versioning mechanism for multimodule
* Versioning improvement
* Refactor configuration, add ordering
* Fix integration tests
* Change packages, unignore test
Co-authored-by: Marcin Aman <marcin.aman@gmail.com>
Diffstat (limited to 'plugins/all-modules-page/src/main/kotlin/templates/ExternalModuleLinkResolver.kt')
-rw-r--r-- | plugins/all-modules-page/src/main/kotlin/templates/ExternalModuleLinkResolver.kt | 77 |
1 files changed, 0 insertions, 77 deletions
diff --git a/plugins/all-modules-page/src/main/kotlin/templates/ExternalModuleLinkResolver.kt b/plugins/all-modules-page/src/main/kotlin/templates/ExternalModuleLinkResolver.kt deleted file mode 100644 index d0e787b6..00000000 --- a/plugins/all-modules-page/src/main/kotlin/templates/ExternalModuleLinkResolver.kt +++ /dev/null @@ -1,77 +0,0 @@ -package org.jetbrains.dokka.allModulesPage.templates - -import org.jetbrains.dokka.DokkaConfiguration -import org.jetbrains.dokka.base.DokkaBase -import org.jetbrains.dokka.base.resolvers.local.DokkaLocationProvider.Companion.identifierToFilename -import org.jetbrains.dokka.base.resolvers.shared.ExternalDocumentation -import org.jetbrains.dokka.base.resolvers.shared.PackageList -import org.jetbrains.dokka.base.resolvers.shared.RecognizedLinkFormat -import org.jetbrains.dokka.links.DRI -import org.jetbrains.dokka.plugability.DokkaContext -import org.jetbrains.dokka.plugability.plugin -import org.jetbrains.dokka.plugability.query -import java.io.File -import java.net.URL - -interface ExternalModuleLinkResolver { - fun resolve(dri: DRI, fileContext: File): String? - fun resolveLinkToModuleIndex(moduleName: String): String? -} - -class DefaultExternalModuleLinkResolver(val context: DokkaContext) : ExternalModuleLinkResolver { - private val elpFactory = context.plugin<DokkaBase>().query { externalLocationProviderFactory } - private val externalDocumentations by lazy(::setupExternalDocumentations) - private val elps by lazy { - elpFactory.flatMap { externalDocumentations.map { ed -> it.getExternalLocationProvider(ed) } }.filterNotNull() - } - - private fun setupExternalDocumentations(): List<ExternalDocumentation> { - val packageLists = - context.configuration.modules.map(::loadPackageListForModule).toMap() - return packageLists.mapNotNull { (module, packageList) -> - packageList?.let { - ExternalDocumentation( - URL("file:/${module.name}/${module.name}"), - packageList - ) - } - } - } - - private fun loadPackageListForModule(module: DokkaConfiguration.DokkaModuleDescription) = - module.sourceOutputDirectory.resolve(File(identifierToFilename(module.name))).let { - it to PackageList.load( - URL("file:" + it.resolve("package-list").path), - 8, - true - ) - } - - override fun resolve(dri: DRI, fileContext: File): String? { - val absoluteLink = elps.mapNotNull { it.resolve(dri) }.firstOrNull() ?: return null - val modulePath = context.configuration.outputDir.absolutePath.split(File.separator) - val contextPath = fileContext.absolutePath.split(File.separator) - val commonPathElements = modulePath.zip(contextPath) - .takeWhile { (a, b) -> a == b }.count() - - return (List(contextPath.size - commonPathElements - 1) { ".." } + modulePath.drop(commonPathElements)).joinToString( - "/" - ) + absoluteLink.removePrefix("file:") - } - - override fun resolveLinkToModuleIndex(moduleName: String): String? = - context.configuration.modules.firstOrNull { it.name == moduleName } - ?.let { module -> - val (_, packageList) = loadPackageListForModule(module) - val extension = when (packageList?.linkFormat) { - RecognizedLinkFormat.KotlinWebsiteHtml, - RecognizedLinkFormat.DokkaOldHtml, - RecognizedLinkFormat.DokkaHtml -> ".html" - RecognizedLinkFormat.DokkaGFM, - RecognizedLinkFormat.DokkaJekyll -> ".md" - else -> "" - } - "${module.relativePathToOutputDirectory}/${identifierToFilename(moduleName)}/index$extension" - } - -} |