diff options
Diffstat (limited to 'plugins/base/src')
6 files changed, 58 insertions, 26 deletions
diff --git a/plugins/base/src/main/kotlin/resolvers/external/DefaultExternalLocationProvider.kt b/plugins/base/src/main/kotlin/resolvers/external/DefaultExternalLocationProvider.kt index b92b5330..2600884d 100644 --- a/plugins/base/src/main/kotlin/resolvers/external/DefaultExternalLocationProvider.kt +++ b/plugins/base/src/main/kotlin/resolvers/external/DefaultExternalLocationProvider.kt @@ -10,15 +10,23 @@ open class DefaultExternalLocationProvider( val extension: String, val dokkaContext: DokkaContext ) : ExternalLocationProvider { + val docURL = externalDocumentation.documentationURL.toString().removeSuffix("/") + "/" + override fun resolve(dri: DRI): String? { - val docURL = externalDocumentation.documentationURL.toString().removeSuffix("/") + "/" externalDocumentation.packageList.locations[dri.toString()]?.let { path -> return "$docURL$path" } - val classNamesChecked = dri.classNames ?: return "$docURL${dri.packageName ?: ""}/index$extension" - val classLink = (listOfNotNull(dri.packageName) + classNamesChecked.split('.')) + if (dri.packageName !in externalDocumentation.packageList.packages) + return null + + return dri.constructPath() + } + + protected open fun DRI.constructPath(): String { + val classNamesChecked = classNames ?: return "$docURL${packageName ?: ""}/index$extension" + val classLink = (listOfNotNull(packageName) + classNamesChecked.split('.')) .joinToString("/", transform = ::identifierToFilename) - val callableChecked = dri.callable ?: return "$docURL$classLink/index$extension" + val callableChecked = callable ?: return "$docURL$classLink/index$extension" return "$docURL$classLink/" + identifierToFilename(callableChecked.name) + extension } } diff --git a/plugins/base/src/main/kotlin/resolvers/external/Dokka010ExternalLocationProvider.kt b/plugins/base/src/main/kotlin/resolvers/external/Dokka010ExternalLocationProvider.kt index 45440d2b..06253ae7 100644 --- a/plugins/base/src/main/kotlin/resolvers/external/Dokka010ExternalLocationProvider.kt +++ b/plugins/base/src/main/kotlin/resolvers/external/Dokka010ExternalLocationProvider.kt @@ -11,15 +11,21 @@ open class Dokka010ExternalLocationProvider( val extension: String, val dokkaContext: DokkaContext ) : ExternalLocationProvider { + val docURL = externalDocumentation.documentationURL.toString().removeSuffix("/") + "/" + override fun resolve(dri: DRI): String? { - val docURL = externalDocumentation.documentationURL.toString().removeSuffix("/") + "/" - val fqName = listOfNotNull(dri.packageName.takeIf { it?.isNotBlank() == true }, - dri.classNames.takeIf { it?.isNotBlank() == true }?.removeCompanion()).joinToString(".") + val fqName = listOfNotNull( + dri.packageName.takeIf { it?.isNotBlank() == true }, + dri.classNames.takeIf { it?.isNotBlank() == true }?.removeCompanion() + ).joinToString(".") val relocationId = fqName.let { if (dri.callable != null) it + "$" + dri.callable!!.toOldString() else it } externalDocumentation.packageList.locations[relocationId]?.let { path -> return "$docURL$path" } + if (dri.packageName !in externalDocumentation.packageList.packages) + return null + val classNamesChecked = dri.classNames?.removeCompanion() ?: return "$docURL${dri.packageName ?: ""}/index$extension" @@ -29,6 +35,7 @@ open class Dokka010ExternalLocationProvider( val callableChecked = dri.callable ?: return "$docURL$classLink/index$extension" return "$docURL$classLink/" + identifierToFilename(callableChecked.name) + extension } + private fun String.removeCompanion() = removeSuffix(".Companion") private fun Callable.toOldString() = name + params.joinToString(", ", "(", ")") + (receiver?.let { "#$it" } ?: "") diff --git a/plugins/base/src/main/kotlin/resolvers/external/ExternalLocationProvider.kt b/plugins/base/src/main/kotlin/resolvers/external/ExternalLocationProvider.kt index 51df1504..11940abc 100644 --- a/plugins/base/src/main/kotlin/resolvers/external/ExternalLocationProvider.kt +++ b/plugins/base/src/main/kotlin/resolvers/external/ExternalLocationProvider.kt @@ -2,6 +2,13 @@ package org.jetbrains.dokka.base.resolvers.external import org.jetbrains.dokka.links.DRI +/** + * Provides the path to the page documenting a [DRI] in an external documentation source + */ interface ExternalLocationProvider { + /** + * @return Path to the page containing the [dri] or null if the path cannot be created + * (eg. when the package-list does not contain [dri]'s package) + */ fun resolve(dri: DRI): String? } diff --git a/plugins/base/src/main/kotlin/resolvers/external/javadoc/JavadocExternalLocationProvider.kt b/plugins/base/src/main/kotlin/resolvers/external/javadoc/JavadocExternalLocationProvider.kt index d4f44a94..b0398cd7 100644 --- a/plugins/base/src/main/kotlin/resolvers/external/javadoc/JavadocExternalLocationProvider.kt +++ b/plugins/base/src/main/kotlin/resolvers/external/javadoc/JavadocExternalLocationProvider.kt @@ -14,17 +14,14 @@ open class JavadocExternalLocationProvider( dokkaContext: DokkaContext ) : DefaultExternalLocationProvider(externalDocumentation, ".html", dokkaContext) { - override fun resolve(dri: DRI): String? { - val docURL = externalDocumentation.documentationURL.toString().removeSuffix("/") + "/" - externalDocumentation.packageList.locations[dri.toString()]?.let { path -> return "$docURL$path" } - - val packageLink = dri.packageName?.replace(".", "/") - if (dri.classNames == null) { + override fun DRI.constructPath(): String { + val packageLink = packageName?.replace(".", "/") + if (classNames == null) { return "$docURL$packageLink/package-summary$extension".htmlEscape() } val classLink = - if (packageLink == null) "${dri.classNames}$extension" else "$packageLink/${dri.classNames}$extension" - val callableChecked = dri.callable ?: return "$docURL$classLink".htmlEscape() + if (packageLink == null) "${classNames}$extension" else "$packageLink/${classNames}$extension" + val callableChecked = callable ?: return "$docURL$classLink".htmlEscape() return ("$docURL$classLink#" + anchorPart(callableChecked)).htmlEscape() } diff --git a/plugins/base/src/main/kotlin/resolvers/local/DefaultLocationProvider.kt b/plugins/base/src/main/kotlin/resolvers/local/DefaultLocationProvider.kt index e085af1a..293ca2d4 100644 --- a/plugins/base/src/main/kotlin/resolvers/local/DefaultLocationProvider.kt +++ b/plugins/base/src/main/kotlin/resolvers/local/DefaultLocationProvider.kt @@ -20,7 +20,7 @@ abstract class DefaultLocationProvider( protected val externalLocationProviderFactories = dokkaContext.plugin<DokkaBase>().query { externalLocationProviderFactory } - protected val packagesIndex: Map<String, ExternalLocationProvider?> = dokkaContext + protected val externalLocationProviders: Map<ExternalDocumentation, ExternalLocationProvider?> = dokkaContext .configuration .sourceSets .flatMap { sourceSet -> @@ -30,18 +30,32 @@ abstract class DefaultLocationProvider( } } .filterNotNull() - .flatMap { extDocInfo -> - extDocInfo.packageList.packages.map { packageName -> - val externalLocationProvider = (externalLocationProviderFactories.asSequence() - .mapNotNull { it.getExternalLocationProvider(extDocInfo) }.firstOrNull() - ?: run { dokkaContext.logger.error("No ExternalLocationProvider for '${extDocInfo.packageList.url}' found"); null }) - packageName to externalLocationProvider - } + .map { extDocInfo -> + val externalLocationProvider = (externalLocationProviderFactories.asSequence() + .mapNotNull { it.getExternalLocationProvider(extDocInfo) }.firstOrNull() + ?: run { dokkaContext.logger.error("No ExternalLocationProvider for '${extDocInfo.packageList.url}' found"); null }) + extDocInfo to externalLocationProvider + } + .toMap() + + protected val packagesIndex: Map<String, ExternalLocationProvider?> = externalLocationProviders + .flatMap { (extDocInfo, externalLocationProvider) -> + extDocInfo.packageList.packages.map { packageName -> packageName to externalLocationProvider } + } + .toMap() + .filterKeys(String::isNotBlank) + + + protected val locationsIndex: Map<String, ExternalLocationProvider?> = externalLocationProviders + .flatMap { (extDocInfo, externalLocationProvider) -> + extDocInfo.packageList.locations.keys.map { relocatedDri -> relocatedDri to externalLocationProvider } } .toMap() .filterKeys(String::isNotBlank) protected open fun getExternalLocation(dri: DRI, sourceSets: Set<DisplaySourceSet>): String? = packagesIndex[dri.packageName]?.resolve(dri) + ?: locationsIndex[dri.toString()]?.resolve(dri) + ?: externalLocationProviders.values.mapNotNull { it?.resolve(dri) }.firstOrNull() } diff --git a/plugins/base/src/main/kotlin/resolvers/shared/PackageList.kt b/plugins/base/src/main/kotlin/resolvers/shared/PackageList.kt index 28ab6235..c1b76a3b 100644 --- a/plugins/base/src/main/kotlin/resolvers/shared/PackageList.kt +++ b/plugins/base/src/main/kotlin/resolvers/shared/PackageList.kt @@ -16,16 +16,15 @@ data class PackageList( val packageListStream = url.readContent() - val (params, packages) = packageListStream .bufferedReader() .useLines { lines -> lines.partition { it.startsWith(PackageListService.DOKKA_PARAM_PREFIX) } } val paramsMap = splitParams(params) val format = linkFormat(paramsMap["format"]?.singleOrNull(), jdkVersion) - val locations = splitLocations(paramsMap["location"].orEmpty()) + val locations = splitLocations(paramsMap["location"].orEmpty()).filterKeys(String::isNotEmpty) - return PackageList(format, packages.toSet(), locations, url) + return PackageList(format, packages.filter(String::isNotBlank).toSet(), locations, url) } |