Skip to content
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
4 changes: 2 additions & 2 deletions galite-plugins/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ subprojects {
apply(plugin = "signing")

dependencies {
if (project.name != "common") {
api(project(":galite-plugins:common"))
if (project.name != "galite-common-plugin") {
api(project(":galite-plugins:galite-common-plugin"))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ plugins {
gradlePlugin {
plugins {
create("") {
id = "org.kopi.common-plugin" // Unique plugin ID
id = "org.kopi.galite-common-plugin" // Unique plugin ID
implementationClass = "org.kopi.galite.plugins.common.GradleExtensionsPlugin" // The main plugin class
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# dbschema-generator Gradle Plugin
# galite-dbschema-generator Gradle Plugin

## Overview

The `dbschema-generator` Gradle plugin is destined for Kotlin projects using JetBrains Exposed, in which the use of multiple database schemas is required. This plugin automates the creation of DBSchema.kt class, that copies already existing table declarations while applying a specific database schema name. The plugin dynamically compiles and integrates generated schema classes into the main source set, ensuring compatibility with existing application logic.
The `galite-dbschema-generator` Gradle plugin is destined for Kotlin projects using JetBrains Exposed, in which the use of multiple database schemas is required. This plugin automates the creation of DBSchema.kt class, that copies already existing table declarations while applying a specific database schema name. The plugin dynamically compiles and integrates generated schema classes into the main source set, ensuring compatibility with existing application logic.

## Features

Expand All @@ -13,17 +13,17 @@ The `dbschema-generator` Gradle plugin is destined for Kotlin projects using Jet

## Installation

To use `dbschema-generator` in your Gradle project, add the following to your `build.gradle.kts`:
To use `galite-dbschema-generator` in your Gradle project, add the following to your `build.gradle.kts`:

```kotlin
plugins {
id("com.kopileft.dbschema-generator") version "1.5.9"
id("org.kopi.galite-dbschema-generator") version "1.5.12"
}
```

```kotlin
dependencies {
implementation("org.kopi", "dbschema-generator", "1.5.9")
implementation("org.kopi", "galite-dbschema-generator", "1.5.12")
}
```

Expand All @@ -35,7 +35,7 @@ pluginManagement {
mavenCentral()
gradlePluginPortal()
maven {
url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
url = uri("https://central.sonatype.com/repository/maven-snapshots/")
}
}
}
Expand All @@ -53,14 +53,15 @@ By default, the plugin:
To configure the `generateDBSchemas` task, we need to configure the project extension `dbSchemaGenerator` with the following information :
- **packageName**: The package name of the existing table declarations. This package should be a priorly compiled package in the project's `compileClasspath`.
- **schemaName**: The custom database schema name to be added to the table declarations.
- **subFolder**: A custom sub-folder name to be added to the original table declarations package for the generated class. If not specified, the default sub-folder name is "generated".

```kotlin
tasks {
generateDBSchemas {
doFirst {
dbSchemaGenerator.data.set(listOf(
Schema(packageName = "com.progmag.pdv.dbschema", schemaName = "public"),
Schema(packageName = "com.progmag.pdv.dbschema", schemaName = "custom")
Schema(packageName = "com.progmag.galite.dbschema", schemaName = "public"), // The generated class will be in the package "com.progmag.galite.dbschema.generated"
Schema(packageName = "com.progmag.galite.dbschema", schemaName = "custom", subFolder = "custom") // The generated class will be in the package "com.progmag.galite.dbschema.custom"
))
}
}
Expand All @@ -80,7 +81,7 @@ To generate schema classes, run:
The generated class will have the following path:

```kotlin
"${packageName.replace(".", File.separator)}${File.separator}$schema${File.separator}DBSchema${schema.uppercase()}.kt"
"${packageName.replace(".", File.separator)}${File.separator}$subFolder${File.separator}DBSchema${schema.uppercase()}.kt"
```


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dependencies {
gradlePlugin {
plugins {
create("") {
id = "org.kopi.dbschema-generator" // Unique plugin ID
id = "org.kopi.galite-dbschema-generator" // Unique plugin ID
implementationClass = "org.kopi.galite.plugins.DBSchemaGeneratorPlugin" // The main plugin class
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ abstract class DBSchemaGeneratorExtension @Inject constructor(objectFactory: Obj
val data: ListProperty<Schema> = objectFactory.listProperty(Schema::class.java)
}

data class Schema(@Input val packageName: String, @Input val schemaName: String)
data class Schema(@Input val packageName: String, @Input val schemaName: String, @Input var subFolder: String = "generated")
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ package org.kopi.galite.plugins
import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.bundling.Jar
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.getByType
import org.gradle.kotlin.dsl.named
import org.gradle.kotlin.dsl.register

import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ abstract class DBSchemaGeneratorTask : JavaExec() {
}

extension.data.get().forEach { data ->
val currentArgs = listOf(data.packageName, data.schemaName, outputDirectory.asFile.absolutePath)
val currentArgs = listOf(data.packageName, data.schemaName, data.subFolder, outputDirectory.asFile.absolutePath)
project.logger.lifecycle("Running DBSchemaGenerator with arguments: $data")

project.javaexec {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ import org.reflections.util.ConfigurationBuilder
object DBSchemaGenerator {
@JvmStatic
fun main(args: Array<String>) {
if (args.size != 3) {
if (args.size != 4) {
return
}
val packageName = args[0]
val schemaName = args[1]
val directory = args[2]
val generatedFile = File(createGeneratedPath(packageName, schemaName, directory))
val subFolder = args[2]
val directory = args[3]
val generatedFile = File(createGeneratedPath(packageName, schemaName, subFolder, directory))

// Initialize Reflections for the package where the objects are defined
val reflections = Reflections(ConfigurationBuilder().forPackages(packageName).addScanners(Scanners.SubTypes))
Expand All @@ -49,15 +50,15 @@ object DBSchemaGenerator {
try {
val kClass = it.kotlin
kClass.visibility == kotlin.reflect.KVisibility.PUBLIC
} catch (e: Exception) {
} catch (_: Exception) {
false
}
}

val generatedCode = buildString {
addHeader()
appendLine()
appendLine("package $packageName.$schemaName")
appendLine("package $packageName.$subFolder")
appendLine()
appendLine("import java.math.BigDecimal")
appendLine()
Expand Down Expand Up @@ -106,10 +107,10 @@ object DBSchemaGenerator {
/**
* Create the generated class path
*/
private fun createGeneratedPath(packageName: String, schema: String, directory: String): String {
private fun createGeneratedPath(packageName: String, schema: String, subFoler: String, directory: String): String {
return "$directory${File.separator}" +
"${packageName.replace(".", File.separator)}${File.separator}" +
"$schema${File.separator}" +
"$subFoler${File.separator}" +
"DBSchema${schema.uppercase()}.kt"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ plugins {
gradlePlugin {
plugins {
create("") {
id = "org.kopi.factory-generator" // Unique plugin ID
id = "org.kopi.galite-factory-generator" // Unique plugin ID
implementationClass = "org.kopi.galite.plugins.FactoryGeneratorPlugin" // The main plugin class
}
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
org.gradle.jvmargs=-Xmx4g
#
group=org.kopi
version=1.5.12
version=1.5.12-02W3-SNAPSHOT
6 changes: 3 additions & 3 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ include("galite-tests")
include("galite-demo:galite-vaadin")
include("galite-demo:galite-vaadin-spring")
include("galite-plugins")
include("galite-plugins:common")
include("galite-plugins:factory-generator")
include("galite-plugins:dbschema-generator")
include("galite-plugins:galite-common-plugin")
include("galite-plugins:galite-factory-generator")
include("galite-plugins:galite-dbschema-generator")
Loading