diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7932023..7d79c4b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,23 +19,12 @@ jobs: distribution: 'zulu' java-version: 21 - - name: Grant execute permission for codegen/gradlew - working-directory: ./codegen - run: chmod +x gradlew + - name: Set up Gradle + uses: gradle/actions/setup-gradle@v4.4.1 - - name: Build - working-directory: ./codegen + - name: Build plugin run: ./gradlew build - - name: Grant execute permission for ./gradlew - run: chmod +x gradlew - - - name: Test plugin (generate Java code) - run: ./gradlew clean domaCodeGenJavaAll build - - - name: Test plugin (generate Kotlin code) - run: ./gradlew clean domaCodeGenKotlinAll build - - name: Set version id: set-version run: ./gradlew properties | grep "^version:" | awk '{print $2}' | { read v; echo "version=$v" >> $GITHUB_OUTPUT; } @@ -45,5 +34,4 @@ jobs: - name: Publish plugin if: github.event_name == 'push' && endsWith(steps.set-version.outputs.version, 'SNAPSHOT') == false - working-directory: ./codegen - run: ./gradlew publishPlugins -Pgradle.publish.key=${{ secrets.GRADLE_PUBLISH_KEY }} -Pgradle.publish.secret=${{ secrets.GRADLE_PUBLISH_SECRET }} + run: ./gradlew :codegen:publishPlugins -Pgradle.publish.key=${{ secrets.GRADLE_PUBLISH_KEY }} -Pgradle.publish.secret=${{ secrets.GRADLE_PUBLISH_SECRET }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8610204..c8eccec 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -48,18 +48,8 @@ jobs: with: token: ${{ secrets.REPO_ACCESS_TOKEN }} - - name: Grant execute permission for gradlew - run: chmod +x gradlew - - - name: Cache Gradle - uses: actions/cache@v4 - with: - path: | - ~/.gradle/caches - ~/.gradle/wrapper - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }} - restore-keys: | - ${{ runner.os }}-gradle- + - name: Set up Gradle + uses: gradle/actions/setup-gradle@v4.4.1 - name: Release ${{ env.RELEASE_VERSION }} run: | diff --git a/CLAUDE.md b/CLAUDE.md index 42e3069..bfc05db 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -9,14 +9,8 @@ Doma CodeGen Plugin is a Gradle plugin that generates Java, Kotlin, and SQL file ## Build Commands ```bash -# Build entire project with code formatting -./gradlew spotlessApply build - -# Build only the plugin module -./gradlew :codegen:build - -# Clean build -./gradlew clean build +# Build the codegen plugin +./gradlew build ``` ## Testing Commands @@ -27,47 +21,57 @@ Doma CodeGen Plugin is a Gradle plugin that generates Java, Kotlin, and SQL file # Run specific module tests ./gradlew :codegen:test -./gradlew :codegen-test:test - -# Test code generation (from codegen-test directory) -cd codegen-test -./gradlew domaCodeGenJavaAll build -./gradlew domaCodeGenKotlinAll build +./gradlew :codegen-h2-test:test +./gradlew :codegen-tc-test:test ``` ## Code Quality ```bash # Apply code formatting (required before commits) -./gradlew spotlessApply +./gradlew :codegen:spotlessApply # Check code formatting -./gradlew spotlessCheck +./gradlew :codegen:spotlessCheck ``` ## Architecture Overview ### Multi-Module Structure -- **codegen**: Main plugin implementation +This is a Gradle composite build with the following structure: + +- **Root project** (`doma-codegen-plugin`): Contains build configuration and release management + - Uses `pluginManagement` with `includeBuild("codegen")` to include the plugin project + - Includes test modules: `codegen-h2-test` and `codegen-tc-test` + +- **codegen**: Main plugin implementation (included build) - Plugin entry point: `CodeGenPlugin.java` - Tasks defined in `org.seasar.doma.gradle.codegen.task` package - Code generators in `org.seasar.doma.gradle.codegen.generator` package - Database dialects in `org.seasar.doma.gradle.codegen.dialect` package + - Has its own `settings.gradle.kts` and `gradle.properties` + - Uses Groovy for some components (see `src/main/groovy`) -- **codegen-test**: Integration test project demonstrating plugin usage +- **codegen-h2-test**: Integration test module using H2 database + - Tests code generation with in-memory H2 database + - Uses the plugin via `id("org.domaframework.doma.codegen")` + - Single configuration: `h2` + +- **codegen-tc-test**: Integration test module using Testcontainers + - Tests code generation with PostgreSQL via Testcontainers + - Supports both Java and Kotlin code generation + - Two configurations: `java` and `kotlin` ### Key Components 1. **Code Generators**: Transform database metadata into Java/Kotlin code using FreeMarker templates - - `JavaGenerator`: Generates Java entities and DAOs - - `KotlinGenerator`: Generates Kotlin entities and DAOs - - `SqlGenerator`: Generates SQL template files 2. **Database Dialects**: Database-specific implementations for metadata extraction - Supports: H2, MySQL, Oracle, PostgreSQL, SQL Server, DB2, HSQLDB 3. **Gradle Tasks**: Plugin provides tasks prefixed with `domaCodeGen` - - Pattern: `domaCodeGen{Java|Kotlin|Sql}{EntityName|All}` + - Pattern: `domaCodeGen{ConfigName}{Java|Kotlin|Sql}{EntityName|All}` + - Example: `domaCodeGenH2JavaAll`, `domaCodeGenKotlinEntityEmployee` 4. **Template System**: FreeMarker templates in `/codegen/src/main/resources/` - Customizable via `templateDir` configuration @@ -83,11 +87,27 @@ cd codegen-test ### Database Connection -The plugin connects to databases to read metadata. Configure in build.gradle: +The plugin connects to databases to read metadata. Configure in build.gradle.kts: ```kotlin domaCodeGen { - url = "jdbc:h2:mem:example" - user = "sa" - password = "" + register("myConfig") { + url = "jdbc:h2:mem:example" + user = "sa" + password = "" + entity { + packageName = "com.example.entity" + } + dao { + packageName = "com.example.dao" + } + } } -``` \ No newline at end of file +``` + +### Important Notes + +- The plugin is published to Gradle Plugin Portal (not Maven Central) +- In development, test modules apply the plugin using `id("org.domaframework.doma.codegen")` which resolves to the local included build +- Each configuration in `domaCodeGen` block creates its own set of tasks +- The `domaCodeGen` configuration is used for JDBC driver dependencies +- CI uses JDK 21 for builds, but the plugin targets Java 17 compatibility \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 0825661..d417bd0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,102 +1,12 @@ -import org.seasar.doma.gradle.codegen.desc.LanguageType - plugins { java - alias(libs.plugins.kotlin.jvm) - alias(libs.plugins.doma.compile) alias(libs.plugins.release) - id("org.domaframework.doma.codegen") } -configure { +release { newVersionCommitMessage.set("[Gradle Release Plugin] - [skip ci] new version commit: ") tagTemplate.set("v\$version") git { requireBranch.set("master") } } - -java { - toolchain.languageVersion.set(JavaLanguageVersion.of(17)) -} - -repositories { - mavenLocal() - mavenCentral() -} - -dependencies { - implementation(libs.doma.core) - annotationProcessor(libs.doma.processor) - - // Use JUnit BOM for version management - testImplementation(platform(libs.junit.bom)) - testImplementation(libs.junit.jupiter.api) - testRuntimeOnly(libs.junit.jupiter.engine) - testRuntimeOnly(libs.junit.platform.launcher) - - testRuntimeOnly(platform(libs.testcontainers.bom)) - testRuntimeOnly(libs.testcontainers.postgresql) - testRuntimeOnly(libs.postgresql) - - domaCodeGen(platform(libs.testcontainers.bom)) - domaCodeGen(libs.testcontainers.postgresql) - domaCodeGen(libs.postgresql) -} - -val initScript = file("init_postgresql.sql") -val _url = "jdbc:tc:postgresql:13.21:///test?TC_INITSCRIPT=file:${initScript.absolutePath}" -val _user = "" -val _password = "" - -domaCodeGen { - register("java") { - val basePackage = "codegen" - url.set(_url) - user.set(_user) - password.set(_password) - entity { - packageName = "${basePackage}.j.entity" - } - dao { - packageName = "${basePackage}.j.dao" - } - } - register("kotlin") { - val basePackage = "codegen" - url.set(_url) - user.set(_user) - password.set(_password) - languageType.set(LanguageType.KOTLIN) - entity { - packageName = "${basePackage}.k.entity" - } - dao { - packageName = "${basePackage}.k.dao" - } - } -} - -tasks { - test { - useJUnitPlatform() - } - - val deleteSrc = register("deleteSrc") { - doLast { - delete("src/main/java/codegen") - delete("src/main/kotlin/codegen") - delete("src/main/resources/META-INF/codegen") - delete("src/test/java/codegen") - delete("src/test/kotlin/codegen") - } - } - - clean { - dependsOn(deleteSrc) - } - - build { - mustRunAfter("domaCodeGenJavaAll", "domaCodeGenKotlinAll") - } -} \ No newline at end of file diff --git a/codegen-h2-test/.gitignore b/codegen-h2-test/.gitignore new file mode 100644 index 0000000..cbaaccb --- /dev/null +++ b/codegen-h2-test/.gitignore @@ -0,0 +1,19 @@ +/.classpath +/.gradle/ +/.project +/.settings/ +/bin/ +/build/ +/target/ +/.metadata +/.idea/ +.factorypath +/.claude/ +/data/ +/.apt_generated/ + +/src/main/java/codegen +/src/main/kotlin/codegen +/src/main/resources/META-INF/codegen +/src/test/java/codegen +/src/test/kotlin/codegen diff --git a/codegen-h2-test/build.gradle.kts b/codegen-h2-test/build.gradle.kts new file mode 100644 index 0000000..7d3943d --- /dev/null +++ b/codegen-h2-test/build.gradle.kts @@ -0,0 +1,73 @@ +plugins { + java + alias(libs.plugins.doma.compile) + id("org.domaframework.doma.codegen") +} + +java { + toolchain.languageVersion.set(JavaLanguageVersion.of(17)) +} + +repositories { + mavenLocal() + mavenCentral() +} + +dependencies { + implementation(libs.doma.core) + annotationProcessor(libs.doma.processor) + + testImplementation(platform(libs.junit.bom)) + testImplementation(libs.junit.jupiter.api) + testRuntimeOnly(libs.junit.jupiter.engine) + testRuntimeOnly(libs.junit.platform.launcher) + + testImplementation(libs.h2) + + domaCodeGen(libs.h2) +} + +val initScript = file("init_h2.sql") +val _url = "jdbc:h2:mem:tets;INIT=RUNSCRIPT FROM 'file:${initScript.absolutePath}'" +val _user = "" +val _password = "" + +domaCodeGen { + register("h2") { + val basePackage = "codegen" + url = _url + user = _user + password = _password + schemaName = "PUBLIC" + entity { + packageName = "${basePackage}.entity" + } + dao { + packageName = "${basePackage}.dao" + } + } +} + +tasks { + compileJava { + dependsOn("domaCodeGenH2All") + } + + test { + useJUnitPlatform() + } + + val deleteSrc = register("deleteSrc") { + doLast { + delete("src/main/java/codegen") + delete("src/main/kotlin/codegen") + delete("src/main/resources/META-INF/codegen") + delete("src/test/java/codegen") + delete("src/test/kotlin/codegen") + } + } + + clean { + dependsOn(deleteSrc) + } +} \ No newline at end of file diff --git a/init_postgresql.sql b/codegen-h2-test/init_h2.sql similarity index 100% rename from init_postgresql.sql rename to codegen-h2-test/init_h2.sql diff --git a/codegen-tc-test/.gitignore b/codegen-tc-test/.gitignore new file mode 100644 index 0000000..cbaaccb --- /dev/null +++ b/codegen-tc-test/.gitignore @@ -0,0 +1,19 @@ +/.classpath +/.gradle/ +/.project +/.settings/ +/bin/ +/build/ +/target/ +/.metadata +/.idea/ +.factorypath +/.claude/ +/data/ +/.apt_generated/ + +/src/main/java/codegen +/src/main/kotlin/codegen +/src/main/resources/META-INF/codegen +/src/test/java/codegen +/src/test/kotlin/codegen diff --git a/codegen-tc-test/build.gradle.kts b/codegen-tc-test/build.gradle.kts new file mode 100644 index 0000000..22d9f1c --- /dev/null +++ b/codegen-tc-test/build.gradle.kts @@ -0,0 +1,97 @@ +import org.seasar.doma.gradle.codegen.desc.LanguageType + +plugins { + java + alias(libs.plugins.kotlin.jvm) + alias(libs.plugins.doma.compile) + id("org.domaframework.doma.codegen") +} + +java { + toolchain.languageVersion.set(JavaLanguageVersion.of(17)) +} + +repositories { + mavenLocal() + mavenCentral() +} + +dependencies { + implementation(libs.doma.core) + annotationProcessor(libs.doma.processor) + + // Use JUnit BOM for version management + testImplementation(platform(libs.junit.bom)) + testImplementation(libs.junit.jupiter.api) + testRuntimeOnly(libs.junit.jupiter.engine) + testRuntimeOnly(libs.junit.platform.launcher) + + testRuntimeOnly(platform(libs.testcontainers.bom)) + testRuntimeOnly(libs.testcontainers.postgresql) + testRuntimeOnly(libs.postgresql) + + domaCodeGen(platform(libs.testcontainers.bom)) + domaCodeGen(libs.testcontainers.postgresql) + domaCodeGen(libs.postgresql) +} + +val initScript = file("init_postgresql.sql") +val _url = "jdbc:tc:postgresql:13.21:///test?TC_INITSCRIPT=file:${initScript.absolutePath}" +val _user = "" +val _password = "" + +domaCodeGen { + register("java") { + val basePackage = "codegen" + url = _url + user = _user + password = _password + entity { + packageName = "${basePackage}.j.entity" + } + dao { + packageName = "${basePackage}.j.dao" + } + } + register("kotlin") { + val basePackage = "codegen" + url = _url + user = _user + password = _password + languageType = LanguageType.KOTLIN + entity { + packageName = "${basePackage}.k.entity" + } + dao { + packageName = "${basePackage}.k.dao" + } + } +} + +tasks { + compileJava { + dependsOn("domaCodeGenJavaAll") + } + + compileKotlin { + dependsOn("domaCodeGenKotlinAll") + } + + test { + useJUnitPlatform() + } + + val deleteSrc = register("deleteSrc") { + doLast { + delete("src/main/java/codegen") + delete("src/main/kotlin/codegen") + delete("src/main/resources/META-INF/codegen") + delete("src/test/java/codegen") + delete("src/test/kotlin/codegen") + } + } + + clean { + dependsOn(deleteSrc) + } +} \ No newline at end of file diff --git a/codegen-tc-test/init_postgresql.sql b/codegen-tc-test/init_postgresql.sql new file mode 100644 index 0000000..eb41e6b --- /dev/null +++ b/codegen-tc-test/init_postgresql.sql @@ -0,0 +1,38 @@ +CREATE TABLE IF NOT EXISTS DEPARTMENT(DEPARTMENT_ID INTEGER NOT NULL PRIMARY KEY, DEPARTMENT_NO INTEGER NOT NULL UNIQUE,DEPARTMENT_NAME VARCHAR(20),LOCATION VARCHAR(20) DEFAULT 'TOKYO', VERSION INTEGER); +CREATE TABLE IF NOT EXISTS ADDRESS(ADDRESS_ID INTEGER NOT NULL PRIMARY KEY, STREET VARCHAR(20) UNIQUE, VERSION INTEGER); +CREATE TABLE IF NOT EXISTS EMPLOYEE(EMPLOYEE_ID INTEGER NOT NULL PRIMARY KEY, EMPLOYEE_NO INTEGER NOT NULL ,EMPLOYEE_NAME VARCHAR(20),MANAGER_ID INTEGER,HIREDATE DATE,SALARY NUMERIC(7,2),DEPARTMENT_ID INTEGER,ADDRESS_ID INTEGER, VERSION INTEGER, CONSTRAINT FK_DEPARTMENT_ID FOREIGN KEY(DEPARTMENT_ID) REFERENCES DEPARTMENT(DEPARTMENT_ID), CONSTRAINT FK_ADDRESS_ID FOREIGN KEY(ADDRESS_ID) REFERENCES ADDRESS(ADDRESS_ID)); +CREATE TABLE IF NOT EXISTS COMP_KEY_ADDRESS(ADDRESS_ID1 INTEGER NOT NULL, ADDRESS_ID2 INTEGER NOT NULL, STREET VARCHAR(20), VERSION INTEGER, CONSTRAINT PK_COMP_KEY_ADDRESS PRIMARY KEY(ADDRESS_ID1, ADDRESS_ID2)); + +INSERT INTO DEPARTMENT VALUES(1,10,'ACCOUNTING','NEW YORK',1); +INSERT INTO DEPARTMENT VALUES(2,20,'RESEARCH','DALLAS',1); +INSERT INTO DEPARTMENT VALUES(3,30,'SALES','CHICAGO',1); +INSERT INTO DEPARTMENT VALUES(4,40,'OPERATIONS','BOSTON',1); +INSERT INTO ADDRESS VALUES(1,'STREET 1',1); +INSERT INTO ADDRESS VALUES(2,'STREET 2',1); +INSERT INTO ADDRESS VALUES(3,'STREET 3',1); +INSERT INTO ADDRESS VALUES(4,'STREET 4',1); +INSERT INTO ADDRESS VALUES(5,'STREET 5',1); +INSERT INTO ADDRESS VALUES(6,'STREET 6',1); +INSERT INTO ADDRESS VALUES(7,'STREET 7',1); +INSERT INTO ADDRESS VALUES(8,'STREET 8',1); +INSERT INTO ADDRESS VALUES(9,'STREET 9',1); +INSERT INTO ADDRESS VALUES(10,'STREET 10',1); +INSERT INTO ADDRESS VALUES(11,'STREET 11',1); +INSERT INTO ADDRESS VALUES(12,'STREET 12',1); +INSERT INTO ADDRESS VALUES(13,'STREET 13',1); +INSERT INTO ADDRESS VALUES(14,'STREET 14',1); +INSERT INTO ADDRESS VALUES(15,'STREET 15',1); +INSERT INTO EMPLOYEE VALUES(1,7369,'SMITH',13,'1980-12-17',800,2,1,1); +INSERT INTO EMPLOYEE VALUES(2,7499,'ALLEN',6,'1981-02-20',1600,3,2,1); +INSERT INTO EMPLOYEE VALUES(3,7521,'WARD',6,'1981-02-22',1250,3,3,1); +INSERT INTO EMPLOYEE VALUES(4,7566,'JONES',9,'1981-04-02',2975,2,4,1); +INSERT INTO EMPLOYEE VALUES(5,7654,'MARTIN',6,'1981-09-28',1250,3,5,1); +INSERT INTO EMPLOYEE VALUES(6,7698,'BLAKE',9,'1981-05-01',2850,3,6,1); +INSERT INTO EMPLOYEE VALUES(7,7782,'CLARK',9,'1981-06-09',2450,1,7,1); +INSERT INTO EMPLOYEE VALUES(8,7788,'SCOTT',4,'1982-12-09',3000.0,2,8,1); +INSERT INTO EMPLOYEE VALUES(9,7839,'KING',NULL,'1981-11-17',5000,1,9,1); +INSERT INTO EMPLOYEE VALUES(10,7844,'TURNER',6,'1981-09-08',1500,3,10,1); +INSERT INTO EMPLOYEE VALUES(11,7876,'ADAMS',8,'1983-01-12',1100,2,11,1); +INSERT INTO EMPLOYEE VALUES(12,7900,'JAMES',6,'1981-12-03',950,3,12,1); +INSERT INTO EMPLOYEE VALUES(13,7902,'FORD',4,'1981-12-03',3000,2,13,1); +INSERT INTO EMPLOYEE VALUES(14,7934,'MILLER',7,'1982-01-23',1300,1,14,1); diff --git a/codegen-tc-test/src/main/java/org/domaframework/doma/Main.java b/codegen-tc-test/src/main/java/org/domaframework/doma/Main.java new file mode 100644 index 0000000..226b6dc --- /dev/null +++ b/codegen-tc-test/src/main/java/org/domaframework/doma/Main.java @@ -0,0 +1,17 @@ +package org.domaframework.doma; + +//TIP To Run code, press or +// click the icon in the gutter. +public class Main { + public static void main(String[] args) { + //TIP Press with your caret at the highlighted text + // to see how IntelliJ IDEA suggests fixing it. + System.out.printf("Hello and welcome!"); + + for (int i = 1; i <= 5; i++) { + //TIP Press to start debugging your code. We have set one breakpoint + // for you, but you can always add more by pressing . + System.out.println("i = " + i); + } + } +} \ No newline at end of file diff --git a/codegen/gradle/wrapper/gradle-wrapper.jar b/codegen/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index e644113..0000000 Binary files a/codegen/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/codegen/gradle/wrapper/gradle-wrapper.properties b/codegen/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index df97d72..0000000 --- a/codegen/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,7 +0,0 @@ -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip -networkTimeout=10000 -validateDistributionUrl=true -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists diff --git a/codegen/gradlew b/codegen/gradlew deleted file mode 100755 index b740cf1..0000000 --- a/codegen/gradlew +++ /dev/null @@ -1,249 +0,0 @@ -#!/bin/sh - -# -# Copyright © 2015-2021 the original authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -############################################################################## -# -# Gradle start up script for POSIX generated by Gradle. -# -# Important for running: -# -# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is -# noncompliant, but you have some other compliant shell such as ksh or -# bash, then to run this script, type that shell name before the whole -# command line, like: -# -# ksh Gradle -# -# Busybox and similar reduced shells will NOT work, because this script -# requires all of these POSIX shell features: -# * functions; -# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», -# «${var#prefix}», «${var%suffix}», and «$( cmd )»; -# * compound commands having a testable exit status, especially «case»; -# * various built-in commands including «command», «set», and «ulimit». -# -# Important for patching: -# -# (2) This script targets any POSIX shell, so it avoids extensions provided -# by Bash, Ksh, etc; in particular arrays are avoided. -# -# The "traditional" practice of packing multiple parameters into a -# space-separated string is a well documented source of bugs and security -# problems, so this is (mostly) avoided, by progressively accumulating -# options in "$@", and eventually passing that to Java. -# -# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, -# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; -# see the in-line comments for details. -# -# There are tweaks for specific operating systems such as AIX, CygWin, -# Darwin, MinGW, and NonStop. -# -# (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt -# within the Gradle project. -# -# You can find Gradle at https://github.com/gradle/gradle/. -# -############################################################################## - -# Attempt to set APP_HOME - -# Resolve links: $0 may be a link -app_path=$0 - -# Need this for daisy-chained symlinks. -while - APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path - [ -h "$app_path" ] -do - ls=$( ls -ld "$app_path" ) - link=${ls#*' -> '} - case $link in #( - /*) app_path=$link ;; #( - *) app_path=$APP_HOME$link ;; - esac -done - -# This is normally unused -# shellcheck disable=SC2034 -APP_BASE_NAME=${0##*/} -# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) -APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD=maximum - -warn () { - echo "$*" -} >&2 - -die () { - echo - echo "$*" - echo - exit 1 -} >&2 - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "$( uname )" in #( - CYGWIN* ) cygwin=true ;; #( - Darwin* ) darwin=true ;; #( - MSYS* | MINGW* ) msys=true ;; #( - NONSTOP* ) nonstop=true ;; -esac - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD=$JAVA_HOME/jre/sh/java - else - JAVACMD=$JAVA_HOME/bin/java - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD=java - if ! command -v java >/dev/null 2>&1 - then - die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -fi - -# Increase the maximum file descriptors if we can. -if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then - case $MAX_FD in #( - max*) - # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC2039,SC3045 - MAX_FD=$( ulimit -H -n ) || - warn "Could not query maximum file descriptor limit" - esac - case $MAX_FD in #( - '' | soft) :;; #( - *) - # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC2039,SC3045 - ulimit -n "$MAX_FD" || - warn "Could not set maximum file descriptor limit to $MAX_FD" - esac -fi - -# Collect all arguments for the java command, stacking in reverse order: -# * args from the command line -# * the main class name -# * -classpath -# * -D...appname settings -# * --module-path (only if needed) -# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. - -# For Cygwin or MSYS, switch paths to Windows format before running java -if "$cygwin" || "$msys" ; then - APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) - CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) - - JAVACMD=$( cygpath --unix "$JAVACMD" ) - - # Now convert the arguments - kludge to limit ourselves to /bin/sh - for arg do - if - case $arg in #( - -*) false ;; # don't mess with options #( - /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath - [ -e "$t" ] ;; #( - *) false ;; - esac - then - arg=$( cygpath --path --ignore --mixed "$arg" ) - fi - # Roll the args list around exactly as many times as the number of - # args, so each arg winds up back in the position where it started, but - # possibly modified. - # - # NB: a `for` loop captures its iteration list before it begins, so - # changing the positional parameters here affects neither the number of - # iterations, nor the values presented in `arg`. - shift # remove old arg - set -- "$@" "$arg" # push replacement arg - done -fi - - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' - -# Collect all arguments for the java command: -# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, -# and any embedded shellness will be escaped. -# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be -# treated as '${Hostname}' itself on the command line. - -set -- \ - "-Dorg.gradle.appname=$APP_BASE_NAME" \ - -classpath "$CLASSPATH" \ - org.gradle.wrapper.GradleWrapperMain \ - "$@" - -# Stop when "xargs" is not available. -if ! command -v xargs >/dev/null 2>&1 -then - die "xargs is not available" -fi - -# Use "xargs" to parse quoted args. -# -# With -n1 it outputs one arg per line, with the quotes and backslashes removed. -# -# In Bash we could simply go: -# -# readarray ARGS < <( xargs -n1 <<<"$var" ) && -# set -- "${ARGS[@]}" "$@" -# -# but POSIX shell has neither arrays nor command substitution, so instead we -# post-process each arg (as a line of input to sed) to backslash-escape any -# character that might be a shell metacharacter, then use eval to reverse -# that process (while maintaining the separation between arguments), and wrap -# the whole thing up as a single "set" statement. -# -# This will of course break if any of these variables contains a newline or -# an unmatched quote. -# - -eval "set -- $( - printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | - xargs -n1 | - sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | - tr '\n' ' ' - )" '"$@"' - -exec "$JAVACMD" "$@" diff --git a/codegen/gradlew.bat b/codegen/gradlew.bat deleted file mode 100644 index 25da30d..0000000 --- a/codegen/gradlew.bat +++ /dev/null @@ -1,92 +0,0 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%"=="" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%"=="" set DIRNAME=. -@rem This is normally unused -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if %ERRORLEVEL% equ 0 goto execute - -echo. 1>&2 -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 -echo. 1>&2 -echo Please set the JAVA_HOME variable in your environment to match the 1>&2 -echo location of your Java installation. 1>&2 - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. 1>&2 -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 -echo. 1>&2 -echo Please set the JAVA_HOME variable in your environment to match the 1>&2 -echo location of your Java installation. 1>&2 - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if %ERRORLEVEL% equ 0 goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -set EXIT_CODE=%ERRORLEVEL% -if %EXIT_CODE% equ 0 set EXIT_CODE=1 -if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% -exit /b %EXIT_CODE% - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/codegen/src/main/java/org/seasar/doma/gradle/codegen/extension/CodeGenConfig.java b/codegen/src/main/java/org/seasar/doma/gradle/codegen/extension/CodeGenConfig.java index e87c310..a5cf109 100644 --- a/codegen/src/main/java/org/seasar/doma/gradle/codegen/extension/CodeGenConfig.java +++ b/codegen/src/main/java/org/seasar/doma/gradle/codegen/extension/CodeGenConfig.java @@ -12,7 +12,6 @@ import java.util.Set; import javax.inject.Inject; import javax.sql.DataSource; - import org.gradle.api.Action; import org.gradle.api.Project; import org.gradle.api.artifacts.Configuration; @@ -153,19 +152,19 @@ private void applyDefaults(Project project) { private Provider dataSourceProvider() { return url.map( - it -> { - String driverClassName = JdbcUtil.inferDriverClassName(it); - if (driverClassName == null) { - throw new CodeGenException(Message.DOMAGEN0024); - } - ClassLoader classLoader = createClassLoader(); - Driver driver = - ClassUtil.newInstance(Driver.class, driverClassName, "driverClassName", classLoader); - DriverWrapper driverWrapper = new DriverWrapper(driver); - return globalFactory - .get() - .createDataSource(driverWrapper, user.getOrNull(), password.getOrNull(), url.get()); - }); + it -> { + String driverClassName = JdbcUtil.inferDriverClassName(it); + if (driverClassName == null) { + throw new CodeGenException(Message.DOMAGEN0024); + } + ClassLoader classLoader = createClassLoader(); + Driver driver = + ClassUtil.newInstance(Driver.class, driverClassName, "driverClassName", classLoader); + DriverWrapper driverWrapper = new DriverWrapper(driver); + return globalFactory + .get() + .createDataSource(driverWrapper, user.getOrNull(), password.getOrNull(), url.get()); + }); } protected ClassLoader createClassLoader() { @@ -187,17 +186,17 @@ protected ClassLoader createClassLoader() { private Provider codeGenDialectProvider() { return url.map( - it -> { - String dialectName = JdbcUtil.inferDialectName(it); - if (dialectName == null) { - throw new CodeGenException(Message.DOMAGEN0025); - } - CodeGenDialect codeGenDialect = CodeGenDialectRegistry.lookup(dialectName); - if (codeGenDialect == null) { - throw new CodeGenException(Message.DOMAGEN0023, dialectName); - } - return codeGenDialect; - }); + it -> { + String dialectName = JdbcUtil.inferDialectName(it); + if (dialectName == null) { + throw new CodeGenException(Message.DOMAGEN0025); + } + CodeGenDialect codeGenDialect = CodeGenDialectRegistry.lookup(dialectName); + if (codeGenDialect == null) { + throw new CodeGenException(Message.DOMAGEN0023, dialectName); + } + return codeGenDialect; + }); } private Provider languageClassResolverProvider() { @@ -206,30 +205,29 @@ private Provider languageClassResolverProvider() { private Provider sourceDirProvider(Project project) { return languageType.map( - it -> project.getLayout().getProjectDirectory().dir("src/main/" + it.name().toLowerCase())); + it -> project.getLayout().getProjectDirectory().dir("src/main/" + it.name().toLowerCase())); } private Provider testSourceDirProvider(Project project) { return languageType.map( - it -> project.getLayout().getProjectDirectory().dir("src/test/" + it.name().toLowerCase())); + it -> project.getLayout().getProjectDirectory().dir("src/test/" + it.name().toLowerCase())); } private Provider generatorProvider() { return globalFactory.map( - it -> - it.createGenerator( - languageType.get(), templateEncoding.get(), templateDir.getAsFile().getOrNull())); + it -> + it.createGenerator( + languageType.get(), templateEncoding.get(), templateDir.getAsFile().getOrNull())); } private Provider sqlFilesProvider() { return resourceDir.map( - it -> { - String packageName = daoConfig.getPackageName().get(); - String path = packageName.replace('.', '/'); - return it.getAsFileTree() - .matching( - filterConfig -> filterConfig.include("META-INF/" + path + "/*/*.sql")); - }); + it -> { + String packageName = daoConfig.getPackageName().get(); + String path = packageName.replace('.', '/'); + return it.getAsFileTree() + .matching(filterConfig -> filterConfig.include("META-INF/" + path + "/*/*.sql")); + }); } private void validateProperties(Project project) { @@ -238,13 +236,13 @@ private void validateProperties(Project project) { } if (!dataSource.isPresent()) { throw new CodeGenException( - Message.DOMAGEN0007, "dataSource", "Specify the \"url\" or the \"dataSource\" property."); + Message.DOMAGEN0007, "dataSource", "Specify the \"url\" or the \"dataSource\" property."); } if (!codeGenDialect.isPresent()) { throw new CodeGenException( - Message.DOMAGEN0007, - "codeGenDialect", - "Specify the \"url\" or the \"codeGenDialect\" property."); + Message.DOMAGEN0007, + "codeGenDialect", + "Specify the \"url\" or the \"codeGenDialect\" property."); } if (!tableNamePattern.isPresent()) { throw new CodeGenException(Message.DOMAGEN0007, "tableNamePattern", ""); diff --git a/gradle.properties b/gradle.properties index 0c281d9..6941e44 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,6 @@ group=org.domaframework.doma version=3.2.1-SNAPSHOT release.useAutomaticVersion=true -domaVersion=3.9.1 +org.gradle.parallel=true +org.gradle.caching=true +org.gradle.jvmargs=-Xmx2048M diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index ea3904e..1c3d0cb 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -2,6 +2,7 @@ # Core dependencies doma = "3.9.1" freemarker = "2.3.34" +h2 = "2.3.232" postgresql = "42.7.7" # Testing @@ -11,7 +12,6 @@ testcontainers = "1.21.2" # Plugins kotlin = "2.2.0" domaCompile = "4.0.0" -runsql = "1.0.3" release = "3.1.0" spotless = "7.0.4" pluginPublish = "1.3.1" @@ -28,6 +28,7 @@ doma-processor = { group = "org.seasar.doma", name = "doma-processor", version.r freemarker = { group = "org.freemarker", name = "freemarker", version.ref = "freemarker" } # Database drivers +h2 = { group = "com.h2database", name = "h2", version.ref = "h2" } postgresql = { group = "org.postgresql", name = "postgresql", version.ref = "postgresql" } # Testing - BOMs diff --git a/settings.gradle.kts b/settings.gradle.kts index 22c2b0c..e8de97b 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -3,3 +3,6 @@ rootProject.name = "doma-codegen-plugin" pluginManagement { includeBuild("codegen") } + +include("codegen-h2-test") +include("codegen-tc-test") diff --git a/template/entity.ftl b/template/entity.ftl deleted file mode 100644 index b6fc4c6..0000000 --- a/template/entity.ftl +++ /dev/null @@ -1 +0,0 @@ -hello \ No newline at end of file