From 8c0344e682fc4ba0e44fc740269c7ba308c47c35 Mon Sep 17 00:00:00 2001 From: aSemy <897017+aSemy@users.noreply.github.com> Date: Tue, 21 Feb 2023 18:51:11 +0100 Subject: Move Gradle plugin tasks into a separate directory (#2705) --- .../dokka/gradle/DokkaMultiModuleTaskTest.kt | 230 --------------------- .../org/jetbrains/dokka/gradle/DokkaTaskTest.kt | 38 ---- .../dokka/gradle/tasks/DokkaMultiModuleTaskTest.kt | 230 +++++++++++++++++++++ .../jetbrains/dokka/gradle/tasks/DokkaTaskTest.kt | 40 ++++ 4 files changed, 270 insertions(+), 268 deletions(-) delete mode 100644 runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleTaskTest.kt delete mode 100644 runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaTaskTest.kt create mode 100644 runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/tasks/DokkaMultiModuleTaskTest.kt create mode 100644 runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/tasks/DokkaTaskTest.kt (limited to 'runners/gradle-plugin/src/test/kotlin/org/jetbrains') 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 deleted file mode 100644 index c45d5da8..00000000 --- a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleTaskTest.kt +++ /dev/null @@ -1,230 +0,0 @@ -@file:Suppress("UnstableApiUsage", "DEPRECATION") - -package org.jetbrains.dokka.gradle - -import org.gradle.kotlin.dsl.create -import org.gradle.kotlin.dsl.withType -import org.gradle.testfixtures.ProjectBuilder -import org.jetbrains.dokka.* -import java.io.File -import kotlin.test.* - -class DokkaMultiModuleTaskTest { - - private val rootProject = ProjectBuilder.builder() - .withName("root") - .build() - - private val childProject = ProjectBuilder.builder() - .withName("child") - .withProjectDir(rootProject.projectDir.resolve("child")) - .withParent(rootProject).build() - - private val childDokkaTask = childProject.tasks.create("childDokkaTask") - - private val multiModuleTask = rootProject.tasks.create("multiModuleTask").apply { - addChildTask(childDokkaTask) - } - - init { - rootProject.allprojects { - tasks.withType().configureEach { - plugins.withDependencies { clear() } - } - } - } - - @Test - fun `child project is withing root project`() { - assertEquals( - rootProject.projectDir, childProject.projectDir.parentFile, - "Expected child project being inside the root project" - ) - - assertEquals( - childProject.projectDir.name, "child", - "Expected folder of child project to be called 'child'" - ) - } - - @Test - fun buildDokkaConfiguration() { - val include1 = childDokkaTask.project.file("include1.md") - val include2 = childDokkaTask.project.file("include2.md") - val topLevelInclude = multiModuleTask.project.file("README.md") - - childDokkaTask.apply { - dokkaSourceSets.create("main") - dokkaSourceSets.create("test") - dokkaSourceSets.configureEach { - includes.from(include1, include2) - } - } - - multiModuleTask.apply { - moduleVersion.set("1.5.0") - moduleName.set("custom Module Name") - outputDirectory.set(project.buildDir.resolve("customOutputDirectory")) - cacheRoot.set(File("customCacheRoot")) - pluginsConfiguration.add( - PluginConfigurationImpl( - "pluginA", - DokkaConfiguration.SerializationFormat.JSON, - """ { "key" : "value2" } """ - ) - ) - failOnWarning.set(true) - offlineMode.set(true) - includes.from(listOf(topLevelInclude)) - } - - val dokkaConfiguration = multiModuleTask.buildDokkaConfiguration() - assertEquals( - DokkaConfigurationImpl( - moduleName = "custom Module Name", - moduleVersion = "1.5.0", - outputDir = multiModuleTask.project.buildDir.resolve("customOutputDirectory"), - cacheRoot = File("customCacheRoot"), - pluginsConfiguration = mutableListOf( - PluginConfigurationImpl( - "pluginA", - DokkaConfiguration.SerializationFormat.JSON, - """ { "key" : "value2" } """ - ) - ), - pluginsClasspath = emptyList(), - failOnWarning = true, - offlineMode = true, - includes = setOf(topLevelInclude), - modules = listOf( - DokkaModuleDescriptionImpl( - name = "child", - relativePathToOutputDirectory = File("child"), - includes = setOf(include1, include2), - sourceOutputDirectory = childDokkaTask.outputDirectory.getSafe() - ) - ) - ), - dokkaConfiguration - ) - } - - @Test - fun `multimodule task should not include unspecified version`() { - childDokkaTask.apply { - dokkaSourceSets.create("main") - dokkaSourceSets.create("test") - } - - multiModuleTask.apply { - moduleVersion.set("unspecified") - } - - val dokkaConfiguration = multiModuleTask.buildDokkaConfiguration() - assertNull(dokkaConfiguration.moduleVersion) - } - - @Test - fun `setting dokkaTaskNames declares proper task dependencies`() { - val dependenciesInitial = multiModuleTask.taskDependencies.getDependencies(multiModuleTask).toSet() - assertEquals(1, dependenciesInitial.size, "Expected one dependency") - val dependency = dependenciesInitial.single() - - assertTrue( - dependency is DokkaTaskPartial, - "Expected dependency to be of Type ${DokkaTaskPartial::class.simpleName}" - ) - assertEquals(childProject, dependency.project, "Expected dependency from child project") - - - val customDokkaTask = childProject.tasks.create("customDokkaTask") - - 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") - - } - - @Test - fun `multimodule task with no child tasks throws DokkaException`() { - val project = ProjectBuilder.builder().build() - val multimodule = project.tasks.create("multimodule") - project.configurations.configureEach { withDependencies { clear() } } - assertFailsWith { multimodule.generateDocumentation() } - } - - @Test - fun childDokkaTaskIncludes() { - val childDokkaTaskInclude1 = childProject.file("include1") - val childDokkaTaskInclude2 = childProject.file("include2") - val childDokkaTaskInclude3 = childProject.file("include3") - - childDokkaTask.apply { - dokkaSourceSets.create("main") { - includes.from(childDokkaTaskInclude1, childDokkaTaskInclude2) - } - dokkaSourceSets.create("main2") { - includes.from(childDokkaTaskInclude3) - } - } - - val secondChildDokkaTaskInclude = childProject.file("include4") - val secondChildDokkaTask = childProject.tasks.create("secondChildDokkaTask") { - dokkaSourceSets.create("main") { - includes.from(secondChildDokkaTaskInclude) - } - } - multiModuleTask.addChildTask(secondChildDokkaTask) - - assertEquals( - mapOf( - ":child:childDokkaTask" to setOf( - childDokkaTaskInclude1, - childDokkaTaskInclude2, - childDokkaTaskInclude3 - ), - ":child:secondChildDokkaTask" to setOf(secondChildDokkaTaskInclude) - ), - multiModuleTask.childDokkaTaskIncludes - ) - } - - @Test - fun sourceChildOutputDirectories() { - val parent = ProjectBuilder.builder().build() - val child = ProjectBuilder.builder().withName("child").withParent(parent).build() - - val parentTask = parent.tasks.create("parent") - val childTask = child.tasks.create("child") - - parentTask.addChildTask(childTask) - childTask.outputDirectory.set(child.file("custom/output")) - - assertEquals( - listOf(parent.file("child/custom/output")), parentTask.sourceChildOutputDirectories, - "Expected child output directory being present" - ) - } - - @Test - fun targetChildOutputDirectories() { - val parent = ProjectBuilder.builder().build() - val child = ProjectBuilder.builder().withName("child").withParent(parent).build() - - val parentTask = parent.tasks.create("parent") - val childTask = child.tasks.create("child") - - parentTask.addChildTask(childTask) - - parentTask.fileLayout.set(DokkaMultiModuleFileLayout { taskParent, taskChild -> - taskParent.project.buildDir.resolve(taskChild.name) - }) - - assertEquals( - listOf(parent.project.buildDir.resolve("child")), parentTask.targetChildOutputDirectories, - "Expected child target output directory being present" - ) - } -} diff --git a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaTaskTest.kt b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaTaskTest.kt deleted file mode 100644 index 31d14544..00000000 --- a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaTaskTest.kt +++ /dev/null @@ -1,38 +0,0 @@ -package org.jetbrains.dokka.gradle - -import org.gradle.kotlin.dsl.create -import org.gradle.testfixtures.ProjectBuilder -import kotlin.test.Test -import kotlin.test.assertEquals -import kotlin.test.assertNull - -class DokkaTaskTest { - @Test - fun `no suppressed source sets are present after in built configuration`() { - val project = ProjectBuilder.builder().build() - val task = project.tasks.create("dokkaTask") - project.configurations.all { withDependencies { clear() } } - - task.dokkaSourceSets.register("main") - task.dokkaSourceSets.register("jvm") - task.dokkaSourceSets.register("test") { - suppress.set(true) - } - - assertEquals( - listOf("main", "jvm").sorted(), - task.buildDokkaConfiguration().sourceSets.map { it.sourceSetID.sourceSetName }.sorted(), - "Expected only unsuppressed source sets `main` and `test` to be present in built configuration" - ) - } - - @Test - fun `module version is not present if not specified`(){ - val project = ProjectBuilder.builder().build() - val task = project.tasks.create("dokkaTask") - project.configurations.all { withDependencies { clear() } } - - task.dokkaSourceSets.register("main") - assertNull(task.buildDokkaConfiguration().moduleVersion) - } -} diff --git a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/tasks/DokkaMultiModuleTaskTest.kt b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/tasks/DokkaMultiModuleTaskTest.kt new file mode 100644 index 00000000..015d25f9 --- /dev/null +++ b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/tasks/DokkaMultiModuleTaskTest.kt @@ -0,0 +1,230 @@ +@file:Suppress("UnstableApiUsage", "DEPRECATION", "PackageDirectoryMismatch") + +package org.jetbrains.dokka.gradle + +import org.gradle.kotlin.dsl.create +import org.gradle.kotlin.dsl.withType +import org.gradle.testfixtures.ProjectBuilder +import org.jetbrains.dokka.* +import java.io.File +import kotlin.test.* + +class DokkaMultiModuleTaskTest { + + private val rootProject = ProjectBuilder.builder() + .withName("root") + .build() + + private val childProject = ProjectBuilder.builder() + .withName("child") + .withProjectDir(rootProject.projectDir.resolve("child")) + .withParent(rootProject).build() + + private val childDokkaTask = childProject.tasks.create("childDokkaTask") + + private val multiModuleTask = rootProject.tasks.create("multiModuleTask").apply { + addChildTask(childDokkaTask) + } + + init { + rootProject.allprojects { + tasks.withType().configureEach { + plugins.withDependencies { clear() } + } + } + } + + @Test + fun `child project is withing root project`() { + assertEquals( + rootProject.projectDir, childProject.projectDir.parentFile, + "Expected child project being inside the root project" + ) + + assertEquals( + childProject.projectDir.name, "child", + "Expected folder of child project to be called 'child'" + ) + } + + @Test + fun buildDokkaConfiguration() { + val include1 = childDokkaTask.project.file("include1.md") + val include2 = childDokkaTask.project.file("include2.md") + val topLevelInclude = multiModuleTask.project.file("README.md") + + childDokkaTask.apply { + dokkaSourceSets.create("main") + dokkaSourceSets.create("test") + dokkaSourceSets.configureEach { + includes.from(include1, include2) + } + } + + multiModuleTask.apply { + moduleVersion.set("1.5.0") + moduleName.set("custom Module Name") + outputDirectory.set(project.buildDir.resolve("customOutputDirectory")) + cacheRoot.set(File("customCacheRoot")) + pluginsConfiguration.add( + PluginConfigurationImpl( + "pluginA", + DokkaConfiguration.SerializationFormat.JSON, + """ { "key" : "value2" } """ + ) + ) + failOnWarning.set(true) + offlineMode.set(true) + includes.from(listOf(topLevelInclude)) + } + + val dokkaConfiguration = multiModuleTask.buildDokkaConfiguration() + assertEquals( + DokkaConfigurationImpl( + moduleName = "custom Module Name", + moduleVersion = "1.5.0", + outputDir = multiModuleTask.project.buildDir.resolve("customOutputDirectory"), + cacheRoot = File("customCacheRoot"), + pluginsConfiguration = mutableListOf( + PluginConfigurationImpl( + "pluginA", + DokkaConfiguration.SerializationFormat.JSON, + """ { "key" : "value2" } """ + ) + ), + pluginsClasspath = emptyList(), + failOnWarning = true, + offlineMode = true, + includes = setOf(topLevelInclude), + modules = listOf( + DokkaModuleDescriptionImpl( + name = "child", + relativePathToOutputDirectory = File("child"), + includes = setOf(include1, include2), + sourceOutputDirectory = childDokkaTask.outputDirectory.getSafe() + ) + ) + ), + dokkaConfiguration + ) + } + + @Test + fun `multimodule task should not include unspecified version`() { + childDokkaTask.apply { + dokkaSourceSets.create("main") + dokkaSourceSets.create("test") + } + + multiModuleTask.apply { + moduleVersion.set("unspecified") + } + + val dokkaConfiguration = multiModuleTask.buildDokkaConfiguration() + assertNull(dokkaConfiguration.moduleVersion) + } + + @Test + fun `setting dokkaTaskNames declares proper task dependencies`() { + val dependenciesInitial = multiModuleTask.taskDependencies.getDependencies(multiModuleTask).toSet() + assertEquals(1, dependenciesInitial.size, "Expected one dependency") + val dependency = dependenciesInitial.single() + + assertTrue( + dependency is DokkaTaskPartial, + "Expected dependency to be of Type ${DokkaTaskPartial::class.simpleName}" + ) + assertEquals(childProject, dependency.project, "Expected dependency from child project") + + + val customDokkaTask = childProject.tasks.create("customDokkaTask") + + 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") + + } + + @Test + fun `multimodule task with no child tasks throws DokkaException`() { + val project = ProjectBuilder.builder().build() + val multimodule = project.tasks.create("multimodule") + project.configurations.configureEach { withDependencies { clear() } } + assertFailsWith { multimodule.generateDocumentation() } + } + + @Test + fun childDokkaTaskIncludes() { + val childDokkaTaskInclude1 = childProject.file("include1") + val childDokkaTaskInclude2 = childProject.file("include2") + val childDokkaTaskInclude3 = childProject.file("include3") + + childDokkaTask.apply { + dokkaSourceSets.create("main") { + includes.from(childDokkaTaskInclude1, childDokkaTaskInclude2) + } + dokkaSourceSets.create("main2") { + includes.from(childDokkaTaskInclude3) + } + } + + val secondChildDokkaTaskInclude = childProject.file("include4") + val secondChildDokkaTask = childProject.tasks.create("secondChildDokkaTask") { + dokkaSourceSets.create("main") { + includes.from(secondChildDokkaTaskInclude) + } + } + multiModuleTask.addChildTask(secondChildDokkaTask) + + assertEquals( + mapOf( + ":child:childDokkaTask" to setOf( + childDokkaTaskInclude1, + childDokkaTaskInclude2, + childDokkaTaskInclude3 + ), + ":child:secondChildDokkaTask" to setOf(secondChildDokkaTaskInclude) + ), + multiModuleTask.childDokkaTaskIncludes + ) + } + + @Test + fun sourceChildOutputDirectories() { + val parent = ProjectBuilder.builder().build() + val child = ProjectBuilder.builder().withName("child").withParent(parent).build() + + val parentTask = parent.tasks.create("parent") + val childTask = child.tasks.create("child") + + parentTask.addChildTask(childTask) + childTask.outputDirectory.set(child.file("custom/output")) + + assertEquals( + listOf(parent.file("child/custom/output")), parentTask.sourceChildOutputDirectories, + "Expected child output directory being present" + ) + } + + @Test + fun targetChildOutputDirectories() { + val parent = ProjectBuilder.builder().build() + val child = ProjectBuilder.builder().withName("child").withParent(parent).build() + + val parentTask = parent.tasks.create("parent") + val childTask = child.tasks.create("child") + + parentTask.addChildTask(childTask) + + parentTask.fileLayout.set(DokkaMultiModuleFileLayout { taskParent, taskChild -> + taskParent.project.buildDir.resolve(taskChild.name) + }) + + assertEquals( + listOf(parent.project.buildDir.resolve("child")), parentTask.targetChildOutputDirectories, + "Expected child target output directory being present" + ) + } +} diff --git a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/tasks/DokkaTaskTest.kt b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/tasks/DokkaTaskTest.kt new file mode 100644 index 00000000..518a01f1 --- /dev/null +++ b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/tasks/DokkaTaskTest.kt @@ -0,0 +1,40 @@ +@file:Suppress("PackageDirectoryMismatch") + +package org.jetbrains.dokka.gradle + +import org.gradle.kotlin.dsl.create +import org.gradle.testfixtures.ProjectBuilder +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNull + +class DokkaTaskTest { + @Test + fun `no suppressed source sets are present after in built configuration`() { + val project = ProjectBuilder.builder().build() + val task = project.tasks.create("dokkaTask") + project.configurations.all { withDependencies { clear() } } + + task.dokkaSourceSets.register("main") + task.dokkaSourceSets.register("jvm") + task.dokkaSourceSets.register("test") { + suppress.set(true) + } + + assertEquals( + listOf("main", "jvm").sorted(), + task.buildDokkaConfiguration().sourceSets.map { it.sourceSetID.sourceSetName }.sorted(), + "Expected only unsuppressed source sets `main` and `test` to be present in built configuration" + ) + } + + @Test + fun `module version is not present if not specified`(){ + val project = ProjectBuilder.builder().build() + val task = project.tasks.create("dokkaTask") + project.configurations.all { withDependencies { clear() } } + + task.dokkaSourceSets.register("main") + assertNull(task.buildDokkaConfiguration().moduleVersion) + } +} -- cgit