From 156faa32a9cd04acf777d083ad1a000eea3e569e Mon Sep 17 00:00:00 2001 From: Sebastiano Poggi Date: Wed, 25 Oct 2023 12:04:13 +0100 Subject: [PATCH 1/3] Use new plugin format for existing plugins --- buildSrc/build.gradle.kts | 13 ------ ...droid-studio-releases-generator.gradle.kts | 38 +++++++++++++++ .../intellij-theme-generator.gradle.kts | 40 ++++++++++++++++ ...atorPlugin.kt => AndroidStudioReleases.kt} | 46 +------------------ .../theme/IntelliJThemeGeneratorPlugin.kt | 44 ------------------ 5 files changed, 80 insertions(+), 101 deletions(-) create mode 100644 buildSrc/src/main/kotlin/android-studio-releases-generator.gradle.kts create mode 100644 buildSrc/src/main/kotlin/intellij-theme-generator.gradle.kts rename buildSrc/src/main/kotlin/org/jetbrains/jewel/buildlogic/demodata/{AndroidStudioReleasesGeneratorPlugin.kt => AndroidStudioReleases.kt} (57%) diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 11c2ce89b..684c247ee 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -3,19 +3,6 @@ plugins { alias(libs.plugins.kotlinx.serialization) } -gradlePlugin { - plugins { - register("intellij-theme-generator") { - id = "intellij-theme-generator" - implementationClass = "org.jetbrains.jewel.buildlogic.theme.IntelliJThemeGeneratorPlugin" - } - register("android-studio-releases-generator") { - id = "android-studio-releases-generator" - implementationClass = "org.jetbrains.jewel.buildlogic.demodata.AndroidStudioReleasesGeneratorPlugin" - } - } -} - kotlin { sourceSets { all { diff --git a/buildSrc/src/main/kotlin/android-studio-releases-generator.gradle.kts b/buildSrc/src/main/kotlin/android-studio-releases-generator.gradle.kts new file mode 100644 index 000000000..7d3e17723 --- /dev/null +++ b/buildSrc/src/main/kotlin/android-studio-releases-generator.gradle.kts @@ -0,0 +1,38 @@ +import com.squareup.kotlinpoet.ClassName +import io.gitlab.arturbosch.detekt.Detekt +import org.gradle.kotlin.dsl.get +import org.gradle.kotlin.dsl.getByType +import org.gradle.kotlin.dsl.register +import org.gradle.kotlin.dsl.withType +import org.jetbrains.jewel.buildlogic.demodata.AndroidStudioReleasesGeneratorTask +import org.jetbrains.jewel.buildlogic.demodata.STUDIO_RELEASES_OUTPUT_CLASS_NAME +import org.jetbrains.jewel.buildlogic.demodata.StudioVersionsGenerationExtension +import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension +import org.jetbrains.kotlin.gradle.tasks.BaseKotlinCompile + +val extension = extensions.findByType(StudioVersionsGenerationExtension::class.java) + ?: extensions.create("androidStudioReleasesGenerator", StudioVersionsGenerationExtension::class.java) + +val task = + tasks.register("generateAndroidStudioReleasesList") { + val className = ClassName.bestGuess(STUDIO_RELEASES_OUTPUT_CLASS_NAME) + outputFile.set( + extension.targetDir.file( + className.packageName.replace(".", "/") + .plus("/${className.simpleName}.kt") + ) + ) + dataUrl.set(extension.dataUrl) + resourcesDirs.set(extension.resourcesDirs) + } +tasks.withType { + dependsOn(task) +} +tasks.withType { + dependsOn(task) +} +pluginManager.withPlugin("org.jetbrains.kotlin.jvm") { + extensions.getByType().apply { + sourceSets["main"].kotlin.srcDir(extension.targetDir) + } +} diff --git a/buildSrc/src/main/kotlin/intellij-theme-generator.gradle.kts b/buildSrc/src/main/kotlin/intellij-theme-generator.gradle.kts new file mode 100644 index 000000000..788b83011 --- /dev/null +++ b/buildSrc/src/main/kotlin/intellij-theme-generator.gradle.kts @@ -0,0 +1,40 @@ +import com.squareup.kotlinpoet.ClassName +import io.gitlab.arturbosch.detekt.Detekt +import org.gradle.kotlin.dsl.container +import org.gradle.kotlin.dsl.get +import org.gradle.kotlin.dsl.getByType +import org.gradle.kotlin.dsl.register +import org.gradle.kotlin.dsl.withType +import org.gradle.util.internal.GUtil +import org.jetbrains.jewel.buildlogic.theme.IntelliJThemeGeneratorTask +import org.jetbrains.jewel.buildlogic.theme.ThemeGeneration +import org.jetbrains.jewel.buildlogic.theme.ThemeGeneratorContainer +import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension +import org.jetbrains.kotlin.gradle.tasks.BaseKotlinCompile + +val extension = ThemeGeneratorContainer(container { ThemeGeneration(it, project) }) +extensions.add("intelliJThemeGenerator", extension) + +extension.all { + val task = tasks.register("generate${GUtil.toCamelCase(name)}Theme") { + outputFile.set(targetDir.file(this@all.themeClassName.map { + val className = ClassName.bestGuess(it) + className.packageName.replace(".", "/") + .plus("/${className.simpleName}.kt") + })) + themeClassName.set(this@all.themeClassName) + ideaVersion.set(this@all.ideaVersion) + themeFile.set(this@all.themeFile) + } + tasks.withType { + dependsOn(task) + } + tasks.withType { + dependsOn(task) + } + pluginManager.withPlugin("org.jetbrains.kotlin.jvm") { + extensions.getByType().apply { + sourceSets["main"].kotlin.srcDir(targetDir) + } + } +} diff --git a/buildSrc/src/main/kotlin/org/jetbrains/jewel/buildlogic/demodata/AndroidStudioReleasesGeneratorPlugin.kt b/buildSrc/src/main/kotlin/org/jetbrains/jewel/buildlogic/demodata/AndroidStudioReleases.kt similarity index 57% rename from buildSrc/src/main/kotlin/org/jetbrains/jewel/buildlogic/demodata/AndroidStudioReleasesGeneratorPlugin.kt rename to buildSrc/src/main/kotlin/org/jetbrains/jewel/buildlogic/demodata/AndroidStudioReleases.kt index 3647105de..3116ca3da 100644 --- a/buildSrc/src/main/kotlin/org/jetbrains/jewel/buildlogic/demodata/AndroidStudioReleasesGeneratorPlugin.kt +++ b/buildSrc/src/main/kotlin/org/jetbrains/jewel/buildlogic/demodata/AndroidStudioReleases.kt @@ -3,11 +3,9 @@ package org.jetbrains.jewel.buildlogic.demodata import com.squareup.kotlinpoet.ClassName import gradle.kotlin.dsl.accessors._c011fd04eb69b06af6f445fec200c5f6.main import gradle.kotlin.dsl.accessors._c011fd04eb69b06af6f445fec200c5f6.sourceSets -import io.gitlab.arturbosch.detekt.Detekt import kotlinx.serialization.json.Json import kotlinx.serialization.json.decodeFromStream import org.gradle.api.DefaultTask -import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.file.DirectoryProperty import org.gradle.api.file.RegularFileProperty @@ -16,51 +14,11 @@ import org.gradle.api.provider.SetProperty import org.gradle.api.tasks.Input import org.gradle.api.tasks.OutputFile import org.gradle.api.tasks.TaskAction -import org.gradle.kotlin.dsl.get -import org.gradle.kotlin.dsl.getByType import org.gradle.kotlin.dsl.property -import org.gradle.kotlin.dsl.register import org.gradle.kotlin.dsl.setProperty -import org.gradle.kotlin.dsl.withType -import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension -import org.jetbrains.kotlin.gradle.tasks.BaseKotlinCompile import java.io.File import java.net.URL -abstract class AndroidStudioReleasesGeneratorPlugin : Plugin { - - final override fun apply(target: Project) { - with(target) { - val extension = extensions.findByType(StudioVersionsGenerationExtension::class.java) - ?: extensions.create("androidStudioReleasesGenerator", StudioVersionsGenerationExtension::class.java) - - val task = - tasks.register("generateAndroidStudioReleasesList") { - val className = ClassName.bestGuess(OUTPUT_CLASS_NAME) - outputFile.set( - extension.targetDir.file( - className.packageName.replace(".", "/") - .plus("/${className.simpleName}.kt") - ) - ) - dataUrl.set(extension.dataUrl) - resourcesDirs.set(extension.resourcesDirs) - } - tasks.withType { - dependsOn(task) - } - tasks.withType { - dependsOn(task) - } - pluginManager.withPlugin("org.jetbrains.kotlin.jvm") { - extensions.getByType().apply { - sourceSets["main"].kotlin.srcDir(extension.targetDir) - } - } - } - } -} - open class StudioVersionsGenerationExtension(project: Project) { val targetDir: DirectoryProperty = project.objects.directoryProperty() @@ -73,7 +31,7 @@ open class StudioVersionsGenerationExtension(project: Project) { .convention("https://jb.gg/android-studio-releases-list.json") } -private const val OUTPUT_CLASS_NAME = "org.jetbrains.jewel.samples.ideplugin.releasessample.AndroidStudioReleases" +internal const val STUDIO_RELEASES_OUTPUT_CLASS_NAME = "org.jetbrains.jewel.samples.ideplugin.releasessample.AndroidStudioReleases" open class AndroidStudioReleasesGeneratorTask : DefaultTask() { @@ -107,7 +65,7 @@ open class AndroidStudioReleasesGeneratorTask : DefaultTask() { val releases = URL(url).openStream() .use { json.decodeFromStream(it) } - val className = ClassName.bestGuess(OUTPUT_CLASS_NAME) + val className = ClassName.bestGuess(STUDIO_RELEASES_OUTPUT_CLASS_NAME) val file = AndroidStudioReleasesReader.readFrom(releases, className, url, lookupDirs) val outputFile = outputFile.get().asFile diff --git a/buildSrc/src/main/kotlin/org/jetbrains/jewel/buildlogic/theme/IntelliJThemeGeneratorPlugin.kt b/buildSrc/src/main/kotlin/org/jetbrains/jewel/buildlogic/theme/IntelliJThemeGeneratorPlugin.kt index a77427a20..f3d908765 100644 --- a/buildSrc/src/main/kotlin/org/jetbrains/jewel/buildlogic/theme/IntelliJThemeGeneratorPlugin.kt +++ b/buildSrc/src/main/kotlin/org/jetbrains/jewel/buildlogic/theme/IntelliJThemeGeneratorPlugin.kt @@ -1,65 +1,21 @@ package org.jetbrains.jewel.buildlogic.theme import com.squareup.kotlinpoet.ClassName -import io.gitlab.arturbosch.detekt.Detekt import kotlinx.serialization.Serializable import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonElement import kotlinx.serialization.json.decodeFromStream import org.gradle.api.DefaultTask import org.gradle.api.NamedDomainObjectContainer -import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.file.DirectoryProperty import org.gradle.api.file.RegularFileProperty import org.gradle.api.tasks.Input import org.gradle.api.tasks.OutputFile import org.gradle.api.tasks.TaskAction -import org.gradle.kotlin.dsl.container -import org.gradle.kotlin.dsl.get -import org.gradle.kotlin.dsl.getByType import org.gradle.kotlin.dsl.property -import org.gradle.kotlin.dsl.register -import org.gradle.kotlin.dsl.withType -import org.gradle.util.internal.GUtil -import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension -import org.jetbrains.kotlin.gradle.tasks.BaseKotlinCompile import java.net.URL -abstract class IntelliJThemeGeneratorPlugin : Plugin { - - final override fun apply(target: Project) { - with(target) { - val extension = ThemeGeneratorContainer(container { ThemeGeneration(it, project) }) - extensions.add("intelliJThemeGenerator", extension) - - extension.all { - val task = tasks.register("generate${GUtil.toCamelCase(name)}Theme") { - outputFile.set(targetDir.file(this@all.themeClassName.map { - val className = ClassName.bestGuess(it) - className.packageName.replace(".", "/") - .plus("/${className.simpleName}.kt") - })) - themeClassName.set(this@all.themeClassName) - ideaVersion.set(this@all.ideaVersion) - themeFile.set(this@all.themeFile) - } - tasks.withType { - dependsOn(task) - } - tasks.withType { - dependsOn(task) - } - pluginManager.withPlugin("org.jetbrains.kotlin.jvm") { - extensions.getByType().apply { - sourceSets["main"].kotlin.srcDir(targetDir) - } - } - } - } - } -} - class ThemeGeneratorContainer(container: NamedDomainObjectContainer) : NamedDomainObjectContainer by container class ThemeGeneration(val name: String, project: Project) { From d0b65f0b3590f667592b6037ce9b1dfddf011e58 Mon Sep 17 00:00:00 2001 From: Sebastiano Poggi Date: Wed, 25 Oct 2023 12:11:43 +0100 Subject: [PATCH 2/3] Use Kotlin setters --- ...droid-studio-releases-generator.gradle.kts | 38 ++++++++++--------- .../intellij-theme-generator.gradle.kts | 32 ++++++++-------- .../kotlin/jewel-check-public-api.gradle.kts | 4 +- 3 files changed, 40 insertions(+), 34 deletions(-) diff --git a/buildSrc/src/main/kotlin/android-studio-releases-generator.gradle.kts b/buildSrc/src/main/kotlin/android-studio-releases-generator.gradle.kts index 7d3e17723..f49a02976 100644 --- a/buildSrc/src/main/kotlin/android-studio-releases-generator.gradle.kts +++ b/buildSrc/src/main/kotlin/android-studio-releases-generator.gradle.kts @@ -1,36 +1,38 @@ +@file:Suppress("UnstableApiUsage") + import com.squareup.kotlinpoet.ClassName import io.gitlab.arturbosch.detekt.Detekt -import org.gradle.kotlin.dsl.get -import org.gradle.kotlin.dsl.getByType -import org.gradle.kotlin.dsl.register -import org.gradle.kotlin.dsl.withType import org.jetbrains.jewel.buildlogic.demodata.AndroidStudioReleasesGeneratorTask import org.jetbrains.jewel.buildlogic.demodata.STUDIO_RELEASES_OUTPUT_CLASS_NAME import org.jetbrains.jewel.buildlogic.demodata.StudioVersionsGenerationExtension import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension import org.jetbrains.kotlin.gradle.tasks.BaseKotlinCompile -val extension = extensions.findByType(StudioVersionsGenerationExtension::class.java) - ?: extensions.create("androidStudioReleasesGenerator", StudioVersionsGenerationExtension::class.java) +val extension: StudioVersionsGenerationExtension = + extensions.findByType(StudioVersionsGenerationExtension::class.java) + ?: extensions.create("androidStudioReleasesGenerator", StudioVersionsGenerationExtension::class.java) val task = tasks.register("generateAndroidStudioReleasesList") { val className = ClassName.bestGuess(STUDIO_RELEASES_OUTPUT_CLASS_NAME) - outputFile.set( - extension.targetDir.file( - className.packageName.replace(".", "/") - .plus("/${className.simpleName}.kt") - ) + outputFile = extension.targetDir.file( + className.packageName.replace(".", "/") + .plus("/${className.simpleName}.kt") ) - dataUrl.set(extension.dataUrl) - resourcesDirs.set(extension.resourcesDirs) + dataUrl = extension.dataUrl + resourcesDirs = extension.resourcesDirs + } + +tasks { + withType { + dependsOn(task) + } + + withType { + dependsOn(task) } -tasks.withType { - dependsOn(task) -} -tasks.withType { - dependsOn(task) } + pluginManager.withPlugin("org.jetbrains.kotlin.jvm") { extensions.getByType().apply { sourceSets["main"].kotlin.srcDir(extension.targetDir) diff --git a/buildSrc/src/main/kotlin/intellij-theme-generator.gradle.kts b/buildSrc/src/main/kotlin/intellij-theme-generator.gradle.kts index 788b83011..3cc99b7c6 100644 --- a/buildSrc/src/main/kotlin/intellij-theme-generator.gradle.kts +++ b/buildSrc/src/main/kotlin/intellij-theme-generator.gradle.kts @@ -1,10 +1,7 @@ +@file:Suppress("UnstableApiUsage") + import com.squareup.kotlinpoet.ClassName import io.gitlab.arturbosch.detekt.Detekt -import org.gradle.kotlin.dsl.container -import org.gradle.kotlin.dsl.get -import org.gradle.kotlin.dsl.getByType -import org.gradle.kotlin.dsl.register -import org.gradle.kotlin.dsl.withType import org.gradle.util.internal.GUtil import org.jetbrains.jewel.buildlogic.theme.IntelliJThemeGeneratorTask import org.jetbrains.jewel.buildlogic.theme.ThemeGeneration @@ -17,21 +14,26 @@ extensions.add("intelliJThemeGenerator", extension) extension.all { val task = tasks.register("generate${GUtil.toCamelCase(name)}Theme") { - outputFile.set(targetDir.file(this@all.themeClassName.map { + outputFile = targetDir.file(this@all.themeClassName.map { val className = ClassName.bestGuess(it) className.packageName.replace(".", "/") .plus("/${className.simpleName}.kt") - })) - themeClassName.set(this@all.themeClassName) - ideaVersion.set(this@all.ideaVersion) - themeFile.set(this@all.themeFile) - } - tasks.withType { - dependsOn(task) + }) + themeClassName = this@all.themeClassName + ideaVersion = this@all.ideaVersion + themeFile = this@all.themeFile } - tasks.withType { - dependsOn(task) + + tasks { + withType { + dependsOn(task) + } + + withType { + dependsOn(task) + } } + pluginManager.withPlugin("org.jetbrains.kotlin.jvm") { extensions.getByType().apply { sourceSets["main"].kotlin.srcDir(targetDir) diff --git a/buildSrc/src/main/kotlin/jewel-check-public-api.gradle.kts b/buildSrc/src/main/kotlin/jewel-check-public-api.gradle.kts index ebc91b8e4..ac00fb529 100644 --- a/buildSrc/src/main/kotlin/jewel-check-public-api.gradle.kts +++ b/buildSrc/src/main/kotlin/jewel-check-public-api.gradle.kts @@ -1,3 +1,5 @@ +@file:Suppress("UnstableApiUsage") + plugins { id("org.jetbrains.kotlinx.binary-compatibility-validator") id("dev.drewhamilton.poko") @@ -13,7 +15,7 @@ apiValidation { } poko { - pokoAnnotation.set("org.jetbrains.jewel.foundation.GenerateDataFunctions") + pokoAnnotation = "org.jetbrains.jewel.foundation.GenerateDataFunctions" } tasks { From b297db0d5a8e46a60b887ebd6d3f8614ff9b28b2 Mon Sep 17 00:00:00 2001 From: Sebastiano Poggi Date: Wed, 25 Oct 2023 15:09:06 +0100 Subject: [PATCH 3/3] Address PR comments --- .../kotlin/android-studio-releases-generator.gradle.kts | 6 ++---- .../src/main/kotlin/intellij-theme-generator.gradle.kts | 4 +--- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/buildSrc/src/main/kotlin/android-studio-releases-generator.gradle.kts b/buildSrc/src/main/kotlin/android-studio-releases-generator.gradle.kts index f49a02976..08e93233a 100644 --- a/buildSrc/src/main/kotlin/android-studio-releases-generator.gradle.kts +++ b/buildSrc/src/main/kotlin/android-studio-releases-generator.gradle.kts @@ -9,7 +9,7 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension import org.jetbrains.kotlin.gradle.tasks.BaseKotlinCompile val extension: StudioVersionsGenerationExtension = - extensions.findByType(StudioVersionsGenerationExtension::class.java) + extensions.findByType() ?: extensions.create("androidStudioReleasesGenerator", StudioVersionsGenerationExtension::class.java) val task = @@ -34,7 +34,5 @@ tasks { } pluginManager.withPlugin("org.jetbrains.kotlin.jvm") { - extensions.getByType().apply { - sourceSets["main"].kotlin.srcDir(extension.targetDir) - } + the().sourceSets["main"].kotlin.srcDir(extension.targetDir) } diff --git a/buildSrc/src/main/kotlin/intellij-theme-generator.gradle.kts b/buildSrc/src/main/kotlin/intellij-theme-generator.gradle.kts index 3cc99b7c6..7c758d892 100644 --- a/buildSrc/src/main/kotlin/intellij-theme-generator.gradle.kts +++ b/buildSrc/src/main/kotlin/intellij-theme-generator.gradle.kts @@ -35,8 +35,6 @@ extension.all { } pluginManager.withPlugin("org.jetbrains.kotlin.jvm") { - extensions.getByType().apply { - sourceSets["main"].kotlin.srcDir(targetDir) - } + the().sourceSets["main"].kotlin.srcDir(targetDir) } }