diff options
author | sebastian.sellmair <sebastian.sellmair@jetbrains.com> | 2020-08-28 11:28:54 +0200 |
---|---|---|
committer | Sebastian Sellmair <34319766+sellmair@users.noreply.github.com> | 2020-08-31 15:10:04 +0200 |
commit | 02ccae10e3f717c330dae5d87b49a0e72f798905 (patch) | |
tree | 4c63d6039fdc5a20c065724e672adbc5c6a3a0e5 /runners/gradle-plugin | |
parent | 8cd28416817dfd7d28bb66b28e849d97cc09012b (diff) | |
download | dokka-02ccae10e3f717c330dae5d87b49a0e72f798905.tar.gz dokka-02ccae10e3f717c330dae5d87b49a0e72f798905.tar.bz2 dokka-02ccae10e3f717c330dae5d87b49a0e72f798905.zip |
Re-use includes form child tasks for all modules page generation
Diffstat (limited to 'runners/gradle-plugin')
2 files changed, 91 insertions, 81 deletions
diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleTask.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleTask.kt index 82e2148f..92560c94 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleTask.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleTask.kt @@ -3,8 +3,6 @@ package org.jetbrains.dokka.gradle import org.gradle.api.internal.tasks.TaskDependencyInternal import org.gradle.api.provider.Property import org.gradle.api.tasks.* -import org.jetbrains.dokka.DokkaConfiguration -import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet import org.jetbrains.dokka.DokkaConfigurationImpl import org.jetbrains.dokka.DokkaModuleDescriptionImpl import org.jetbrains.dokka.DokkaMultimoduleBootstrapImpl @@ -14,26 +12,15 @@ import java.io.File @Deprecated("Use 'DokkaMultimoduleTask' instead", ReplaceWith("DokkaMultimoduleTask")) typealias DokkaMultimoduleTask = DokkaMultiModuleTask +private typealias TaskPath = String abstract class DokkaMultiModuleTask : AbstractDokkaParentTask(DokkaMultimoduleBootstrapImpl::class) { - /** - * Name of the file containing all necessary module information. - * This file has to be placed inside the subproject root directory. - */ - @Internal - val documentationFileName: Property<String> = project.objects.safeProperty<String>() - .safeConvention("README.md") - @Internal val fileLayout: Property<DokkaMultiModuleFileLayout> = project.objects.safeProperty<DokkaMultiModuleFileLayout>() .safeConvention(DokkaMultiModuleFileLayout.CompactInParent) @get:InputFiles - internal val childDocumentationFiles: Iterable<File> - get() = childDokkaTasks.map { task -> task.project.projectDir.resolve(documentationFileName.getSafe()) } - - @get:InputFiles internal val sourceChildOutputDirectories: Iterable<File> get() = childDokkaTasks.map { task -> task.outputDirectory.getSafe() } @@ -41,6 +28,12 @@ abstract class DokkaMultiModuleTask : AbstractDokkaParentTask(DokkaMultimoduleBo internal val targetChildOutputDirectories: Iterable<File> get() = childDokkaTasks.map { task -> targetChildOutputDirectory(task) } + @get:Input + internal val childDokkaTaskIncludes: Map<TaskPath, Set<File>> + get() = childDokkaTasks.filterIsInstance<DokkaTask>().associate { task -> + task.path to task.dokkaSourceSets.flatMap { it.includes }.toSet() + } + @Internal override fun getTaskDependencies(): TaskDependencyInternal = super.getTaskDependencies() + childDokkaTasks @@ -62,9 +55,9 @@ abstract class DokkaMultiModuleTask : AbstractDokkaParentTask(DokkaMultimoduleBo pluginsClasspath = plugins.resolve().toList(), modules = childDokkaTasks.map { dokkaTask -> DokkaModuleDescriptionImpl( - name = dokkaTask.project.name, - path = targetChildOutputDirectory(dokkaTask).relativeTo(outputDirectory.getSafe()), - docFile = dokkaTask.project.projectDir.resolve(documentationFileName.get()).absoluteFile + name = dokkaTask.moduleName.getSafe(), + relativePathToOutputDirectory = targetChildOutputDirectory(dokkaTask).relativeTo(outputDirectory.getSafe()), + includes = childDokkaTaskIncludes[dokkaTask.path].orEmpty() ) } ) diff --git a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleTaskTest.kt b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleTaskTest.kt index 5b9413c8..bea80f1e 100644 --- a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleTaskTest.kt +++ b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleTaskTest.kt @@ -2,8 +2,7 @@ package org.jetbrains.dokka.gradle -import org.gradle.kotlin.dsl.create -import org.gradle.kotlin.dsl.withType +import org.gradle.kotlin.dsl.* import org.gradle.testfixtures.ProjectBuilder import org.jetbrains.dokka.DokkaConfigurationImpl import org.jetbrains.dokka.DokkaException @@ -25,10 +24,14 @@ class DokkaMultiModuleTaskTest { .withProjectDir(rootProject.projectDir.resolve("child")) .withParent(rootProject).build() + private val childDokkaTask = childProject.tasks.create<DokkaTask>("childDokkaTask") + + private val multiModuleTask = rootProject.tasks.create<DokkaMultiModuleTask>("multiModuleTask").apply { + addChildTask(childDokkaTask) + } + init { rootProject.allprojects { project -> - project.plugins.apply("org.jetbrains.kotlin.jvm") - project.plugins.apply("org.jetbrains.dokka") project.tasks.withType<AbstractDokkaTask>().configureEach { task -> task.plugins.withDependencies { dependencies -> dependencies.clear() } } @@ -50,70 +53,66 @@ class DokkaMultiModuleTaskTest { @Test fun buildDokkaConfiguration() { - childProject.tasks.withType<DokkaTask>().configureEach { task -> - task.outputDirectory by task.project.buildDir.resolve("output") + val include1 = childDokkaTask.project.file("include1.md") + val include2 = childDokkaTask.project.file("include2.md") + + childDokkaTask.apply { + dokkaSourceSets.create("main") + dokkaSourceSets.create("test") + dokkaSourceSets.configureEach { + it.includes.from(include1, include2) + } } - val multimoduleTasks = rootProject.tasks.withType<DokkaMultiModuleTask>() - assertTrue(multimoduleTasks.isNotEmpty(), "Expected at least one multimodule task") - - multimoduleTasks.configureEach { task -> - task.moduleName by "custom Module Name" - task.documentationFileName by "customDocumentationFileName.md" - task.outputDirectory by task.project.buildDir.resolve("customOutputDirectory") - task.cacheRoot by File("customCacheRoot") - task.pluginsConfiguration.put("pluginA", "configA") - task.failOnWarning by true - task.offlineMode by true + multiModuleTask.apply { + moduleName by "custom Module Name" + outputDirectory by project.buildDir.resolve("customOutputDirectory") + cacheRoot by File("customCacheRoot") + pluginsConfiguration.put("pluginA", "configA") + failOnWarning by true + offlineMode by true } - multimoduleTasks.forEach { task -> - val dokkaConfiguration = task.buildDokkaConfiguration() - assertEquals( - DokkaConfigurationImpl( - moduleName = "custom Module Name", - outputDir = task.project.buildDir.resolve("customOutputDirectory"), - cacheRoot = File("customCacheRoot"), - pluginsConfiguration = mapOf("pluginA" to "configA"), - pluginsClasspath = emptyList(), - failOnWarning = true, - offlineMode = true, - modules = listOf( - DokkaModuleDescriptionImpl( - name = "child", - path = File("child"), - docFile = childProject.projectDir.resolve("customDocumentationFileName.md") - ) + val dokkaConfiguration = multiModuleTask.buildDokkaConfiguration() + assertEquals( + DokkaConfigurationImpl( + moduleName = "custom Module Name", + outputDir = multiModuleTask.project.buildDir.resolve("customOutputDirectory"), + cacheRoot = File("customCacheRoot"), + pluginsConfiguration = mapOf("pluginA" to "configA"), + pluginsClasspath = emptyList(), + failOnWarning = true, + offlineMode = true, + modules = listOf( + DokkaModuleDescriptionImpl( + name = "child", + relativePathToOutputDirectory = File("child"), + includes = setOf(include1, include2) ) - ), - dokkaConfiguration - ) - } + ) + ), + dokkaConfiguration + ) } @Test fun `setting dokkaTaskNames declares proper task dependencies`() { - val multimoduleTasks = rootProject.tasks.withType<DokkaMultiModuleTask>() - assertTrue(multimoduleTasks.isNotEmpty(), "Expected at least one multimodule task") + val dependenciesInitial = multiModuleTask.taskDependencies.getDependencies(multiModuleTask).toSet() + assertEquals(1, dependenciesInitial.size, "Expected one dependency") + val dependency = dependenciesInitial.single() - multimoduleTasks.toList().forEach { task -> - val dependencies = task.taskDependencies.getDependencies(task).toSet() - assertEquals(1, dependencies.size, "Expected one dependency") - val dependency = dependencies.single() + assertTrue(dependency is DokkaTask, "Expected dependency to be of Type ${DokkaTask::class.simpleName}") + assertEquals(childProject, dependency.project, "Expected dependency from child project") - assertTrue(dependency is DokkaTask, "Expected dependency to be of Type ${DokkaTask::class.simpleName}") - assertEquals(childProject, dependency.project, "Expected dependency from child project") - } val customDokkaTask = childProject.tasks.create<DokkaTask>("customDokkaTask") - multimoduleTasks.toList().forEach { task -> - task.addSubprojectChildTasks("customDokkaTask") - val dependencies = task.taskDependencies.getDependencies(task).toSet() + multiModuleTask.addSubprojectChildTasks("customDokkaTask") + val dependenciesAfter = multiModuleTask.taskDependencies.getDependencies(multiModuleTask).toSet() + + assertEquals(2, dependenciesAfter.size, "Expected two dependencies") + assertTrue(customDokkaTask in dependenciesAfter, "Expected 'customDokkaTask' in dependencies") - assertEquals(2, dependencies.size, "Expected two dependencies") - assertTrue(customDokkaTask in dependencies, "Expected 'customDokkaTask' in dependencies") - } } @Test @@ -125,19 +124,38 @@ class DokkaMultiModuleTaskTest { } @Test - fun childDocumentationFiles() { - val parent = ProjectBuilder.builder().build() - val child = ProjectBuilder.builder().withName("child").withParent(parent).build() - - val parentTask = parent.tasks.create<DokkaMultiModuleTask>("parent") - val childTask = child.tasks.create<DokkaTask>("child") + fun childDokkaTaskIncludes() { + val childDokkaTaskInclude1 = childProject.file("include1") + val childDokkaTaskInclude2 = childProject.file("include2") + val childDokkaTaskInclude3 = childProject.file("include3") + + childDokkaTask.apply { + dokkaSourceSets.create("main") { + it.includes.from(childDokkaTaskInclude1, childDokkaTaskInclude2) + } + dokkaSourceSets.create("main2") { + it.includes.from(childDokkaTaskInclude3) + } + } - parentTask.addChildTask(childTask) - parentTask.documentationFileName by "module.txt" + val secondChildDokkaTaskInclude = childProject.file("include4") + val secondChildDokkaTask = childProject.tasks.create<DokkaTask>("secondChildDokkaTask") { + dokkaSourceSets.create("main") { + it.includes.from(secondChildDokkaTaskInclude) + } + } + multiModuleTask.addChildTask(secondChildDokkaTask) assertEquals( - listOf(parent.file("child/module.txt")), parentTask.childDocumentationFiles, - "Expected child documentation file being present" + mapOf( + ":child:childDokkaTask" to setOf( + childDokkaTaskInclude1, + childDokkaTaskInclude2, + childDokkaTaskInclude3 + ), + ":child:secondChildDokkaTask" to setOf(secondChildDokkaTaskInclude) + ), + multiModuleTask.childDokkaTaskIncludes ) } @@ -177,6 +195,5 @@ class DokkaMultiModuleTaskTest { listOf(parent.project.buildDir.resolve("child")), parentTask.targetChildOutputDirectories, "Expected child target output directory being present" ) - } } |