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..08e93233a --- /dev/null +++ b/buildSrc/src/main/kotlin/android-studio-releases-generator.gradle.kts @@ -0,0 +1,38 @@ +@file:Suppress("UnstableApiUsage") + +import com.squareup.kotlinpoet.ClassName +import io.gitlab.arturbosch.detekt.Detekt +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: StudioVersionsGenerationExtension = + extensions.findByType() + ?: extensions.create("androidStudioReleasesGenerator", StudioVersionsGenerationExtension::class.java) + +val task = + tasks.register("generateAndroidStudioReleasesList") { + val className = ClassName.bestGuess(STUDIO_RELEASES_OUTPUT_CLASS_NAME) + outputFile = extension.targetDir.file( + className.packageName.replace(".", "/") + .plus("/${className.simpleName}.kt") + ) + dataUrl = extension.dataUrl + resourcesDirs = extension.resourcesDirs + } + +tasks { + withType { + dependsOn(task) + } + + withType { + dependsOn(task) + } +} + +pluginManager.withPlugin("org.jetbrains.kotlin.jvm") { + 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 new file mode 100644 index 000000000..7c758d892 --- /dev/null +++ b/buildSrc/src/main/kotlin/intellij-theme-generator.gradle.kts @@ -0,0 +1,40 @@ +@file:Suppress("UnstableApiUsage") + +import com.squareup.kotlinpoet.ClassName +import io.gitlab.arturbosch.detekt.Detekt +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 = targetDir.file(this@all.themeClassName.map { + val className = ClassName.bestGuess(it) + className.packageName.replace(".", "/") + .plus("/${className.simpleName}.kt") + }) + themeClassName = this@all.themeClassName + ideaVersion = this@all.ideaVersion + themeFile = this@all.themeFile + } + + tasks { + withType { + dependsOn(task) + } + + withType { + dependsOn(task) + } + } + + pluginManager.withPlugin("org.jetbrains.kotlin.jvm") { + the().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 { 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) {