Package io.github.suppierk.codegen
Class GeneratorTask
java.lang.Object
org.gradle.api.internal.AbstractTask
org.gradle.api.DefaultTask
io.github.suppierk.codegen.GeneratorTask
- All Implemented Interfaces:
Comparable<org.gradle.api.Task>,org.gradle.api.internal.DynamicObjectAware,org.gradle.api.internal.TaskInternal,org.gradle.api.Named,org.gradle.api.plugins.ExtensionAware,org.gradle.api.Task,org.gradle.util.Configurable<org.gradle.api.Task>
@CacheableTask
public class GeneratorTask
extends org.gradle.api.DefaultTask
Gradle task that orchestrates Testcontainers database startup, Flyway migrations, and jOOQ code
generation for a single configuration.
The task temporarily rewires the JooqConfig JDBC configuration to point at the managed
container, runs Flyway within the same class loader that resolves user migrations, and finally
delegates to the original JooqGenerate task.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.gradle.api.Task
org.gradle.api.Task.Namer -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final DatabaseExtensionDatabase definition supplying container overrides and driver selection.protected StringName of the logical database currently processed (if provided by the DSL).protected static final StringFallback Flyway location used when no migration locations are defined.protected final FlywayConfigFlyway configuration provided by the schema DSL.protected final nu.studer.gradle.jooq.JooqConfigjOOQ configuration currently being processed.protected StringOptional driver override supplied by the DSL.protected StringName of the schema currently processed (if provided by the DSL).Fields inherited from interface org.gradle.api.Task
TASK_ACTION, TASK_CONSTRUCTOR_ARGS, TASK_DEPENDS_ON, TASK_DESCRIPTION, TASK_GROUP, TASK_NAME, TASK_OVERWRITE, TASK_TYPE -
Constructor Summary
ConstructorsConstructorDescriptionGeneratorTask(DatabaseExtension databaseExtension, FlywayConfig flywayConfig, nu.studer.gradle.jooq.JooqConfig jooqConfig, org.gradle.api.tasks.TaskProvider<nu.studer.gradle.jooq.JooqGenerate> jooqGenerateTask) Creates a new task instance bound to a specific combination of database, Flyway configuration and jOOQ configuration. -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyDslOverrides(String databaseName, String schemaName, String driverClassName) Applies schema metadata captured from the DSL.static StringassumeJooqGenerateTaskName(nu.studer.gradle.jooq.JooqConfig jooqConfig) Derives the originalJooqGeneratetask name for the supplied configuration, following the same conventions asJooqPlugin.Gathers the runtime classpath entries that should back Flyway execution.voidConfigures task inputs and outputs to make Gradle caching effective.protected final URLClassLoaderCreates a dedicated class loader containing the runtime classpath needed for Flyway execution.static StringcreateTaskName(nu.studer.gradle.jooq.JooqConfig jooqConfig) Computes the Gradle task name used to expose this generator task for a given jOOQ configuration.protected final voidensureDriverAvailable(String driverClassName, ClassLoader fallbackLoader) Ensures the supplied driver class can be resolved via either the current context class loader or the provided fallback.org.gradle.api.file.ConfigurableFileCollectionRuntime classpath Gradle should fingerprint to detect Flyway code changes.org.gradle.api.file.ConfigurableFileCollectionClasspath Gradle should fingerprint for jOOQ runtime changes.org.gradle.api.file.ConfigurableFileCollectionReturns the Flyway migration locations the task uses to decide whether regeneration is required.org.gradle.api.file.DirectoryPropertyReturns the directory Gradle should treat as build output for the generated sources.protected final BooleanresolveBoolean(Function<FlywayConfig, Boolean> getter) Resolves a boolean property from schema overrides or the base Flyway configuration.protected final StringresolveDriver(String fallbackDriver) Resolves the JDBC driver to use, preferring DSL overrides, then Flyway defaults, and finally the existing jOOQ configuration.protected final IntegerresolveInteger(Function<FlywayConfig, Integer> getter) Resolves an integer property from schema overrides or the base Flyway configuration.resolveList(Function<FlywayConfig, List<String>> getter) Resolves a list property from schema overrides or the base Flyway configuration.resolveMap(Function<FlywayConfig, Map<String, String>> getter) Resolves a map property from schema overrides or the base Flyway configuration.protected final StringresolveSchema(String fallbackSchema) Resolves the schema to target, preferring DSL overrides, then Flyway defaults, and finally the existing jOOQ configuration.protected final StringresolveString(Function<FlywayConfig, String> getter) Resolves a string property from schema overrides or the base Flyway configuration.voidrun()Task action that: Launches the requested Testcontainers database Runs Flyway migrations against the container Temporarily rewires theJooqConfigJDBC properties to point at the container Executes the originalJooqGeneratetask Restores the jOOQ configurationprotected final voidrunFlywayMigrations(AbstractDatabaseContainer db, String schema) Runs Flyway migrations using a container supplied by the extension.protected final voidrunFlywayMigrations(AbstractDatabaseContainer db, String schema, URLClassLoader classLoader) Runs Flyway migrations using a dedicated class loader.protected final voidwithDatabase(String driverClassName, io.github.suppierk.codegen.AbstractDatabaseTask.DatabaseAction action) Executes the supplied action with a managed database container and dedicated class loader.Methods inherited from class org.gradle.api.DefaultTask
compareTo, configure, dependsOn, doFirst, doFirst, doFirst, doLast, doLast, doLast, finalizedBy, getActions, getAnt, getDependsOn, getDescription, getDestroyables, getDidWork, getEnabled, getExtensions, getFinalizedBy, getGroup, getInputs, getLocalState, getLogger, getLogging, getMustRunAfter, getName, getOutputs, getPath, getProject, getShouldRunAfter, getState, getTaskDependencies, getTemporaryDir, getTimeout, hasProperty, mustRunAfter, onlyIf, onlyIf, onlyIf, property, setActions, setDependsOn, setDescription, setDidWork, setEnabled, setFinalizedBy, setGroup, setMustRunAfter, setOnlyIf, setOnlyIf, setOnlyIf, setProperty, setShouldRunAfter, shouldRunAfter, usesServiceMethods inherited from class org.gradle.api.internal.AbstractTask
acceptServiceReferences, appendParallelSafeAction, doNotTrackState, getAsDynamicObject, getConvention, getIdentityPath, getImpliesSubProjects, getLifecycleDependencies, getOnlyIf, getReasonNotToTrackState, getReasonTaskIsIncompatibleWithConfigurationCache, getRequiredServices, getServices, getSharedResources, getStandardOutputCapture, getTaskActions, getTaskIdentity, getTemporaryDirFactory, hasTaskActions, injectIntoNewInstance, isCompatibleWithConfigurationCache, isEnabled, isHasCustomActions, notCompatibleWithConfigurationCache, prependParallelSafeAction, setImpliesSubProjectsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.gradle.api.Task
doNotTrackState, getConvention, notCompatibleWithConfigurationCache
-
Field Details
-
FALLBACK_FLYWAY_LOCATION
Fallback Flyway location used when no migration locations are defined.- See Also:
-
databaseExtension
Database definition supplying container overrides and driver selection. -
flywayConfig
Flyway configuration provided by the schema DSL. -
jooqConfig
@Nonnull protected final nu.studer.gradle.jooq.JooqConfig jooqConfigjOOQ configuration currently being processed. -
overrideDriverClassName
Optional driver override supplied by the DSL. -
schemaName
Name of the schema currently processed (if provided by the DSL). -
databaseName
Name of the logical database currently processed (if provided by the DSL).
-
-
Constructor Details
-
GeneratorTask
@Inject public GeneratorTask(@Nonnull DatabaseExtension databaseExtension, @Nonnull FlywayConfig flywayConfig, @Nonnull nu.studer.gradle.jooq.JooqConfig jooqConfig, @Nonnull org.gradle.api.tasks.TaskProvider<nu.studer.gradle.jooq.JooqGenerate> jooqGenerateTask) Creates a new task instance bound to a specific combination of database, Flyway configuration and jOOQ configuration.- Parameters:
databaseExtension- database specification coming from thejooqCodegenDSLflywayConfig- Flyway configuration that should be applied to this schemajooqConfig- original jOOQ configurationjooqGenerateTask- provider for the underlyingJooqGeneratetask
-
-
Method Details
-
createTaskName
@Nonnull public static String createTaskName(@Nonnull nu.studer.gradle.jooq.JooqConfig jooqConfig) throws IllegalStateException Computes the Gradle task name used to expose this generator task for a given jOOQ configuration.- Parameters:
jooqConfig- configuration to inspect- Returns:
- Gradle task name (e.g.
generateMainDatabaseClasses) - Throws:
IllegalStateException- See Also:
-
assumeJooqGenerateTaskName
@Nonnull public static String assumeJooqGenerateTaskName(@Nonnull nu.studer.gradle.jooq.JooqConfig jooqConfig) throws IllegalStateException Derives the originalJooqGeneratetask name for the supplied configuration, following the same conventions asJooqPlugin.- Parameters:
jooqConfig- configuration to inspect- Returns:
- jOOQ task name (e.g.
generateMainJooq) - Throws:
IllegalStateException
-
run
public void run()Task action that:- Launches the requested Testcontainers database
- Runs Flyway migrations against the container
- Temporarily rewires the
JooqConfigJDBC properties to point at the container - Executes the original
JooqGeneratetask - Restores the jOOQ configuration
- See Also:
-
getOutputDirectory
@OutputDirectory @Nonnull public org.gradle.api.file.DirectoryProperty getOutputDirectory()Returns the directory Gradle should treat as build output for the generated sources.- Returns:
- directory containing generated jOOQ sources
-
getMigrationInputs
@InputFiles @PathSensitive(RELATIVE) @Nonnull public org.gradle.api.file.ConfigurableFileCollection getMigrationInputs()Returns the Flyway migration locations the task uses to decide whether regeneration is required.- Returns:
- collection of resolved migration directories
-
getJooqRuntimeClasspath
@Classpath @Nonnull public org.gradle.api.file.ConfigurableFileCollection getJooqRuntimeClasspath()Classpath Gradle should fingerprint for jOOQ runtime changes.- Returns:
- file collection with jOOQ runtime dependencies
-
configureCaching
public void configureCaching()Configures task inputs and outputs to make Gradle caching effective. Captures DSL derived data, Flyway fingerprints, normalized jOOQ configuration hashes, and the migration locations so that Gradle can determine when regeneration is necessary.- See Also:
-
applyDslOverrides
public void applyDslOverrides(@Nonnull String databaseName, @Nonnull String schemaName, @Nullable String driverClassName) Applies schema metadata captured from the DSL.- Parameters:
databaseName- logical database identifier (used for diagnostics)schemaName- logical schema identifier (used for diagnostics)driverClassName- optional driver override provided by the DSL
-
getFlywayClasspath
@Classpath @Nonnull public org.gradle.api.file.ConfigurableFileCollection getFlywayClasspath()Runtime classpath Gradle should fingerprint to detect Flyway code changes.- Returns:
- file collection representing the Flyway runtime classpath
-
runFlywayMigrations
protected final void runFlywayMigrations(@Nonnull AbstractDatabaseContainer db, @Nonnull String schema) Runs Flyway migrations using a container supplied by the extension.- Parameters:
db- database container to targetschema- schema to migrate
-
runFlywayMigrations
protected final void runFlywayMigrations(@Nonnull AbstractDatabaseContainer db, @Nonnull String schema, @Nonnull URLClassLoader classLoader) Runs Flyway migrations using a dedicated class loader.- Parameters:
db- database container to targetschema- schema to migrateclassLoader- class loader to use when resolving application classes
-
resolveSchema
Resolves the schema to target, preferring DSL overrides, then Flyway defaults, and finally the existing jOOQ configuration. Throws a detailed exception when the DSL does not identify a schema or when Flyway and jOOQ disagree.- Parameters:
fallbackSchema- schema declared in the jOOQ configuration- Returns:
- resolved schema name
-
resolveDriver
Resolves the JDBC driver to use, preferring DSL overrides, then Flyway defaults, and finally the existing jOOQ configuration. Throws a descriptive exception when no driver can be found so that users know how to amend their configuration.- Parameters:
fallbackDriver- driver declared in the jOOQ configuration- Returns:
- resolved driver class name
-
ensureDriverAvailable
protected final void ensureDriverAvailable(@Nonnull String driverClassName, @Nonnull ClassLoader fallbackLoader) Ensures the supplied driver class can be resolved via either the current context class loader or the provided fallback. Prevents confusing Testcontainers errors by verifying driver availability up front.- Parameters:
driverClassName- fully qualified JDBC driver class namefallbackLoader- class loader capable of resolving project dependencies
-
createFlywayClassLoader
Creates a dedicated class loader containing the runtime classpath needed for Flyway execution.- Returns:
- new
URLClassLoaderinstance
-
withDatabase
protected final void withDatabase(@Nonnull String driverClassName, @Nonnull io.github.suppierk.codegen.AbstractDatabaseTask.DatabaseAction action) Executes the supplied action with a managed database container and dedicated class loader.- Parameters:
driverClassName- JDBC driver class to resolveaction- callback invoked once the container is ready
-
collectFlywayClasspathEntries
Gathers the runtime classpath entries that should back Flyway execution.- Returns:
- set of files contributing to the Flyway classpath
-
resolveString
Resolves a string property from schema overrides or the base Flyway configuration.- Parameters:
getter- accessor to invoke on the configuration- Returns:
- resolved value or
null
-
resolveList
@Nonnull protected final List<String> resolveList(@Nonnull Function<FlywayConfig, List<String>> getter) Resolves a list property from schema overrides or the base Flyway configuration.- Parameters:
getter- accessor to invoke on the configuration- Returns:
- resolved list (never
null)
-
resolveMap
@Nonnull protected final Map<String,String> resolveMap(@Nonnull Function<FlywayConfig, Map<String, String>> getter) Resolves a map property from schema overrides or the base Flyway configuration.- Parameters:
getter- accessor to invoke on the configuration- Returns:
- resolved map combining overrides and defaults
-
resolveInteger
Resolves an integer property from schema overrides or the base Flyway configuration.- Parameters:
getter- accessor to invoke on the configuration- Returns:
- resolved integer or
null
-
resolveBoolean
Resolves a boolean property from schema overrides or the base Flyway configuration.- Parameters:
getter- accessor to invoke on the configuration- Returns:
- resolved boolean or
null
-