From 5befaf65766247178d8a1d10f92b5d524d55b2e3 Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Tue, 5 Dec 2023 16:37:21 +0100 Subject: [PATCH] [jOOQ/jOOQ#12985] Support a Groovy DSL in jOOQ-codegen-gradle --- jOOQ-codegen-gradle/build.gradle.kts | 3 + .../gradle/CodegenPluginExtension.java | 48 + .../jooq/codegen/gradle/MetaExtensions.java | 832 ++++++++++++++++++ .../codegen/gradle/NamedConfiguration.java | 48 + .../kotlin/org/jooq/meta/kotlin/Extensions.kt | 4 +- .../org/jooq/util/jaxb/tools/MiniJAXB.java | 4 +- 6 files changed, 935 insertions(+), 4 deletions(-) create mode 100644 jOOQ-codegen-gradle/src/main/java/org/jooq/codegen/gradle/MetaExtensions.java diff --git a/jOOQ-codegen-gradle/build.gradle.kts b/jOOQ-codegen-gradle/build.gradle.kts index 4d507493ac..e5824ef794 100644 --- a/jOOQ-codegen-gradle/build.gradle.kts +++ b/jOOQ-codegen-gradle/build.gradle.kts @@ -1,5 +1,8 @@ +import org.gradle.kotlin.dsl.groovy + plugins { id("java") + id("groovy") kotlin("jvm") version "1.9.20" id("com.gradle.plugin-publish") version "1.2.0" } diff --git a/jOOQ-codegen-gradle/src/main/java/org/jooq/codegen/gradle/CodegenPluginExtension.java b/jOOQ-codegen-gradle/src/main/java/org/jooq/codegen/gradle/CodegenPluginExtension.java index 85e31f6ec2..59e27b3dd3 100644 --- a/jOOQ-codegen-gradle/src/main/java/org/jooq/codegen/gradle/CodegenPluginExtension.java +++ b/jOOQ-codegen-gradle/src/main/java/org/jooq/codegen/gradle/CodegenPluginExtension.java @@ -1,3 +1,40 @@ +/* + * 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. + * + * Other licenses: + * ----------------------------------------------------------------------------- + * Commercial licenses for this work are available. These replace the above + * ASL 2.0 and offer limited warranties, support, maintenance, and commercial + * database integrations. + * + * For more information, please visit: https://www.jooq.org/legal/licensing + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ package org.jooq.codegen.gradle; import org.gradle.api.NamedDomainObjectContainer; @@ -15,6 +52,9 @@ import java.util.List; import static java.util.stream.Collectors.toList; +import groovy.lang.*; +import org.codehaus.groovy.runtime.*; + /** * The configuration object of the jooq plugin extension. */ @@ -36,6 +76,14 @@ public class CodegenPluginExtension { MiniJAXB.append(this.configuration, configuration); } + public void configuration(Closure closure) { + MetaExtensions.ConfigurationExtension c = new MetaExtensions.ConfigurationExtension(); + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(c); + closure.call(c); + configuration(c); + } + public NamedDomainObjectContainer getExecutions() { return executions; } diff --git a/jOOQ-codegen-gradle/src/main/java/org/jooq/codegen/gradle/MetaExtensions.java b/jOOQ-codegen-gradle/src/main/java/org/jooq/codegen/gradle/MetaExtensions.java new file mode 100644 index 0000000000..bb898fb329 --- /dev/null +++ b/jOOQ-codegen-gradle/src/main/java/org/jooq/codegen/gradle/MetaExtensions.java @@ -0,0 +1,832 @@ +/* + * 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. + * + * Other licenses: + * ----------------------------------------------------------------------------- + * Commercial licenses for this work are available. These replace the above + * ASL 2.0 and offer limited warranties, support, maintenance, and commercial + * database integrations. + * + * For more information, please visit: https://www.jooq.org/legal/licensing + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ +package org.jooq.codegen.gradle; + +import java.util.*; +import groovy.lang.*; +import org.jooq.meta.jaxb.*; + +/** + * Extensions for the jOOQ-meta types, to enable groovy DSL usage. + */ +public class MetaExtensions { + + + public static class ConfigurationExtension extends Configuration { + public void jdbc(Closure closure) { + JdbcExtension o = new JdbcExtension(); + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(o); + closure.call(o); + setJdbc(o); + } + public void generator(Closure closure) { + GeneratorExtension o = new GeneratorExtension(); + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(o); + closure.call(o); + setGenerator(o); + } + } + + public static class JdbcExtension extends Jdbc { + + public void properties(Closure closure) { + ArrayList l = new ArrayList() { + public void property(Closure c) { + PropertyExtension o = new PropertyExtension(); + c.setResolveStrategy(Closure.DELEGATE_FIRST); + c.setDelegate(o); + c.call(o); + add(o); + } + }; + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(l); + closure.call(l); + setProperties(l); + } + } + + public static class PropertyExtension extends Property { + } + + public static class GeneratorExtension extends Generator { + public void strategy(Closure closure) { + StrategyExtension o = new StrategyExtension(); + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(o); + closure.call(o); + setStrategy(o); + } + public void database(Closure closure) { + DatabaseExtension o = new DatabaseExtension(); + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(o); + closure.call(o); + setDatabase(o); + } + public void generate(Closure closure) { + GenerateExtension o = new GenerateExtension(); + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(o); + closure.call(o); + setGenerate(o); + } + public void target(Closure closure) { + TargetExtension o = new TargetExtension(); + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(o); + closure.call(o); + setTarget(o); + } + } + + public static class StrategyExtension extends Strategy { + public void matchers(Closure closure) { + MatchersExtension o = new MatchersExtension(); + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(o); + closure.call(o); + setMatchers(o); + } + } + + public static class MatchersExtension extends Matchers { + + public void catalogs(Closure closure) { + ArrayList l = new ArrayList() { + public void catalog(Closure c) { + MatchersCatalogTypeExtension o = new MatchersCatalogTypeExtension(); + c.setResolveStrategy(Closure.DELEGATE_FIRST); + c.setDelegate(o); + c.call(o); + add(o); + } + }; + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(l); + closure.call(l); + setCatalogs(l); + } + + public void schemas(Closure closure) { + ArrayList l = new ArrayList() { + public void schema(Closure c) { + MatchersSchemaTypeExtension o = new MatchersSchemaTypeExtension(); + c.setResolveStrategy(Closure.DELEGATE_FIRST); + c.setDelegate(o); + c.call(o); + add(o); + } + }; + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(l); + closure.call(l); + setSchemas(l); + } + + public void tables(Closure closure) { + ArrayList l = new ArrayList() { + public void table(Closure c) { + MatchersTableTypeExtension o = new MatchersTableTypeExtension(); + c.setResolveStrategy(Closure.DELEGATE_FIRST); + c.setDelegate(o); + c.call(o); + add(o); + } + }; + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(l); + closure.call(l); + setTables(l); + } + + public void indexes(Closure closure) { + ArrayList l = new ArrayList() { + public void index(Closure c) { + MatchersIndexTypeExtension o = new MatchersIndexTypeExtension(); + c.setResolveStrategy(Closure.DELEGATE_FIRST); + c.setDelegate(o); + c.call(o); + add(o); + } + }; + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(l); + closure.call(l); + setIndexes(l); + } + + public void primaryKeys(Closure closure) { + ArrayList l = new ArrayList() { + public void primaryKey(Closure c) { + MatchersPrimaryKeyTypeExtension o = new MatchersPrimaryKeyTypeExtension(); + c.setResolveStrategy(Closure.DELEGATE_FIRST); + c.setDelegate(o); + c.call(o); + add(o); + } + }; + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(l); + closure.call(l); + setPrimaryKeys(l); + } + + public void uniqueKeys(Closure closure) { + ArrayList l = new ArrayList() { + public void uniqueKey(Closure c) { + MatchersUniqueKeyTypeExtension o = new MatchersUniqueKeyTypeExtension(); + c.setResolveStrategy(Closure.DELEGATE_FIRST); + c.setDelegate(o); + c.call(o); + add(o); + } + }; + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(l); + closure.call(l); + setUniqueKeys(l); + } + + public void foreignKeys(Closure closure) { + ArrayList l = new ArrayList() { + public void foreignKey(Closure c) { + MatchersForeignKeyTypeExtension o = new MatchersForeignKeyTypeExtension(); + c.setResolveStrategy(Closure.DELEGATE_FIRST); + c.setDelegate(o); + c.call(o); + add(o); + } + }; + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(l); + closure.call(l); + setForeignKeys(l); + } + + public void fields(Closure closure) { + ArrayList l = new ArrayList() { + public void field(Closure c) { + MatchersFieldTypeExtension o = new MatchersFieldTypeExtension(); + c.setResolveStrategy(Closure.DELEGATE_FIRST); + c.setDelegate(o); + c.call(o); + add(o); + } + }; + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(l); + closure.call(l); + setFields(l); + } + + public void routines(Closure closure) { + ArrayList l = new ArrayList() { + public void routine(Closure c) { + MatchersRoutineTypeExtension o = new MatchersRoutineTypeExtension(); + c.setResolveStrategy(Closure.DELEGATE_FIRST); + c.setDelegate(o); + c.call(o); + add(o); + } + }; + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(l); + closure.call(l); + setRoutines(l); + } + + public void sequences(Closure closure) { + ArrayList l = new ArrayList() { + public void sequence(Closure c) { + MatchersSequenceTypeExtension o = new MatchersSequenceTypeExtension(); + c.setResolveStrategy(Closure.DELEGATE_FIRST); + c.setDelegate(o); + c.call(o); + add(o); + } + }; + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(l); + closure.call(l); + setSequences(l); + } + + public void enums(Closure closure) { + ArrayList l = new ArrayList() { + public void enum_(Closure c) { + MatchersEnumTypeExtension o = new MatchersEnumTypeExtension(); + c.setResolveStrategy(Closure.DELEGATE_FIRST); + c.setDelegate(o); + c.call(o); + add(o); + } + }; + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(l); + closure.call(l); + setEnums(l); + } + + public void embeddables(Closure closure) { + ArrayList l = new ArrayList() { + public void embeddable(Closure c) { + MatchersEmbeddableTypeExtension o = new MatchersEmbeddableTypeExtension(); + c.setResolveStrategy(Closure.DELEGATE_FIRST); + c.setDelegate(o); + c.call(o); + add(o); + } + }; + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(l); + closure.call(l); + setEmbeddables(l); + } + + public void udts(Closure closure) { + ArrayList l = new ArrayList() { + public void udt(Closure c) { + MatchersUDTTypeExtension o = new MatchersUDTTypeExtension(); + c.setResolveStrategy(Closure.DELEGATE_FIRST); + c.setDelegate(o); + c.call(o); + add(o); + } + }; + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(l); + closure.call(l); + setUdts(l); + } + + public void attributes(Closure closure) { + ArrayList l = new ArrayList() { + public void attribute(Closure c) { + MatchersAttributeTypeExtension o = new MatchersAttributeTypeExtension(); + c.setResolveStrategy(Closure.DELEGATE_FIRST); + c.setDelegate(o); + c.call(o); + add(o); + } + }; + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(l); + closure.call(l); + setAttributes(l); + } + } + + public static class MatchersCatalogTypeExtension extends MatchersCatalogType { + public void catalogClass(Closure closure) { + MatcherRuleExtension o = new MatcherRuleExtension(); + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(o); + closure.call(o); + setCatalogClass(o); + } + } + + public static class MatcherRuleExtension extends MatcherRule { + } + + public static class MatchersSchemaTypeExtension extends MatchersSchemaType { + } + + public static class MatchersTableTypeExtension extends MatchersTableType { + } + + public static class MatchersIndexTypeExtension extends MatchersIndexType { + } + + public static class MatchersPrimaryKeyTypeExtension extends MatchersPrimaryKeyType { + } + + public static class MatchersUniqueKeyTypeExtension extends MatchersUniqueKeyType { + } + + public static class MatchersForeignKeyTypeExtension extends MatchersForeignKeyType { + } + + public static class MatchersFieldTypeExtension extends MatchersFieldType { + } + + public static class MatchersRoutineTypeExtension extends MatchersRoutineType { + } + + public static class MatchersSequenceTypeExtension extends MatchersSequenceType { + } + + public static class MatchersEnumTypeExtension extends MatchersEnumType { + } + + public static class MatchersEmbeddableTypeExtension extends MatchersEmbeddableType { + } + + public static class MatchersUDTTypeExtension extends MatchersUDTType { + } + + public static class MatchersAttributeTypeExtension extends MatchersAttributeType { + } + + public static class DatabaseExtension extends Database { + public void syntheticObjects(Closure closure) { + SyntheticObjectsTypeExtension o = new SyntheticObjectsTypeExtension(); + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(o); + closure.call(o); + setSyntheticObjects(o); + } + + public void properties(Closure closure) { + ArrayList l = new ArrayList() { + public void property(Closure c) { + PropertyExtension o = new PropertyExtension(); + c.setResolveStrategy(Closure.DELEGATE_FIRST); + c.setDelegate(o); + c.call(o); + add(o); + } + }; + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(l); + closure.call(l); + setProperties(l); + } + + public void comments(Closure closure) { + ArrayList l = new ArrayList() { + public void comment(Closure c) { + CommentTypeExtension o = new CommentTypeExtension(); + c.setResolveStrategy(Closure.DELEGATE_FIRST); + c.setDelegate(o); + c.call(o); + add(o); + } + }; + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(l); + closure.call(l); + setComments(l); + } + + public void catalogs(Closure closure) { + ArrayList l = new ArrayList() { + public void catalog(Closure c) { + CatalogMappingTypeExtension o = new CatalogMappingTypeExtension(); + c.setResolveStrategy(Closure.DELEGATE_FIRST); + c.setDelegate(o); + c.call(o); + add(o); + } + }; + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(l); + closure.call(l); + setCatalogs(l); + } + + public void schemata(Closure closure) { + ArrayList l = new ArrayList() { + public void schema(Closure c) { + SchemaMappingTypeExtension o = new SchemaMappingTypeExtension(); + c.setResolveStrategy(Closure.DELEGATE_FIRST); + c.setDelegate(o); + c.call(o); + add(o); + } + }; + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(l); + closure.call(l); + setSchemata(l); + } + + public void embeddables(Closure closure) { + ArrayList l = new ArrayList() { + public void embeddable(Closure c) { + EmbeddableDefinitionTypeExtension o = new EmbeddableDefinitionTypeExtension(); + c.setResolveStrategy(Closure.DELEGATE_FIRST); + c.setDelegate(o); + c.call(o); + add(o); + } + }; + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(l); + closure.call(l); + setEmbeddables(l); + } + + public void customTypes(Closure closure) { + ArrayList l = new ArrayList() { + public void customType(Closure c) { + CustomTypeExtension o = new CustomTypeExtension(); + c.setResolveStrategy(Closure.DELEGATE_FIRST); + c.setDelegate(o); + c.call(o); + add(o); + } + }; + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(l); + closure.call(l); + setCustomTypes(l); + } + + public void enumTypes(Closure closure) { + ArrayList l = new ArrayList() { + public void enumType(Closure c) { + EnumTypeExtension o = new EnumTypeExtension(); + c.setResolveStrategy(Closure.DELEGATE_FIRST); + c.setDelegate(o); + c.call(o); + add(o); + } + }; + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(l); + closure.call(l); + setEnumTypes(l); + } + + public void forcedTypes(Closure closure) { + ArrayList l = new ArrayList() { + public void forcedType(Closure c) { + ForcedTypeExtension o = new ForcedTypeExtension(); + c.setResolveStrategy(Closure.DELEGATE_FIRST); + c.setDelegate(o); + c.call(o); + add(o); + } + }; + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(l); + closure.call(l); + setForcedTypes(l); + } + } + + public static class SyntheticObjectsTypeExtension extends SyntheticObjectsType { + + public void readonlyColumns(Closure closure) { + ArrayList l = new ArrayList() { + public void readonlyColumn(Closure c) { + SyntheticReadonlyColumnTypeExtension o = new SyntheticReadonlyColumnTypeExtension(); + c.setResolveStrategy(Closure.DELEGATE_FIRST); + c.setDelegate(o); + c.call(o); + add(o); + } + }; + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(l); + closure.call(l); + setReadonlyColumns(l); + } + + public void readonlyRowids(Closure closure) { + ArrayList l = new ArrayList() { + public void readonlyRowid(Closure c) { + SyntheticReadonlyRowidTypeExtension o = new SyntheticReadonlyRowidTypeExtension(); + c.setResolveStrategy(Closure.DELEGATE_FIRST); + c.setDelegate(o); + c.call(o); + add(o); + } + }; + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(l); + closure.call(l); + setReadonlyRowids(l); + } + + public void columns(Closure closure) { + ArrayList l = new ArrayList() { + public void column(Closure c) { + SyntheticColumnTypeExtension o = new SyntheticColumnTypeExtension(); + c.setResolveStrategy(Closure.DELEGATE_FIRST); + c.setDelegate(o); + c.call(o); + add(o); + } + }; + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(l); + closure.call(l); + setColumns(l); + } + + public void identities(Closure closure) { + ArrayList l = new ArrayList() { + public void identity(Closure c) { + SyntheticIdentityTypeExtension o = new SyntheticIdentityTypeExtension(); + c.setResolveStrategy(Closure.DELEGATE_FIRST); + c.setDelegate(o); + c.call(o); + add(o); + } + }; + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(l); + closure.call(l); + setIdentities(l); + } + + public void enums(Closure closure) { + ArrayList l = new ArrayList() { + public void enum_(Closure c) { + SyntheticEnumTypeExtension o = new SyntheticEnumTypeExtension(); + c.setResolveStrategy(Closure.DELEGATE_FIRST); + c.setDelegate(o); + c.call(o); + add(o); + } + }; + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(l); + closure.call(l); + setEnums(l); + } + + public void primaryKeys(Closure closure) { + ArrayList l = new ArrayList() { + public void primaryKey(Closure c) { + SyntheticPrimaryKeyTypeExtension o = new SyntheticPrimaryKeyTypeExtension(); + c.setResolveStrategy(Closure.DELEGATE_FIRST); + c.setDelegate(o); + c.call(o); + add(o); + } + }; + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(l); + closure.call(l); + setPrimaryKeys(l); + } + + public void uniqueKeys(Closure closure) { + ArrayList l = new ArrayList() { + public void uniqueKey(Closure c) { + SyntheticUniqueKeyTypeExtension o = new SyntheticUniqueKeyTypeExtension(); + c.setResolveStrategy(Closure.DELEGATE_FIRST); + c.setDelegate(o); + c.call(o); + add(o); + } + }; + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(l); + closure.call(l); + setUniqueKeys(l); + } + + public void foreignKeys(Closure closure) { + ArrayList l = new ArrayList() { + public void foreignKey(Closure c) { + SyntheticForeignKeyTypeExtension o = new SyntheticForeignKeyTypeExtension(); + c.setResolveStrategy(Closure.DELEGATE_FIRST); + c.setDelegate(o); + c.call(o); + add(o); + } + }; + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(l); + closure.call(l); + setForeignKeys(l); + } + + public void views(Closure closure) { + ArrayList l = new ArrayList() { + public void view(Closure c) { + SyntheticViewTypeExtension o = new SyntheticViewTypeExtension(); + c.setResolveStrategy(Closure.DELEGATE_FIRST); + c.setDelegate(o); + c.call(o); + add(o); + } + }; + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(l); + closure.call(l); + setViews(l); + } + + public void daos(Closure closure) { + ArrayList l = new ArrayList() { + public void dao(Closure c) { + SyntheticDaoTypeExtension o = new SyntheticDaoTypeExtension(); + c.setResolveStrategy(Closure.DELEGATE_FIRST); + c.setDelegate(o); + c.call(o); + add(o); + } + }; + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(l); + closure.call(l); + setDaos(l); + } + } + + public static class SyntheticReadonlyColumnTypeExtension extends SyntheticReadonlyColumnType { + } + + public static class SyntheticReadonlyRowidTypeExtension extends SyntheticReadonlyRowidType { + } + + public static class SyntheticColumnTypeExtension extends SyntheticColumnType { + } + + public static class SyntheticIdentityTypeExtension extends SyntheticIdentityType { + } + + public static class SyntheticEnumTypeExtension extends SyntheticEnumType { + } + + public static class SyntheticPrimaryKeyTypeExtension extends SyntheticPrimaryKeyType { + } + + public static class SyntheticUniqueKeyTypeExtension extends SyntheticUniqueKeyType { + } + + public static class SyntheticForeignKeyTypeExtension extends SyntheticForeignKeyType { + } + + public static class SyntheticViewTypeExtension extends SyntheticViewType { + } + + public static class SyntheticDaoTypeExtension extends SyntheticDaoType { + + public void methods(Closure closure) { + ArrayList l = new ArrayList() { + public void method(Closure c) { + SyntheticDaoMethodTypeExtension o = new SyntheticDaoMethodTypeExtension(); + c.setResolveStrategy(Closure.DELEGATE_FIRST); + c.setDelegate(o); + c.call(o); + add(o); + } + }; + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(l); + closure.call(l); + setMethods(l); + } + } + + public static class SyntheticDaoMethodTypeExtension extends SyntheticDaoMethodType { + } + + public static class CommentTypeExtension extends CommentType { + } + + public static class CatalogMappingTypeExtension extends CatalogMappingType { + + public void schemata(Closure closure) { + ArrayList l = new ArrayList() { + public void schema(Closure c) { + SchemaMappingTypeExtension o = new SchemaMappingTypeExtension(); + c.setResolveStrategy(Closure.DELEGATE_FIRST); + c.setDelegate(o); + c.call(o); + add(o); + } + }; + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(l); + closure.call(l); + setSchemata(l); + } + } + + public static class SchemaMappingTypeExtension extends SchemaMappingType { + } + + public static class EmbeddableDefinitionTypeExtension extends EmbeddableDefinitionType { + + public void fields(Closure closure) { + ArrayList l = new ArrayList() { + public void field(Closure c) { + EmbeddableFieldExtension o = new EmbeddableFieldExtension(); + c.setResolveStrategy(Closure.DELEGATE_FIRST); + c.setDelegate(o); + c.call(o); + add(o); + } + }; + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(l); + closure.call(l); + setFields(l); + } + } + + public static class EmbeddableFieldExtension extends EmbeddableField { + } + + public static class CustomTypeExtension extends CustomType { + public void lambdaConverter(Closure closure) { + LambdaConverterExtension o = new LambdaConverterExtension(); + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(o); + closure.call(o); + setLambdaConverter(o); + } + } + + public static class LambdaConverterExtension extends LambdaConverter { + } + + public static class EnumTypeExtension extends EnumType { + } + + public static class ForcedTypeExtension extends ForcedType { + } + + public static class GenerateExtension extends Generate { + } + + public static class TargetExtension extends Target { + } + + +} \ No newline at end of file diff --git a/jOOQ-codegen-gradle/src/main/java/org/jooq/codegen/gradle/NamedConfiguration.java b/jOOQ-codegen-gradle/src/main/java/org/jooq/codegen/gradle/NamedConfiguration.java index 2a36139e95..20798c02a2 100644 --- a/jOOQ-codegen-gradle/src/main/java/org/jooq/codegen/gradle/NamedConfiguration.java +++ b/jOOQ-codegen-gradle/src/main/java/org/jooq/codegen/gradle/NamedConfiguration.java @@ -1,3 +1,40 @@ +/* + * 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. + * + * Other licenses: + * ----------------------------------------------------------------------------- + * Commercial licenses for this work are available. These replace the above + * ASL 2.0 and offer limited warranties, support, maintenance, and commercial + * database integrations. + * + * For more information, please visit: https://www.jooq.org/legal/licensing + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ package org.jooq.codegen.gradle; import org.jooq.meta.jaxb.Configuration; @@ -7,6 +44,9 @@ import org.jooq.util.jaxb.tools.MiniJAXB; import javax.inject.Inject; +import groovy.lang.*; +import org.codehaus.groovy.runtime.*; + /** * A wrapper for a name, configuration pair. */ @@ -45,6 +85,14 @@ public class NamedConfiguration { MiniJAXB.append(this.configuration, configuration); } + public void configuration(Closure closure) { + MetaExtensions.ConfigurationExtension c = new MetaExtensions.ConfigurationExtension(); + closure.setResolveStrategy(Closure.DELEGATE_FIRST); + closure.setDelegate(c); + closure.call(c); + configuration(c); + } + @Override public String toString() { return "NamedConfiguration [" + name + ", " + configuration + "]"; diff --git a/jOOQ-meta-kotlin/src/main/kotlin/org/jooq/meta/kotlin/Extensions.kt b/jOOQ-meta-kotlin/src/main/kotlin/org/jooq/meta/kotlin/Extensions.kt index 349b0ac867..1660ba5d2b 100644 --- a/jOOQ-meta-kotlin/src/main/kotlin/org/jooq/meta/kotlin/Extensions.kt +++ b/jOOQ-meta-kotlin/src/main/kotlin/org/jooq/meta/kotlin/Extensions.kt @@ -176,7 +176,7 @@ fun Matchers.enums(block: MutableList.() -> Unit) { } @JvmName("mutableListMatchersEnumType") -fun MutableList.enum(block: MatchersEnumType.() -> Unit) { +fun MutableList.enum_(block: MatchersEnumType.() -> Unit) { val e = MatchersEnumType() block(e) add(e) @@ -278,7 +278,7 @@ fun SyntheticObjectsType.enums(block: MutableList.() -> Unit) } @JvmName("mutableListSyntheticEnumType") -fun MutableList.enum(block: SyntheticEnumType.() -> Unit) { +fun MutableList.enum_(block: SyntheticEnumType.() -> Unit) { val e = SyntheticEnumType() block(e) add(e) diff --git a/jOOQ/src/main/java/org/jooq/util/jaxb/tools/MiniJAXB.java b/jOOQ/src/main/java/org/jooq/util/jaxb/tools/MiniJAXB.java index adfbf4735d..c2713126fc 100644 --- a/jOOQ/src/main/java/org/jooq/util/jaxb/tools/MiniJAXB.java +++ b/jOOQ/src/main/java/org/jooq/util/jaxb/tools/MiniJAXB.java @@ -484,8 +484,8 @@ public final class MiniJAXB { return first; Class klass = (Class) first.getClass(); - if (klass != second.getClass()) - throw new IllegalArgumentException("Can only append identical types"); + if (!klass.isAssignableFrom(second.getClass()) && !second.getClass().isAssignableFrom(klass)) + throw new IllegalArgumentException("Can only append compatible types"); // [#8527] support enum types else if (klass.isEnum()) return first;