diff options
author | aSemy <897017+aSemy@users.noreply.github.com> | 2023-02-27 16:50:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-27 16:50:38 +0100 |
commit | 6af794d4173d6aef9b84dbc7647eb3a1a54677d5 (patch) | |
tree | b0fb10469b388736772f112bbf91cc60bee7fad8 /runners/gradle-plugin/src/test/kotlin | |
parent | f5581c51d0de23d2b038e00b1a152faebaef0920 (diff) | |
download | dokka-6af794d4173d6aef9b84dbc7647eb3a1a54677d5.tar.gz dokka-6af794d4173d6aef9b84dbc7647eb3a1a54677d5.tar.bz2 dokka-6af794d4173d6aef9b84dbc7647eb3a1a54677d5.zip |
Use Gradle file property types for task inputs & outputs (#2707)
Diffstat (limited to 'runners/gradle-plugin/src/test/kotlin')
9 files changed, 195 insertions, 57 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 2cac940f..c5ea42a5 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 @@ -7,6 +7,7 @@ import org.gradle.kotlin.dsl.create import org.gradle.kotlin.dsl.getByName import org.gradle.testfixtures.ProjectBuilder import org.jetbrains.dokka.DokkaConfigurationImpl +import org.jetbrains.dokka.gradle.utils.subprojects_ import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFailsWith @@ -19,7 +20,7 @@ class AbstractDokkaParentTaskTest { private val subSubproject0 = ProjectBuilder.builder().withName("subSubproject0").withParent(subproject0).build() init { - rootProject.subprojects { + rootProject.subprojects_ { tasks.create<DokkaTask>("dokkaTask") } } @@ -190,12 +191,10 @@ class AbstractDokkaParentTaskTest { } } -internal open class TestDokkaParentTask : AbstractDokkaParentTask() { +internal abstract 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/DokkaConfigurationJsonTest.kt b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaConfigurationJsonTest.kt index 108c7fe0..d01847a0 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 @@ -2,7 +2,13 @@ package org.jetbrains.dokka.gradle import org.gradle.kotlin.dsl.withType import org.gradle.testfixtures.ProjectBuilder -import org.jetbrains.dokka.* +import org.jetbrains.dokka.DokkaConfiguration +import org.jetbrains.dokka.DokkaConfigurationImpl +import org.jetbrains.dokka.PluginConfigurationImpl +import org.jetbrains.dokka.gradle.utils.create_ +import org.jetbrains.dokka.gradle.utils.externalDocumentationLink_ +import org.jetbrains.dokka.gradle.utils.withDependencies_ +import org.jetbrains.dokka.toCompactJsonString import java.io.File import java.net.URL import kotlin.test.Test @@ -15,23 +21,31 @@ class DokkaConfigurationJsonTest { val project = ProjectBuilder.builder().build() project.plugins.apply("org.jetbrains.dokka") val dokkaTask = project.tasks.withType<DokkaTask>().first() - dokkaTask.plugins.withDependencies { clear() } + dokkaTask.plugins.withDependencies_ { clear() } dokkaTask.apply { this.failOnWarning.set(true) this.offlineMode.set(true) this.outputDirectory.set(File("customOutputDir")) this.cacheRoot.set(File("customCacheRoot")) this.pluginsConfiguration.add( - PluginConfigurationImpl("A", DokkaConfiguration.SerializationFormat.JSON, """ { "key" : "value1" } """) + PluginConfigurationImpl( + "A", + DokkaConfiguration.SerializationFormat.JSON, + """ { "key" : "value1" } """ + ) ) this.pluginsConfiguration.add( - PluginConfigurationImpl("B", DokkaConfiguration.SerializationFormat.JSON, """ { "key" : "value2" } """) + PluginConfigurationImpl( + "B", + DokkaConfiguration.SerializationFormat.JSON, + """ { "key" : "value2" } """ + ) ) - this.dokkaSourceSets.create("main") { + this.dokkaSourceSets.create_("main") { displayName.set("customSourceSetDisplayName") reportUndocumented.set(true) - externalDocumentationLink { + externalDocumentationLink_ { packageListUrl.set(URL("http://some.url")) url.set(URL("http://some.other.url")) } 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 75e2b63e..b5230114 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 @@ -4,6 +4,9 @@ import org.gradle.kotlin.dsl.withType import org.gradle.testfixtures.ProjectBuilder import org.jetbrains.dokka.DokkaConfiguration import org.jetbrains.dokka.PluginConfigurationImpl +import org.jetbrains.dokka.gradle.utils.create_ +import org.jetbrains.dokka.gradle.utils.externalDocumentationLink_ +import org.jetbrains.dokka.gradle.utils.withDependencies_ import org.junit.Rule import org.junit.rules.TemporaryFolder import java.io.File @@ -24,19 +27,31 @@ class DokkaConfigurationSerializableTest { val project = ProjectBuilder.builder().build() project.plugins.apply("org.jetbrains.dokka") val dokkaTask = project.tasks.withType<DokkaTask>().first() - dokkaTask.plugins.withDependencies { clear() } + dokkaTask.plugins.withDependencies_ { clear() } dokkaTask.apply { this.failOnWarning.set(true) this.offlineMode.set(true) this.outputDirectory.set(File("customOutputDir")) this.cacheRoot.set(File("customCacheRoot")) - this.pluginsConfiguration.add(PluginConfigurationImpl("A", DokkaConfiguration.SerializationFormat.JSON, """ { "key" : "value1" } """)) - this.pluginsConfiguration.add(PluginConfigurationImpl("B", DokkaConfiguration.SerializationFormat.JSON, """ { "key" : "value2" } """)) - this.dokkaSourceSets.create("main") { + this.pluginsConfiguration.add( + PluginConfigurationImpl( + "A", + DokkaConfiguration.SerializationFormat.JSON, + """ { "key" : "value1" } """ + ) + ) + this.pluginsConfiguration.add( + PluginConfigurationImpl( + "B", + DokkaConfiguration.SerializationFormat.JSON, + """ { "key" : "value2" } """ + ) + ) + this.dokkaSourceSets.create_("main") { displayName.set("customSourceSetDisplayName") reportUndocumented.set(true) - externalDocumentationLink { + externalDocumentationLink_ { packageListUrl.set(URL("http://some.url")) url.set(URL("http://some.other.url")) } 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 index d00664b5..6f0ce8a2 100644 --- 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 @@ -16,12 +16,15 @@ class DokkaMultiModuleFileLayoutTest { @Test fun `no copy`() { val project = ProjectBuilder.builder().build() + project.plugins.apply("org.jetbrains.dokka") + val child = project.tasks.create<DokkaTask>("child") val parent = project.tasks.create<DokkaMultiModuleTask>("parent") child.outputDirectory.set(File("some/path")) assertEquals( - File("some/path"), NoCopy.targetChildOutputDirectory(parent, child), + File("some/path"), + NoCopy.targetChildOutputDirectory(parent, child).get().asFile.relativeTo(project.projectDir), "Expected original file path returned" ) } @@ -29,16 +32,21 @@ class DokkaMultiModuleFileLayoutTest { @Test fun `compact in parent`() { val rootProject = ProjectBuilder.builder().build() + val parentProject = ProjectBuilder.builder().withName("parent").withParent(rootProject).build() + parentProject.plugins.apply("org.jetbrains.dokka") + val intermediateProject = ProjectBuilder.builder().withName("intermediate").withParent(parentProject).build() val childProject = ProjectBuilder.builder().withName("child").withParent(intermediateProject).build() + childProject.plugins.apply("org.jetbrains.dokka") val parentTask = parentProject.tasks.create<DokkaMultiModuleTask>("parentTask") val childTask = childProject.tasks.create<DokkaTask>("childTask") val targetOutputDirectory = CompactInParent.targetChildOutputDirectory(parentTask, childTask) assertEquals( - parentTask.outputDirectory.get().resolve("intermediate/child"), targetOutputDirectory, + parentTask.outputDirectory.get().asFile.resolve("intermediate/child"), + targetOutputDirectory.get().asFile, "Expected nested file structure representing project structure" ) } @@ -47,17 +55,21 @@ class DokkaMultiModuleFileLayoutTest { fun copyChildOutputDirectory() { /* Prepare */ val project = ProjectBuilder.builder().build() + project.plugins.apply("org.jetbrains.dokka") + val childTask = project.tasks.create<DokkaTask>("child") val parentTask = project.tasks.create<DokkaMultiModuleTask>("parent") - val sourceOutputDirectory = childTask.outputDirectory.get() + val sourceOutputDirectory = childTask.outputDirectory.get().asFile sourceOutputDirectory.mkdirs() sourceOutputDirectory.resolve("some.file").writeText("some text") val subFolder = sourceOutputDirectory.resolve("subFolder") subFolder.mkdirs() subFolder.resolve("other.file").writeText("other text") - parentTask.fileLayout.set(DokkaMultiModuleFileLayout { parent, _ -> parent.project.file("target/output") }) + parentTask.fileLayout.set(DokkaMultiModuleFileLayout { parent, _ -> + parent.project.provider { parent.project.layout.projectDirectory.dir("target/output") } + }) parentTask.copyChildOutputDirectory(childTask) /* Assertions */ @@ -99,10 +111,12 @@ class DokkaMultiModuleFileLayoutTest { @Test fun `copyChildOutputDirectory target output directory within itself throws DokkaException`() { val project = ProjectBuilder.builder().build() + project.plugins.apply("org.jetbrains.dokka") + val childTask = project.tasks.create<DokkaTask>("child") val parentTask = project.tasks.create<DokkaMultiModuleTask>("parent") parentTask.fileLayout.set(DokkaMultiModuleFileLayout { _, child -> - child.outputDirectory.get().resolve("subfolder") + child.outputDirectory.dir("subfolder") }) assertFailsWith<DokkaException> { parentTask.copyChildOutputDirectory(childTask) } } @@ -110,6 +124,8 @@ class DokkaMultiModuleFileLayoutTest { @Test fun `copyChildOutputDirectory NoCopy`() { val project = ProjectBuilder.builder().build() + project.plugins.apply("org.jetbrains.dokka") + val childTask = project.tasks.create<DokkaTask>("child") val parentTask = project.tasks.create<DokkaMultiModuleTask>("parent") parentTask.fileLayout.set(NoCopy) 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 52485cdc..fe6869e9 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 @@ -2,7 +2,8 @@ package org.jetbrains.dokka.gradle import org.gradle.kotlin.dsl.withType import org.gradle.testfixtures.ProjectBuilder -import org.jetbrains.dokka.DokkaSourceSetID +import org.jetbrains.dokka.gradle.utils.configureEach_ +import org.jetbrains.dokka.gradle.utils.create_ import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension import java.io.File import kotlin.test.Test @@ -13,12 +14,12 @@ class KotlinDslDokkaTaskConfigurationTest { fun `configure dokka task`() { val project = ProjectBuilder.builder().build() project.plugins.apply("org.jetbrains.dokka") - project.tasks.withType<DokkaTask>().configureEach { + project.tasks.withType<DokkaTask>().configureEach_ { outputDirectory.set(File("test")) } project.tasks.withType(DokkaTask::class.java).forEach { dokkaTask -> - assertEquals(File("test"), dokkaTask.outputDirectory.get()) + assertEquals(File("test"), dokkaTask.outputDirectory.get().asFile.relativeTo(project.projectDir)) } } @@ -30,7 +31,7 @@ class KotlinDslDokkaTaskConfigurationTest { project.tasks.withType(DokkaTask::class.java).forEach { dokkaTask -> dokkaTask.dokkaSourceSets.run { val commonMain = create("commonMain") - val jvmMain = create("jvmMain") { + val jvmMain = create_("jvmMain") { dependsOn("commonMain") } 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/tasks/DokkaCollectorTaskTest.kt index b9c20dce..3c7b58a0 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/tasks/DokkaCollectorTaskTest.kt @@ -1,10 +1,17 @@ -package org.jetbrains.dokka.gradle +package org.jetbrains.dokka.gradle.tasks 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.gradle.AbstractDokkaTask +import org.jetbrains.dokka.gradle.DokkaCollectorTask +import org.jetbrains.dokka.gradle.DokkaTask +import org.jetbrains.dokka.gradle.utils.all_ +import org.jetbrains.dokka.gradle.utils.allprojects_ +import org.jetbrains.dokka.gradle.utils.configureEach_ +import org.jetbrains.dokka.gradle.utils.withDependencies_ import java.io.File import kotlin.test.* @@ -16,20 +23,20 @@ class DokkaCollectorTaskTest { val childProject = ProjectBuilder.builder().withParent(rootProject).build() childProject.plugins.apply("org.jetbrains.kotlin.jvm") - rootProject.allprojects { + rootProject.allprojects_ { plugins.apply("org.jetbrains.dokka") - tasks.withType<AbstractDokkaTask>().configureEach { - plugins.withDependencies { clear() } + tasks.withType<AbstractDokkaTask>().configureEach_ { + plugins.withDependencies_ { clear() } } - tasks.withType<DokkaTask>().configureEach { - dokkaSourceSets.configureEach { + tasks.withType<DokkaTask>().configureEach_ { + dokkaSourceSets.configureEach_ { classpath.setFrom(emptyList<Any>()) } } } val collectorTasks = rootProject.tasks.withType<DokkaCollectorTask>() - collectorTasks.configureEach { + collectorTasks.configureEach_ { moduleName.set("custom Module Name") outputDirectory.set(File("customOutputDirectory")) cacheRoot.set(File("customCacheRoot")) @@ -44,8 +51,8 @@ class DokkaCollectorTaskTest { assertEquals( DokkaConfigurationImpl( moduleName = "custom Module Name", - outputDir = File("customOutputDirectory"), - cacheRoot = File("customCacheRoot"), + outputDir = rootProject.projectDir.resolve("customOutputDirectory"), + cacheRoot = rootProject.projectDir.resolve("customCacheRoot"), failOnWarning = true, offlineMode = true, sourceSets = task.childDokkaTasks @@ -67,20 +74,20 @@ class DokkaCollectorTaskTest { val childProject = ProjectBuilder.builder().withParent(rootProject).build() childProject.plugins.apply("org.jetbrains.kotlin.jvm") - rootProject.allprojects { + rootProject.allprojects_ { plugins.apply("org.jetbrains.dokka") - tasks.withType<AbstractDokkaTask>().configureEach { - plugins.withDependencies { clear() } + tasks.withType<AbstractDokkaTask>().configureEach_ { + plugins.withDependencies_ { clear() } } - tasks.withType<DokkaTask>().configureEach { - dokkaSourceSets.configureEach { + tasks.withType<DokkaTask>().configureEach_ { + dokkaSourceSets.configureEach_ { classpath.setFrom(emptyList<Any>()) } } } val collectorTasks = rootProject.tasks.withType<DokkaCollectorTask>() - collectorTasks.configureEach { + collectorTasks.configureEach_ { cacheRoot.set(null as File?) } @@ -96,7 +103,7 @@ class DokkaCollectorTaskTest { fun `with no child tasks throws DokkaException`() { val project = ProjectBuilder.builder().build() val collectorTask = project.tasks.create<DokkaCollectorTask>("collector") - project.configurations.all { withDependencies { clear() } } + project.configurations.all_ { withDependencies_ { clear() } } assertFailsWith<DokkaException> { collectorTask.generateDocumentation() } } } 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 index ecbe3355..6df809ff 100644 --- 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 @@ -6,6 +6,10 @@ import org.gradle.kotlin.dsl.create import org.gradle.kotlin.dsl.withType import org.gradle.testfixtures.ProjectBuilder import org.jetbrains.dokka.* +import org.jetbrains.dokka.gradle.utils.allprojects_ +import org.jetbrains.dokka.gradle.utils.configureEach_ +import org.jetbrains.dokka.gradle.utils.create_ +import org.jetbrains.dokka.gradle.utils.withDependencies_ import java.io.File import kotlin.test.* @@ -27,9 +31,11 @@ class DokkaMultiModuleTaskTest { } init { - rootProject.allprojects { - tasks.withType<AbstractDokkaTask>().configureEach { - plugins.withDependencies { clear() } + rootProject.plugins.apply("org.jetbrains.dokka") + childProject.plugins.apply("org.jetbrains.dokka") + rootProject.allprojects_ { + tasks.withType<AbstractDokkaTask>().configureEach_ { + plugins.withDependencies_ { clear() } } } } @@ -56,7 +62,7 @@ class DokkaMultiModuleTaskTest { childDokkaTask.apply { dokkaSourceSets.create("main") dokkaSourceSets.create("test") - dokkaSourceSets.configureEach { + dokkaSourceSets.configureEach_ { includes.from(include1, include2) } } @@ -84,7 +90,7 @@ class DokkaMultiModuleTaskTest { moduleName = "custom Module Name", moduleVersion = "1.5.0", outputDir = multiModuleTask.project.buildDir.resolve("customOutputDirectory"), - cacheRoot = File("customCacheRoot"), + cacheRoot = multiModuleTask.project.projectDir.resolve("customCacheRoot"), pluginsConfiguration = mutableListOf( PluginConfigurationImpl( "pluginA", @@ -101,7 +107,7 @@ class DokkaMultiModuleTaskTest { name = "child", relativePathToOutputDirectory = File("child"), includes = setOf(include1, include2), - sourceOutputDirectory = childDokkaTask.outputDirectory.get() + sourceOutputDirectory = childDokkaTask.outputDirectory.get().asFile ) ) ), @@ -151,7 +157,7 @@ class DokkaMultiModuleTaskTest { fun `multimodule task with no child tasks throws DokkaException`() { val project = ProjectBuilder.builder().build() val multimodule = project.tasks.create<DokkaMultiModuleTask>("multimodule") - project.configurations.configureEach { withDependencies { clear() } } + project.configurations.configureEach_ { withDependencies_ { clear() } } assertFailsWith<DokkaException> { multimodule.generateDocumentation() } } @@ -162,17 +168,17 @@ class DokkaMultiModuleTaskTest { val childDokkaTaskInclude3 = childProject.file("include3") childDokkaTask.apply { - dokkaSourceSets.create("main") { + dokkaSourceSets.create_("main") { includes.from(childDokkaTaskInclude1, childDokkaTaskInclude2) } - dokkaSourceSets.create("main2") { + dokkaSourceSets.create_("main2") { includes.from(childDokkaTaskInclude3) } } val secondChildDokkaTaskInclude = childProject.file("include4") val secondChildDokkaTask = childProject.tasks.create<DokkaTaskPartial>("secondChildDokkaTask") { - dokkaSourceSets.create("main") { + dokkaSourceSets.create_("main") { includes.from(secondChildDokkaTaskInclude) } } @@ -194,7 +200,9 @@ class DokkaMultiModuleTaskTest { @Test fun sourceChildOutputDirectories() { val parent = ProjectBuilder.builder().build() + parent.plugins.apply("org.jetbrains.dokka") val child = ProjectBuilder.builder().withName("child").withParent(parent).build() + child.plugins.apply("org.jetbrains.dokka") val parentTask = parent.tasks.create<DokkaMultiModuleTask>("parent") val childTask = child.tasks.create<DokkaTask>("child") @@ -203,7 +211,8 @@ class DokkaMultiModuleTaskTest { childTask.outputDirectory.set(child.file("custom/output")) assertEquals( - listOf(parent.file("child/custom/output")), parentTask.sourceChildOutputDirectories, + listOf(parent.file("child/custom/output")), + parentTask.sourceChildOutputDirectories.files.toList(), "Expected child output directory being present" ) } @@ -219,11 +228,12 @@ class DokkaMultiModuleTaskTest { parentTask.addChildTask(childTask) parentTask.fileLayout.set(DokkaMultiModuleFileLayout { taskParent, taskChild -> - taskParent.project.buildDir.resolve(taskChild.name) + taskParent.project.layout.buildDirectory.dir(taskChild.name) }) assertEquals( - listOf(parent.project.buildDir.resolve("child")), parentTask.targetChildOutputDirectories, + listOf(parent.project.buildDir.resolve("child")), + parentTask.targetChildOutputDirectories.get().map { it.asFile }, "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 index 518a01f1..79b80fa3 100644 --- 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 @@ -4,6 +4,9 @@ package org.jetbrains.dokka.gradle import org.gradle.kotlin.dsl.create import org.gradle.testfixtures.ProjectBuilder +import org.jetbrains.dokka.gradle.utils.all_ +import org.jetbrains.dokka.gradle.utils.register_ +import org.jetbrains.dokka.gradle.utils.withDependencies_ import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNull @@ -12,12 +15,14 @@ class DokkaTaskTest { @Test fun `no suppressed source sets are present after in built configuration`() { val project = ProjectBuilder.builder().build() + project.plugins.apply("org.jetbrains.dokka") + val task = project.tasks.create<DokkaTask>("dokkaTask") - project.configurations.all { withDependencies { clear() } } + project.configurations.all_ { withDependencies_ { clear() } } task.dokkaSourceSets.register("main") task.dokkaSourceSets.register("jvm") - task.dokkaSourceSets.register("test") { + task.dokkaSourceSets.register_("test") { suppress.set(true) } @@ -29,10 +34,12 @@ class DokkaTaskTest { } @Test - fun `module version is not present if not specified`(){ + fun `module version is not present if not specified`() { val project = ProjectBuilder.builder().build() + project.plugins.apply("org.jetbrains.dokka") + val task = project.tasks.create<DokkaTask>("dokkaTask") - project.configurations.all { withDependencies { clear() } } + 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/utils/samWithReceiverWorkarounds.kt b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/utils/samWithReceiverWorkarounds.kt new file mode 100644 index 00000000..4738f7d8 --- /dev/null +++ b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/utils/samWithReceiverWorkarounds.kt @@ -0,0 +1,69 @@ +package org.jetbrains.dokka.gradle.utils + +import org.gradle.api.* +import org.gradle.api.artifacts.Configuration +import org.gradle.api.artifacts.DependencySet +import org.jetbrains.dokka.gradle.GradleDokkaSourceSetBuilder +import org.jetbrains.dokka.gradle.GradleExternalDocumentationLinkBuilder + + +/** + * Workarounds because `SamWithReceiver` not working in test sources + * https://youtrack.jetbrains.com/issue/KTIJ-14684 + * + * The `SamWithReceiver` plugin is automatically applied by the `kotlin-dsl` plugin. + * It converts all [org.gradle.api.Action] so the parameter is the receiver: + * + * ``` + * // with SamWithReceiver ✅ + * tasks.configureEach { + * val task: Task = this + * } + * + * // without SamWithReceiver + * tasks.configureEach { it -> + * val task: Task = it + * } + * ``` + * + * This is nice because it means that the Dokka Gradle Plugin more closely matches `build.gradle.kts` files. + * + * However, [IntelliJ is bugged](https://youtrack.jetbrains.com/issue/KTIJ-14684) and doesn't + * acknowledge that `SamWithReceiver` has been applied in test sources. The code works and compiles, + * but IntelliJ shows red errors. + * + * These functions are workarounds, and should be removed ASAP. + */ +@Suppress("unused") +private object Explain + +fun Project.subprojects_(configure: Project.() -> Unit) = + subprojects(configure) + +@Suppress("SpellCheckingInspection") +fun Project.allprojects_(configure: Project.() -> Unit) = + allprojects(configure) + +fun <T> DomainObjectCollection<T>.configureEach_(configure: T.() -> Unit) = + configureEach(configure) + +fun <T> DomainObjectCollection<T>.all_(configure: T.() -> Unit) = + all(configure) + +fun Configuration.withDependencies_(action: DependencySet.() -> Unit): Configuration = + withDependencies(action) + + +fun <T> NamedDomainObjectContainer<T>.create_(name: String, configure: T.() -> Unit): T = + create(name, configure) + +fun <T> NamedDomainObjectContainer<T>.register_( + name: String, + configure: T.() -> Unit +): NamedDomainObjectProvider<T> = + register(name, configure) + + +fun GradleDokkaSourceSetBuilder.externalDocumentationLink_( + action: GradleExternalDocumentationLinkBuilder.() -> Unit +) = externalDocumentationLink(action) |