Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KSP custom generated file name
Browse files Browse the repository at this point in the history
programadorthi committed Nov 15, 2024
1 parent 4d75c3d commit b77572f
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -33,12 +33,16 @@ import io.ktor.util.Attributes

public class RoutingProcessorProvider : SymbolProcessorProvider {
override fun create(environment: SymbolProcessorEnvironment): SymbolProcessor {
return RoutingProcessor(codeGenerator = environment.codeGenerator)
return RoutingProcessor(
codeGenerator = environment.codeGenerator,
options = environment.options
)
}
}

private class RoutingProcessor(
private val codeGenerator: CodeGenerator,
private val options: Map<String, String>,
) : SymbolProcessor {
private var invoked = false

@@ -316,7 +320,7 @@ private class RoutingProcessor(
FileSpec
.builder(
packageName = "dev.programadorthi.routing.generated",
fileName = "ModuleRoutes"
fileName = "${options["Routing_Module_Name"] ?: "Module"}Routes",
)
.addFileComment("Generated by Kotlin Routing")
.addFunction(this)
Original file line number Diff line number Diff line change
@@ -15,6 +15,15 @@ class KotlinRoutingGradlePlugin : Plugin<Project> {
"KSP plugin not found. Please, apply ksp plugin before routing plugin"
}

val kspExtension = extensions.findByName("ksp") ?: error("KSP config not found")
val argMethod = kspExtension.javaClass.getMethod("arg", String::class.java, String::class.java)
val customModuleName = project.path
.split(Regex("""\W"""))
.joinToString(separator = "", prefix = "_") { part ->
part.replaceFirstChar { it.titlecase() }
}
argMethod.invoke(kspExtension, "Routing_Module_Name", customModuleName)

val kex = kotlinExtension
if (kex is KotlinSingleTargetExtension<*>) {
dependencies.add("ksp", PROCESSOR)

0 comments on commit b77572f

Please sign in to comment.