From 0a09318eae5b21194507708af51a4469ec5d57aa Mon Sep 17 00:00:00 2001
From: aSemy <897017+aSemy@users.noreply.github.com>
Date: Tue, 21 Feb 2023 17:50:02 +0100
Subject: Apply kotlin-dsl plugin (#2702)

Update code to use idiomatic Gradle API
---
 .../dokka/gradle/AbstractDokkaParentTaskTest.kt    |  4 +--
 .../gradle/ConfigureWithKotlinSourceSetGistTest.kt |  6 ++--
 .../dokka/gradle/DokkaCollectorTaskTest.kt         | 32 ++++++++++++----------
 .../dokka/gradle/DokkaConfigurationJsonTest.kt     | 26 ++++++++----------
 .../gradle/DokkaConfigurationSerializableTest.kt   | 26 ++++++++----------
 .../dokka/gradle/DokkaMultiModuleTaskTest.kt       | 16 +++++------
 .../org/jetbrains/dokka/gradle/DokkaTaskTest.kt    |  6 ++--
 .../gradle/GradleDokkaSourceSetBuilderTest.kt      | 10 +++----
 .../gradle/KotlinDslDokkaTaskConfigurationTest.kt  |  8 +++---
 .../dokka/gradle/KotlinSourceSetGistTest.kt        |  4 +--
 10 files changed, 69 insertions(+), 69 deletions(-)

(limited to 'runners/gradle-plugin/src/test/kotlin/org')

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 173c0b53..2cac940f 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
@@ -19,8 +19,8 @@ class AbstractDokkaParentTaskTest {
     private val subSubproject0 = ProjectBuilder.builder().withName("subSubproject0").withParent(subproject0).build()
 
     init {
-        rootProject.subprojects { project ->
-            project.tasks.create<DokkaTask>("dokkaTask")
+        rootProject.subprojects {
+            tasks.create<DokkaTask>("dokkaTask")
         }
     }
 
diff --git a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/ConfigureWithKotlinSourceSetGistTest.kt b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/ConfigureWithKotlinSourceSetGistTest.kt
index c06a3992..c1e0c85b 100644
--- a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/ConfigureWithKotlinSourceSetGistTest.kt
+++ b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/ConfigureWithKotlinSourceSetGistTest.kt
@@ -95,9 +95,9 @@ class ConfigureWithKotlinSourceSetGistTest {
         mainSourceSet.kotlin.sourceDirectories.elements.get().map { it.asFile }.forEach { it.mkdirs() }
 
         /* Make sure to remove dependencies that cannot be resolved during test */
-        project.configurations.configureEach { configuration ->
-            configuration.withDependencies { dependencies ->
-                dependencies.removeIf { dependency -> dependency !is FileCollectionDependency }
+        project.configurations.configureEach {
+            withDependencies {
+                removeIf { dependency -> dependency !is FileCollectionDependency }
             }
         }
 
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 bb2b5c1f..d22dac90 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
@@ -4,6 +4,10 @@ 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.DokkaDefaults.cacheRoot
+import org.jetbrains.dokka.DokkaDefaults.failOnWarning
+import org.jetbrains.dokka.DokkaDefaults.moduleName
+import org.jetbrains.dokka.DokkaDefaults.offlineMode
 import org.jetbrains.dokka.DokkaException
 import java.io.File
 import kotlin.test.Test
@@ -19,25 +23,25 @@ class DokkaCollectorTaskTest {
         val childProject = ProjectBuilder.builder().withParent(rootProject).build()
         childProject.plugins.apply("org.jetbrains.kotlin.jvm")
 
-        rootProject.allprojects { project ->
-            project.plugins.apply("org.jetbrains.dokka")
-            project.tasks.withType<AbstractDokkaTask>().configureEach { task ->
-                task.plugins.withDependencies { dependencies -> dependencies.clear() }
+        rootProject.allprojects {
+            plugins.apply("org.jetbrains.dokka")
+            tasks.withType<AbstractDokkaTask>().configureEach {
+                plugins.withDependencies { clear() }
             }
-            project.tasks.withType<DokkaTask>().configureEach { task ->
-                task.dokkaSourceSets.configureEach { sourceSet ->
-                    sourceSet.classpath.setFrom(emptyList<Any>())
+            tasks.withType<DokkaTask>().configureEach {
+                dokkaSourceSets.configureEach {
+                    classpath.setFrom(emptyList<Any>())
                 }
             }
         }
 
         val collectorTasks = rootProject.tasks.withType<DokkaCollectorTask>()
-        collectorTasks.configureEach { task ->
-            task.moduleName.set("custom Module Name")
-            task.outputDirectory.set(File("customOutputDirectory"))
-            task.cacheRoot.set(File("customCacheRoot"))
-            task.failOnWarning.set(true)
-            task.offlineMode.set(true)
+        collectorTasks.configureEach {
+            moduleName.set("custom Module Name")
+            outputDirectory.set(File("customOutputDirectory"))
+            cacheRoot.set(File("customCacheRoot"))
+            failOnWarning.set(true)
+            offlineMode.set(true)
         }
 
         assertTrue(collectorTasks.isNotEmpty(), "Expected at least one collector task")
@@ -68,7 +72,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 { configuration -> configuration.withDependencies { it.clear() } }
+        project.configurations.all { withDependencies { 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 64aa1334..108c7fe0 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
@@ -15,9 +15,7 @@ class DokkaConfigurationJsonTest {
         val project = ProjectBuilder.builder().build()
         project.plugins.apply("org.jetbrains.dokka")
         val dokkaTask = project.tasks.withType<DokkaTask>().first()
-        dokkaTask.plugins.withDependencies { dependencies ->
-            dependencies.clear()
-        }
+        dokkaTask.plugins.withDependencies { clear() }
         dokkaTask.apply {
             this.failOnWarning.set(true)
             this.offlineMode.set(true)
@@ -29,19 +27,19 @@ class DokkaConfigurationJsonTest {
             this.pluginsConfiguration.add(
                 PluginConfigurationImpl("B", DokkaConfiguration.SerializationFormat.JSON, """ { "key" : "value2" } """)
             )
-            this.dokkaSourceSets.create("main") { sourceSet ->
-                sourceSet.displayName.set("customSourceSetDisplayName")
-                sourceSet.reportUndocumented.set(true)
+            this.dokkaSourceSets.create("main") {
+                displayName.set("customSourceSetDisplayName")
+                reportUndocumented.set(true)
 
-                sourceSet.externalDocumentationLink { link ->
-                    link.packageListUrl.set(URL("http://some.url"))
-                    link.url.set(URL("http://some.other.url"))
+                externalDocumentationLink {
+                    packageListUrl.set(URL("http://some.url"))
+                    url.set(URL("http://some.other.url"))
                 }
-                sourceSet.perPackageOption { packageOption ->
-                    packageOption.includeNonPublic.set(true)
-                    packageOption.reportUndocumented.set(true)
-                    packageOption.skipDeprecated.set(true)
-                    packageOption.documentedVisibilities.set(setOf(DokkaConfiguration.Visibility.PRIVATE))
+                perPackageOption {
+                    includeNonPublic.set(true)
+                    reportUndocumented.set(true)
+                    skipDeprecated.set(true)
+                    documentedVisibilities.set(setOf(DokkaConfiguration.Visibility.PRIVATE))
                 }
             }
         }
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 ac8f040e..75e2b63e 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
@@ -24,9 +24,7 @@ class DokkaConfigurationSerializableTest {
         val project = ProjectBuilder.builder().build()
         project.plugins.apply("org.jetbrains.dokka")
         val dokkaTask = project.tasks.withType<DokkaTask>().first()
-        dokkaTask.plugins.withDependencies { dependencies ->
-            dependencies.clear()
-        }
+        dokkaTask.plugins.withDependencies { clear() }
         dokkaTask.apply {
             this.failOnWarning.set(true)
             this.offlineMode.set(true)
@@ -34,20 +32,20 @@ class DokkaConfigurationSerializableTest {
             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") { sourceSet ->
-                sourceSet.displayName.set("customSourceSetDisplayName")
-                sourceSet.reportUndocumented.set(true)
+            this.dokkaSourceSets.create("main") {
+                displayName.set("customSourceSetDisplayName")
+                reportUndocumented.set(true)
 
-                sourceSet.externalDocumentationLink { link ->
-                    link.packageListUrl.set(URL("http://some.url"))
-                    link.url.set(URL("http://some.other.url"))
+                externalDocumentationLink {
+                    packageListUrl.set(URL("http://some.url"))
+                    url.set(URL("http://some.other.url"))
                 }
 
-                sourceSet.perPackageOption { packageOption ->
-                    packageOption.includeNonPublic.set(true)
-                    packageOption.reportUndocumented.set(true)
-                    packageOption.skipDeprecated.set(true)
-                    packageOption.documentedVisibilities.set(setOf(DokkaConfiguration.Visibility.PRIVATE))
+                perPackageOption {
+                    includeNonPublic.set(true)
+                    reportUndocumented.set(true)
+                    skipDeprecated.set(true)
+                    documentedVisibilities.set(setOf(DokkaConfiguration.Visibility.PRIVATE))
                 }
             }
         }
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 4bace6d0..c45d5da8 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
@@ -27,9 +27,9 @@ class DokkaMultiModuleTaskTest {
     }
 
     init {
-        rootProject.allprojects { project ->
-            project.tasks.withType<AbstractDokkaTask>().configureEach { task ->
-                task.plugins.withDependencies { dependencies -> dependencies.clear() }
+        rootProject.allprojects {
+            tasks.withType<AbstractDokkaTask>().configureEach {
+                plugins.withDependencies { clear() }
             }
         }
     }
@@ -57,7 +57,7 @@ class DokkaMultiModuleTaskTest {
             dokkaSourceSets.create("main")
             dokkaSourceSets.create("test")
             dokkaSourceSets.configureEach {
-                it.includes.from(include1, include2)
+                includes.from(include1, include2)
             }
         }
 
@@ -151,7 +151,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 { it.withDependencies { it.clear() } }
+        project.configurations.configureEach { withDependencies { clear() } }
         assertFailsWith<DokkaException> { multimodule.generateDocumentation() }
     }
 
@@ -163,17 +163,17 @@ class DokkaMultiModuleTaskTest {
 
         childDokkaTask.apply {
             dokkaSourceSets.create("main") {
-                it.includes.from(childDokkaTaskInclude1, childDokkaTaskInclude2)
+                includes.from(childDokkaTaskInclude1, childDokkaTaskInclude2)
             }
             dokkaSourceSets.create("main2") {
-                it.includes.from(childDokkaTaskInclude3)
+                includes.from(childDokkaTaskInclude3)
             }
         }
 
         val secondChildDokkaTaskInclude = childProject.file("include4")
         val secondChildDokkaTask = childProject.tasks.create<DokkaTaskPartial>("secondChildDokkaTask") {
             dokkaSourceSets.create("main") {
-                it.includes.from(secondChildDokkaTaskInclude)
+                includes.from(secondChildDokkaTaskInclude)
             }
         }
         multiModuleTask.addChildTask(secondChildDokkaTask)
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
index 85a320a8..31d14544 100644
--- 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
@@ -11,12 +11,12 @@ class DokkaTaskTest {
     fun `no suppressed source sets are present after in built configuration`() {
         val project = ProjectBuilder.builder().build()
         val task = project.tasks.create<DokkaTask>("dokkaTask")
-        project.configurations.all { configuration -> configuration.withDependencies { it.clear() } }
+        project.configurations.all { withDependencies { clear() } }
 
         task.dokkaSourceSets.register("main")
         task.dokkaSourceSets.register("jvm")
         task.dokkaSourceSets.register("test") {
-            it.suppress.set(true)
+            suppress.set(true)
         }
 
         assertEquals(
@@ -30,7 +30,7 @@ class DokkaTaskTest {
     fun `module version is not present if not specified`(){
         val project = ProjectBuilder.builder().build()
         val task = project.tasks.create<DokkaTask>("dokkaTask")
-        project.configurations.all { configuration -> configuration.withDependencies { it.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/GradleDokkaSourceSetBuilderTest.kt b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/GradleDokkaSourceSetBuilderTest.kt
index e0476c1f..fb834ff8 100644
--- a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/GradleDokkaSourceSetBuilderTest.kt
+++ b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/GradleDokkaSourceSetBuilderTest.kt
@@ -225,9 +225,9 @@ class GradleDokkaSourceSetBuilderTest {
             })
 
         sourceSet.sourceLink {
-            it.remoteLineSuffix.set("ls2")
-            it.localDirectory.set(project.file("p2"))
-            it.remoteUrl.set(URL("https://u2"))
+            remoteLineSuffix.set("ls2")
+            localDirectory.set(project.file("p2"))
+            remoteUrl.set(URL("https://u2"))
         }
 
         sourceSet.sourceLink(project.closureOf<GradleSourceLinkBuilder> {
@@ -269,7 +269,7 @@ class GradleDokkaSourceSetBuilderTest {
         })
 
         sourceSet.perPackageOption {
-            it.matchingRegex.set("p2.*")
+            matchingRegex.set("p2.*")
         }
 
         sourceSet.perPackageOption(project.closureOf<GradlePackageOptionsBuilder> {
@@ -311,7 +311,7 @@ class GradleDokkaSourceSetBuilderTest {
         )
 
         sourceSet.externalDocumentationLink {
-            it.url.set(URL("https://u2"))
+            url.set(URL("https://u2"))
         }
 
         sourceSet.externalDocumentationLink(project.closureOf<GradleExternalDocumentationLinkBuilder> {
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 58b86495..e5b8d091 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
@@ -14,7 +14,7 @@ class KotlinDslDokkaTaskConfigurationTest {
         val project = ProjectBuilder.builder().build()
         project.plugins.apply("org.jetbrains.dokka")
         project.tasks.withType<DokkaTask>().configureEach {
-            it.outputDirectory.set(File("test"))
+            outputDirectory.set(File("test"))
         }
 
         project.tasks.withType(DokkaTask::class.java).forEach { dokkaTask ->
@@ -31,7 +31,7 @@ class KotlinDslDokkaTaskConfigurationTest {
             dokkaTask.dokkaSourceSets.run {
                 val commonMain = create("commonMain")
                 val jvmMain = create("jvmMain") {
-                    it.dependsOn("commonMain")
+                    dependsOn("commonMain")
                 }
 
                 assertEquals(
@@ -65,7 +65,7 @@ class KotlinDslDokkaTaskConfigurationTest {
             dokkaSourceSets.run {
                 val commonMain = create("commonMain")
                 val jvmMain = create("jvmMain") {
-                    it.dependsOn(commonMain)
+                    dependsOn(commonMain)
                 }
 
                 assertEquals(
@@ -86,7 +86,7 @@ class KotlinDslDokkaTaskConfigurationTest {
         project.tasks.withType(DokkaTask::class.java).first().apply {
             dokkaSourceSets.run {
                 val special = create("special") {
-                    it.dependsOn(kotlin.sourceSets.getByName("main"))
+                    dependsOn(kotlin.sourceSets.getByName("main"))
                 }
 
                 assertEquals(
diff --git a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/KotlinSourceSetGistTest.kt b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/KotlinSourceSetGistTest.kt
index bf3da6ef..dcb537dd 100644
--- a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/KotlinSourceSetGistTest.kt
+++ b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/KotlinSourceSetGistTest.kt
@@ -117,8 +117,8 @@ class KotlinSourceSetGistTest {
 
         /* Only work with file dependencies */
         project.configurations.forEach { configuration ->
-            configuration.withDependencies { dependencies ->
-                dependencies.removeIf { dependency ->
+            configuration.withDependencies {
+                removeIf { dependency ->
                     dependency !is FileCollectionDependency
                 }
             }
-- 
cgit