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

Gradle Plugin: Expose finalizeCoroutines as Gradle task option #2759

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Changes from 4 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
907fd7a
apply kotlin-dsl plugin, update code to use idiomatic Gradle API (clo…
aSemy Oct 11, 2022
9f1db10
Merge remote-tracking branch 'origin/master' into feat/apply_kotlin_d…
aSemy Oct 13, 2022
ebdb4e7
Merge remote-tracking branch 'origin/master' into feat/apply_kotlin_d…
aSemy Nov 4, 2022
fb08197
Merge branch 'feat/apply_kotlin_dsl_plugin' into feat/expose_finalize…
aSemy Nov 28, 2022
bdb6092
expose finalizeCoroutines as a Gradle Task option
aSemy Nov 28, 2022
e2c8f61
set finalizeCoroutines=false in serialization/coroutines integration …
aSemy Nov 30, 2022
2af1dcd
--init -> --init-script
aSemy Nov 30, 2022
5751ca1
publish dokka plugin before integration tests
aSemy Nov 30, 2022
3f5b27e
try fixing plugin version
aSemy Nov 30, 2022
db21caf
try fixing plugin publishing
aSemy Nov 30, 2022
cba6b41
try fixing plugin publishing
aSemy Nov 30, 2022
e9cd257
try fixing plugin publishing for integration tests...
aSemy Nov 30, 2022
fa05900
try fixing plugin publishing for integration tests...
aSemy Nov 30, 2022
c7ee570
try fixing plugin publishing for integration tests...
aSemy Nov 30, 2022
6f7c9cd
try fixing plugin publishing for integration tests...
aSemy Nov 30, 2022
cb05319
update qodana
aSemy Nov 30, 2022
ccd7d94
rm qodana code-finder (fails on pipeline: Unable to find image 'jetbr…
aSemy Nov 30, 2022
dbd6ebd
Merge branch 'master' into feat/expose_finalizeCoroutines_in_gradle
aSemy Dec 13, 2022
744598d
Merge branch 'master' into feat/expose_finalizeCoroutines_in_gradle
aSemy Dec 15, 2022
4f808b8
Merge remote-tracking branch 'origin/master' into feat/apply_kotlin_d…
aSemy Jan 28, 2023
24b4b98
Merge remote-tracking branch 'fork/aSemy/feat/apply_kotlin_dsl_plugin…
aSemy Jan 29, 2023
910a070
Merge remote-tracking branch 'origin/master' into feat/apply_kotlin_d…
aSemy Feb 1, 2023
0994afb
fix imports
aSemy Feb 1, 2023
1ea5b84
Merge branch 'feat/apply_kotlin_dsl_plugin' into feat/expose_finalize…
aSemy Feb 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions runners/gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ import org.jetbrains.*

plugins {
`java-gradle-plugin`
`kotlin-dsl`
id("com.gradle.plugin-publish") version "0.20.0"
}

Original file line number Diff line number Diff line change
@@ -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`.
@@ -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() }
}
Original file line number Diff line number Diff line change
@@ -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)
@@ -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)
}
}
}
Original file line number Diff line number Diff line change
@@ -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
@@ -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")
Original file line number Diff line number Diff line change
@@ -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")
}
}

Original file line number Diff line number Diff line change
@@ -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 }
}
}

Original file line number Diff line number Diff line change
@@ -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 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")
@@ -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() }
}
}
Original file line number Diff line number Diff line change
@@ -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
@@ -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)
}
}
}
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
Original file line number Diff line number Diff line change
@@ -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() }
}
}
}
@@ -56,7 +56,7 @@ class DokkaMultiModuleTaskTest {
dokkaSourceSets.create("main")
dokkaSourceSets.create("test")
dokkaSourceSets.configureEach {
it.includes.from(include1, include2)
includes.from(include1, include2)
}
}

@@ -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() }
}

@@ -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)
Original file line number Diff line number Diff line change
@@ -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(
@@ -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)
Original file line number Diff line number Diff line change
@@ -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> {
@@ -270,7 +270,7 @@ class GradleDokkaSourceSetBuilderTest {
})

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

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

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

sourceSet.externalDocumentationLink(project.closureOf<GradleExternalDocumentationLinkBuilder> {
Loading