Skip to content

Add option to prevent Gradle plugin from adding dependency on KSP #571

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

Merged
merged 4 commits into from
Jan 26, 2024
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
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Project> {
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<KspExtension>()?.arg("dataframe.resolutionDir", target.projectDir.absolutePath)
}
target.plugins.apply(SchemaGeneratorPlugin::class.java)
}
}
Expand All @@ -31,6 +47,5 @@ internal class KspPluginApplier : Plugin<Project> {
target.configurations.getByName("ksp").dependencies.add(
target.dependencies.create("org.jetbrains.kotlinx.dataframe:symbol-processor-all:$preprocessorVersion")
)
target.extensions.getByType<KspExtension>().arg("dataframe.resolutionDir", target.projectDir.absolutePath)
}
}
Original file line number Diff line number Diff line change
@@ -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<String>.joinToCamelCaseString(): String {
return joinToString(separator = "") { it.capitalize() }
return joinToString(separator = "") { s -> s.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() } }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, changes in the behaviour is not clear for me here. Is it related to the KSP update, isn't it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

capitalize was deprecated some time ago. I come across the warning and decided to fix it

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ImportDataSchemaStatement> = resolvePathImports(resolver).toList()

class ImportDataSchemaStatement(
val origin: KSFile,
Expand Down