Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flatten multi-module structure #1980

Merged
merged 4 commits into from
Jul 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/main/kotlin/defaultExternalLinks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fun ExternalDocumentationLink.Companion.jdk(jdkVersion: Int): ExternalDocumentat
ExternalDocumentationLink(
url =
if (jdkVersion < 11) "https://docs.oracle.com/javase/${jdkVersion}/docs/api/"
else "https://docs.oracle.com/en/java/javase/${jdkVersion}/docs/api/java.base/",
else "https://docs.oracle.com/en/java/javase/${jdkVersion}/docs/api/",
packageListUrl =
if (jdkVersion < 11) "https://docs.oracle.com/javase/${jdkVersion}/docs/api/package-list"
else "https://docs.oracle.com/en/java/javase/${jdkVersion}/docs/api/element-list"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,4 @@ abstract class DokkaTestGenerator<T : TestMethods>(
protected val additionalPlugins: List<DokkaPlugin> = emptyList()
) {
abstract fun generate()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ class AllModulesPagePlugin : DokkaPlugin() {
val multiModuleLinkResolver by extending {
externalModuleLinkResolver providing ::DefaultExternalModuleLinkResolver
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.jetbrains.dokka.allModulesPage

import org.jetbrains.dokka.DokkaConfiguration
import org.jetbrains.dokka.DokkaConfiguration.DokkaModuleDescription
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.PackageList.Companion.PACKAGE_LIST_NAME
import org.jetbrains.dokka.base.resolvers.shared.RecognizedLinkFormat
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.plugability.DokkaContext
Expand Down Expand Up @@ -42,10 +42,10 @@ class DefaultExternalModuleLinkResolver(val context: DokkaContext) : ExternalMod
this
}

private fun loadPackageListForModule(module: DokkaConfiguration.DokkaModuleDescription) =
module.sourceOutputDirectory.resolve(File(identifierToFilename(module.name))).let {
private fun loadPackageListForModule(module: DokkaModuleDescription) =
module.sourceOutputDirectory.walkTopDown().maxDepth(3).firstOrNull { it.name == PACKAGE_LIST_NAME }?.let {
PackageList.load(
URL("file:" + it.resolve("package-list").path),
URL("file:" + it.path),
8,
true
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ class MultiModuleDocumentationTest : MultiModuleAbstractTest() {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ResolveLinkCommandResolutionTest : MultiModuleAbstractTest() {
}

val expected = createHTML().a {
href = "../../module2/package2/-sample/index.html"
href = "../module2/package2/-sample/index.html"
span {
+"Sample"
}
Expand Down Expand Up @@ -97,12 +97,12 @@ class ResolveLinkCommandResolutionTest : MultiModuleAbstractTest() {

fun setup(content: String): File {
folder.create()
val innerModule1 = folder.newFolder("module1", "module1")
val innerModule2 = folder.newFolder("module2", "module2")
val innerModule1 = folder.newFolder("module1")
val innerModule2 = folder.newFolder("module2")
val packageList = innerModule2.resolve("package-list")
packageList.writeText(mockedPackageListForPackages(RecognizedLinkFormat.DokkaHtml, "package2"))
val contentFile = innerModule1.resolve("index.html")
contentFile.writeText(content)
return contentFile
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ResolveLinkGfmCommandResolutionTest : MultiModuleAbstractTest() {
sourceOutputDirectory = folder.root.resolve("module2"),
)
)
this.outputDir = folder.root
outputDir = folder.root
}

@Test
Expand All @@ -49,7 +49,7 @@ class ResolveLinkGfmCommandResolutionTest : MultiModuleAbstractTest() {
}
}.toString()

val expected = "[Sample text inside](../../module2/package2/-sample/index.md)"
val expected = "[Sample text inside](../module2/package2/-sample/index.md)"

val content = setup(link)
val configuration = configuration()
Expand All @@ -63,8 +63,8 @@ class ResolveLinkGfmCommandResolutionTest : MultiModuleAbstractTest() {

private fun setup(content: String): File {
folder.create()
val innerModule1 = folder.newFolder("module1", "module1")
val innerModule2 = folder.newFolder("module2", "module2")
val innerModule1 = folder.newFolder( "module1")
val innerModule2 = folder.newFolder( "module2")
val packageList = innerModule2.resolve("package-list")
packageList.writeText(mockedPackageListForPackages(RecognizedLinkFormat.DokkaGFM, "package2"))
val contentFile = innerModule1.resolve("index.md")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.jetbrains.dokka.allModulesPage.templates

import org.jetbrains.dokka.base.renderers.PackageListService
import org.jetbrains.dokka.base.resolvers.shared.PackageList
import org.jetbrains.dokka.base.resolvers.shared.RecognizedLinkFormat

internal fun mockedPackageListForPackages(format: RecognizedLinkFormat, vararg packages: String): String =
"""
${PackageListService.DOKKA_PARAM_PREFIX}.format:${format.formatName}
${PackageListService.DOKKA_PARAM_PREFIX}.linkExtension:${format.linkExtension}
${PackageList.DOKKA_PARAM_PREFIX}.format:${format.formatName}
${PackageList.DOKKA_PARAM_PREFIX}.linkExtension:${format.linkExtension}

${packages.sorted().joinToString(separator = "\n", postfix = "\n") { it }}
""".trimIndent()
""".trimIndent()
23 changes: 14 additions & 9 deletions plugins/base/api/base.api
Original file line number Diff line number Diff line change
Expand Up @@ -277,25 +277,24 @@ public abstract interface class org/jetbrains/dokka/base/renderers/OutputWriter
}

public final class org/jetbrains/dokka/base/renderers/PackageListCreator : org/jetbrains/dokka/transformers/pages/PageTransformer {
public fun <init> (Lorg/jetbrains/dokka/plugability/DokkaContext;Lorg/jetbrains/dokka/base/resolvers/shared/LinkFormat;Ljava/util/List;Z)V
public synthetic fun <init> (Lorg/jetbrains/dokka/plugability/DokkaContext;Lorg/jetbrains/dokka/base/resolvers/shared/LinkFormat;Ljava/util/List;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Lorg/jetbrains/dokka/plugability/DokkaContext;Lorg/jetbrains/dokka/base/resolvers/shared/LinkFormat;Ljava/util/List;)V
public synthetic fun <init> (Lorg/jetbrains/dokka/plugability/DokkaContext;Lorg/jetbrains/dokka/base/resolvers/shared/LinkFormat;Ljava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun getContext ()Lorg/jetbrains/dokka/plugability/DokkaContext;
public final fun getFormat ()Lorg/jetbrains/dokka/base/resolvers/shared/LinkFormat;
public final fun getOutputFilesNames ()Ljava/util/List;
public final fun getRemoveModulePrefix ()Z
public fun invoke (Lorg/jetbrains/dokka/pages/RootPageNode;)Lorg/jetbrains/dokka/pages/RootPageNode;
}

public final class org/jetbrains/dokka/base/renderers/PackageListService {
public static final field Companion Lorg/jetbrains/dokka/base/renderers/PackageListService$Companion;
public static final field DOKKA_PARAM_PREFIX Ljava/lang/String;
public fun <init> (Lorg/jetbrains/dokka/plugability/DokkaContext;Lorg/jetbrains/dokka/pages/RootPageNode;)V
public final fun createPackageList (Lorg/jetbrains/dokka/pages/ModulePage;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
public final fun createPackageList (Lorg/jetbrains/dokka/pages/ModulePage;Lorg/jetbrains/dokka/base/resolvers/shared/LinkFormat;)Ljava/lang/String;
public final fun getContext ()Lorg/jetbrains/dokka/plugability/DokkaContext;
public final fun getRootPage ()Lorg/jetbrains/dokka/pages/RootPageNode;
}

public final class org/jetbrains/dokka/base/renderers/PackageListService$Companion {
public final fun renderPackageList (Ljava/util/Map;Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
}

public final class org/jetbrains/dokka/base/renderers/RootCreator : org/jetbrains/dokka/transformers/pages/PageTransformer {
Expand Down Expand Up @@ -734,19 +733,25 @@ public abstract interface class org/jetbrains/dokka/base/resolvers/shared/LinkFo

public final class org/jetbrains/dokka/base/resolvers/shared/PackageList {
public static final field Companion Lorg/jetbrains/dokka/base/resolvers/shared/PackageList$Companion;
public fun <init> (Lorg/jetbrains/dokka/base/resolvers/shared/RecognizedLinkFormat;Ljava/util/Set;Ljava/util/Map;Ljava/net/URL;)V
public static final field DOKKA_PARAM_PREFIX Ljava/lang/String;
public static final field MODULE_DELIMITER Ljava/lang/String;
public static final field PACKAGE_LIST_NAME Ljava/lang/String;
public static final field SINGLE_MODULE_NAME Ljava/lang/String;
public fun <init> (Lorg/jetbrains/dokka/base/resolvers/shared/RecognizedLinkFormat;Ljava/util/Map;Ljava/util/Map;Ljava/net/URL;)V
public final fun component1 ()Lorg/jetbrains/dokka/base/resolvers/shared/RecognizedLinkFormat;
public final fun component2 ()Ljava/util/Set;
public final fun component2 ()Ljava/util/Map;
public final fun component3 ()Ljava/util/Map;
public final fun component4 ()Ljava/net/URL;
public final fun copy (Lorg/jetbrains/dokka/base/resolvers/shared/RecognizedLinkFormat;Ljava/util/Set;Ljava/util/Map;Ljava/net/URL;)Lorg/jetbrains/dokka/base/resolvers/shared/PackageList;
public static synthetic fun copy$default (Lorg/jetbrains/dokka/base/resolvers/shared/PackageList;Lorg/jetbrains/dokka/base/resolvers/shared/RecognizedLinkFormat;Ljava/util/Set;Ljava/util/Map;Ljava/net/URL;ILjava/lang/Object;)Lorg/jetbrains/dokka/base/resolvers/shared/PackageList;
public final fun copy (Lorg/jetbrains/dokka/base/resolvers/shared/RecognizedLinkFormat;Ljava/util/Map;Ljava/util/Map;Ljava/net/URL;)Lorg/jetbrains/dokka/base/resolvers/shared/PackageList;
public static synthetic fun copy$default (Lorg/jetbrains/dokka/base/resolvers/shared/PackageList;Lorg/jetbrains/dokka/base/resolvers/shared/RecognizedLinkFormat;Ljava/util/Map;Ljava/util/Map;Ljava/net/URL;ILjava/lang/Object;)Lorg/jetbrains/dokka/base/resolvers/shared/PackageList;
public fun equals (Ljava/lang/Object;)Z
public final fun getLinkFormat ()Lorg/jetbrains/dokka/base/resolvers/shared/RecognizedLinkFormat;
public final fun getLocations ()Ljava/util/Map;
public final fun getModules ()Ljava/util/Map;
public final fun getPackages ()Ljava/util/Set;
public final fun getUrl ()Ljava/net/URL;
public fun hashCode ()I
public final fun moduleFor (Ljava/lang/String;)Ljava/lang/String;
public fun toString ()Ljava/lang/String;
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/base/src/main/kotlin/DokkaBase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class DokkaBase : DokkaPlugin() {
}

val rootCreator by extending {
htmlPreprocessors with RootCreator
htmlPreprocessors with RootCreator applyIf { !delayTemplateSubstitution }
}

val defaultSamplesTransformer by extending {
Expand Down
29 changes: 18 additions & 11 deletions plugins/base/src/main/kotlin/renderers/PackageListService.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package org.jetbrains.dokka.base.renderers

import org.jetbrains.dokka.base.DokkaBase
import org.jetbrains.dokka.base.resolvers.shared.LinkFormat
import org.jetbrains.dokka.base.resolvers.shared.PackageList.Companion.DOKKA_PARAM_PREFIX
import org.jetbrains.dokka.base.resolvers.shared.PackageList.Companion.SINGLE_MODULE_NAME
import org.jetbrains.dokka.base.resolvers.shared.PackageList.Companion.MODULE_DELIMITER
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.pages.*
import org.jetbrains.dokka.plugability.DokkaContext
Expand All @@ -10,7 +14,7 @@ import org.jetbrains.kotlin.utils.addToStdlib.safeAs

class PackageListService(val context: DokkaContext, val rootPage: RootPageNode) {

fun createPackageList(module: ModulePage, format: String, linkExtension: String): String {
fun createPackageList(module: ModulePage, format: LinkFormat): String {

val packages = mutableSetOf<String>()
val nonStandardLocations = mutableMapOf<String, String>()
Expand All @@ -31,27 +35,30 @@ class PackageListService(val context: DokkaContext, val rootPage: RootPageNode)
?: run { context.logger.error("Cannot resolve path for ${node.name}!"); null }

if (dri != DRI.topLevel && locationProvider.expectedLocationForDri(dri) != nodeLocation) {
nonStandardLocations[dri.toString()] = "$nodeLocation.$linkExtension"
nonStandardLocations[dri.toString()] = "$nodeLocation.${format.linkExtension}"
}
}

node.children.forEach { visit(it) }
}

visit(module)
return renderPackageList(nonStandardLocations, mapOf(SINGLE_MODULE_NAME to packages), format.formatName, format.linkExtension)
}

return buildString {
companion object {
fun renderPackageList(nonStandardLocations: Map<String, String>, modules: Map<String, Set<String>>, format: String, linkExtension: String): String = buildString {
appendLine("$DOKKA_PARAM_PREFIX.format:${format}")
appendLine("$DOKKA_PARAM_PREFIX.linkExtension:${linkExtension}")
nonStandardLocations.map { (signature, location) -> "$DOKKA_PARAM_PREFIX.location:$signature\u001f$location" }
.sorted().joinTo(this, separator = "\n", postfix = "\n")
nonStandardLocations.map { (signature, location) ->
"$DOKKA_PARAM_PREFIX.location:$signature\u001f$location"
}.sorted().joinTo(this, separator = "\n", postfix = "\n")

packages.sorted().joinTo(this, separator = "\n", postfix = "\n")
modules.mapNotNull { (module, packages) ->
("$MODULE_DELIMITER$module\n".takeIf { module != SINGLE_MODULE_NAME }.orEmpty() +
packages.filter(String::isNotBlank).sorted().joinToString(separator = "\n"))
.takeIf { packages.isNotEmpty() }
}.joinTo(this, separator = "\n", postfix = "\n")
}

}

companion object {
const val DOKKA_PARAM_PREFIX = "\$dokka"
}
}
10 changes: 5 additions & 5 deletions plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import org.jetbrains.dokka.plugability.configuration
import org.jetbrains.dokka.transformers.pages.PageTransformer

abstract class NavigationDataProvider {
open fun navigableChildren(input: RootPageNode): NavigationNode =
input.children.filterIsInstance<ContentPage>().single().let { visit(it) }
open fun navigableChildren(input: RootPageNode): NavigationNode = input.withDescendants()
.first { it is ModulePage || it is MultimoduleRootPage }.let { visit(it as ContentPage) }

open fun visit(page: ContentPage): NavigationNode =
NavigationNode(
Expand Down Expand Up @@ -167,9 +167,9 @@ private fun List<String>.toRenderSpecificResourcePage(): List<RendererSpecificRe
class SourcesetDependencyAppender(val context: DokkaContext) : PageTransformer {
private val name = "scripts/sourceset_dependencies.js"
override fun invoke(input: RootPageNode): RootPageNode {
val dependenciesMap = context.configuration.sourceSets.map {
val dependenciesMap = context.configuration.sourceSets.associate {
it.sourceSetID to it.dependentSourceSets
}.toMap()
}

fun createDependenciesJson(): String =
dependenciesMap.map { (key, values) -> key.toString() to values.map { it.toString() } }.toMap()
Expand All @@ -191,4 +191,4 @@ class SourcesetDependencyAppender(val context: DokkaContext) : PageTransformer {
children = input.children + deps
).transformContentPagesTree { it.modified(embeddedResources = it.embeddedResources + name) }
}
}
}
18 changes: 7 additions & 11 deletions plugins/base/src/main/kotlin/renderers/preprocessors.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jetbrains.dokka.base.renderers

import org.jetbrains.dokka.base.resolvers.shared.LinkFormat
import org.jetbrains.dokka.model.withDescendants
import org.jetbrains.dokka.pages.*
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.transformers.pages.PageTransformer
Expand All @@ -13,25 +14,20 @@ object RootCreator : PageTransformer {
class PackageListCreator(
val context: DokkaContext,
val format: LinkFormat,
val outputFilesNames: List<String> = listOf("package-list"),
val removeModulePrefix: Boolean = true
val outputFilesNames: List<String> = listOf("package-list")
) : PageTransformer {
override fun invoke(input: RootPageNode) =
input.modified(children = input.children.map {
it.takeUnless { it is ModulePage }
?: it.modified(children = it.children + packageList(input, it as ModulePage))
})

override fun invoke(input: RootPageNode) = input.transformPageNodeTree { pageNode ->
pageNode.takeIf { it is ModulePage }?.let { it.modified(children = it.children + packageList(input, it as ModulePage)) } ?: pageNode
}

private fun packageList(rootPageNode: RootPageNode, module: ModulePage): List<RendererSpecificPage> {
val content = PackageListService(context, rootPageNode).createPackageList(
module,
format.formatName,
format.linkExtension
format
)
return outputFilesNames.map { fileName ->
RendererSpecificResourcePage(
"${rootPageNode.name}/${fileName}",
fileName,
emptyList(),
RenderingStrategy.Write(content)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,21 @@ open class DefaultExternalLocationProvider(
}

protected open fun DRI.constructPath(): String {
val classNamesChecked = classNames ?: return "$docURL${packageName ?: ""}/index$extension"
val modulePart = packageName?.let { packageName ->
externalDocumentation.packageList.moduleFor(packageName)?.let {
if (it.isNotBlank())
"$it/"
else
""
}
}.orEmpty()

val docWithModule = docURL + modulePart
val classNamesChecked = classNames ?: return "$docWithModule${packageName ?: ""}/index$extension"
val classLink = (listOfNotNull(packageName) + classNamesChecked.split('.'))
.joinToString("/", transform = ::identifierToFilename)

val fileName = callable?.let { identifierToFilename(it.name) } ?: "index"
return "$docURL$classLink/$fileName$extension"
return "$docWithModule$classLink/$fileName$extension"
}
}
Loading