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

Use new plugin format for existing plugins #206

Merged
merged 4 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 0 additions & 13 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<StudioVersionsGenerationExtension>()
?: extensions.create("androidStudioReleasesGenerator", StudioVersionsGenerationExtension::class.java)

val task =
tasks.register<AndroidStudioReleasesGeneratorTask>("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<BaseKotlinCompile> {
dependsOn(task)
}

withType<Detekt> {
dependsOn(task)
}
}

pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
the<KotlinJvmProjectExtension>().sourceSets["main"].kotlin.srcDir(extension.targetDir)
}
40 changes: 40 additions & 0 deletions buildSrc/src/main/kotlin/intellij-theme-generator.gradle.kts
Original file line number Diff line number Diff line change
@@ -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> { ThemeGeneration(it, project) })
extensions.add("intelliJThemeGenerator", extension)

extension.all {
val task = tasks.register<IntelliJThemeGeneratorTask>("generate${GUtil.toCamelCase(name)}Theme") {
outputFile = targetDir.file([email protected] {
val className = ClassName.bestGuess(it)
className.packageName.replace(".", "/")
.plus("/${className.simpleName}.kt")
})
themeClassName = [email protected]
ideaVersion = [email protected]
themeFile = [email protected]
}

tasks {
withType<BaseKotlinCompile> {
dependsOn(task)
}

withType<Detekt> {
dependsOn(task)
}
}

pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
the<KotlinJvmProjectExtension>().sourceSets["main"].kotlin.srcDir(targetDir)
}
}
4 changes: 3 additions & 1 deletion buildSrc/src/main/kotlin/jewel-check-public-api.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@file:Suppress("UnstableApiUsage")

plugins {
id("org.jetbrains.kotlinx.binary-compatibility-validator")
id("dev.drewhamilton.poko")
Expand All @@ -13,7 +15,7 @@ apiValidation {
}

poko {
pokoAnnotation.set("org.jetbrains.jewel.foundation.GenerateDataFunctions")
pokoAnnotation = "org.jetbrains.jewel.foundation.GenerateDataFunctions"
}

tasks {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<Project> {

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<AndroidStudioReleasesGeneratorTask>("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<BaseKotlinCompile> {
dependsOn(task)
}
tasks.withType<Detekt> {
dependsOn(task)
}
pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
extensions.getByType<KotlinJvmProjectExtension>().apply {
sourceSets["main"].kotlin.srcDir(extension.targetDir)
}
}
}
}
}

open class StudioVersionsGenerationExtension(project: Project) {

val targetDir: DirectoryProperty = project.objects.directoryProperty()
Expand All @@ -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() {

Expand Down Expand Up @@ -107,7 +65,7 @@ open class AndroidStudioReleasesGeneratorTask : DefaultTask() {
val releases = URL(url).openStream()
.use { json.decodeFromStream<ApiAndroidStudioReleases>(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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Project> {

final override fun apply(target: Project) {
with(target) {
val extension = ThemeGeneratorContainer(container<ThemeGeneration> { ThemeGeneration(it, project) })
extensions.add("intelliJThemeGenerator", extension)

extension.all {
val task = tasks.register<IntelliJThemeGeneratorTask>("generate${GUtil.toCamelCase(name)}Theme") {
outputFile.set(targetDir.file([email protected] {
val className = ClassName.bestGuess(it)
className.packageName.replace(".", "/")
.plus("/${className.simpleName}.kt")
}))
themeClassName.set([email protected])
ideaVersion.set([email protected])
themeFile.set([email protected])
}
tasks.withType<BaseKotlinCompile> {
dependsOn(task)
}
tasks.withType<Detekt> {
dependsOn(task)
}
pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
extensions.getByType<KotlinJvmProjectExtension>().apply {
sourceSets["main"].kotlin.srcDir(targetDir)
}
}
}
}
}
}

class ThemeGeneratorContainer(container: NamedDomainObjectContainer<ThemeGeneration>) : NamedDomainObjectContainer<ThemeGeneration> by container

class ThemeGeneration(val name: String, project: Project) {
Expand Down