aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Saveau <asaveau@google.com>2020-07-14 20:39:22 +0000
committerMarcin Aman <maman@virtuslab.com>2020-07-22 19:48:43 +0200
commitaca4731ccad3d57aa8b4f6fab250ed3a72e394c4 (patch)
tree5708fb99fdfcc7f53b0d0f64a598ca18aa6e4097
parent3a33418e26dc3c70521e89e8ec01f2eb045a6f02 (diff)
downloaddokka-aca4731ccad3d57aa8b4f6fab250ed3a72e394c4.tar.gz
dokka-aca4731ccad3d57aa8b4f6fab250ed3a72e394c4.tar.bz2
dokka-aca4731ccad3d57aa8b4f6fab250ed3a72e394c4.zip
Follow Javadoc file path convention
The current file path looks like `/androidx.fragment.app/package-summary.html` which is non-standard. This CL changes the path to look like `/androidx/fragment/app/package-summary.html`.
-rw-r--r--plugins/javadoc/src/main/kotlin/javadoc/location/JavadocLocationProvider.kt11
-rw-r--r--plugins/javadoc/src/test/kotlin/javadoc/location/JavadocLocationTest.kt32
2 files changed, 32 insertions, 11 deletions
diff --git a/plugins/javadoc/src/main/kotlin/javadoc/location/JavadocLocationProvider.kt b/plugins/javadoc/src/main/kotlin/javadoc/location/JavadocLocationProvider.kt
index 49278b06..0ce20c78 100644
--- a/plugins/javadoc/src/main/kotlin/javadoc/location/JavadocLocationProvider.kt
+++ b/plugins/javadoc/src/main/kotlin/javadoc/location/JavadocLocationProvider.kt
@@ -18,7 +18,10 @@ class JavadocLocationProvider(pageRoot: RootPageNode, dokkaContext: DokkaContext
private val pathIndex = IdentityHashMap<PageNode, List<String>>().apply {
fun registerPath(page: PageNode, prefix: List<String> = emptyList()) {
- val newPrefix = prefix + page.takeIf { it is JavadocPackagePageNode }?.name.orEmpty()
+ val packagePath = page.takeIf { it is JavadocPackagePageNode }?.name.orEmpty()
+ .replace(".", "/")
+ val newPathPrefix = prefix + packagePath
+
val path = (prefix + when (page) {
is AllClassesPage -> listOf("allclasses")
is TreeViewPage -> if (page.classes == null)
@@ -28,14 +31,14 @@ class JavadocLocationProvider(pageRoot: RootPageNode, dokkaContext: DokkaContext
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")
+ listOf(packagePath, "package-summary")
else
listOf("index")
else -> emptyList()
}).filterNot { it.isEmpty() }
put(page, path)
- page.children.forEach { registerPath(it, newPrefix) }
+ page.children.forEach { registerPath(it, newPathPrefix) }
}
put(pageRoot, listOf("index"))
@@ -123,4 +126,4 @@ class JavadocLocationProvider(pageRoot: RootPageNode, dokkaContext: DokkaContext
override fun ancestors(node: PageNode): List<PageNode> {
TODO("Not yet implemented")
}
-} \ No newline at end of file
+}
diff --git a/plugins/javadoc/src/test/kotlin/javadoc/location/JavadocLocationTest.kt b/plugins/javadoc/src/test/kotlin/javadoc/location/JavadocLocationTest.kt
index 235f68c0..b7a578a5 100644
--- a/plugins/javadoc/src/test/kotlin/javadoc/location/JavadocLocationTest.kt
+++ b/plugins/javadoc/src/test/kotlin/javadoc/location/JavadocLocationTest.kt
@@ -37,8 +37,8 @@ class JavadocTest : AbstractCoreTest() {
}
testInline(
"""
- |/jvmSrc/javadoc/Test.kt
- |package javadoc
+ |/jvmSrc/javadoc/test/Test.kt
+ |package javadoc.test
|import java.io.Serializable
|class Test<A>() : Serializable, Cloneable {
| fun test() {}
@@ -120,9 +120,27 @@ class JavadocTest : AbstractCoreTest() {
}
}
- private fun htmlTranslator(rootPageNode: RootPageNode, dokkaContext: DokkaContext) = JavadocContentToHtmlTranslator(
- dokkaContext.plugin<JavadocPlugin>().querySingle { locationProviderFactory }
- .getLocationProvider(rootPageNode),
- dokkaContext
- )
+ @Test
+ fun `resolved package path`() {
+
+ locationTestInline { rootPageNode, dokkaContext ->
+ val locationProvider = dokkaContext.plugin<JavadocPlugin>().querySingle { locationProviderFactory }
+ .getLocationProvider(rootPageNode)
+ val packageNode = rootPageNode.firstChildOfType<JavadocPackagePageNode>()
+ val packagePath = locationProvider.resolve(packageNode)
+
+ assertEquals("javadoc/test/package-summary", packagePath)
+ }
+ }
+
+ private fun htmlTranslator(rootPageNode: RootPageNode, dokkaContext: DokkaContext): JavadocContentToHtmlTranslator {
+ val locationProvider = dokkaContext.plugin<JavadocPlugin>().querySingle { locationProviderFactory }
+ .getLocationProvider(rootPageNode)
+ return htmlTranslator(dokkaContext, locationProvider)
+ }
+
+ private fun htmlTranslator(
+ dokkaContext: DokkaContext,
+ locationProvider: JavadocLocationProvider
+ ) = JavadocContentToHtmlTranslator(locationProvider, dokkaContext)
}