-
Notifications
You must be signed in to change notification settings - Fork 405
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
all-modules-page: Validate cross-module links during resolution #2901
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ import org.jetbrains.dokka.base.DokkaBase | |
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 | ||
import org.jetbrains.dokka.plugability.plugin | ||
|
@@ -52,15 +51,19 @@ class DefaultExternalModuleLinkResolver(val context: DokkaContext) : ExternalMod | |
} | ||
|
||
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) | ||
val resolvedLinks = elps.mapNotNull { it.resolve(dri)?.removePrefix("file:") } | ||
val modulePath = context.configuration.outputDir.absolutePath | ||
val validLink = resolvedLinks.firstOrNull { | ||
val absolutePath = File(modulePath + it) | ||
absolutePath.isFile | ||
} ?: return null | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will it not work for the non-local external It is nice to fix the issue at least for cross-module links. Also, I think the fix should check links only if |
||
val modulePathParts = modulePath.split(File.separator) | ||
val contextPathParts = fileContext.absolutePath.split(File.separator) | ||
val commonPathElements = modulePathParts.zip(contextPathParts) | ||
.takeWhile { (a, b) -> a == b }.count() | ||
|
||
return (List(contextPath.size - commonPathElements - 1) { ".." } + modulePath.drop(commonPathElements)).joinToString( | ||
"/" | ||
) + absoluteLink.removePrefix("file:") | ||
return (List(contextPathParts.size - commonPathElements - 1) { ".." } + modulePathParts.drop(commonPathElements)) | ||
.joinToString("/") + validLink | ||
} | ||
|
||
override fun resolveLinkToModuleIndex(moduleName: String): String? = | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,7 +56,7 @@ class ResolveLinkCommandResolutionTest : MultiModuleAbstractTest() { | |
} | ||
} | ||
|
||
val contentFile = setup(link) | ||
val contentFile = setup(link, testedDri) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
val configuration = configuration() | ||
|
||
testFromData(configuration, useOutputLocationFromConfig = true) { | ||
|
@@ -95,10 +95,16 @@ class ResolveLinkCommandResolutionTest : MultiModuleAbstractTest() { | |
} | ||
} | ||
|
||
fun setup(content: String): File { | ||
private fun setup(content: String, resolutionTarget: DRI? = null): File { | ||
folder.create() | ||
val innerModule1 = folder.newFolder("module1") | ||
val innerModule2 = folder.newFolder("module2") | ||
if (resolutionTarget != null) { | ||
val resolvedFile = innerModule2 | ||
.resolve("${resolutionTarget.packageName}/-${resolutionTarget.classNames?.toLowerCase()}/index.html") | ||
resolvedFile.parentFile.mkdirs() | ||
resolvedFile.createNewFile() | ||
} | ||
val packageList = innerModule2.resolve("package-list") | ||
packageList.writeText(mockedPackageListForPackages(RecognizedLinkFormat.DokkaHtml, "package2")) | ||
val contentFile = innerModule1.resolve("index.html") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This checks assumes that dependee submodules have been already processed but that is upto process order
in
all-modules-page
plugin. For our project it lead to situation where same DRI was sometimes resolved and sometimes not.I workaround it by checking paths against Dokka's output in submodules since partial tasks will be done before multimodule starts but that is not clean solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. Thank you for noticing it. The workaround is correct, but it should not depend on particular paths like
build/dokka/htmlMultiModule
orbuild/dokka/htmlPartial/
. It would be great to usemodule.sourceOutputDirectory