Skip to content

Commit

Permalink
Added config to make generated file names match the object name
Browse files Browse the repository at this point in the history
  • Loading branch information
EpicSquid committed Jan 19, 2023
1 parent cbc1a4f commit 20759ed
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
object PluginCoordinates {
const val ID = "com.jetbrains.exposed.gradle.plugin"
const val GROUP = "com.jetbrains.exposed.gradle"
const val VERSION = "0.2.2.1-SNAPSHOT"
const val VERSION = "0.2.2.2-SNAPSHOT"
const val IMPLEMENTATION_CLASS = "com.jetbrains.exposed.gradle.plugin.ExposedGradlePlugin"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ class ExposedCodeGenerator {
} else {
val fileSpecs = mutableListOf<FileSpec>()
for (table in tables) {
val fileSpec = FileSpec.builder(configuration.packageName, table.fullName.toCamelCase(capitalizeFirst = true))
val fileSpec = FileSpec.builder(configuration.packageName,
if (configuration.useFullNames) table.fullName.toCamelCase(capitalizeFirst = true)
else table.name.toCamelCase(capitalizeFirst = true)
)
fileSpec.addType(generateExposedTable(table, configuration))
fileSpecs.add(fileSpec.build())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ data class ExposedCodeGeneratorConfiguration(
val generatedFileName: String? = if (generateSingleFile) "" else null,
val collate: String? = null,
val columnMappings: Map<String, String> = emptyMap(),
val dateTimeProvider: String? = null
val dateTimeProvider: String? = null,
val useFullNames: Boolean = generateSingleFile
)
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ abstract class ExposedGenerateCodeTask : DefaultTask() {
@get:Optional
abstract val generateSingleFile: Property<Boolean>

@get:Input
@get:Option(
option = "useFullNames",
description = "If generateSingleFile is false, set to false to use the same name as the Table object for the file name"
)
@get:Optional
abstract val useFullNames: Property<Boolean>

@get:Input
@get:Option(
option = "generatedFileName",
Expand Down Expand Up @@ -148,8 +156,8 @@ abstract class ExposedGenerateCodeTask : DefaultTask() {
generatedFileName.orNull,
collate.orNull,
columnMappings.getOrElse(emptyMap()),
dateTimeProvider.orNull

dateTimeProvider.orNull,
useFullNames.getOrElse(true),
)
ExposedCodeGenerator(tables, config)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ abstract class ExposedGradleExtension @Inject constructor(project: Project) {

var dateTimeProvider: String? = null
var generateSingleFile: Boolean = false
var useFullNames: Boolean = true
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ abstract class ExposedGradlePlugin : Plugin<Project> {
it.dateTimeProvider.set(getStringProperty(project, extension, "dateTimeProvider"))
it.packageName.set(getStringProperty(project, extension, "packageName"))
it.generateSingleFile.set(getProperty(project, extension, "generateSingleFile") as Boolean)
it.useFullNames.set(getProperty(project, extension, "useFullNames") as Boolean)
it.generatedFileName.set(getStringProperty(project, extension, "generatedFileName"))
it.collate.set(getStringProperty(project, extension, "collate"))
// TODO
Expand Down

0 comments on commit 20759ed

Please sign in to comment.