diff options
author | Błażej Kardyś <bkardys@virtuslab.com> | 2020-05-19 19:02:58 +0200 |
---|---|---|
committer | Błażej Kardyś <bkardys@virtuslab.com> | 2020-05-20 13:31:00 +0200 |
commit | 6b85bb2ec2764a2c8b14717ef8e013a0f3c6e99f (patch) | |
tree | f29b4101c306d824f39787d817bd038fbf740779 | |
parent | ff450fedb3c8bdc318b55954bc37d93b30b9277c (diff) | |
download | dokka-6b85bb2ec2764a2c8b14717ef8e013a0f3c6e99f.tar.gz dokka-6b85bb2ec2764a2c8b14717ef8e013a0f3c6e99f.tar.bz2 dokka-6b85bb2ec2764a2c8b14717ef8e013a0f3c6e99f.zip |
Merging of platform dependent hints in sourceset tree
10 files changed, 63 insertions, 20 deletions
diff --git a/core/src/main/kotlin/configuration.kt b/core/src/main/kotlin/configuration.kt index 88924924..e74d10d7 100644 --- a/core/src/main/kotlin/configuration.kt +++ b/core/src/main/kotlin/configuration.kt @@ -40,6 +40,7 @@ interface DokkaConfiguration { val classpath: List<String> val sourceRoots: List<SourceRoot> val dependentSourceRoots: List<SourceRoot> + val dependentSourceSets: List<String> val samples: List<String> val includes: List<String> val includeNonPublic: Boolean diff --git a/core/src/main/kotlin/defaultConfiguration.kt b/core/src/main/kotlin/defaultConfiguration.kt index 08f70b45..9f36606a 100644 --- a/core/src/main/kotlin/defaultConfiguration.kt +++ b/core/src/main/kotlin/defaultConfiguration.kt @@ -20,6 +20,7 @@ data class PassConfigurationImpl ( override val classpath: List<String>, override val sourceRoots: List<SourceRootImpl>, override val dependentSourceRoots: List<SourceRootImpl>, + override val dependentSourceSets: List<String>, override val samples: List<String>, override val includes: List<String>, override val includeNonPublic: Boolean, diff --git a/core/src/main/kotlin/model/SourceSetData.kt b/core/src/main/kotlin/model/SourceSetData.kt index 8f67f272..964d5ca9 100644 --- a/core/src/main/kotlin/model/SourceSetData.kt +++ b/core/src/main/kotlin/model/SourceSetData.kt @@ -8,15 +8,19 @@ data class SourceSetData( val moduleName: String, val sourceSetName: String, val platform: Platform, - val sourceRoots: List<DokkaConfiguration.SourceRoot> = emptyList() + val sourceRoots: List<DokkaConfiguration.SourceRoot> = emptyList(), + val dependentSourceSets: List<String> = emptyList() ) class SourceSetCache { private val sourceSets = HashMap<String, SourceSetData>() + val allSourceSets: List<SourceSetData> + get() = sourceSets.values.toList() + fun getSourceSet(pass: DokkaConfiguration.PassConfiguration) = sourceSets.getOrPut("${pass.moduleName}/${pass.sourceSetName}", - { SourceSetData(pass.moduleName, pass.sourceSetName, pass.analysisPlatform, pass.sourceRoots) } + { SourceSetData(pass.moduleName, pass.sourceSetName, pass.analysisPlatform, pass.sourceRoots, pass.dependentSourceSets) } ) } diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt index dd293e54..64c03bc7 100644 --- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt @@ -6,7 +6,6 @@ import kotlinx.html.stream.createHTML import org.jetbrains.dokka.base.DokkaBase import org.jetbrains.dokka.base.renderers.DefaultRenderer import org.jetbrains.dokka.links.DRI -import org.jetbrains.dokka.model.DFunction import org.jetbrains.dokka.model.SourceSetData import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.plugability.DokkaContext @@ -19,6 +18,12 @@ open class HtmlRenderer( context: DokkaContext ) : DefaultRenderer<FlowContent>(context) { + private val sourceSetDependencyMap = with(context.sourceSetCache) { + allSourceSets.map { sourceSet -> + sourceSet to allSourceSets.filter { sourceSet.dependentSourceSets.contains(it.sourceSetName ) } + }.toMap() + } + private val pageList = mutableListOf<String>() override val preprocessors = context.plugin<DokkaBase>().query { htmlPreprocessors } + @@ -49,16 +54,26 @@ open class HtmlRenderer( ) { div("platform-hinted") { attributes["data-platform-hinted"] = "data-platform-hinted" - val contents = nodes.toList().mapIndexed { index, (sourceSet, elements) -> - sourceSet to createHTML(prettyPrint = false).div(classes = "content") { - if (index == 0) attributes["data-active"] = "" - attributes["data-togglable"] = sourceSet.sourceSetName + var counter = 0 + val contents = nodes.toList().map { (sourceSet, elements) -> + sourceSet to createHTML(prettyPrint = false).div { elements.forEach { buildContentNode(it, pageContext, setOf(sourceSet)) } + }.stripDiv() + }.groupBy(Pair<SourceSetData, String>::second, Pair<SourceSetData, String>::first).entries.flatMap { (html, sourceSets) -> + sourceSets.filterNot { + sourceSetDependencyMap[it].orEmpty().any { dependency -> sourceSets.contains(dependency) } + }.map { + it to createHTML(prettyPrint = false).div(classes = "content") { + if (counter++ == 0) attributes["data-active"] = "" + attributes["data-togglable"] = it.sourceSetName + unsafe { + +html + } + } } } - if (contents.size != 1) { div("platform-bookmarks-row") { attributes["data-toggle-list"] = "data-toggle-list" diff --git a/runners/cli/src/main/kotlin/cli/main.kt b/runners/cli/src/main/kotlin/cli/main.kt index f0d22aff..0818bd63 100644 --- a/runners/cli/src/main/kotlin/cli/main.kt +++ b/runners/cli/src/main/kotlin/cli/main.kt @@ -66,11 +66,12 @@ class Arguments(val parser: DokkaArgumentsParser) : DokkaConfiguration.PassConfi ) override val sourceSetName: String by parser.stringOption( - listOf("-module"), + listOf("-sourceSetName"), "Name of the source set", "main" ) + override val classpath: List<String> by parser.repeatableOption<String>( listOf("-classpath"), "Classpath for symbol resolution" @@ -82,10 +83,15 @@ class Arguments(val parser: DokkaArgumentsParser) : DokkaConfiguration.PassConfi ) { SourceRootImpl(it) } override val dependentSourceRoots: List<DokkaConfiguration.SourceRoot> by parser.repeatableOption( - listOf("-src"), - "Source file or directory (allows many paths separated by the system path separator)" + listOf("-dependentRoots"), + "Source roots of dependent source sets" ) { SourceRootImpl(it) } + override val dependentSourceSets: List<String> by parser.repeatableOption<String>( + listOf("-dependentSets"), + "Names of dependent source sets" + ) + override val samples: List<String> by parser.repeatableOption<String>( listOf("-sample"), "Source root for samples" diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ConfigurationExtractor.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ConfigurationExtractor.kt index ca7e4f1e..c69c6f67 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ConfigurationExtractor.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ConfigurationExtractor.kt @@ -47,6 +47,7 @@ class ConfigurationExtractor(private val project: Project) { classpath, sourceSet.kotlin.sourceDirectories.filter { it.exists() }.toList(), dependencies, + sourceSet.dependsOn.map { it.name }, compilation.target.targetName ) } @@ -54,7 +55,7 @@ class ConfigurationExtractor(private val project: Project) { fun extractFromJavaPlugin(): PlatformData? = project.convention.findPlugin(JavaPluginConvention::class.java) ?.run { sourceSets.findByName(SourceSet.MAIN_SOURCE_SET_NAME)?.allSource?.srcDirs } - ?.let { PlatformData(null, emptyList(), it.toList(), emptyList(), "") } + ?.let { PlatformData(null, emptyList(), it.toList(), emptyList(), emptyList(), "") } fun extractFromKotlinTasks(passName: String, kotlinTasks: List<Task>): PlatformData? = try { @@ -84,7 +85,8 @@ class ConfigurationExtractor(private val project: Project) { task.name, getClasspath(it), getSourceSet(it), - getDependentSourceSet(it), + getDependentSourceSetRoots(it), + getDependentSourceSet(it).map { it.name }, it?.platformType?.toString() ?: "" ) } @@ -126,7 +128,7 @@ class ConfigurationExtractor(private val project: Project) { } classpath.addAll(project.files(allClasspath).toList()) - return PlatformData(null, classpath, allSourceRoots.toList(), emptyList(), "") + return PlatformData(null, classpath, allSourceRoots.toList(), emptyList(), emptyList(),"") } private fun getSourceSet(target: KotlinTarget, variantName: String? = null): List<File> = @@ -151,11 +153,12 @@ class ConfigurationExtractor(private val project: Project) { ?.filter { it.exists() } .orEmpty() - private fun getDependentSourceSet(compilation: KotlinCompilation<*>?): List<File> = compilation - ?.let { it.allKotlinSourceSets - it.kotlinSourceSets } - ?.flatMap { it.kotlin.sourceDirectories } - ?.filter { it.exists() } - .orEmpty() + private fun getDependentSourceSet(compilation: KotlinCompilation<*>?) = compilation + ?.let { it.allKotlinSourceSets - it.kotlinSourceSets }.orEmpty() + + private fun getDependentSourceSetRoots(compilation: KotlinCompilation<*>?): List<File> = + getDependentSourceSet(compilation)?.flatMap { it.kotlin.sourceDirectories } + .filter { it.exists() } private fun getClasspath(compilation: KotlinCompilation<*>?): List<File> = compilation ?.compileDependencyFiles @@ -212,6 +215,7 @@ class ConfigurationExtractor(private val project: Project) { val classpath: List<File>, val sourceRoots: List<File>, val dependentSourceRoots: List<File>, + val dependentSourceSets: List<String>, val platform: String ) : Serializable }
\ No newline at end of file diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt index 109e7838..d72ec0f9 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt @@ -268,8 +268,10 @@ open class DokkaTask : DefaultTask(), Configurable { autoConfig: PlatformData ) = userConfig.copy().apply { + sourceSetName = autoConfig.name ?: "" sourceRoots.addAll(userConfig.sourceRoots.union(autoConfig.sourceRoots.toSourceRoots()).distinct()) dependentSourceRoots.addAll(userConfig.dependentSourceRoots.union(autoConfig.dependentSourceRoots.toSourceRoots()).distinct()) + dependentSourceSets.addAll(userConfig.dependentSourceSets.union(autoConfig.dependentSourceSets).distinct()) classpath = userConfig.classpath.union(autoConfig.classpath.map { it.absolutePath }).distinct() if (userConfig.platform == null && autoConfig.platform != "") platform = autoConfig.platform diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/configurationImplementations.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/configurationImplementations.kt index 9719686e..5c300cc3 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/configurationImplementations.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/configurationImplementations.kt @@ -30,6 +30,7 @@ open class GradlePassConfigurationImpl(@Transient val name: String = ""): PassCo @Input override var sourceSetName: String = "" @Input override var sourceRoots: MutableList<SourceRoot> = mutableListOf() @Input override var dependentSourceRoots: MutableList<SourceRoot> = mutableListOf() + @Input override var dependentSourceSets: MutableList<String> = mutableListOf() @Input override var samples: List<String> = emptyList() @Input override var includes: List<String> = emptyList() @Input override var includeNonPublic: Boolean = false diff --git a/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt b/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt index ac22eb57..e00e5f88 100644 --- a/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt +++ b/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt @@ -93,6 +93,12 @@ abstract class AbstractDokkaMojo : AbstractMojo() { var sourceRoots: List<SourceRoot> = emptyList() @Parameter + var dependentSourceRoots: List<SourceRoot> = emptyList() + + @Parameter + var dependentSourceSets: List<String> = emptyList() + + @Parameter var samples: List<String> = emptyList() @Parameter @@ -206,7 +212,8 @@ abstract class AbstractDokkaMojo : AbstractMojo() { classpath = classpath, sourceSetName = sourceSetName, sourceRoots = sourceDirectories.map { SourceRootImpl(it) }, - dependentSourceRoots = sourceRoots.map { SourceRootImpl(path = it.path) }, + dependentSourceRoots = dependentSourceRoots.map { SourceRootImpl(path = it.path) }, + dependentSourceSets = dependentSourceSets, samples = samples, includes = includes, collectInheritedExtensionsFromLibraries = collectInheritedExtensionsFromLibraries, // TODO: Should we implement this? diff --git a/testApi/src/main/kotlin/testApi/testRunner/TestRunner.kt b/testApi/src/main/kotlin/testApi/testRunner/TestRunner.kt index 43d99dad..6c323ea2 100644 --- a/testApi/src/main/kotlin/testApi/testRunner/TestRunner.kt +++ b/testApi/src/main/kotlin/testApi/testRunner/TestRunner.kt @@ -171,6 +171,7 @@ abstract class AbstractCoreTest { var classpath: List<String> = emptyList(), var sourceRoots: List<String> = emptyList(), var dependentSourceRoots: List<String> = emptyList(), + var dependentSourceSets: List<String> = emptyList(), var samples: List<String> = emptyList(), var includes: List<String> = emptyList(), var includeNonPublic: Boolean = true, @@ -198,6 +199,7 @@ abstract class AbstractCoreTest { classpath = classpath, sourceRoots = sourceRoots.map { SourceRootImpl(it) }, dependentSourceRoots = dependentSourceRoots.map { SourceRootImpl(it) }, + dependentSourceSets = dependentSourceSets, samples = samples, includes = includes, includeNonPublic = includeNonPublic, |