Skip to content

Commit

Permalink
Support for providing sourceRoots as relative paths
Browse files Browse the repository at this point in the history
  • Loading branch information
whyoleg committed Nov 21, 2023
1 parent 6fbc222 commit 57aa90c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -374,4 +374,42 @@ class CliIntegrationTest : AbstractCliIntegrationTest() {

assertTrue(dokkaOutputDir.isDirectory, "Missing dokka output directory")
}

@Test
fun `relative paths in configuraiton should work`() {
val resourcePath =
javaClass.getResource("/my-file.json")?.toURI() ?: throw IllegalStateException("No JSON found!")
val jsonPath = File(resourcePath)

val dokkaOutputDir = File(projectDir, "output-relative")
assertTrue(dokkaOutputDir.mkdirs())
jsonPath.writeText(
jsonBuilder(
outputPath = dokkaOutputDir.invariantSeparatorsPath,
pluginsClasspath = basePluginJarFile.absoluteFile.invariantSeparatorsPath,
projectPath = "src", // relative path
)
)

ProcessBuilder(
"java", "-jar", cliJarFile.absolutePath, jsonPath.absolutePath
).directory(projectDir).redirectErrorStream(true).start().also { process ->
val result = process.awaitProcessResult()
assertEquals(0, result.exitCode, "Expected exitCode 0 (Success)")
}

assertTrue(dokkaOutputDir.isDirectory, "Missing dokka output directory")

val htmlFiles = dokkaOutputDir.allHtmlFiles().map { it.relativeTo(dokkaOutputDir).path }.toList()

// check that both Kotlin and Java sources are processed

// kotlin:
assertContains(htmlFiles, "-dokka -example/it.basic/index.html")
assertContains(htmlFiles, "-dokka -example/it.basic/-public-class/public-documented-function.html")

// java:
assertContains(htmlFiles, "-dokka -example/it.basic.java/index.html")
assertContains(htmlFiles, "-dokka -example/it.basic.java/-sample-java-class/public-documented-function.html")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,14 @@ private class DokkaDescriptorVisitor(
private val syntheticDocProvider = SyntheticDescriptorDocumentationProvider(kDocFinder, sourceSet)

private fun Collection<DeclarationDescriptor>.filterDescriptorsInSourceSet() = filter {
it.toSourceElement.containingFile.toString().let { path ->
path.isNotBlank() && sourceSet.sourceRoots.any { root ->
Paths.get(path).startsWith(root.toPath())
val pathString = it.toSourceElement.containingFile.toString()
when {
pathString.isBlank() -> false
else -> {
val absolutePath = Paths.get(pathString).toAbsolutePath()
sourceSet.sourceRoots.any { root ->
absolutePath.startsWith(root.toPath().toAbsolutePath())
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,16 @@ internal class DokkaSymbolVisitor(
get() = (psi as? KtModifierListOwner)?.hasExpectModifier() == true

private fun <T : KtSymbol> Collection<T>.filterSymbolsInSourceSet() = filter {
it.psi?.containingFile?.virtualFile?.path?.let { path ->
path.isNotBlank() && sourceSet.sourceRoots.any { root ->
Paths.get(path).startsWith(root.toPath())
val pathString = it.psi?.containingFile?.virtualFile?.path
when {
pathString.isNullOrBlank() -> false
else -> {
val absolutePath = Paths.get(pathString).toAbsolutePath()
sourceSet.sourceRoots.any { root ->
absolutePath.startsWith(root.toPath().toAbsolutePath())
}
}
} == true
}
}

fun visitModule(): DModule {
Expand Down

0 comments on commit 57aa90c

Please sign in to comment.