Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apply kotlin-dsl plugin #2702

Merged
merged 7 commits into from Feb 21, 2023
1 change: 1 addition & 0 deletions runners/gradle-plugin/build.gradle.kts
Expand Up @@ -3,6 +3,7 @@ import org.jetbrains.*

plugins {
`java-gradle-plugin`
aSemy marked this conversation as resolved.
Show resolved Hide resolved
aSemy marked this conversation as resolved.
Show resolved Hide resolved
`kotlin-dsl`
id("com.gradle.plugin-publish") version "0.20.0"
}

Expand Down
Expand Up @@ -4,22 +4,22 @@ import org.gradle.api.NamedDomainObjectContainer
import org.gradle.api.internal.plugins.DslObject
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.Nested
import org.gradle.kotlin.dsl.container
import org.gradle.work.DisableCachingByDefault

@DisableCachingByDefault(because = "Abstract super-class, not to be instantiated directly")
abstract class AbstractDokkaLeafTask : AbstractDokkaTask() {

@get:Internal
val dokkaSourceSets: NamedDomainObjectContainer<GradleDokkaSourceSetBuilder> =
project.container(GradleDokkaSourceSetBuilder::class.java, gradleDokkaSourceSetBuilderFactory())
.also { container ->
DslObject(this).extensions.add("dokkaSourceSets", container)
project.kotlinOrNull?.sourceSets?.all { kotlinSourceSet ->
container.register(kotlinSourceSet.name) { dokkaSourceSet ->
dokkaSourceSet.configureWithKotlinSourceSet(kotlinSourceSet)
}
project.container(GradleDokkaSourceSetBuilder::class, gradleDokkaSourceSetBuilderFactory()).also { container ->
DslObject(this).extensions.add("dokkaSourceSets", container)
project.kotlinOrNull?.sourceSets?.all sourceSet@{
container.register(name) {
configureWithKotlinSourceSet(this@sourceSet)
}
}
}

/**
* Only contains source sets that are marked with `isDocumented`.
Expand All @@ -29,7 +29,7 @@ abstract class AbstractDokkaLeafTask : AbstractDokkaTask() {
@get:Nested
protected val unsuppressedSourceSets: List<GradleDokkaSourceSetBuilder>
get() = dokkaSourceSets
.toList()
.also(::checkSourceSetDependencies)
.filterNot { it.suppress.getSafe() }
.toList()
.also(::checkSourceSetDependencies)
.filterNot { it.suppress.getSafe() }
}
Expand Up @@ -4,25 +4,26 @@ import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.Dependency
import org.gradle.api.attributes.Usage
import org.gradle.kotlin.dsl.named

internal fun Project.maybeCreateDokkaDefaultPluginConfiguration(): Configuration {
return configurations.maybeCreate("dokkaPlugin") {
attributes.attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage::class.java, "java-runtime"))
attributes.attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage.JAVA_RUNTIME))
isCanBeConsumed = false
}
}

internal fun Project.maybeCreateDokkaDefaultRuntimeConfiguration(): Configuration {
return configurations.maybeCreate("dokkaRuntime") {
attributes.attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage::class.java, "java-runtime"))
attributes.attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage.JAVA_RUNTIME))
isCanBeConsumed = false
}
}

internal fun Project.maybeCreateDokkaPluginConfiguration(dokkaTaskName: String, additionalDependencies: Collection<Dependency> = emptySet()): Configuration {
return project.configurations.maybeCreate("${dokkaTaskName}Plugin") {
extendsFrom(maybeCreateDokkaDefaultPluginConfiguration())
attributes.attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage::class.java, "java-runtime"))
attributes.attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage.JAVA_RUNTIME))
isCanBeConsumed = false
dependencies.add(project.dokkaArtifacts.dokkaAnalysis) // compileOnly in base plugin
dependencies.add(project.dokkaArtifacts.dokkaBase)
Expand All @@ -33,10 +34,10 @@ internal fun Project.maybeCreateDokkaPluginConfiguration(dokkaTaskName: String,
internal fun Project.maybeCreateDokkaRuntimeConfiguration(dokkaTaskName: String): Configuration {
return project.configurations.maybeCreate("${dokkaTaskName}Runtime") {
extendsFrom(maybeCreateDokkaDefaultRuntimeConfiguration())
attributes.attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage::class.java, "java-runtime"))
attributes.attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage.JAVA_RUNTIME))
isCanBeConsumed = false
defaultDependencies { dependencies ->
dependencies.add(project.dokkaArtifacts.dokkaCore)
defaultDependencies {
add(project.dokkaArtifacts.dokkaCore)
}
}
}
Expand Up @@ -6,6 +6,7 @@ import org.gradle.api.UnknownDomainObjectException
import org.gradle.api.provider.HasMultipleValues
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import org.gradle.kotlin.dsl.*
import org.gradle.util.Path
import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
Expand All @@ -31,13 +32,13 @@ internal fun parsePath(path: String): Path = Path.path(path)

internal val Project.kotlinOrNull: KotlinProjectExtension?
get() = try {
project.extensions.findByType(KotlinProjectExtension::class.java)
project.extensions.findByType()
} catch (e: NoClassDefFoundError) {
null
}

internal val Project.kotlin: KotlinProjectExtension
get() = project.extensions.getByType(KotlinProjectExtension::class.java)
get() = project.extensions.getByType()

internal fun Project.isAndroidProject() = try {
project.extensions.getByName("android")
Expand Down
Expand Up @@ -18,8 +18,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")
}
}

Expand Down
Expand Up @@ -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 }
}
}

Expand Down
Expand Up @@ -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
Expand All @@ -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 by "custom Module Name"
task.outputDirectory by File("customOutputDirectory")
task.cacheRoot by File("customCacheRoot")
task.failOnWarning by true
task.offlineMode by true
collectorTasks.configureEach {
moduleName by "custom Module Name"
outputDirectory by File("customOutputDirectory")
cacheRoot by File("customCacheRoot")
failOnWarning by true
offlineMode by true
}

assertTrue(collectorTasks.isNotEmpty(), "Expected at least one collector task")
Expand Down Expand Up @@ -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() }
}
}
Expand Up @@ -5,6 +5,7 @@ package org.jetbrains.dokka.gradle
import org.gradle.kotlin.dsl.withType
import org.gradle.testfixtures.ProjectBuilder
import org.jetbrains.dokka.*
import org.jetbrains.dokka.DokkaDefaults.reportUndocumented
import java.io.File
import java.net.URL
import kotlin.test.Test
Expand All @@ -17,29 +18,27 @@ 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 by true
this.offlineMode by true
this.outputDirectory by File("customOutputDir")
this.cacheRoot by 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 by "customSourceSetDisplayName"
sourceSet.reportUndocumented by true
this.dokkaSourceSets.create("main") {
displayName by "customSourceSetDisplayName"
reportUndocumented by true

sourceSet.externalDocumentationLink { link ->
link.packageListUrl by URL("http://some.url")
link.url by URL("http://some.other.url")
externalDocumentationLink {
packageListUrl by URL("http://some.url")
url by URL("http://some.other.url")
}
sourceSet.perPackageOption { packageOption ->
packageOption.includeNonPublic by true
packageOption.reportUndocumented by true
packageOption.skipDeprecated by true
packageOption.documentedVisibilities by setOf(DokkaConfiguration.Visibility.PRIVATE)
perPackageOption {
includeNonPublic by true
reportUndocumented by true
skipDeprecated by true
documentedVisibilities by setOf(DokkaConfiguration.Visibility.PRIVATE)
}
}
}
Expand Down
Expand Up @@ -25,30 +25,28 @@ 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 by true
this.offlineMode by true
this.outputDirectory by File("customOutputDir")
this.cacheRoot by 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 by "customSourceSetDisplayName"
sourceSet.reportUndocumented by true
this.dokkaSourceSets.create("main") {
displayName by "customSourceSetDisplayName"
reportUndocumented by true

sourceSet.externalDocumentationLink { link ->
link.packageListUrl by URL("http://some.url")
link.url by URL("http://some.other.url")
externalDocumentationLink {
packageListUrl by URL("http://some.url")
url by URL("http://some.other.url")
}

sourceSet.perPackageOption { packageOption ->
packageOption.includeNonPublic by true
packageOption.reportUndocumented by true
packageOption.skipDeprecated by true
packageOption.documentedVisibilities by setOf(DokkaConfiguration.Visibility.PRIVATE)
perPackageOption {
includeNonPublic by true
reportUndocumented by true
skipDeprecated by true
documentedVisibilities by setOf(DokkaConfiguration.Visibility.PRIVATE)
}
}
}
Expand Down
Expand Up @@ -26,9 +26,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() }
}
}
}
Expand Down Expand Up @@ -56,7 +56,7 @@ class DokkaMultiModuleTaskTest {
dokkaSourceSets.create("main")
dokkaSourceSets.create("test")
dokkaSourceSets.configureEach {
it.includes.from(include1, include2)
includes.from(include1, include2)
}
}

Expand Down Expand Up @@ -135,7 +135,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() }
}

Expand All @@ -147,17 +147,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)
Expand Down
Expand Up @@ -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 by true
suppress by true
}

assertEquals(
Expand All @@ -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)
Expand Down
Expand Up @@ -226,9 +226,9 @@ class GradleDokkaSourceSetBuilderTest {
})

sourceSet.sourceLink {
it.remoteLineSuffix by "ls2"
it.localDirectory by project.file("p2")
it.remoteUrl by URL("https://u2")
remoteLineSuffix by "ls2"
localDirectory by project.file("p2")
remoteUrl by URL("https://u2")
}

sourceSet.sourceLink(project.closureOf<GradleSourceLinkBuilder> {
Expand Down Expand Up @@ -270,7 +270,7 @@ class GradleDokkaSourceSetBuilderTest {
})

sourceSet.perPackageOption {
it.matchingRegex by "p2.*"
matchingRegex by "p2.*"
}

sourceSet.perPackageOption(project.closureOf<GradlePackageOptionsBuilder> {
Expand Down Expand Up @@ -312,7 +312,7 @@ class GradleDokkaSourceSetBuilderTest {
)

sourceSet.externalDocumentationLink {
it.url by URL("https://u2")
url by URL("https://u2")
}

sourceSet.externalDocumentationLink(project.closureOf<GradleExternalDocumentationLinkBuilder> {
Expand Down