From c4b2635130549364ea66fd5e32d937413edb2fe8 Mon Sep 17 00:00:00 2001 From: Nikita Klimenko Date: Thu, 25 Jan 2024 18:21:23 +0200 Subject: [PATCH 1/5] update ksp --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index c1a9d6fb3c..577d582190 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,5 @@ [versions] -ksp = "1.9.0-1.0.12" +ksp = "1.9.21-1.0.15" kotlinJupyter = "0.11.0-358" ktlint = "3.4.5" kotlin = "1.9.0" From 97dfbe4125b7e39fae4792879bd896d92c16ac2c Mon Sep 17 00:00:00 2001 From: Nikita Klimenko Date: Thu, 25 Jan 2024 18:22:14 +0200 Subject: [PATCH 2/5] fix deprecation --- .../jetbrains/dataframe/gradle/toCamelCaseByDelimiters.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/dataframe-gradle-plugin/src/main/kotlin/org/jetbrains/dataframe/gradle/toCamelCaseByDelimiters.kt b/plugins/dataframe-gradle-plugin/src/main/kotlin/org/jetbrains/dataframe/gradle/toCamelCaseByDelimiters.kt index 107bd12902..c66faa1a3a 100644 --- a/plugins/dataframe-gradle-plugin/src/main/kotlin/org/jetbrains/dataframe/gradle/toCamelCaseByDelimiters.kt +++ b/plugins/dataframe-gradle-plugin/src/main/kotlin/org/jetbrains/dataframe/gradle/toCamelCaseByDelimiters.kt @@ -1,9 +1,11 @@ package org.jetbrains.dataframe.gradle +import java.util.Locale + fun String.toCamelCaseByDelimiters(delimiters: Regex): String { - return split(delimiters).joinToCamelCaseString().decapitalize() + return split(delimiters).joinToCamelCaseString().replaceFirstChar { it.lowercase(Locale.getDefault()) } } fun List.joinToCamelCaseString(): String { - return joinToString(separator = "") { it.capitalize() } + return joinToString(separator = "") { s -> s.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() } } } From a2eb0004b995fdbade570091bb4ef61275be4a3f Mon Sep 17 00:00:00 2001 From: Nikita Klimenko Date: Thu, 25 Jan 2024 18:24:03 +0200 Subject: [PATCH 3/5] refactor resolveImportStatements --- .../kotlin/org/jetbrains/dataframe/ksp/DataSchemaGenerator.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/plugins/symbol-processor/src/main/kotlin/org/jetbrains/dataframe/ksp/DataSchemaGenerator.kt b/plugins/symbol-processor/src/main/kotlin/org/jetbrains/dataframe/ksp/DataSchemaGenerator.kt index cb3ccfae9d..bc98fa3f48 100644 --- a/plugins/symbol-processor/src/main/kotlin/org/jetbrains/dataframe/ksp/DataSchemaGenerator.kt +++ b/plugins/symbol-processor/src/main/kotlin/org/jetbrains/dataframe/ksp/DataSchemaGenerator.kt @@ -48,9 +48,7 @@ class DataSchemaGenerator( private val codeGenerator: com.google.devtools.ksp.processing.CodeGenerator, ) { - fun resolveImportStatements() = listOf( - ::resolvePathImports, - ).flatMap { it(resolver) } + fun resolveImportStatements(): List = resolvePathImports(resolver).toList() class ImportDataSchemaStatement( val origin: KSFile, From e15cb54d4c60ce5f640b4035dbfe3422a5787aa6 Mon Sep 17 00:00:00 2001 From: Nikita Klimenko Date: Thu, 25 Jan 2024 18:34:02 +0200 Subject: [PATCH 4/5] add option to prevent Gradle plugin from adding dependency on KSP We add plugin automatically for better onboarding experience, but it makes project depend on some specific KSP version. KSP complains when people use it with different version of compiler: ksp-1.9.0-1.0.12 is too old for kotlin-1.9.21. Please upgrade ksp or downgrade kotlin-gradle-plugin to 1.9.0. In dataframe project itself we always need to update Kotlin version in two steps. With this change (and one more PR later) it won't be necessary anymore Still, it's ok to use preprocessor built for 1.9.0 with KSP 1.9.21. That's why we need an option for people to decide version of KSP they need in their project. People will be able to use our preprocessor built for older versions of KSP API most of the time without problems thanks to backward compatibility --- .../ConvenienceSchemaGeneratorPlugin.kt | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 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 8aa0ba4cc7..9411193d65 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 @@ -3,13 +3,29 @@ package org.jetbrains.dataframe.gradle import com.google.devtools.ksp.gradle.KspExtension import org.gradle.api.Plugin import org.gradle.api.Project -import org.gradle.kotlin.dsl.getByType +import org.gradle.kotlin.dsl.findByType import java.util.* @Suppress("unused") class ConvenienceSchemaGeneratorPlugin : Plugin { override fun apply(target: Project) { - target.plugins.apply(KspPluginApplier::class.java) + val name = "kotlin.dataframe.add.ksp" + val property = target.findProperty(name)?.toString() + var addKsp = true + + if (property != null) { + if (property.equals("true", ignoreCase = true) || property.equals("false", ignoreCase = true)) { + addKsp = property.toBoolean() + } else { + target.logger.warn("Invalid value '$property' for '$name' property. Defaulting to '$addKsp'. Please use 'true' or 'false'.") + } + } + if (addKsp) { + target.plugins.apply(KspPluginApplier::class.java) + } + target.afterEvaluate { + target.extensions.findByType()?.arg("dataframe.resolutionDir", target.projectDir.absolutePath) + } target.plugins.apply(SchemaGeneratorPlugin::class.java) } } @@ -31,6 +47,5 @@ internal class KspPluginApplier : Plugin { target.configurations.getByName("ksp").dependencies.add( target.dependencies.create("org.jetbrains.kotlinx.dataframe:symbol-processor-all:$preprocessorVersion") ) - target.extensions.getByType().arg("dataframe.resolutionDir", target.projectDir.absolutePath) } } From 63f08f46d556f40f5fd613a00a541ff5c0ac3f36 Mon Sep 17 00:00:00 2001 From: Nikita Klimenko Date: Thu, 25 Jan 2024 19:51:43 +0200 Subject: [PATCH 5/5] make `forEach` inline to enable composable and suspend calls in lambda --- .../kotlin/org/jetbrains/kotlinx/dataframe/api/forEach.kt | 8 ++++---- .../kotlin/org/jetbrains/kotlinx/dataframe/api/forEach.kt | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/forEach.kt b/core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/forEach.kt index 9e5ec62a7c..8f2a7f2fb7 100644 --- a/core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/forEach.kt +++ b/core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/forEach.kt @@ -7,21 +7,21 @@ import org.jetbrains.kotlinx.dataframe.columns.values // region DataColumn -public fun DataColumn.forEach(action: (T) -> Unit): Unit = values.forEach(action) +public inline fun DataColumn.forEach(action: (T) -> Unit): Unit = values().forEach(action) -public fun DataColumn.forEachIndexed(action: (Int, T) -> Unit): Unit = values.forEachIndexed(action) +public inline fun DataColumn.forEachIndexed(action: (Int, T) -> Unit): Unit = values().forEachIndexed(action) // endregion // region DataFrame -public fun DataFrame.forEach(action: RowExpression): Unit = rows().forEach { action(it, it) } +public inline fun DataFrame.forEach(action: RowExpression): Unit = rows().forEach { action(it, it) } // endregion // region GroupBy -public fun GroupBy.forEach(body: (GroupBy.Entry) -> Unit): Unit = keys.forEach { key -> +public inline fun GroupBy.forEach(body: (GroupBy.Entry) -> Unit): Unit = keys.forEach { key -> val group = groups[key.index()] body(GroupBy.Entry(key, group)) } diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/forEach.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/forEach.kt index 9e5ec62a7c..8f2a7f2fb7 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/forEach.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/forEach.kt @@ -7,21 +7,21 @@ import org.jetbrains.kotlinx.dataframe.columns.values // region DataColumn -public fun DataColumn.forEach(action: (T) -> Unit): Unit = values.forEach(action) +public inline fun DataColumn.forEach(action: (T) -> Unit): Unit = values().forEach(action) -public fun DataColumn.forEachIndexed(action: (Int, T) -> Unit): Unit = values.forEachIndexed(action) +public inline fun DataColumn.forEachIndexed(action: (Int, T) -> Unit): Unit = values().forEachIndexed(action) // endregion // region DataFrame -public fun DataFrame.forEach(action: RowExpression): Unit = rows().forEach { action(it, it) } +public inline fun DataFrame.forEach(action: RowExpression): Unit = rows().forEach { action(it, it) } // endregion // region GroupBy -public fun GroupBy.forEach(body: (GroupBy.Entry) -> Unit): Unit = keys.forEach { key -> +public inline fun GroupBy.forEach(body: (GroupBy.Entry) -> Unit): Unit = keys.forEach { key -> val group = groups[key.index()] body(GroupBy.Entry(key, group)) }