Skip to content

Commit

Permalink
Merge pull request #842 from mgroth0/custom-configs
Browse files Browse the repository at this point in the history
allow applying ksp to custom configs
  • Loading branch information
Jolanrensen authored Sep 3, 2024
2 parents 6b72272 + b0ed93f commit ea7dbe8
Showing 1 changed file with 37 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,29 @@ import java.util.Properties

@Suppress("unused")
class ConvenienceSchemaGeneratorPlugin : Plugin<Project> {
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) {
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'.",
"Invalid value '$property' for '$PROP_ADD_KSP' property. Defaulting to '$addKsp'. Please use 'true' or 'false'.",
)
}
}
Expand All @@ -32,7 +44,7 @@ class ConvenienceSchemaGeneratorPlugin : Plugin<Project> {
// 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

Expand All @@ -45,29 +57,28 @@ class ConvenienceSchemaGeneratorPlugin : Plugin<Project> {
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.findProperty(PROP_KSP_CONFIGS)
?.let { (it as String) }
?.split(",")
?.map { it.trim() }
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<KspExtension>().arg(
Expand Down

0 comments on commit ea7dbe8

Please sign in to comment.