aboutsummaryrefslogtreecommitdiff
path: root/runners/gradle-plugin/src/test/kotlin
diff options
context:
space:
mode:
authorsebastian.sellmair <sebastian.sellmair@jetbrains.com>2020-08-05 22:56:16 +0200
committerSebastian Sellmair <34319766+sellmair@users.noreply.github.com>2020-08-14 17:51:11 +0200
commite3c1b2bdbfe20e602fbf570df946edc94266e5ff (patch)
treeccd210e61209e7540954667a34d8d4126a8a0c70 /runners/gradle-plugin/src/test/kotlin
parent23827bed7b4877b15633e1924f7ee3864f8ebe2c (diff)
downloaddokka-e3c1b2bdbfe20e602fbf570df946edc94266e5ff.tar.gz
dokka-e3c1b2bdbfe20e602fbf570df946edc94266e5ff.tar.bz2
dokka-e3c1b2bdbfe20e602fbf570df946edc94266e5ff.zip
API refinement for AbstractDokkaParentTask and DokkaMultiModuleTask
Diffstat (limited to 'runners/gradle-plugin/src/test/kotlin')
-rw-r--r--runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaParentTaskTest.kt255
-rw-r--r--runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaCollectorTaskTest.kt26
-rw-r--r--runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaConfigurationJsonTest.kt14
-rw-r--r--runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaConfigurationSerializableTest.kt13
-rw-r--r--runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleFileLayoutTest.kt100
-rw-r--r--runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleTaskTest.kt88
-rw-r--r--runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaPluginApplyTest.kt (renamed from runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaTasksTest.kt)21
-rw-r--r--runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/KotlinDslDokkaTaskConfigurationTest.kt11
8 files changed, 409 insertions, 119 deletions
diff --git a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaParentTaskTest.kt b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaParentTaskTest.kt
index da0f3f35..f0e05637 100644
--- a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaParentTaskTest.kt
+++ b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/AbstractDokkaParentTaskTest.kt
@@ -1,107 +1,200 @@
package org.jetbrains.dokka.gradle
-import org.gradle.kotlin.dsl.register
-import org.gradle.kotlin.dsl.withType
+import org.gradle.api.Project
+import org.gradle.api.UnknownTaskException
+import org.gradle.kotlin.dsl.create
+import org.gradle.kotlin.dsl.getByName
import org.gradle.testfixtures.ProjectBuilder
+import org.jetbrains.dokka.DokkaConfigurationImpl
import kotlin.test.Test
import kotlin.test.assertEquals
-import kotlin.test.assertTrue
+import kotlin.test.assertFailsWith
class AbstractDokkaParentTaskTest {
private val rootProject = ProjectBuilder.builder().build()
private val subproject0 = ProjectBuilder.builder().withName("subproject0").withParent(rootProject).build()
private val subproject1 = ProjectBuilder.builder().withName("subproject1").withParent(rootProject).build()
- private val subSubproject0a = ProjectBuilder.builder().withName("subSubproject0a").withParent(subproject0).build()
+ private val subSubproject0 = ProjectBuilder.builder().withName("subSubproject0").withParent(subproject0).build()
init {
- rootProject.allprojects { project -> project.plugins.apply("org.jetbrains.dokka") }
+ rootProject.subprojects { project ->
+ project.tasks.create<DokkaTask>("dokkaTask")
+ }
}
- private val parentTasks = rootProject.tasks.withType<AbstractDokkaParentTask>().toList()
+ private val parentTask = rootProject.tasks.create<TestDokkaParentTask>("parent")
+
@Test
- fun `at least one parent task is registered`() {
- assertTrue(
- parentTasks.isNotEmpty(),
- "Expected at least one ${AbstractDokkaParentTask::class.simpleName} task in rootProject"
+ fun `add and remove tasks by reference`() {
+ assertEquals(
+ emptySet(), parentTask.childDokkaTasks,
+ "Expected no childDokkaTasks by default"
+ )
+
+ parentTask.addChildTask(subproject0.dokkaTask)
+ assertEquals(
+ setOf(subproject0.dokkaTask), parentTask.childDokkaTasks,
+ "Expected ${subproject0.dokkaTask.path} being registered as child task"
+ )
+
+ parentTask.addChildTask(subproject1.dokkaTask)
+ assertEquals(
+ setOf(subproject0.dokkaTask, subproject1.dokkaTask), parentTask.childDokkaTasks,
+ "Expected both dokka tasks being present"
+ )
+
+ parentTask.removeChildTask(subproject0.dokkaTask)
+ assertEquals(
+ setOf(subproject1.dokkaTask), parentTask.childDokkaTasks,
+ "Expected ${subproject0.dokkaTask.path} being removed from child tasks"
+ )
+
+ parentTask.addChildTask(subSubproject0.dokkaTask)
+ assertEquals(
+ setOf(subproject1.dokkaTask, subSubproject0.dokkaTask), parentTask.childDokkaTasks,
+ "Expected ${subSubproject0.dokkaTask.path} being added as child task"
+ )
+
+ parentTask.addChildTask(subSubproject0.dokkaTask)
+ assertEquals(
+ setOf(subproject1.dokkaTask, subSubproject0.dokkaTask), parentTask.childDokkaTasks,
+ "Expected no effect for adding a task twice"
)
}
@Test
- fun `configuring subprojects`() {
- parentTasks.forEach { task ->
- assertEquals(
- setOf(":subproject0", ":subproject1", ":subproject0:subSubproject0a"), task.subprojectPaths,
- "Expected all sub projects registered by default"
- )
-
- assertEquals(
- listOf(subproject0, subproject1, subSubproject0a), task.subprojects,
- "Expected all sub projects registered by default"
- )
-
- assertEquals(3, task.dokkaTasks.size, "Expected three referenced dokka tasks")
- assertTrue(listOf(subproject0, subproject1, subSubproject0a).all { project ->
- task.dokkaTasks.any { task -> task in project.tasks }
- }, "Expected all sub projects to contribute to referenced dokka tasks")
-
- task.removeSubproject(subproject0)
- assertEquals(
- setOf(":subproject1", ":subproject0:subSubproject0a"), task.subprojectPaths,
- "Expected subproject0 to be removed (without removing its children)"
- )
-
- task.addSubproject(subproject0)
- assertEquals(
- setOf(":subproject1", ":subproject0:subSubproject0a", ":subproject0"), task.subprojectPaths,
- "Expected subproject0 being added again"
- )
-
- task.addSubproject(subproject0)
- assertEquals(
- setOf(":subproject1", ":subproject0:subSubproject0a", ":subproject0"), task.subprojectPaths,
- "Expected adding same project twice to be ignored"
- )
-
- task.removeAllProjects(subproject0)
- assertEquals(
- setOf(":subproject1"), task.subprojectPaths,
- "Expected subproject0 and subSubproject0a to be removed"
- )
-
- task.addAllProjects(subproject0)
- assertEquals(
- setOf(":subproject1", ":subproject0", ":subproject0:subSubproject0a"), task.subprojectPaths,
- "Expected subproject0 and subSubproject0a to be added again"
- )
- }
+ fun `add and remove by absolute path`() {
+ parentTask.addChildTask(":subproject0:dokkaTask")
+ assertEquals(
+ setOf(subproject0.dokkaTask), parentTask.childDokkaTasks,
+ "Expected ${subproject0.dokkaTask.path} as child task"
+ )
+
+ parentTask.addChildTask(":subproject0:subSubproject0:dokkaTask")
+ assertEquals(
+ setOf(subproject0.dokkaTask, subSubproject0.dokkaTask), parentTask.childDokkaTasks,
+ "Expected ${subSubproject0.dokkaTask.path} being added as child task"
+ )
+
+ parentTask.removeChildTask(":subproject0:dokkaTask")
+ assertEquals(
+ setOf(subSubproject0.dokkaTask), parentTask.childDokkaTasks,
+ "Expected ${subproject0.dokkaTask.path} being removed as child task"
+ )
}
@Test
- fun `configure dokkaTaskNames`() {
- parentTasks.forEach { task ->
- assertEquals(
- 3, task.dokkaTasks.size,
- "Expected 3 tasks referenced by default"
- )
-
- val customDokkaTaskName = "custom${task.name}"
- task.dokkaTaskNames = setOf(customDokkaTaskName)
- assertTrue(task.dokkaTasks.isEmpty(), "Expected no $customDokkaTaskName. Found: ${task.dokkaTasks}")
-
- rootProject.subprojects { subproject ->
- subproject.tasks.register<DokkaTask>(customDokkaTaskName)
- }
-
- assertEquals(
- 3, task.dokkaTasks.size,
- "Expected three $customDokkaTaskName found"
- )
-
- task.dokkaTasks.forEach { dokkaTask ->
- assertEquals(customDokkaTaskName, dokkaTask.name)
- }
- }
+ fun `add and remove by relative path`() {
+ parentTask.addChildTask("subproject0:dokkaTask")
+ assertEquals(
+ setOf(subproject0.dokkaTask), parentTask.childDokkaTasks,
+ "Expected ${subproject0.dokkaTask.path} as child task"
+ )
+
+ parentTask.addChildTask("subproject0:subSubproject0:dokkaTask")
+ assertEquals(
+ setOf(subproject0.dokkaTask, subSubproject0.dokkaTask), parentTask.childDokkaTasks,
+ "Expected ${subSubproject0.dokkaTask.path} being added as child task"
+ )
+
+ parentTask.removeChildTask("subproject0:dokkaTask")
+ assertEquals(
+ setOf(subSubproject0.dokkaTask), parentTask.childDokkaTasks,
+ "Expected ${subproject0.dokkaTask.path} being removed as child task"
+ )
+ }
+
+ @Test
+ fun `add and remove by relative path ob subproject0`() {
+ val parentTask = subproject0.tasks.create<TestDokkaParentTask>("parent")
+
+ parentTask.addChildTask("subSubproject0:dokkaTask")
+ assertEquals(
+ setOf(subSubproject0.dokkaTask), parentTask.childDokkaTasks,
+ "Expected ${subSubproject0.dokkaTask.path} being registered as child"
+ )
+
+ parentTask.removeChildTask("subSubproject0:dokkaTask")
+ assertEquals(
+ emptySet(), parentTask.childDokkaTasks,
+ "Expected ${subSubproject0.dokkaTask.path} being removed as child"
+ )
+ }
+
+ @Test
+ fun `add and remove by project and name`() {
+ parentTask.addChildTasks(rootProject.subprojects, "dokkaTask")
+ assertEquals(
+ setOf(subproject0.dokkaTask, subproject1.dokkaTask, subSubproject0.dokkaTask), parentTask.childDokkaTasks,
+ "Expected all subproject tasks being registered as child task"
+ )
+
+ parentTask.removeChildTasks(rootProject.subprojects, "dokkaTask")
+ assertEquals(
+ emptySet(), parentTask.childDokkaTasks,
+ "Expected all tasks being removed"
+ )
+
+ parentTask.addChildTasks(listOf(subproject0), "dokkaTask")
+ assertEquals(
+ setOf(subproject0.dokkaTask), parentTask.childDokkaTasks,
+ "Expected only ${subproject0.dokkaTask.path} being registered as child"
+ )
+
+ parentTask.addSubprojectChildTasks("dokkaTask")
+ assertEquals(
+ setOf(subproject0.dokkaTask, subproject1.dokkaTask, subSubproject0.dokkaTask), parentTask.childDokkaTasks,
+ "Expected all subproject tasks being registered as child task"
+ )
+
+ parentTask.removeSubprojectChildTasks("dokkaTask")
+ assertEquals(
+ emptySet(), parentTask.childDokkaTasks,
+ "Expected all tasks being removed"
+ )
+
+ parentTask.addSubprojectChildTasks("dokkaTask")
+ assertEquals(
+ setOf(subproject0.dokkaTask, subproject1.dokkaTask, subSubproject0.dokkaTask), parentTask.childDokkaTasks,
+ "Expected all subproject tasks being registered as child task"
+ )
+
+ parentTask.removeChildTasks(subproject0)
+ assertEquals(
+ setOf(subproject1.dokkaTask, subSubproject0.dokkaTask), parentTask.childDokkaTasks,
+ "Expected only ${subproject0.dokkaTask.path} being removed"
+ )
+
+ parentTask.addSubprojectChildTasks("dokkaTask")
+ parentTask.removeChildTasks(listOf(subproject0, subproject1))
+ assertEquals(
+ setOf(subSubproject0.dokkaTask), parentTask.childDokkaTasks,
+ "Expected ${subproject0.dokkaTask.path} and ${subproject1.dokkaTask.path} being removed"
+ )
+ }
+
+ @Test
+ fun `adding invalid path will not throw exception`() {
+ parentTask.addChildTask(":some:stupid:path")
+ parentTask.childDokkaTasks
+ }
+
+ @Test
+ fun `adding non dokka task will throw exception`() {
+ val badTask = rootProject.tasks.create("badTask")
+ parentTask.addChildTask(badTask.path)
+ assertFailsWith<IllegalArgumentException> { parentTask.childDokkaTasks }
+ }
+}
+
+internal open class TestDokkaParentTask : AbstractDokkaParentTask() {
+ override fun buildDokkaConfiguration(): DokkaConfigurationImpl {
+ throw NotImplementedError()
}
}
+
+private val Project.dokkaTask: DokkaTask get() = tasks.getByName<DokkaTask>("dokkaTask")
+
+
diff --git a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaCollectorTaskTest.kt b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaCollectorTaskTest.kt
index 18128e34..d7f0e946 100644
--- a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaCollectorTaskTest.kt
+++ b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaCollectorTaskTest.kt
@@ -1,13 +1,14 @@
package org.jetbrains.dokka.gradle
-import org.gradle.api.artifacts.Dependency
-import org.gradle.api.artifacts.FileCollectionDependency
+import org.gradle.kotlin.dsl.create
import org.gradle.kotlin.dsl.withType
import org.gradle.testfixtures.ProjectBuilder
import org.jetbrains.dokka.DokkaConfigurationImpl
+import org.jetbrains.dokka.DokkaException
import java.io.File
import kotlin.test.Test
import kotlin.test.assertEquals
+import kotlin.test.assertFailsWith
import kotlin.test.assertTrue
class DokkaCollectorTaskTest {
@@ -32,15 +33,15 @@ class DokkaCollectorTaskTest {
val collectorTasks = rootProject.tasks.withType<DokkaCollectorTask>()
collectorTasks.configureEach { task ->
- task.outputDirectory = File("customOutputDirectory")
- task.cacheRoot = File("customCacheRoot")
- task.failOnWarning = true
- task.offlineMode = true
+ task.outputDirectory by File("customOutputDirectory")
+ task.cacheRoot by File("customCacheRoot")
+ task.failOnWarning by true
+ task.offlineMode by true
}
assertTrue(collectorTasks.isNotEmpty(), "Expected at least one collector task")
- collectorTasks.forEach { task ->
+ collectorTasks.toList().forEach { task ->
val dokkaConfiguration = task.buildDokkaConfiguration()
assertEquals(
DokkaConfigurationImpl(
@@ -48,17 +49,24 @@ class DokkaCollectorTaskTest {
cacheRoot = File("customCacheRoot"),
failOnWarning = true,
offlineMode = true,
- sourceSets = task.dokkaTasks
+ sourceSets = task.childDokkaTasks
.map { it.buildDokkaConfiguration() }
.map { it.sourceSets }
.reduce { acc, list -> acc + list },
- pluginsClasspath = task.dokkaTasks
+ pluginsClasspath = task.childDokkaTasks
.map { it.plugins.resolve() }
.reduce { acc, mutableSet -> acc + mutableSet }
),
dokkaConfiguration
)
}
+ }
+ @Test
+ fun `with no child tasks throws DokkaException`() {
+ val project = ProjectBuilder.builder().build()
+ val collectorTask = project.tasks.create<DokkaCollectorTask>("collector")
+ project.configurations.all { configuration -> configuration.withDependencies { it.clear() } }
+ assertFailsWith<DokkaException> { collectorTask.generateDocumentation() }
}
}
diff --git a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaConfigurationJsonTest.kt b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaConfigurationJsonTest.kt
index 7a3bc2bd..29532877 100644
--- a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaConfigurationJsonTest.kt
+++ b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaConfigurationJsonTest.kt
@@ -1,3 +1,5 @@
+@file:Suppress("UnstableApiUsage")
+
package org.jetbrains.dokka.gradle
import org.gradle.kotlin.dsl.withType
@@ -19,12 +21,12 @@ class DokkaConfigurationJsonTest {
dependencies.clear()
}
dokkaTask.apply {
- this.failOnWarning = true
- this.offlineMode = true
- this.outputDirectory = File("customOutputDir")
- this.cacheRoot = File("customCacheRoot")
- this.pluginsConfiguration["0"] = "a"
- this.pluginsConfiguration["1"] = "b"
+ this.failOnWarning by true
+ this.offlineMode by true
+ this.outputDirectory by File("customOutputDir")
+ this.cacheRoot by File("customCacheRoot")
+ this.pluginsConfiguration.put("0", "a")
+ this.pluginsConfiguration.put("1", "b")
this.dokkaSourceSets.create("main") { sourceSet ->
sourceSet.moduleDisplayName by "moduleDisplayName"
sourceSet.displayName by "customSourceSetDisplayName"
diff --git a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaConfigurationSerializableTest.kt b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaConfigurationSerializableTest.kt
index e4dc5afc..f22a5b8c 100644
--- a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaConfigurationSerializableTest.kt
+++ b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaConfigurationSerializableTest.kt
@@ -13,6 +13,7 @@ import java.net.URL
import kotlin.test.Test
import kotlin.test.assertEquals
+@Suppress("UnstableApiUsage")
class DokkaConfigurationSerializableTest {
@get:Rule
@@ -27,12 +28,12 @@ class DokkaConfigurationSerializableTest {
dependencies.clear()
}
dokkaTask.apply {
- this.failOnWarning = true
- this.offlineMode = true
- this.outputDirectory = File("customOutputDir")
- this.cacheRoot = File("customCacheRoot")
- this.pluginsConfiguration["0"] = "a"
- this.pluginsConfiguration["1"] = "b"
+ this.failOnWarning by true
+ this.offlineMode by true
+ this.outputDirectory by File("customOutputDir")
+ this.cacheRoot by File("customCacheRoot")
+ this.pluginsConfiguration.put("0", "a")
+ this.pluginsConfiguration.put("1", "b")
this.dokkaSourceSets.create("main") { sourceSet ->
sourceSet.moduleDisplayName by "moduleDisplayName"
sourceSet.displayName by "customSourceSetDisplayName"
diff --git a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleFileLayoutTest.kt b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleFileLayoutTest.kt
new file mode 100644
index 00000000..36abacfc
--- /dev/null
+++ b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaMultiModuleFileLayoutTest.kt
@@ -0,0 +1,100 @@
+package org.jetbrains.dokka.gradle
+
+import org.gradle.kotlin.dsl.create
+import org.gradle.testfixtures.ProjectBuilder
+import org.jetbrains.dokka.gradle.DokkaMultiModuleFileLayout.CompactInParent
+import org.jetbrains.dokka.gradle.DokkaMultiModuleFileLayout.NoCopy
+import java.io.File
+import kotlin.test.Test
+import kotlin.test.assertEquals
+import kotlin.test.assertTrue
+
+class DokkaMultiModuleFileLayoutTest {
+
+ @Test
+ fun `no copy`() {
+ val project = ProjectBuilder.builder().build()
+ val child = project.tasks.create<DokkaTask>("child")
+ val parent = project.tasks.create<DokkaMultiModuleTask>("parent")
+ child.outputDirectory by File("some/path")
+
+ assertEquals(
+ File("some/path"), NoCopy.targetChildOutputDirectory(parent, child),
+ "Expected original file path returned"
+ )
+ }
+
+ @Test
+ fun `compact in parent`() {
+ val rootProject = ProjectBuilder.builder().build()
+ val parentProject = ProjectBuilder.builder().withName("parent").withParent(rootProject).build()
+ val intermediateProject = ProjectBuilder.builder().withName("intermediate").withParent(parentProject).build()
+ val childProject = ProjectBuilder.builder().withName("child").withParent(intermediateProject).build()
+
+ val parentTask = parentProject.tasks.create<DokkaMultiModuleTask>("parentTask")
+ val childTask = childProject.tasks.create<DokkaTask>("childTask")
+
+ val targetOutputDirectory = CompactInParent.targetChildOutputDirectory(parentTask, childTask)
+ assertEquals(
+ parentTask.outputDirectory.getSafe().resolve("intermediate/child"), targetOutputDirectory,
+ "Expected nested file structure representing project structure"
+ )
+ }
+
+ @Test
+ fun copyChildOutputDirectory() {
+ /* Prepare */
+ val project = ProjectBuilder.builder().build()
+ val childTask = project.tasks.create<DokkaTask>("child")
+ val parentTask = project.tasks.create<DokkaMultiModuleTask>("parent")
+
+ val sourceOutputDirectory = childTask.outputDirectory.getSafe()
+ sourceOutputDirectory.mkdirs()
+ sourceOutputDirectory.resolve("some.file").writeText("some text")
+ val subFolder = sourceOutputDirectory.resolve("subFolder")
+ subFolder.mkdirs()
+ subFolder.resolve("other.file").writeText("other text")
+
+ val layout = object : DokkaMultiModuleFileLayout {
+ override fun targetChildOutputDirectory(parent: AbstractDokkaParentTask, child: AbstractDokkaTask): File {
+ return parent.project.file("target/output")
+ }
+ }
+ layout.copyChildOutputDirectory(parentTask, childTask)
+
+ /* Assertions */
+ val targetOutputDirectory = project.file("target/output")
+ assertTrue(
+ targetOutputDirectory.exists() && targetOutputDirectory.isDirectory,
+ "Expected target output directory ${targetOutputDirectory.path} to exist"
+ )
+
+ val targetSomeFile = targetOutputDirectory.resolve("some.file")
+ assertTrue(
+ targetSomeFile.exists() && targetSomeFile.isFile,
+ "Expected sample file to exist in target output directory"
+ )
+
+ assertEquals(
+ "some text", targetSomeFile.readText(),
+ "Expected content to be written into sample file"
+ )
+
+ val targetSubFolder = targetOutputDirectory.resolve("subFolder")
+ assertTrue(
+ targetSubFolder.exists() && targetSubFolder.isDirectory,
+ "Expected sub folder being present in target output directory"
+ )
+
+ val targetOtherFile = targetSubFolder.resolve("other.file")
+ assertTrue(
+ targetOtherFile.exists() && targetOtherFile.isFile,
+ "Expected nested 'other.file' being copied into target"
+ )
+
+ assertEquals(
+ "other text", targetOtherFile.readText(),
+ "Expected content to be written into 'other.file'"
+ )
+ }
+}
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 8814a897..a7c9946d 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
@@ -1,13 +1,17 @@
+@file:Suppress("UnstableApiUsage")
+
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.DokkaConfigurationImpl
+import org.jetbrains.dokka.DokkaException
import org.jetbrains.dokka.DokkaModuleDescriptionImpl
import java.io.File
import kotlin.test.Test
import kotlin.test.assertEquals
+import kotlin.test.assertFailsWith
import kotlin.test.assertTrue
class DokkaMultiModuleTaskTest {
@@ -47,19 +51,19 @@ class DokkaMultiModuleTaskTest {
@Test
fun buildDokkaConfiguration() {
childProject.tasks.withType<DokkaTask>().configureEach { task ->
- task.outputDirectory = task.project.buildDir.resolve("output")
+ task.outputDirectory by task.project.buildDir.resolve("output")
}
- val multimoduleTasks = rootProject.tasks.withType<DokkaMultimoduleTask>()
+ val multimoduleTasks = rootProject.tasks.withType<DokkaMultiModuleTask>()
assertTrue(multimoduleTasks.isNotEmpty(), "Expected at least one multimodule task")
multimoduleTasks.configureEach { task ->
task.documentationFileName = "customDocumentationFileName.md"
- task.outputDirectory = task.project.buildDir.resolve("customOutputDirectory")
- task.cacheRoot = File("customCacheRoot")
- task.pluginsConfiguration["pluginA"] = "configA"
- task.failOnWarning = true
- task.offlineMode = true
+ 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
}
multimoduleTasks.forEach { task ->
@@ -75,7 +79,7 @@ class DokkaMultiModuleTaskTest {
modules = listOf(
DokkaModuleDescriptionImpl(
name = "child",
- path = File("../../child/build/output"),
+ path = File("child"),
docFile = childProject.projectDir.resolve("customDocumentationFileName.md")
)
)
@@ -87,7 +91,7 @@ class DokkaMultiModuleTaskTest {
@Test
fun `setting dokkaTaskNames declares proper task dependencies`() {
- val multimoduleTasks = rootProject.tasks.withType<DokkaMultimoduleTask>()
+ val multimoduleTasks = rootProject.tasks.withType<DokkaMultiModuleTask>()
assertTrue(multimoduleTasks.isNotEmpty(), "Expected at least one multimodule task")
multimoduleTasks.toList().forEach { task ->
@@ -102,11 +106,75 @@ class DokkaMultiModuleTaskTest {
val customDokkaTask = childProject.tasks.create<DokkaTask>("customDokkaTask")
multimoduleTasks.toList().forEach { task ->
- task.dokkaTaskNames += "customDokkaTask"
+ task.addSubprojectChildTasks("customDokkaTask")
val dependencies = task.taskDependencies.getDependencies(task).toSet()
assertEquals(2, dependencies.size, "Expected two dependencies")
assertTrue(customDokkaTask in dependencies, "Expected 'customDokkaTask' in dependencies")
}
}
+
+ @Test
+ fun `multimodule task with no child tasks throws DokkaException`() {
+ val project = ProjectBuilder.builder().build()
+ val multimodule = project.tasks.create<DokkaMultiModuleTask>("multimodule")
+ project.configurations.configureEach { it.withDependencies { it.clear() } }
+ assertFailsWith<DokkaException> { multimodule.generateDocumentation() }
+ }
+
+ @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")
+
+ parentTask.addChildTask(childTask)
+ parentTask.documentationFileName = "module.txt"
+
+ assertEquals(
+ listOf(parent.file("child/module.txt")), parentTask.childDocumentationFiles,
+ "Expected child documentation file being present"
+ )
+ }
+
+ @Test
+ fun sourceChildOutputDirectories() {
+ 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")
+
+ parentTask.addChildTask(childTask)
+ childTask.outputDirectory by 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<DokkaMultiModuleTask>("parent")
+ val childTask = child.tasks.create<DokkaTask>("child")
+
+ parentTask.addChildTask(childTask)
+ parentTask.fileLayout = object : DokkaMultiModuleFileLayout {
+ override fun targetChildOutputDirectory(parent: AbstractDokkaParentTask, child: AbstractDokkaTask): File {
+ return parent.project.buildDir.resolve(child.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/DokkaTasksTest.kt b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaPluginApplyTest.kt
index b948c540..db218b9f 100644
--- a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaTasksTest.kt
+++ b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaPluginApplyTest.kt
@@ -8,7 +8,7 @@ import kotlin.test.assertEquals
import kotlin.test.assertSame
import kotlin.test.assertTrue
-class DokkaTasksTest {
+class DokkaPluginApplyTest {
@Test
fun `one task per format is registered`() {
@@ -62,4 +62,23 @@ class DokkaTasksTest {
)
}
}
+
+ @Test
+ fun `parent dokka tasks have children configured`() {
+ val root = ProjectBuilder.builder().withName("root").build()
+ val child = ProjectBuilder.builder().withName("child").withParent(root).build()
+ root.plugins.apply("org.jetbrains.dokka")
+ child.plugins.apply("org.jetbrains.dokka")
+
+ val parentTasks = root.tasks.withType<AbstractDokkaParentTask>()
+ assertTrue(parentTasks.isNotEmpty(), "Expected at least one parent task being created")
+
+ parentTasks.toList().forEach { parentTask ->
+ assertEquals(1, parentTask.childDokkaTasks.size, "Expected one child dokka task")
+ assertEquals(
+ child, parentTask.childDokkaTasks.single().project,
+ "Expected child dokka task from child project"
+ )
+ }
+ }
}
diff --git a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/KotlinDslDokkaTaskConfigurationTest.kt b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/KotlinDslDokkaTaskConfigurationTest.kt
index 013ad3f2..6a356b79 100644
--- a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/KotlinDslDokkaTaskConfigurationTest.kt
+++ b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/KotlinDslDokkaTaskConfigurationTest.kt
@@ -1,6 +1,6 @@
package org.jetbrains.dokka.gradle
-import dokka
+import org.gradle.kotlin.dsl.withType
import org.gradle.testfixtures.ProjectBuilder
import org.jetbrains.dokka.DokkaSourceSetID
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
@@ -9,17 +9,16 @@ import kotlin.test.Test
import kotlin.test.assertEquals
class KotlinDslDokkaTaskConfigurationTest {
-
@Test
- fun `configure project using dokka extension function`() {
+ fun `configure dokka task`() {
val project = ProjectBuilder.builder().build()
project.plugins.apply("org.jetbrains.dokka")
- project.dokka {
- outputDirectory = File("test")
+ project.tasks.withType<DokkaTask>().configureEach {
+ it.outputDirectory by File("test")
}
project.tasks.withType(DokkaTask::class.java).forEach { dokkaTask ->
- assertEquals(File("test"), dokkaTask.outputDirectory)
+ assertEquals(File("test"), dokkaTask.outputDirectory.getSafe())
}
}