diff options
author | Błażej Kardyś <bkardys@virtuslab.com> | 2020-09-10 16:54:16 +0200 |
---|---|---|
committer | Paweł Marks <Kordyjan@users.noreply.github.com> | 2020-09-14 11:56:05 +0200 |
commit | 30d6e6c3d82993e76c3942fc9faf102f36736673 (patch) | |
tree | e3d62f9f9a1aa731f9b35ae5bd384f4dfa9e875a /plugins/javadoc | |
parent | 066e810bd5fc6fc5bab8e897fd3ec9032b76ec3d (diff) | |
download | dokka-30d6e6c3d82993e76c3942fc9faf102f36736673.tar.gz dokka-30d6e6c3d82993e76c3942fc9faf102f36736673.tar.bz2 dokka-30d6e6c3d82993e76c3942fc9faf102f36736673.zip |
Adding javadoc source set based filtering
Diffstat (limited to 'plugins/javadoc')
4 files changed, 121 insertions, 10 deletions
diff --git a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/JavadocPageCreator.kt b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/JavadocPageCreator.kt index 4e5f2689..f104beb7 100644 --- a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/JavadocPageCreator.kt +++ b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/JavadocPageCreator.kt @@ -1,12 +1,10 @@ package org.jetbrains.dokka.javadoc -import org.jetbrains.dokka.javadoc.pages.* import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet -import org.jetbrains.dokka.Platform import org.jetbrains.dokka.base.signatures.SignatureProvider -import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter import org.jetbrains.dokka.base.transformers.pages.comments.DocTagToContentConverter import org.jetbrains.dokka.base.translators.documentables.briefFromContentNodes +import org.jetbrains.dokka.javadoc.pages.* import org.jetbrains.dokka.model.* import org.jetbrains.dokka.model.doc.Description import org.jetbrains.dokka.model.doc.Index @@ -82,7 +80,7 @@ open class JavadocPageCreator( JavadocContentGroup( setOf(m.dri), JavadocContentKind.OverviewSummary, - m.jvmSourceSets.toDisplaySourceSets() + m.sourceSets.toDisplaySourceSets() ) { title(m.name, m.brief(), documentationVersion, dri = setOf(m.dri), kind = ContentKind.Main) leafList(setOf(m.dri), @@ -101,7 +99,7 @@ open class JavadocPageCreator( JavadocContentGroup( setOf(p.dri), JavadocContentKind.PackageSummary, - p.jvmSourceSets.toDisplaySourceSets() + p.sourceSets.toDisplaySourceSets() ) { title("Package ${p.name}", p.brief(), dri = setOf(p.dri), kind = ContentKind.Packages) fun allClasslikes(c: DClasslike): List<DClasslike> = c.classlikes.flatMap { allClasslikes(it) } + c @@ -133,7 +131,7 @@ open class JavadocPageCreator( JavadocContentGroup( setOf(c.dri), JavadocContentKind.Class, - c.jvmSourceSets.toDisplaySourceSets() + c.sourceSets.toDisplaySourceSets() ) { title( c.name.orEmpty(), @@ -169,11 +167,8 @@ open class JavadocPageCreator( ) } - private val Documentable.jvmSourceSets - get() = sourceSets.filter { it.analysisPlatform == Platform.jvm } - private val Documentable.highestJvmSourceSet - get() = jvmSourceSets.let { sources -> + get() = sourceSets.let { sources -> sources.firstOrNull { it != expectPresentInSet } ?: sources.firstOrNull() } diff --git a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/JavadocPlugin.kt b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/JavadocPlugin.kt index 50eb319d..031d8695 100644 --- a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/JavadocPlugin.kt +++ b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/JavadocPlugin.kt @@ -9,6 +9,7 @@ import org.jetbrains.dokka.base.renderers.PackageListCreator import org.jetbrains.dokka.base.renderers.RootCreator import org.jetbrains.dokka.base.resolvers.shared.RecognizedLinkFormat import org.jetbrains.dokka.javadoc.pages.* +import org.jetbrains.dokka.javadoc.transformers.documentables.JavadocDocumentableJVMSourceSetFilter import org.jetbrains.dokka.kotlinAsJava.KotlinAsJavaPlugin import org.jetbrains.dokka.plugability.DokkaPlugin import org.jetbrains.dokka.plugability.querySingle @@ -37,6 +38,10 @@ class JavadocPlugin : DokkaPlugin() { } override dokkaBasePlugin.documentableToPageTranslator } + val documentableSourceSetFilter by extending { + CoreExtensions.preMergeDocumentableTransformer providing { context -> JavadocDocumentableJVMSourceSetFilter(context) } + } + val javadocLocationProviderFactory by extending { dokkaBasePlugin.locationProviderFactory providing { context -> JavadocLocationProviderFactory(context) diff --git a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/transformers/documentables/JavadocDocumentableJVMSourceSetFilter.kt b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/transformers/documentables/JavadocDocumentableJVMSourceSetFilter.kt new file mode 100644 index 00000000..dac6504e --- /dev/null +++ b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/transformers/documentables/JavadocDocumentableJVMSourceSetFilter.kt @@ -0,0 +1,21 @@ +package org.jetbrains.dokka.javadoc.transformers.documentables + +import org.jetbrains.dokka.DokkaConfiguration +import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.model.DModule +import org.jetbrains.dokka.plugability.DokkaContext +import org.jetbrains.dokka.transformers.documentation.PreMergeDocumentableTransformer + +class JavadocDocumentableJVMSourceSetFilter(val context: DokkaContext) : PreMergeDocumentableTransformer { + + private val allowedSourceSets = context.configuration.sourceSets.filter { it.analysisPlatform == Platform.jvm } + .flatMap { it.getAllDependentSourceSets() }.distinct() + + private fun DokkaConfiguration.DokkaSourceSet.getAllDependentSourceSets(): List<DokkaConfiguration.DokkaSourceSet> = + dependentSourceSets.flatMap { setId -> + context.configuration.sourceSets.find { it.sourceSetID == setId }?.getAllDependentSourceSets().orEmpty() + } + this + + override fun invoke(modules: List<DModule>): List<DModule> = + modules.filter { module -> allowedSourceSets.containsAll(module.sourceSets) } +}
\ No newline at end of file diff --git a/plugins/javadoc/src/test/kotlin/org/jetbrains/dokka/javadoc/transformers/documentables/JavadocDocumentableJVMSourceSetFilterTest.kt b/plugins/javadoc/src/test/kotlin/org/jetbrains/dokka/javadoc/transformers/documentables/JavadocDocumentableJVMSourceSetFilterTest.kt new file mode 100644 index 00000000..ca6b7a3d --- /dev/null +++ b/plugins/javadoc/src/test/kotlin/org/jetbrains/dokka/javadoc/transformers/documentables/JavadocDocumentableJVMSourceSetFilterTest.kt @@ -0,0 +1,90 @@ +package org.jetbrains.dokka.javadoc.transformers.documentables + +import org.jetbrains.dokka.DokkaSourceSetID +import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest +import org.junit.jupiter.api.Test +import kotlin.test.assertEquals + +class JavadocDocumentableJVMSourceSetFilterTest: AbstractCoreTest() { + + private val config = dokkaConfiguration { + format = "javadoc" + sourceSets { + sourceSet { + sourceRoots = listOf("jvmSrc/") + analysisPlatform = "jvm" + name = "jvm" + dependentSourceSets = setOf(DokkaSourceSetID("root", "common")) + } + sourceSet { + sourceRoots = listOf("jsSrc/") + analysisPlatform = "js" + name = "js" + } + sourceSet { + sourceRoots = listOf("commonSrc/") + analysisPlatform = "common" + name = "common" + } + sourceSet { + sourceRoots = listOf("otherCommonSrc/") + analysisPlatform = "common" + name = "otherCommon" + } + } + } + private val query = """ + /jvmSrc/source0.kt + package package0 + /** + * Documentation for ClassA + */ + class ClassA { + fun a() {} + fun b() {} + fun c() {} + } + + /jsSrc/source1.kt + package package1 + /** + * Documentation for ClassB + */ + class ClassB { + fun d() {} + fun e() {} + fun f() {} + } + + /commonSrc/source2.kt + package package1 + /** + * Documentation for ClassC + */ + class ClassC { + fun g() {} + fun h() {} + fun j() {} + } + + /otherCommonSrc/source3.kt + package package1 + /** + * Documentation for ClassD + */ + class ClassD { + fun l() {} + fun m() {} + fun n() {} + } + """.trimIndent() + + @Test + fun `non-jvm and not dependent common source sets are ommited`() { + testInline(query, config) { + documentablesFirstTransformationStep = { modules -> + assertEquals(4, modules.size) + } + } + } +}
\ No newline at end of file |