From 77e88a11d9d4746234d543ffaba09ef0912779ca Mon Sep 17 00:00:00 2001 From: mgroth0 Date: Mon, 26 Aug 2024 17:11:16 -0400 Subject: [PATCH 1/4] allow applying ksp to custom configs --- .../ConvenienceSchemaGeneratorPlugin.kt | 44 +++++++++---------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/plugins/dataframe-gradle-plugin/src/main/kotlin/org/jetbrains/dataframe/gradle/ConvenienceSchemaGeneratorPlugin.kt b/plugins/dataframe-gradle-plugin/src/main/kotlin/org/jetbrains/dataframe/gradle/ConvenienceSchemaGeneratorPlugin.kt index 26bbedfd2a..816c77e7ec 100644 --- a/plugins/dataframe-gradle-plugin/src/main/kotlin/org/jetbrains/dataframe/gradle/ConvenienceSchemaGeneratorPlugin.kt +++ b/plugins/dataframe-gradle-plugin/src/main/kotlin/org/jetbrains/dataframe/gradle/ConvenienceSchemaGeneratorPlugin.kt @@ -5,6 +5,7 @@ import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.artifacts.UnknownConfigurationException import org.gradle.kotlin.dsl.getByType +import org.jetbrains.kotlin.gradle.plugin.extraProperties import java.util.Properties @Suppress("unused") @@ -32,7 +33,7 @@ class ConvenienceSchemaGeneratorPlugin : Plugin { // configure it to depend on symbol-processor-all target.plugins.whenPluginAdded { if ("com.google.devtools.ksp" in this.javaClass.packageName) { - val isMultiplatform = + val isMultiplatform by lazy { when { target.plugins.hasPlugin("org.jetbrains.kotlin.jvm") -> false @@ -45,29 +46,26 @@ class ConvenienceSchemaGeneratorPlugin : Plugin { false } } - val mainKspCfg = if (isMultiplatform) "kspJvm" else "ksp" - val testKspCfg = if (isMultiplatform) "kspJvmTest" else "kspTest" - try { - target.configurations.getByName(mainKspCfg).dependencies.add( - target.dependencies.create( - "org.jetbrains.kotlinx.dataframe:symbol-processor-all:$preprocessorVersion", - ), - ) - } catch (e: UnknownConfigurationException) { - target.logger.warn( - "Configuration '$mainKspCfg' not found. Please make sure the KSP plugin is applied.", - ) } - try { - target.configurations.getByName(testKspCfg).dependencies.add( - target.dependencies.create( - "org.jetbrains.kotlinx.dataframe:symbol-processor-all:$preprocessorVersion", - ), - ) - } catch (e: UnknownConfigurationException) { - target.logger.warn( - "Configuration '$testKspCfg' not found. Please make sure the KSP plugin is applied.", - ) + val overriddenConfigs = + target.properties.get("kotlin.dataframe.ksp.configs")?.let { (it as String)}?.split(",") + val configs = when { + overriddenConfigs != null -> overriddenConfigs + isMultiplatform -> listOf("kspJvm","kspJvmTest") + else -> listOf("ksp","kspTest") + } + configs.forEach { cfg -> + try { + target.configurations.getByName(cfg).dependencies.add( + target.dependencies.create( + "org.jetbrains.kotlinx.dataframe:symbol-processor-all:$preprocessorVersion", + ), + ) + } catch (e: UnknownConfigurationException) { + target.logger.warn( + "Configuration '$cfg' not found. Please make sure the KSP plugin is applied.", + ) + } } target.logger.info("Added DataFrame dependency to the KSP plugin.") target.extensions.getByType().arg( From 09dfa5f5599449ebcb7a92370f7966e1c4f25d2f Mon Sep 17 00:00:00 2001 From: mgroth0 Date: Mon, 26 Aug 2024 17:16:52 -0400 Subject: [PATCH 2/4] allow both regular or extra property for custom ksp configs --- .../gradle/ConvenienceSchemaGeneratorPlugin.kt | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/plugins/dataframe-gradle-plugin/src/main/kotlin/org/jetbrains/dataframe/gradle/ConvenienceSchemaGeneratorPlugin.kt b/plugins/dataframe-gradle-plugin/src/main/kotlin/org/jetbrains/dataframe/gradle/ConvenienceSchemaGeneratorPlugin.kt index 816c77e7ec..469bb1d92a 100644 --- a/plugins/dataframe-gradle-plugin/src/main/kotlin/org/jetbrains/dataframe/gradle/ConvenienceSchemaGeneratorPlugin.kt +++ b/plugins/dataframe-gradle-plugin/src/main/kotlin/org/jetbrains/dataframe/gradle/ConvenienceSchemaGeneratorPlugin.kt @@ -47,8 +47,19 @@ class ConvenienceSchemaGeneratorPlugin : Plugin { } } } - val overriddenConfigs = - target.properties.get("kotlin.dataframe.ksp.configs")?.let { (it as String)}?.split(",") + val customConfigsProp = "kotlin.dataframe.ksp.configs" + var overriddenConfigs = + target.properties.get(customConfigsProp)?.let { (it as String)}?.split(",") + if (overriddenConfigs != null) { + overriddenConfigs = + target.extraProperties.get(customConfigsProp)?.let { (it as String)}?.split(",") + } else { + if (customConfigsProp in target.extraProperties.properties) { + target.logger.warn( + "`$customConfigsProp` set as both a regular and an extra property. Only the regular property value is used.", + ) + } + } val configs = when { overriddenConfigs != null -> overriddenConfigs isMultiplatform -> listOf("kspJvm","kspJvmTest") From 9fc8e7d7c706fadacb428b0577706e875d2537b5 Mon Sep 17 00:00:00 2001 From: mgroth0 Date: Fri, 30 Aug 2024 00:18:07 -0400 Subject: [PATCH 3/4] add changes from review - use findProperty, no longer warn since gradle has a conventional precendence for regular vs extra property - put properties as in companion - write some documentation on the properties - ran --- .../ConvenienceSchemaGeneratorPlugin.kt | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/plugins/dataframe-gradle-plugin/src/main/kotlin/org/jetbrains/dataframe/gradle/ConvenienceSchemaGeneratorPlugin.kt b/plugins/dataframe-gradle-plugin/src/main/kotlin/org/jetbrains/dataframe/gradle/ConvenienceSchemaGeneratorPlugin.kt index 469bb1d92a..601c290ace 100644 --- a/plugins/dataframe-gradle-plugin/src/main/kotlin/org/jetbrains/dataframe/gradle/ConvenienceSchemaGeneratorPlugin.kt +++ b/plugins/dataframe-gradle-plugin/src/main/kotlin/org/jetbrains/dataframe/gradle/ConvenienceSchemaGeneratorPlugin.kt @@ -5,14 +5,25 @@ import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.artifacts.UnknownConfigurationException import org.gradle.kotlin.dsl.getByType -import org.jetbrains.kotlin.gradle.plugin.extraProperties import java.util.Properties @Suppress("unused") class ConvenienceSchemaGeneratorPlugin : Plugin { + companion object { + /** + * (boolean, default `true`) whether to add KSP plugin + */ + const val PROP_ADD_KSP = "kotlin.dataframe.add.ksp" + + /** + * (string, default `null`) comma-delimited list of configurations to add KSP processing to. + * Defaults to guessing configurations based on which kotlin plugin is applied (jvm or multiplatform) + */ + const val PROP_KSP_CONFIGS = "kotlin.dataframe.ksp.configs" + } + override fun apply(target: Project) { - val name = "kotlin.dataframe.add.ksp" - val property = target.findProperty(name)?.toString() + val property = target.findProperty(PROP_ADD_KSP)?.toString() var addKsp = true if (property != null) { @@ -20,7 +31,7 @@ class ConvenienceSchemaGeneratorPlugin : Plugin { addKsp = property.toBoolean() } else { target.logger.warn( - "Invalid value '$property' for '$name' property. Defaulting to '$addKsp'. Please use 'true' or 'false'.", + "Invalid value '$property' for '$PROP_ADD_KSP' property. Defaulting to '$addKsp'. Please use 'true' or 'false'.", ) } } @@ -47,23 +58,11 @@ class ConvenienceSchemaGeneratorPlugin : Plugin { } } } - val customConfigsProp = "kotlin.dataframe.ksp.configs" - var overriddenConfigs = - target.properties.get(customConfigsProp)?.let { (it as String)}?.split(",") - if (overriddenConfigs != null) { - overriddenConfigs = - target.extraProperties.get(customConfigsProp)?.let { (it as String)}?.split(",") - } else { - if (customConfigsProp in target.extraProperties.properties) { - target.logger.warn( - "`$customConfigsProp` set as both a regular and an extra property. Only the regular property value is used.", - ) - } - } + val overriddenConfigs = target.findProperty(PROP_KSP_CONFIGS)?.let { (it as String) }?.split(",") val configs = when { overriddenConfigs != null -> overriddenConfigs - isMultiplatform -> listOf("kspJvm","kspJvmTest") - else -> listOf("ksp","kspTest") + isMultiplatform -> listOf("kspJvm", "kspJvmTest") + else -> listOf("ksp", "kspTest") } configs.forEach { cfg -> try { From b0ed93fbc772c3f3c8d1fbaeba83bb0fd4486f4b Mon Sep 17 00:00:00 2001 From: Jolan Rensen Date: Tue, 3 Sep 2024 12:01:36 +0200 Subject: [PATCH 4/4] added trim to PROP_KSP_CONFIGS --- .../dataframe/gradle/ConvenienceSchemaGeneratorPlugin.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/dataframe-gradle-plugin/src/main/kotlin/org/jetbrains/dataframe/gradle/ConvenienceSchemaGeneratorPlugin.kt b/plugins/dataframe-gradle-plugin/src/main/kotlin/org/jetbrains/dataframe/gradle/ConvenienceSchemaGeneratorPlugin.kt index 601c290ace..0257465a8e 100644 --- a/plugins/dataframe-gradle-plugin/src/main/kotlin/org/jetbrains/dataframe/gradle/ConvenienceSchemaGeneratorPlugin.kt +++ b/plugins/dataframe-gradle-plugin/src/main/kotlin/org/jetbrains/dataframe/gradle/ConvenienceSchemaGeneratorPlugin.kt @@ -58,7 +58,10 @@ class ConvenienceSchemaGeneratorPlugin : Plugin { } } } - val overriddenConfigs = target.findProperty(PROP_KSP_CONFIGS)?.let { (it as String) }?.split(",") + val overriddenConfigs = target.findProperty(PROP_KSP_CONFIGS) + ?.let { (it as String) } + ?.split(",") + ?.map { it.trim() } val configs = when { overriddenConfigs != null -> overriddenConfigs isMultiplatform -> listOf("kspJvm", "kspJvmTest")