diff --git a/.github/renovate.json b/.github/renovate.json index 80b7343..3da4646 100644 --- a/.github/renovate.json +++ b/.github/renovate.json @@ -50,7 +50,8 @@ "org.junit.jupiter:", "io.strikt:", "io.mockk:", - "ch.qos.logback:" + "ch.qos.logback:", + "com.pinterest.ktlint:ktlint-cli:" ] }, { diff --git a/artifact-tests/build.gradle.kts b/artifact-tests/build.gradle.kts index 6278213..e7a4763 100644 --- a/artifact-tests/build.gradle.kts +++ b/artifact-tests/build.gradle.kts @@ -1,5 +1,6 @@ plugins { `kotlin-convention` + `linter-convention` } dependencies { diff --git a/artifact-tests/src/test/kotlin/dev/monosoul/jooq/artifact/GradleContainer.kt b/artifact-tests/src/test/kotlin/dev/monosoul/jooq/artifact/GradleContainer.kt index 9eb569f..50f5e31 100644 --- a/artifact-tests/src/test/kotlin/dev/monosoul/jooq/artifact/GradleContainer.kt +++ b/artifact-tests/src/test/kotlin/dev/monosoul/jooq/artifact/GradleContainer.kt @@ -9,16 +9,15 @@ import org.testcontainers.containers.output.ToStringConsumer import org.testcontainers.containers.startupcheck.IndefiniteWaitOneShotStartupCheckStrategy class GradleContainer( - dockerSocketPath: String = "/var/run/docker.sock", + dockerSocketPath: String = "/var/run/docker.sock", ) : GenericContainer("gradle:jdk17-alpine") { - private val toStringLogConsumer = ToStringConsumer() val output: String get() = toStringLogConsumer.toUtf8String() val projectPath = "/home/gradle/project" init { withLogConsumer( - Slf4jLogConsumer(LoggerFactory.getLogger("GradleContainer[$dockerImageName]")) + Slf4jLogConsumer(LoggerFactory.getLogger("GradleContainer[$dockerImageName]")), ) withLogConsumer(toStringLogConsumer) addFsBind("build/local-repository", "$projectPath/local-repository") @@ -26,10 +25,12 @@ class GradleContainer( withWorkingDirectory(projectPath) withStartupCheckStrategy( - IndefiniteWaitOneShotStartupCheckStrategy() + IndefiniteWaitOneShotStartupCheckStrategy(), ) } - private fun addFsBind(hostPath: String, containerPath: String) = - addFileSystemBind(hostPath, containerPath, READ_ONLY, SHARED) + private fun addFsBind( + hostPath: String, + containerPath: String, + ) = addFileSystemBind(hostPath, containerPath, READ_ONLY, SHARED) } diff --git a/artifact-tests/src/test/kotlin/dev/monosoul/jooq/artifact/JooqCodegenLoggingLevelsTest.kt b/artifact-tests/src/test/kotlin/dev/monosoul/jooq/artifact/JooqCodegenLoggingLevelsTest.kt index 67766a1..f30266f 100644 --- a/artifact-tests/src/test/kotlin/dev/monosoul/jooq/artifact/JooqCodegenLoggingLevelsTest.kt +++ b/artifact-tests/src/test/kotlin/dev/monosoul/jooq/artifact/JooqCodegenLoggingLevelsTest.kt @@ -9,20 +9,21 @@ import strikt.assertions.contains import strikt.assertions.isSuccess class JooqCodegenLoggingLevelsTest { - @ParameterizedTest @ValueSource(strings = ["", "--quiet"]) fun `should not have jOOQ codegen warnings with non verbose log levels`(logLevel: String) { // given - val gradleContainer = GradleContainer().apply { - setUp() - val arguments = listOfNotNull( - "gradle", - "generateJooqClasses", - logLevel.takeIf { it.isNotBlank() } - ).toTypedArray() - withCommand(*arguments) - } + val gradleContainer = + GradleContainer().apply { + setUp() + val arguments = + listOfNotNull( + "gradle", + "generateJooqClasses", + logLevel.takeIf { it.isNotBlank() }, + ).toTypedArray() + withCommand(*arguments) + } // when & then expect { @@ -41,10 +42,11 @@ class JooqCodegenLoggingLevelsTest { @ValueSource(strings = ["--info", "--warn", "--debug"]) fun `should have jOOQ codegen warnings with verbose log levels`(logLevel: String) { // given - val gradleContainer = GradleContainer().apply { - setUp() - withCommand("gradle", "generateJooqClasses", logLevel) - } + val gradleContainer = + GradleContainer().apply { + setUp() + withCommand("gradle", "generateJooqClasses", logLevel) + } // when & then expect { @@ -64,59 +66,59 @@ class JooqCodegenLoggingLevelsTest { withCopyToContainer( Transferable.of( """ - import org.jooq.meta.jaxb.Logging + import org.jooq.meta.jaxb.Logging - plugins { - id("dev.monosoul.jooq-docker") version "${Versions.PLUGIN_VERSION}" - } + plugins { + id("dev.monosoul.jooq-docker") version "${Versions.PLUGIN_VERSION}" + } - repositories { - mavenCentral() - } + repositories { + mavenCentral() + } - tasks { - generateJooqClasses { - withContainer { - image { - name = "postgres:14.4-alpine" - } + tasks { + generateJooqClasses { + withContainer { + image { + name = "postgres:14.4-alpine" } } } + } - dependencies { - jooqCodegen("org.postgresql:postgresql:42.3.6") - } - """.trimIndent() + dependencies { + jooqCodegen("org.postgresql:postgresql:42.3.6") + } + """.trimIndent(), ), - "$projectPath/build.gradle.kts" + "$projectPath/build.gradle.kts", ) withCopyToContainer( Transferable.of( """ - pluginManagement { - repositories { - maven { - name = "localBuild" - url = uri("./local-repository") - } - mavenCentral() - gradlePluginPortal { - content { - excludeGroup("org.jooq") - excludeGroup("org.flywaydb") - excludeGroupByRegex("com\\.fasterxml.*") - excludeGroupByRegex("com\\.google.*") - excludeGroupByRegex("org\\.junit.*") - excludeGroupByRegex("net\\.java.*") - excludeGroupByRegex("jakarta.*") - } + pluginManagement { + repositories { + maven { + name = "localBuild" + url = uri("./local-repository") + } + mavenCentral() + gradlePluginPortal { + content { + excludeGroup("org.jooq") + excludeGroup("org.flywaydb") + excludeGroupByRegex("com\\.fasterxml.*") + excludeGroupByRegex("com\\.google.*") + excludeGroupByRegex("org\\.junit.*") + excludeGroupByRegex("net\\.java.*") + excludeGroupByRegex("jakarta.*") } } } - """.trimIndent() + } + """.trimIndent(), ), - "$projectPath/settings.gradle.kts" + "$projectPath/settings.gradle.kts", ) } } diff --git a/artifact-tests/src/test/kotlin/dev/monosoul/jooq/artifact/PluginWorksArtifactTest.kt b/artifact-tests/src/test/kotlin/dev/monosoul/jooq/artifact/PluginWorksArtifactTest.kt index 2513aa3..540c878 100644 --- a/artifact-tests/src/test/kotlin/dev/monosoul/jooq/artifact/PluginWorksArtifactTest.kt +++ b/artifact-tests/src/test/kotlin/dev/monosoul/jooq/artifact/PluginWorksArtifactTest.kt @@ -7,7 +7,6 @@ import strikt.assertions.contains import strikt.assertions.isSuccess class PluginWorksArtifactTest { - /** * Runs the plugin in a containerized environment to make sure the artifact produced actually works. * Running in a container is necessary to make sure host's testcontainers.properties file doesn't interfere @@ -16,20 +15,21 @@ class PluginWorksArtifactTest { @Test fun `should be possible to load the plugin and generate jooq classes`() { // given - val gradleContainer = GradleContainer().apply { - withCopyToContainer(forClasspathResource("/testproject"), projectPath) - withCopyToContainer( - forClasspathResource("/.testcontainers.properties.template"), - "/root/.testcontainers.properties" - ) - withEnv("TESTCONTAINERS_DOCKER_CLIENT_STRATEGY", "org.testcontainers.dockerclient.UnixSocketClientProviderStrategy") - withCommand( - "gradle", - "classes", - "--info", - "--stacktrace", - ) - } + val gradleContainer = + GradleContainer().apply { + withCopyToContainer(forClasspathResource("/testproject"), projectPath) + withCopyToContainer( + forClasspathResource("/.testcontainers.properties.template"), + "/root/.testcontainers.properties", + ) + withEnv("TESTCONTAINERS_DOCKER_CLIENT_STRATEGY", "org.testcontainers.dockerclient.UnixSocketClientProviderStrategy") + withCommand( + "gradle", + "classes", + "--info", + "--stacktrace", + ) + } // when & then expect { diff --git a/artifact-tests/src/test/kotlin/dev/monosoul/jooq/artifact/PostgresContainer.kt b/artifact-tests/src/test/kotlin/dev/monosoul/jooq/artifact/PostgresContainer.kt index 36c97dd..42dedce 100644 --- a/artifact-tests/src/test/kotlin/dev/monosoul/jooq/artifact/PostgresContainer.kt +++ b/artifact-tests/src/test/kotlin/dev/monosoul/jooq/artifact/PostgresContainer.kt @@ -4,5 +4,5 @@ import org.testcontainers.containers.PostgreSQLContainer import org.testcontainers.utility.DockerImageName class PostgresContainer( - image: String = "postgres:14.4-alpine" + image: String = "postgres:14.4-alpine", ) : PostgreSQLContainer(DockerImageName.parse(image)) diff --git a/artifact-tests/src/test/kotlin/dev/monosoul/jooq/artifact/WorksAfterFailingToFindDockerArtifactTest.kt b/artifact-tests/src/test/kotlin/dev/monosoul/jooq/artifact/WorksAfterFailingToFindDockerArtifactTest.kt index 2ea0ee0..e1b052a 100644 --- a/artifact-tests/src/test/kotlin/dev/monosoul/jooq/artifact/WorksAfterFailingToFindDockerArtifactTest.kt +++ b/artifact-tests/src/test/kotlin/dev/monosoul/jooq/artifact/WorksAfterFailingToFindDockerArtifactTest.kt @@ -7,16 +7,16 @@ import strikt.assertions.contains import strikt.assertions.isSuccess class WorksAfterFailingToFindDockerArtifactTest { - @Test fun `should be possible to generate jooq classes even after it failed on first attempt`() { // given - val gradleContainer = GradleContainer(dockerSocketPath = "/var/run/docker-alt.sock").apply { - withEnv("TESTCONTAINERS_RYUK_DISABLED", "true") - withCopyToContainer(forClasspathResource("/testproject"), projectPath) - withCopyToContainer(forClasspathResource("/gradle_run.sh"), "/gradle_run.sh") - withCommand("/gradle_run.sh") - } + val gradleContainer = + GradleContainer(dockerSocketPath = "/var/run/docker-alt.sock").apply { + withEnv("TESTCONTAINERS_RYUK_DISABLED", "true") + withCopyToContainer(forClasspathResource("/testproject"), projectPath) + withCopyToContainer(forClasspathResource("/gradle_run.sh"), "/gradle_run.sh") + withCommand("/gradle_run.sh") + } // when & then expect { diff --git a/build.gradle.kts b/build.gradle.kts index 0e71ada..bdac864 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,6 +5,7 @@ plugins { `coverage-convention` `shadow-convention` `test-fixtures-convention` + `linter-convention` } group = "dev.monosoul.jooq" @@ -16,7 +17,7 @@ tasks { relocate("docker.client.strategy", "${project.group}.docker.client.strategy") relocate( "TESTCONTAINERS_DOCKER_CLIENT_STRATEGY", - "${project.group.toString().uppercase().replace(".", "_")}_TESTCONTAINERS_DOCKER_CLIENT_STRATEGY" + "${project.group.toString().uppercase().replace(".", "_")}_TESTCONTAINERS_DOCKER_CLIENT_STRATEGY", ) } diff --git a/buildSrc/src/main/kotlin/linter-convention.gradle.kts b/buildSrc/src/main/kotlin/linter-convention.gradle.kts new file mode 100644 index 0000000..69b1d3b --- /dev/null +++ b/buildSrc/src/main/kotlin/linter-convention.gradle.kts @@ -0,0 +1,93 @@ +import org.gradle.api.attributes.Bundling.BUNDLING_ATTRIBUTE +import org.gradle.api.attributes.Bundling.EXTERNAL + +plugins { + kotlin("jvm") +} + +val Project.libs: VersionCatalog + get() = rootProject.extensions.getByType().named("libs") + +val ktlint: Configuration by configurations.creating + +dependencies { + ktlint(libs.findLibrary("ktlint").get()) { + attributes { + attributes { + attribute(BUNDLING_ATTRIBUTE, getObjects().named(Bundling::class, EXTERNAL)) + } + } + } +} + +tasks { + val sourceInputFiles = fileTree(mapOf("dir" to "src", "include" to "**/*.kt")) + + val ktlintCheckSources by registering(JavaExec::class) { + inputs.files(sourceInputFiles) + + description = "Check Kotlin code style." + group = "ktlint" + classpath = ktlint + mainClass.set("com.pinterest.ktlint.Main") + jvmArgs("--add-opens", "java.base/java.lang=ALL-UNNAMED") + args("--color", "src/**/*.kt") + } + + val ktlintFormatSources by registering(JavaExec::class) { + inputs.files(sourceInputFiles) + + description = "Fix Kotlin code style deviations." + group = "ktlint" + classpath = ktlint + mainClass.set("com.pinterest.ktlint.Main") + jvmArgs("--add-opens", "java.base/java.lang=ALL-UNNAMED") + args("--color", "-F", "src/**/*.kt") + } + + val buildscriptInputFiles = fileTree(mapOf("dir" to ".", "include" to "*.gradle.kts")) + + val ktlintCheckBuildScript by registering(JavaExec::class) { + inputs.files(buildscriptInputFiles) + + description = "Check buildscript code style." + group = "ktlint" + classpath = ktlint + mainClass.set("com.pinterest.ktlint.Main") + jvmArgs("--add-opens", "java.base/java.lang=ALL-UNNAMED") + args("--color", "*.gradle.kts") + } + + val ktlintFormatBuildScript by registering(JavaExec::class) { + inputs.files(buildscriptInputFiles) + + description = "Fix buildscript code style deviations." + group = "ktlint" + classpath = ktlint + mainClass.set("com.pinterest.ktlint.Main") + jvmArgs("--add-opens", "java.base/java.lang=ALL-UNNAMED") + args("--color", "-F", "*.gradle.kts") + } + + val ktlintCheckAll by registering { + dependsOn(ktlintCheckBuildScript, ktlintCheckSources) + + description = "Check all files code style." + group = "ktlint" + } + + register("ktlintFormatAll") { + dependsOn(ktlintFormatBuildScript, ktlintFormatSources) + + description = "Fix all code style deviations." + group = "ktlint" + } + + check { + dependsOn(ktlintCheckAll) + } + + withType { + shouldRunAfter(ktlintCheckBuildScript, ktlintCheckSources) + } +} diff --git a/extra-tests/build.gradle.kts b/extra-tests/build.gradle.kts index 11b2dfc..3b016a0 100644 --- a/extra-tests/build.gradle.kts +++ b/extra-tests/build.gradle.kts @@ -8,6 +8,7 @@ plugins { `kotlin-dsl` `kotlin-convention` + `linter-convention` } dependencies { diff --git a/extra-tests/src/test/kotlin/dev/monosoul/jooq/functional/ConfigurationCacheJooqDockerPluginFunctionalTest.kt b/extra-tests/src/test/kotlin/dev/monosoul/jooq/functional/ConfigurationCacheJooqDockerPluginFunctionalTest.kt index 4148b80..8c55535 100644 --- a/extra-tests/src/test/kotlin/dev/monosoul/jooq/functional/ConfigurationCacheJooqDockerPluginFunctionalTest.kt +++ b/extra-tests/src/test/kotlin/dev/monosoul/jooq/functional/ConfigurationCacheJooqDockerPluginFunctionalTest.kt @@ -12,7 +12,6 @@ import strikt.java.notExists import java.io.File class ConfigurationCacheJooqDockerPluginFunctionalTest : FunctionalTestBase() { - @TempDir private lateinit var localBuildCacheDirectory: File @@ -22,17 +21,17 @@ class ConfigurationCacheJooqDockerPluginFunctionalTest : FunctionalTestBase() { configureLocalGradleCache() prepareBuildGradleFile { """ - plugins { - id("dev.monosoul.jooq-docker") - } + plugins { + id("dev.monosoul.jooq-docker") + } - repositories { - mavenCentral() - } + repositories { + mavenCentral() + } - dependencies { - jooqCodegen("org.postgresql:postgresql:42.3.6") - } + dependencies { + jooqCodegen("org.postgresql:postgresql:42.3.6") + } """.trimIndent() } copyResource(from = "/V01__init.sql", to = "src/main/resources/db/migration/V01__init.sql") @@ -57,7 +56,7 @@ class ConfigurationCacheJooqDockerPluginFunctionalTest : FunctionalTestBase() { } } that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java"), ).exists() } } @@ -68,29 +67,29 @@ class ConfigurationCacheJooqDockerPluginFunctionalTest : FunctionalTestBase() { configureLocalGradleCache() prepareBuildGradleFile { """ - plugins { - id("dev.monosoul.jooq-docker") - } + plugins { + id("dev.monosoul.jooq-docker") + } - repositories { - mavenCentral() - } - - tasks { - generateJooqClasses { - schemas.set(listOf("public", "other")) - usingXmlConfig() - } + repositories { + mavenCentral() + } + + tasks { + generateJooqClasses { + schemas.set(listOf("public", "other")) + usingXmlConfig() } + } - dependencies { - jooqCodegen("org.postgresql:postgresql:42.3.6") - } + dependencies { + jooqCodegen("org.postgresql:postgresql:42.3.6") + } """.trimIndent() } copyResource( from = "/V01__init_multiple_schemas.sql", - to = "src/main/resources/db/migration/V01__init_multiple_schemas.sql" + to = "src/main/resources/db/migration/V01__init_multiple_schemas.sql", ) copyResource(from = "/jooq-generator.xml", to = "src/main/resources/db/jooq.xml") @@ -105,10 +104,10 @@ class ConfigurationCacheJooqDockerPluginFunctionalTest : FunctionalTestBase() { get { output }.contains("Configuration cache entry stored") } that( - projectFile("build/generated-jooq/org/jooq/generated/public_/tables/Foo.java") + projectFile("build/generated-jooq/org/jooq/generated/public_/tables/Foo.java"), ).exists() that( - projectFile("build/generated-jooq/org/jooq/generated/other/tables/Bar.java") + projectFile("build/generated-jooq/org/jooq/generated/other/tables/Bar.java"), ).notExists() } @@ -123,10 +122,10 @@ class ConfigurationCacheJooqDockerPluginFunctionalTest : FunctionalTestBase() { get { output }.contains("Configuration cache entry reused") } that( - projectFile("build/generated-jooq/org/jooq/generated/public_/tables/Foo.java") + projectFile("build/generated-jooq/org/jooq/generated/public_/tables/Foo.java"), ).exists() that( - projectFile("build/generated-jooq/org/jooq/generated/other/tables/Bar.java") + projectFile("build/generated-jooq/org/jooq/generated/other/tables/Bar.java"), ).exists() } } @@ -134,11 +133,11 @@ class ConfigurationCacheJooqDockerPluginFunctionalTest : FunctionalTestBase() { private fun configureLocalGradleCache() { writeProjectFile("settings.gradle.kts") { """ - buildCache { - local { - directory = "${localBuildCacheDirectory.path}" - } + buildCache { + local { + directory = "${localBuildCacheDirectory.path}" } + } """.trimIndent() } } diff --git a/libs.versions.toml b/libs.versions.toml index 6b982d8..020954f 100644 --- a/libs.versions.toml +++ b/libs.versions.toml @@ -17,6 +17,8 @@ junit-jupiter = { module = "org.junit.jupiter:junit-jupiter" } strikt = "io.strikt:strikt-jvm:0.34.1" mockk = "io.mockk:mockk-jvm:1.13.7" +ktlint = "com.pinterest.ktlint:ktlint-cli:1.0.1" + # plugins gradle-plugin-publish = "com.gradle.publish:plugin-publish-plugin:1.2.1" shadow = "com.github.johnrengelman:shadow:8.1.1" diff --git a/src/main/kotlin/dev/monosoul/jooq/GenerateJooqClassesTask.kt b/src/main/kotlin/dev/monosoul/jooq/GenerateJooqClassesTask.kt index 14dae28..adbad11 100644 --- a/src/main/kotlin/dev/monosoul/jooq/GenerateJooqClassesTask.kt +++ b/src/main/kotlin/dev/monosoul/jooq/GenerateJooqClassesTask.kt @@ -44,337 +44,353 @@ import javax.inject.Inject import org.gradle.api.artifacts.Configuration as GradleConfiguration @CacheableTask -open class GenerateJooqClassesTask @Inject constructor( - objectFactory: ObjectFactory, - private val providerFactory: ProviderFactory, - private val fsOperations: FileSystemOperations, - private val projectLayout: ProjectLayout, -) : DefaultTask(), SettingsAware { - /** - * List of schemas to take into account when running migrations and generating code. - */ - @Input - val schemas = objectFactory.listProperty().convention(listOf("public")) - - /** - * Base package for generated classes. - */ - @Input - val basePackageName = objectFactory.property().convention("org.jooq.generated") - - /** - * Flyway configuration. - */ - @Input - val flywayProperties = objectFactory.mapProperty().convention(emptyMap()) - - /** - * List of schemas to not generate schema information for (generate classes as for default schema). - */ - @Input - val outputSchemaToDefault = objectFactory.setProperty().convention(emptySet()) - - /** - * Map of schema name to specific package name. - */ - @Input - val schemaToPackageMapping = objectFactory.mapProperty().convention(emptyMap()) - - /** - * Include Flyway migration history table to generated code. - */ - @Input - val includeFlywayTable = objectFactory.property().convention(false) - - private val _generatorConfig = objectFactory.property>().convention( - providerFactory.provider { - configurationProvider.defaultConfiguration() - }.map(::PrivateValueHolder) - ) - - /** - * Use [usingJavaConfig] or [usingXmlConfig] to provide configuration. - */ - @get:Input - @Suppress("unused") - val generatorConfig: Property> get() = _generatorConfig - - /** - * Location of Flyway migrations to use for code generation. - * - * Can be: - * - [MigrationLocation.Filesystem]: - * - directory with SQL migrations - * - [MigrationLocation.Classpath]: - * - directory with Java-based migrations (compiled classes) - * - directory with JAR files having Java-based or SQL migrations - * - path to a single JAR file having Java-based or SQL migrations - * - * Default: "src/main/resources/db/migration" directory of current project. - * - * @see MigrationLocation - */ - @Nested - val migrationLocations = objectFactory.listProperty().convention( - listOf( - MigrationLocation.Filesystem(objectFactory.fileCollection().from("src/main/resources/db/migration")) - ) - ) - - /** - * Location of generated classes. - */ - @OutputDirectory - val outputDirectory = - objectFactory.directoryProperty().convention(projectLayout.buildDirectory.dir("generated-jooq")) - - /** - * Classpath for code generation. Derived from jooqCodegen configuration. - */ - @Classpath - val codegenClasspath = objectFactory.fileCollection().from( - project.configurations.named(JooqDockerPlugin.CONFIGURATION_NAME) - ) - - private val localPluginSettings = objectFactory.property() - - private val globalPluginSettings = project.extensions.getByType().pluginSettings - - private val _pluginSettings: Provider> - get() = localPluginSettings.orElse(globalPluginSettings).map(::PrivateValueHolder) - - /** - * Use [withContainer] or [withoutContainer] to provide configuration. - */ - @Nested - @Suppress("unused") - fun getPluginSettings(): Provider> = _pluginSettings - - private val migrationRunner = UniversalMigrationRunner(schemas, migrationLocations, flywayProperties) - - private val codegenRunner = UniversalJooqCodegenRunner() - - private val configurationProvider = ConfigurationProvider( - basePackageName = basePackageName, - outputDirectory = outputDirectory, - outputSchemaToDefault = outputSchemaToDefault, - schemaToPackageMapping = schemaToPackageMapping, - schemas = schemas, - logLevel = logger.getCodegenLogging(), - ) - - private fun classLoaders() = CodegenClasspathAwareClassLoaders.from(codegenClasspath) - - init { - group = "jooq" - description = "Generates jOOQ classes from Flyway migrations" - } +open class GenerateJooqClassesTask + @Inject + constructor( + objectFactory: ObjectFactory, + private val providerFactory: ProviderFactory, + private val fsOperations: FileSystemOperations, + private val projectLayout: ProjectLayout, + ) : DefaultTask(), SettingsAware { + /** + * List of schemas to take into account when running migrations and generating code. + */ + @Input + val schemas = objectFactory.listProperty().convention(listOf("public")) + + /** + * Base package for generated classes. + */ + @Input + val basePackageName = objectFactory.property().convention("org.jooq.generated") + + /** + * Flyway configuration. + */ + @Input + val flywayProperties = objectFactory.mapProperty().convention(emptyMap()) + + /** + * List of schemas to not generate schema information for (generate classes as for default schema). + */ + @Input + val outputSchemaToDefault = objectFactory.setProperty().convention(emptySet()) + + /** + * Map of schema name to specific package name. + */ + @Input + val schemaToPackageMapping = objectFactory.mapProperty().convention(emptyMap()) + + /** + * Include Flyway migration history table to generated code. + */ + @Input + val includeFlywayTable = objectFactory.property().convention(false) + + private val _generatorConfig = + objectFactory.property>().convention( + providerFactory.provider { + configurationProvider.defaultConfiguration() + }.map(::PrivateValueHolder), + ) + + /** + * Use [usingJavaConfig] or [usingXmlConfig] to provide configuration. + */ + @get:Input + @Suppress("unused") + val generatorConfig: Property> get() = _generatorConfig + + /** + * Location of Flyway migrations to use for code generation. + * + * Can be: + * - [MigrationLocation.Filesystem]: + * - directory with SQL migrations + * - [MigrationLocation.Classpath]: + * - directory with Java-based migrations (compiled classes) + * - directory with JAR files having Java-based or SQL migrations + * - path to a single JAR file having Java-based or SQL migrations + * + * Default: "src/main/resources/db/migration" directory of current project. + * + * @see MigrationLocation + */ + @Nested + val migrationLocations = + objectFactory.listProperty().convention( + listOf( + MigrationLocation.Filesystem(objectFactory.fileCollection().from("src/main/resources/db/migration")), + ), + ) + + /** + * Location of generated classes. + */ + @OutputDirectory + val outputDirectory = + objectFactory.directoryProperty().convention(projectLayout.buildDirectory.dir("generated-jooq")) + + /** + * Classpath for code generation. Derived from jooqCodegen configuration. + */ + @Classpath + val codegenClasspath = + objectFactory.fileCollection().from( + project.configurations.named(JooqDockerPlugin.CONFIGURATION_NAME), + ) + + private val localPluginSettings = objectFactory.property() + + private val globalPluginSettings = project.extensions.getByType().pluginSettings - override fun withContainer(configure: Action) = localPluginSettings.set( - globalPluginSettings.map { settings -> - settings.let { it as? WithContainer }?.copy()?.apply(configure::execute) ?: WithContainer(configure) + private val _pluginSettings: Provider> + get() = localPluginSettings.orElse(globalPluginSettings).map(::PrivateValueHolder) + + /** + * Use [withContainer] or [withoutContainer] to provide configuration. + */ + @Nested + @Suppress("unused") + fun getPluginSettings(): Provider> = _pluginSettings + + private val migrationRunner = UniversalMigrationRunner(schemas, migrationLocations, flywayProperties) + + private val codegenRunner = UniversalJooqCodegenRunner() + + private val configurationProvider = + ConfigurationProvider( + basePackageName = basePackageName, + outputDirectory = outputDirectory, + outputSchemaToDefault = outputSchemaToDefault, + schemaToPackageMapping = schemaToPackageMapping, + schemas = schemas, + logLevel = logger.getCodegenLogging(), + ) + + private fun classLoaders() = CodegenClasspathAwareClassLoaders.from(codegenClasspath) + + init { + group = "jooq" + description = "Generates jOOQ classes from Flyway migrations" } - ) - override fun withoutContainer(configure: Action) = localPluginSettings.set( - globalPluginSettings.map { settings -> - settings.let { it as? WithoutContainer }?.copy()?.apply(configure::execute) ?: WithoutContainer(configure) + override fun withContainer(configure: Action) = + localPluginSettings.set( + globalPluginSettings.map { settings -> + settings.let { it as? WithContainer }?.copy()?.apply(configure::execute) ?: WithContainer(configure) + }, + ) + + override fun withoutContainer(configure: Action) = + localPluginSettings.set( + globalPluginSettings.map { settings -> + settings.let { it as? WithoutContainer }?.copy()?.apply(configure::execute) ?: WithoutContainer(configure) + }, + ) + + /** + * Configure the jOOQ code generator with an XML configuration file. + */ + @Suppress("unused") + fun usingXmlConfig( + file: RegularFile = projectLayout.projectDirectory.file("src/main/resources/db/jooq.xml"), + customizer: Action = Action { }, + ) { + _generatorConfig.set( + configurationProvider.fromXml(providerFactory.fileContents(file)).map { config -> + config.also { customizer.execute(it.generator) } + }.map(::PrivateValueHolder), + ) + } + + /** + * Configure the jOOQ code generator with an XML configuration file. + */ + @Suppress("unused") + fun usingXmlConfig( + file: RegularFile, + closure: Closure, + ) = usingXmlConfig(file, closure::callWith) + + /** + * Configure the jOOQ code generator programmatically with [Generator]. + */ + @Suppress("unused") + fun usingJavaConfig(customizer: Action) { + _generatorConfig.set( + providerFactory.provider { + configurationProvider.defaultConfiguration().also { + customizer.execute(it.generator) + } + }.map(::PrivateValueHolder), + ) } - ) - - /** - * Configure the jOOQ code generator with an XML configuration file. - */ - @Suppress("unused") - fun usingXmlConfig( - file: RegularFile = projectLayout.projectDirectory.file("src/main/resources/db/jooq.xml"), - customizer: Action = Action { } - ) { - _generatorConfig.set( - configurationProvider.fromXml(providerFactory.fileContents(file)).map { config -> - config.also { customizer.execute(it.generator) } - }.map(::PrivateValueHolder) - ) - } - /** - * Configure the jOOQ code generator with an XML configuration file. - */ - @Suppress("unused") - fun usingXmlConfig(file: RegularFile, closure: Closure) = usingXmlConfig(file, closure::callWith) - - /** - * Configure the jOOQ code generator programmatically with [Generator]. - */ - @Suppress("unused") - fun usingJavaConfig(customizer: Action) { - _generatorConfig.set( - providerFactory.provider { - configurationProvider.defaultConfiguration().also { - customizer.execute(it.generator) + /** + * Configure the jOOQ code generator programmatically with [Generator]. + */ + @Suppress("unused") + fun usingJavaConfig(closure: Closure) = usingJavaConfig(closure::callWith) + + @TaskAction + fun generateClasses() { + _pluginSettings.get().value + .runWithDatabaseCredentials(classLoaders()) { classLoaders, credentials -> + val schemaVersion = migrationRunner.migrateDb(classLoaders, credentials) + generateJooqClasses(classLoaders, credentials, schemaVersion) } - }.map(::PrivateValueHolder) - ) - } + } - /** - * Configure the jOOQ code generator programmatically with [Generator]. - */ - @Suppress("unused") - fun usingJavaConfig(closure: Closure) = usingJavaConfig(closure::callWith) - - @TaskAction - fun generateClasses() { - _pluginSettings.get().value - .runWithDatabaseCredentials(classLoaders()) { classLoaders, credentials -> - val schemaVersion = migrationRunner.migrateDb(classLoaders, credentials) - generateJooqClasses(classLoaders, credentials, schemaVersion) + private fun generateJooqClasses( + jdbcAwareClassLoader: CodegenClasspathAwareClassLoaders, + credentials: DatabaseCredentials, + schemaVersion: SchemaVersion, + ) { + fsOperations.delete { + delete(outputDirectory) } - } - - private fun generateJooqClasses( - jdbcAwareClassLoader: CodegenClasspathAwareClassLoaders, - credentials: DatabaseCredentials, - schemaVersion: SchemaVersion - ) { - fsOperations.delete { - delete(outputDirectory) + codegenRunner.generateJooqClasses( + codegenAwareClassLoader = jdbcAwareClassLoader, + configuration = + _generatorConfig.get().value.postProcess( + schemaVersion = schemaVersion, + credentials = credentials, + extraTableExclusions = + listOfNotNull( + migrationRunner.flywayTableName.takeUnless { includeFlywayTable.get() }, + ), + ), + ) } - codegenRunner.generateJooqClasses( - codegenAwareClassLoader = jdbcAwareClassLoader, - configuration = _generatorConfig.get().value.postProcess( - schemaVersion = schemaVersion, - credentials = credentials, - extraTableExclusions = listOfNotNull( - migrationRunner.flywayTableName.takeUnless { includeFlywayTable.get() } - ) + + /** + * Set location of Flyway migrations to use for code generation + * + * @see migrationLocations + * @see MigrationLocation + */ + fun ListProperty.set(migrationLocation: MigrationLocation) = set(listOf(migrationLocation)) + + /** + * Set location of SQL migrations on the file system to use for code generation + * + * Example: + * + * ``` + * migrationLocations.setFromFilesystem(project.files("src/main/resources/db/migration")) + * ``` + * + * @see migrationLocations + * @see MigrationLocation + * @see Project.files + */ + fun ListProperty.setFromFilesystem(files: FileCollection) = + set( + MigrationLocation.Filesystem(files), ) - ) + + /** + * Set location of SQL migrations on the file system to use for code generation + * + * Example: + * + * ``` + * migrationLocations.setFromFilesystem("src/main/resources/db/migration") + * ``` + * + * @see migrationLocations + * @see MigrationLocation + */ + fun ListProperty.setFromFilesystem(path: String) = setFromFilesystem(project.files(path)) + + /** + * Add location of Java-based or SQL migrations to Flyway classpath from the specified path + * + * Example: + * + * ``` + * tasks.generateJooqClasses { + * migrationLocations.setFromClasspath(project.files("build/libs/some.jar")) + * } + * ``` + * + * @see migrationLocations + * @see MigrationLocation + * @see Project.files + * @see Project.project + * @see FileCollection + */ + fun ListProperty.setFromClasspath( + path: FileCollection, + location: String = "/db/migration", + ) = set(MigrationLocation.Classpath(path, location)) + + /** + * Add location of Java-based or SQL migrations to Flyway classpath from the specified provider + * + * Examples: + * + * Using compiled Java-based migrations from a Gradle submodule: + * + * ``` + * tasks.generateJooqClasses { + * migrationLocations.setFromClasspath( + * project(":migrations").sourceSets.main.map { it.output } + * ) + * } + * ``` + * + * Similarly, if you use some extra dependencies in your migrations module, you can do this: + * + * + * ``` + * tasks.generateJooqClasses { + * migrationLocations.setFromClasspath( + * // notice extra + it.runtimeClasspath + * project(":migrations").sourceSets.main.map { it.output + it.runtimeClasspath } + * ) + * } + * ``` + * + * @see migrationLocations + * @see MigrationLocation + * @see Project.project + */ + fun ListProperty.setFromClasspath( + pathProvider: Provider, + location: String = "/db/migration", + ) = setFromClasspath(project.files(pathProvider), location) + + /** + * Add location of Java-based or SQL migrations to Flyway classpath from a configuration + * + * Example: + * + * ``` + * val migrationClasspath by configurations.creating + * + * dependencies { + * migrationClasspath("third.party:some.artifact:some.version") + * } + * + * tasks.generateJooqClasses { + * migrationLocations.setFromClasspath(migrationClasspath) + * } + * ``` + * + * @see migrationLocations + * @see MigrationLocation + * @see Project.getConfigurations + * @see GradleConfiguration + */ + fun ListProperty.setFromClasspath( + configuration: GradleConfiguration, + location: String = "/db/migration", + ) = setFromClasspath(project.files(configuration), location) } - /** - * Set location of Flyway migrations to use for code generation - * - * @see migrationLocations - * @see MigrationLocation - */ - fun ListProperty.set(migrationLocation: MigrationLocation) = set(listOf(migrationLocation)) - - /** - * Set location of SQL migrations on the file system to use for code generation - * - * Example: - * - * ``` - * migrationLocations.setFromFilesystem(project.files("src/main/resources/db/migration")) - * ``` - * - * @see migrationLocations - * @see MigrationLocation - * @see Project.files - */ - fun ListProperty.setFromFilesystem(files: FileCollection) = set( - MigrationLocation.Filesystem(files) - ) - - /** - * Set location of SQL migrations on the file system to use for code generation - * - * Example: - * - * ``` - * migrationLocations.setFromFilesystem("src/main/resources/db/migration") - * ``` - * - * @see migrationLocations - * @see MigrationLocation - */ - fun ListProperty.setFromFilesystem(path: String) = setFromFilesystem(project.files(path)) - - /** - * Add location of Java-based or SQL migrations to Flyway classpath from the specified path - * - * Example: - * - * ``` - * tasks.generateJooqClasses { - * migrationLocations.setFromClasspath(project.files("build/libs/some.jar")) - * } - * ``` - * - * @see migrationLocations - * @see MigrationLocation - * @see Project.files - * @see Project.project - * @see FileCollection - */ - fun ListProperty.setFromClasspath( - path: FileCollection, - location: String = "/db/migration" - ) = set(MigrationLocation.Classpath(path, location)) - - /** - * Add location of Java-based or SQL migrations to Flyway classpath from the specified provider - * - * Examples: - * - * Using compiled Java-based migrations from a Gradle submodule: - * - * ``` - * tasks.generateJooqClasses { - * migrationLocations.setFromClasspath( - * project(":migrations").sourceSets.main.map { it.output } - * ) - * } - * ``` - * - * Similarly, if you use some extra dependencies in your migrations module, you can do this: - * - * - * ``` - * tasks.generateJooqClasses { - * migrationLocations.setFromClasspath( - * // notice extra + it.runtimeClasspath - * project(":migrations").sourceSets.main.map { it.output + it.runtimeClasspath } - * ) - * } - * ``` - * - * @see migrationLocations - * @see MigrationLocation - * @see Project.project - */ - fun ListProperty.setFromClasspath( - pathProvider: Provider, - location: String = "/db/migration" - ) = setFromClasspath(project.files(pathProvider), location) - - /** - * Add location of Java-based or SQL migrations to Flyway classpath from a configuration - * - * Example: - * - * ``` - * val migrationClasspath by configurations.creating - * - * dependencies { - * migrationClasspath("third.party:some.artifact:some.version") - * } - * - * tasks.generateJooqClasses { - * migrationLocations.setFromClasspath(migrationClasspath) - * } - * ``` - * - * @see migrationLocations - * @see MigrationLocation - * @see Project.getConfigurations - * @see GradleConfiguration - */ - fun ListProperty.setFromClasspath( - configuration: GradleConfiguration, - location: String = "/db/migration" - ) = setFromClasspath(project.files(configuration), location) -} - -private data class PrivateValueHolder(@get:Nested val value: T) : ValueHolder() +private data class PrivateValueHolder( + @get:Nested val value: T, +) : ValueHolder() diff --git a/src/main/kotlin/dev/monosoul/jooq/JooqDockerPlugin.kt b/src/main/kotlin/dev/monosoul/jooq/JooqDockerPlugin.kt index b7f3092..752f61f 100644 --- a/src/main/kotlin/dev/monosoul/jooq/JooqDockerPlugin.kt +++ b/src/main/kotlin/dev/monosoul/jooq/JooqDockerPlugin.kt @@ -15,37 +15,42 @@ import org.gradle.kotlin.dsl.register import org.gradle.kotlin.dsl.withType import javax.inject.Inject -open class JooqDockerPlugin @Inject constructor( - private val providerFactory: ProviderFactory -) : Plugin { - - override fun apply(project: Project) = with(project) { - configurations.create(CONFIGURATION_NAME) { - attributes { - attribute(BUNDLING_ATTRIBUTE, objects.named(Bundling::class, Bundling.EXTERNAL)) - } - } - extensions.create("jooq", providerFactory.provider { - // TODO: this is a workaround for https://github.com/gradle/gradle/issues/21876 - project.properties.entries.filter { (key, _) -> - key.startsWith(PropertiesReader.PREFIX) - }.mapNotNull { (key, value) -> - (value as? String)?.let { key to it } - }.toMap() - }) - tasks.register("generateJooqClasses") - pluginManager.withPlugin("org.gradle.java") { - extensions.findByType()?.run { - sourceSets.named(MAIN_SOURCE_SET_NAME) { - java { - srcDirs(tasks.withType()) +open class JooqDockerPlugin + @Inject + constructor( + private val providerFactory: ProviderFactory, + ) : Plugin { + override fun apply(project: Project) = + with(project) { + configurations.create(CONFIGURATION_NAME) { + attributes { + attribute(BUNDLING_ATTRIBUTE, objects.named(Bundling::class, Bundling.EXTERNAL)) + } + } + extensions.create( + "jooq", + providerFactory.provider { + // TODO: this is a workaround for https://github.com/gradle/gradle/issues/21876 + project.properties.entries.filter { (key, _) -> + key.startsWith(PropertiesReader.PREFIX) + }.mapNotNull { (key, value) -> + (value as? String)?.let { key to it } + }.toMap() + }, + ) + tasks.register("generateJooqClasses") + pluginManager.withPlugin("org.gradle.java") { + extensions.findByType()?.run { + sourceSets.named(MAIN_SOURCE_SET_NAME) { + java { + srcDirs(tasks.withType()) + } + } } } } - } - } - internal companion object { - const val CONFIGURATION_NAME = "jooqCodegen" + internal companion object { + const val CONFIGURATION_NAME = "jooqCodegen" + } } -} diff --git a/src/main/kotlin/dev/monosoul/jooq/JooqExtension.kt b/src/main/kotlin/dev/monosoul/jooq/JooqExtension.kt index 8b36d98..b7791f9 100644 --- a/src/main/kotlin/dev/monosoul/jooq/JooqExtension.kt +++ b/src/main/kotlin/dev/monosoul/jooq/JooqExtension.kt @@ -13,29 +13,31 @@ import org.gradle.kotlin.dsl.property import java.io.Serializable import javax.inject.Inject -open class JooqExtension @Inject constructor( - private val propertiesProvider: Provider>, - objectFactory: ObjectFactory, -) : Serializable, SettingsAware { - internal val pluginSettings: Property = objectFactory.property() - .convention( - propertiesProvider.map { - WithContainer().applyPropertiesFrom(it) - } - ) +open class JooqExtension + @Inject + constructor( + private val propertiesProvider: Provider>, + objectFactory: ObjectFactory, + ) : Serializable, SettingsAware { + internal val pluginSettings: Property = + objectFactory.property() + .convention( + propertiesProvider.map { + WithContainer().applyPropertiesFrom(it) + }, + ) - @Suppress("unused") - override fun withContainer(configure: Action) { - pluginSettings.set( - propertiesProvider.map { WithContainer(configure).applyPropertiesFrom(it) } - ) - } + @Suppress("unused") + override fun withContainer(configure: Action) { + pluginSettings.set( + propertiesProvider.map { WithContainer(configure).applyPropertiesFrom(it) }, + ) + } - @Suppress("unused") - override fun withoutContainer(configure: Action) { - pluginSettings.set( - propertiesProvider.map { WithoutContainer(configure).applyPropertiesFrom(it) } - ) + @Suppress("unused") + override fun withoutContainer(configure: Action) { + pluginSettings.set( + propertiesProvider.map { WithoutContainer(configure).applyPropertiesFrom(it) }, + ) + } } -} - diff --git a/src/main/kotlin/dev/monosoul/jooq/codegen/BuiltInJooqCodegenRunner.kt b/src/main/kotlin/dev/monosoul/jooq/codegen/BuiltInJooqCodegenRunner.kt index b32c88e..8c26f54 100644 --- a/src/main/kotlin/dev/monosoul/jooq/codegen/BuiltInJooqCodegenRunner.kt +++ b/src/main/kotlin/dev/monosoul/jooq/codegen/BuiltInJooqCodegenRunner.kt @@ -4,12 +4,12 @@ import org.jooq.codegen.GenerationTool import org.jooq.meta.jaxb.Configuration internal class BuiltInJooqCodegenRunner( - private val codegenAwareClassLoader: ClassLoader + private val codegenAwareClassLoader: ClassLoader, ) : JooqCodegenRunner { - - private val codeGenTool = GenerationTool().apply { - setClassLoader(codegenAwareClassLoader) - } + private val codeGenTool = + GenerationTool().apply { + setClassLoader(codegenAwareClassLoader) + } override fun generateJooqClasses(configuration: Configuration) = codeGenTool.run(configuration) } diff --git a/src/main/kotlin/dev/monosoul/jooq/codegen/ConfigurationProvider.kt b/src/main/kotlin/dev/monosoul/jooq/codegen/ConfigurationProvider.kt index 7f7eb74..f7df6a5 100644 --- a/src/main/kotlin/dev/monosoul/jooq/codegen/ConfigurationProvider.kt +++ b/src/main/kotlin/dev/monosoul/jooq/codegen/ConfigurationProvider.kt @@ -34,39 +34,41 @@ internal class ConfigurationProvider( private val schemas: ListProperty, private val logLevel: Logging, ) { - fun fromXml(file: FileContents) = file.asBytes.map { it.inputStream().use(::load).applyCommonConfiguration() } - fun defaultConfiguration() = Generator() - .withName(JavaGenerator::class.qualifiedName) - .withDatabase( - Database() - .withSchemata(schemas.get().map(this::toSchemaMappingType)) - .withIncludes(".*") - .withExcludes("") - ) - .withGenerate(Generate()) - .let { - Configuration().withGenerator(it) - } - .applyCommonConfiguration() + fun defaultConfiguration() = + Generator() + .withName(JavaGenerator::class.qualifiedName) + .withDatabase( + Database() + .withSchemata(schemas.get().map(this::toSchemaMappingType)) + .withIncludes(".*") + .withExcludes(""), + ) + .withGenerate(Generate()) + .let { + Configuration().withGenerator(it) + } + .applyCommonConfiguration() - private fun Configuration.applyCommonConfiguration() = also { config -> - config.withLogging(logLevel) - config.generator.apply { - withTarget(codeGenTarget()) - nonNullStrategy.apply(schemaToPackageMapping.get().toMappingApplier()) + private fun Configuration.applyCommonConfiguration() = + also { config -> + config.withLogging(logLevel) + config.generator.apply { + withTarget(codeGenTarget()) + nonNullStrategy.apply(schemaToPackageMapping.get().toMappingApplier()) + } } - } private val Generator.nonNullStrategy get() = strategy ?: Strategy().also(::withStrategy) private val Strategy.nonNullMatchers get() = matchers ?: Matchers().also(::withMatchers) - private fun codeGenTarget() = Target() - .withPackageName(basePackageName.get()) - .withDirectory(outputDirectory.asFile.get().toString()) - .withEncoding("UTF-8") - .withClean(true) + private fun codeGenTarget() = + Target() + .withPackageName(basePackageName.get()) + .withDirectory(outputDirectory.asFile.get().toString()) + .withEncoding("UTF-8") + .withClean(true) private fun toSchemaMappingType(schemaName: String): SchemaMappingType { return SchemaMappingType() @@ -74,34 +76,37 @@ internal class ConfigurationProvider( .withOutputSchemaToDefault(outputSchemaToDefault.get().contains(schemaName)) } - private fun Map.toMappingApplier(): (Strategy) -> Unit = { strategy -> - if (isNotEmpty()) { - strategy - .nonNullMatchers - .withSchemas(*toSchemasMatchers()) - .withCatalogs(*toCatalogMatchers()) + private fun Map.toMappingApplier(): (Strategy) -> Unit = + { strategy -> + if (isNotEmpty()) { + strategy + .nonNullMatchers + .withSchemas(*toSchemasMatchers()) + .withCatalogs(*toCatalogMatchers()) + } } - } - private fun Map.toSchemasMatchers() = map { (schema, pkg) -> - MatchersSchemaType() - .withExpression(schema) - .withSchemaIdentifier( - MatcherRule() - .withTransform(AS_IS) - .withExpression(pkg) - ) - }.toTypedArray() + private fun Map.toSchemasMatchers() = + map { (schema, pkg) -> + MatchersSchemaType() + .withExpression(schema) + .withSchemaIdentifier( + MatcherRule() + .withTransform(AS_IS) + .withExpression(pkg), + ) + }.toTypedArray() - private fun Map.toCatalogMatchers() = map { (schema, pkg) -> - MatchersCatalogType() - .withExpression(schema) - .withCatalogIdentifier( - MatcherRule() - .withTransform(AS_IS) - .withExpression(pkg) - ) - }.toTypedArray() + private fun Map.toCatalogMatchers() = + map { (schema, pkg) -> + MatchersCatalogType() + .withExpression(schema) + .withCatalogIdentifier( + MatcherRule() + .withTransform(AS_IS) + .withExpression(pkg), + ) + }.toTypedArray() internal companion object { private fun load(inputStream: InputStream): Configuration = GenerationTool.load(inputStream) @@ -110,7 +115,7 @@ internal class ConfigurationProvider( database.withExcludes( listOfNotNull(database.excludes, *excludes.toTypedArray()) .filterNot(String::isBlank) - .joinToString("|") + .joinToString("|"), ) } @@ -128,7 +133,7 @@ internal class ConfigurationProvider( .withDriver(credentials.jdbcDriverClassName) .withUrl(credentials.jdbcUrl) .withUser(credentials.username) - .withPassword(credentials.password) + .withPassword(credentials.password), ) } } diff --git a/src/main/kotlin/dev/monosoul/jooq/codegen/ReflectiveJooqCodegenRunner.kt b/src/main/kotlin/dev/monosoul/jooq/codegen/ReflectiveJooqCodegenRunner.kt index a300dc8..fc7f11c 100644 --- a/src/main/kotlin/dev/monosoul/jooq/codegen/ReflectiveJooqCodegenRunner.kt +++ b/src/main/kotlin/dev/monosoul/jooq/codegen/ReflectiveJooqCodegenRunner.kt @@ -10,12 +10,12 @@ import java.io.InputStream import kotlin.reflect.jvm.jvmName internal class ReflectiveJooqCodegenRunner( - codegenAwareClassLoader: ClassLoader + codegenAwareClassLoader: ClassLoader, ) : JooqCodegenRunner { - - private val codeGenTool = ReflectiveGenerationTool(codegenAwareClassLoader).apply { - setClassLoader(codegenAwareClassLoader) - } + private val codeGenTool = + ReflectiveGenerationTool(codegenAwareClassLoader).apply { + setClassLoader(codegenAwareClassLoader) + } override fun generateJooqClasses(configuration: Configuration) = codeGenTool.run(configuration) @@ -32,10 +32,11 @@ internal class ReflectiveJooqCodegenRunner( * @see GenerationTool.setClassLoader */ fun setClassLoader(classLoader: ClassLoader) { - val setClassLoaderMethod = toolClass.getDeclaredMethod( - GenerationTool::setClassLoader.name, - ClassLoader::class.java - ) + val setClassLoaderMethod = + toolClass.getDeclaredMethod( + GenerationTool::setClassLoader.name, + ClassLoader::class.java, + ) setClassLoaderMethod.invoke(tool, classLoader) } @@ -48,23 +49,25 @@ internal class ReflectiveJooqCodegenRunner( runMethod.invoke(tool, preparedConfiguration) } - private fun Configuration.sanitize() = apply { - // [#100] MiniJAXB class provided by jOOQ doesn't respect default value of XmlElement - // It serializes the value even if it's the same as the default value - generator?.strategy?.also { - if (it.name == defaultGeneratorStrategyName) { - it.name = null + private fun Configuration.sanitize() = + apply { + // [#100] MiniJAXB class provided by jOOQ doesn't respect default value of XmlElement + // It serializes the value even if it's the same as the default value + generator?.strategy?.also { + if (it.name == defaultGeneratorStrategyName) { + it.name = null + } } } - } - private fun Configuration.toXmlByteArray() = ByteArrayOutputStream().also { stream -> - stream.writer().use { writer -> - @Suppress("UnstableApiUsage") - MiniJAXB.marshal(this, writer) - writer.flush() - } - }.toByteArray() + private fun Configuration.toXmlByteArray() = + ByteArrayOutputStream().also { stream -> + stream.writer().use { writer -> + @Suppress("UnstableApiUsage") + MiniJAXB.marshal(this, writer) + writer.flush() + } + }.toByteArray() /** * @see GenerationTool.load diff --git a/src/main/kotlin/dev/monosoul/jooq/codegen/UniversalJooqCodegenRunner.kt b/src/main/kotlin/dev/monosoul/jooq/codegen/UniversalJooqCodegenRunner.kt index ea9e6d8..bfbb2ca 100644 --- a/src/main/kotlin/dev/monosoul/jooq/codegen/UniversalJooqCodegenRunner.kt +++ b/src/main/kotlin/dev/monosoul/jooq/codegen/UniversalJooqCodegenRunner.kt @@ -9,7 +9,10 @@ import org.slf4j.LoggerFactory internal class UniversalJooqCodegenRunner { private val logger: Logger = LoggerFactory.getLogger(javaClass) - fun generateJooqClasses(codegenAwareClassLoader: CodegenClasspathAwareClassLoaders, configuration: Configuration) { + fun generateJooqClasses( + codegenAwareClassLoader: CodegenClasspathAwareClassLoaders, + configuration: Configuration, + ) { runCatching { ReflectiveJooqCodegenRunner(codegenAwareClassLoader.buildscriptExclusive) }.onFailure { diff --git a/src/main/kotlin/dev/monosoul/jooq/container/GenericDatabaseContainer.kt b/src/main/kotlin/dev/monosoul/jooq/container/GenericDatabaseContainer.kt index 76e6a3e..c6af65a 100644 --- a/src/main/kotlin/dev/monosoul/jooq/container/GenericDatabaseContainer.kt +++ b/src/main/kotlin/dev/monosoul/jooq/container/GenericDatabaseContainer.kt @@ -17,24 +17,23 @@ import kotlin.reflect.full.declaredMembers import kotlin.reflect.jvm.isAccessible class GenericDatabaseContainer( - private val image: Image, - private val database: Database.Internal, - private val jdbcAwareClassLoader: ClassLoader, + private val image: Image, + private val database: Database.Internal, + private val jdbcAwareClassLoader: ClassLoader, ) : JdbcDatabaseContainer( image.let { failFastAlways.set(false) DockerImageName.parse(it.name) - } -) { - + }, + ) { private val driverLoadLock = ReentrantLock() private var driver: Driver? = null init { withLogConsumer( Slf4jLogConsumer( - LoggerFactory.getLogger("JooqGenerationDb[$dockerImageName]") - ) + LoggerFactory.getLogger("JooqGenerationDb[$dockerImageName]"), + ), ) withEnv(image.envVars) withExposedPorts(database.port) @@ -66,23 +65,25 @@ class GenericDatabaseContainer( return driver!! } - private fun getNewJdbcDriverInstance() = try { - @Suppress("DEPRECATION") - jdbcAwareClassLoader.loadClass(driverClassName).newInstance() as Driver - } catch (e: Exception) { - when (e) { - is InstantiationException, is IllegalAccessException, is ClassNotFoundException -> { - throw NoDriverFoundException("Could not get Driver", e) + private fun getNewJdbcDriverInstance() = + try { + @Suppress("DEPRECATION") + jdbcAwareClassLoader.loadClass(driverClassName).newInstance() as Driver + } catch (e: Exception) { + when (e) { + is InstantiationException, is IllegalAccessException, is ClassNotFoundException -> { + throw NoDriverFoundException("Could not get Driver", e) + } + else -> throw e } - else -> throw e } - } private companion object { /** * Workaround for https://github.com/testcontainers/testcontainers-java/issues/6441 */ - val failFastAlways = DockerClientProviderStrategy::class.declaredMembers + val failFastAlways = + DockerClientProviderStrategy::class.declaredMembers .single { it.name == "FAIL_FAST_ALWAYS" } .apply { isAccessible = true } .let { diff --git a/src/main/kotlin/dev/monosoul/jooq/migration/BuiltInMigrationRunner.kt b/src/main/kotlin/dev/monosoul/jooq/migration/BuiltInMigrationRunner.kt index e03a8a3..4f29730 100644 --- a/src/main/kotlin/dev/monosoul/jooq/migration/BuiltInMigrationRunner.kt +++ b/src/main/kotlin/dev/monosoul/jooq/migration/BuiltInMigrationRunner.kt @@ -4,7 +4,6 @@ import dev.monosoul.jooq.settings.DatabaseCredentials import org.flywaydb.core.Flyway internal class BuiltInMigrationRunner(codegenAwareClassLoader: ClassLoader) : MigrationRunner { - private val flyway = Flyway.configure(codegenAwareClassLoader) override fun migrateDb( @@ -13,7 +12,7 @@ internal class BuiltInMigrationRunner(codegenAwareClassLoader: ClassLoader) : Mi flywayProperties: Map, credentials: DatabaseCredentials, defaultFlywaySchema: String, - flywayTable: String + flywayTable: String, ) = flyway .dataSource(credentials.jdbcUrl, credentials.username, credentials.password) .schemas(*schemas) diff --git a/src/main/kotlin/dev/monosoul/jooq/migration/MigrationLocation.kt b/src/main/kotlin/dev/monosoul/jooq/migration/MigrationLocation.kt index 84aae49..deb70cc 100644 --- a/src/main/kotlin/dev/monosoul/jooq/migration/MigrationLocation.kt +++ b/src/main/kotlin/dev/monosoul/jooq/migration/MigrationLocation.kt @@ -47,9 +47,8 @@ sealed class MigrationLocation { /** * One or multiple locations of migration SQL scripts */ - override val path: FileCollection + override val path: FileCollection, ) : MigrationLocation() { - /** * Migration locations in Flyway accepted format. * @@ -57,6 +56,7 @@ sealed class MigrationLocation { */ @get:Internal override val locations: List get() = path.map { "${Location.FILESYSTEM_PREFIX}${it.absolutePath}" } + override fun extraClasspath(): List = emptyList() } @@ -110,7 +110,7 @@ sealed class MigrationLocation { */ data class Classpath( override val path: FileCollection, - private val classpathLocations: List + private val classpathLocations: List, ) : MigrationLocation() { override val locations: List = classpathLocations.map { "classpath:$it" } @@ -119,7 +119,7 @@ sealed class MigrationLocation { */ constructor( path: FileCollection, - classpathLocation: String + classpathLocation: String, ) : this(path, listOf(classpathLocation)) /** @@ -128,13 +128,14 @@ sealed class MigrationLocation { @Suppress("unused") constructor(path: FileCollection) : this(path, "/db/migration") - override fun extraClasspath(): List = path.asSequence() - .flatMap { file -> - listOf(file).plus( - file.listFiles { _, name -> name.endsWith(".jar") }?.asList() ?: emptyList() - ) - } - .map { it.toURI().toURL() } - .toList() + override fun extraClasspath(): List = + path.asSequence() + .flatMap { file -> + listOf(file).plus( + file.listFiles { _, name -> name.endsWith(".jar") }?.asList() ?: emptyList(), + ) + } + .map { it.toURI().toURL() } + .toList() } } diff --git a/src/main/kotlin/dev/monosoul/jooq/migration/ReflectiveMigrationRunner.kt b/src/main/kotlin/dev/monosoul/jooq/migration/ReflectiveMigrationRunner.kt index 49fc34b..c958f0b 100644 --- a/src/main/kotlin/dev/monosoul/jooq/migration/ReflectiveMigrationRunner.kt +++ b/src/main/kotlin/dev/monosoul/jooq/migration/ReflectiveMigrationRunner.kt @@ -10,7 +10,6 @@ import kotlin.reflect.KFunction4 import kotlin.reflect.jvm.jvmName internal class ReflectiveMigrationRunner(codegenAwareClassLoader: ClassLoader) : MigrationRunner { - private val flyway = ReflectiveFlywayConfiguration(codegenAwareClassLoader) override fun migrateDb( @@ -19,7 +18,7 @@ internal class ReflectiveMigrationRunner(codegenAwareClassLoader: ClassLoader) : flywayProperties: Map, credentials: DatabaseCredentials, defaultFlywaySchema: String, - flywayTable: String + flywayTable: String, ) = flyway .dataSource(credentials) .schemas(*schemas) @@ -46,80 +45,92 @@ internal class ReflectiveMigrationRunner(codegenAwareClassLoader: ClassLoader) : * FluentConfiguration.dataSource(String, String, String) * @see FluentConfiguration.dataSource */ - fun dataSource(credentials: DatabaseCredentials) = also { - val dataSourceMethod = configurationClass.getMethod( - fourArgFunctionName(FluentConfiguration::dataSource), - String::class.java, - String::class.java, - String::class.java - ) - dataSourceMethod.invoke(configuration, credentials.jdbcUrl, credentials.username, credentials.password) - } + fun dataSource(credentials: DatabaseCredentials) = + also { + val dataSourceMethod = + configurationClass.getMethod( + fourArgFunctionName(FluentConfiguration::dataSource), + String::class.java, + String::class.java, + String::class.java, + ) + dataSourceMethod.invoke(configuration, credentials.jdbcUrl, credentials.username, credentials.password) + } /** * FluentConfiguration.schemas(String...) * @see FluentConfiguration.schemas */ - fun schemas(vararg schemas: String) = also { - val schemasMethod = configurationClass.getMethod( - twoArgFunctionName(FluentConfiguration::schemas), - Array::class.java - ) - schemasMethod.invoke(configuration, schemas) - } + fun schemas(vararg schemas: String) = + also { + val schemasMethod = + configurationClass.getMethod( + twoArgFunctionName(FluentConfiguration::schemas), + Array::class.java, + ) + schemasMethod.invoke(configuration, schemas) + } /** * FluentConfiguration.locations(String...) * @see FluentConfiguration.locations */ - fun locations(vararg locations: String) = also { - val locationsMethod = configurationClass.getMethod( - twoArgFunctionName, FluentConfiguration>( - FluentConfiguration::locations - ), - Array::class.java - ) - locationsMethod.invoke(configuration, locations) - } + fun locations(vararg locations: String) = + also { + val locationsMethod = + configurationClass.getMethod( + twoArgFunctionName, FluentConfiguration>( + FluentConfiguration::locations, + ), + Array::class.java, + ) + locationsMethod.invoke(configuration, locations) + } /** * FluentConfiguration.defaultSchema(String) * @see FluentConfiguration.defaultSchema */ - fun defaultSchema(schema: String) = also { - val defaultSchemaMethod = configurationClass.getMethod( - twoArgFunctionName(FluentConfiguration::defaultSchema), - String::class.java - ) - defaultSchemaMethod.invoke(configuration, schema) - } + fun defaultSchema(schema: String) = + also { + val defaultSchemaMethod = + configurationClass.getMethod( + twoArgFunctionName(FluentConfiguration::defaultSchema), + String::class.java, + ) + defaultSchemaMethod.invoke(configuration, schema) + } /** * FluentConfiguration.table(String) * @see FluentConfiguration.table */ - fun table(table: String) = also { - val tableMethod = configurationClass.getMethod( - twoArgFunctionName(FluentConfiguration::table), - String::class.java - ) - tableMethod.invoke(configuration, table) - } + fun table(table: String) = + also { + val tableMethod = + configurationClass.getMethod( + twoArgFunctionName(FluentConfiguration::table), + String::class.java, + ) + tableMethod.invoke(configuration, table) + } /** * * FluentConfiguration.configuration(Map) * @see FluentConfiguration.configuration */ - fun configuration(props: Map) = also { - val configurationMethod = configurationClass.getMethod( - twoArgFunctionName, FluentConfiguration>( - FluentConfiguration::configuration - ), - Map::class.java - ) - configurationMethod.invoke(configuration, props) - } + fun configuration(props: Map) = + also { + val configurationMethod = + configurationClass.getMethod( + twoArgFunctionName, FluentConfiguration>( + FluentConfiguration::configuration, + ), + Map::class.java, + ) + configurationMethod.invoke(configuration, props) + } /** * FluentConfiguration.load() @@ -131,14 +142,16 @@ internal class ReflectiveMigrationRunner(codegenAwareClassLoader: ClassLoader) : return ReflectiveFlyway( flywayClass = flywayClass, migrateResultClass = codegenAwareClassLoader.loadClass(MigrateResult::class.jvmName), - flywayInstance = loadMethod.invoke(configuration) + flywayInstance = loadMethod.invoke(configuration), ) } private companion object { // those functions are required to provide a hint for overloaded functions fun oneArgFunctionName(ref: KFunction1) = ref.name + fun twoArgFunctionName(ref: KFunction2) = ref.name + fun fourArgFunctionName(ref: KFunction4) = ref.name } } @@ -152,7 +165,6 @@ internal class ReflectiveMigrationRunner(codegenAwareClassLoader: ClassLoader) : private val migrateResultClass: Class<*>, private val flywayInstance: Any, ) { - /** * Flyway.migrate() * @see Flyway.migrate diff --git a/src/main/kotlin/dev/monosoul/jooq/migration/UniversalMigrationRunner.kt b/src/main/kotlin/dev/monosoul/jooq/migration/UniversalMigrationRunner.kt index 53236a3..ef82da7 100644 --- a/src/main/kotlin/dev/monosoul/jooq/migration/UniversalMigrationRunner.kt +++ b/src/main/kotlin/dev/monosoul/jooq/migration/UniversalMigrationRunner.kt @@ -26,17 +26,21 @@ internal class UniversalMigrationRunner( flywayProperties.getting(TABLE).getOrElse("flyway_schema_history") } - fun migrateDb(classLoaders: CodegenClasspathAwareClassLoaders, credentials: DatabaseCredentials): SchemaVersion { + fun migrateDb( + classLoaders: CodegenClasspathAwareClassLoaders, + credentials: DatabaseCredentials, + ): SchemaVersion { val resolvedMigrationLocations = migrationLocations.get() logger.info("Migration locations: {}", resolvedMigrationLocations) - val extraClasspath = resolvedMigrationLocations.flatMap { it.extraClasspath() }.also { - logger.info("Migration will run using extra classpath: {}", it) - }.toTypedArray() + val extraClasspath = + resolvedMigrationLocations.flatMap { it.extraClasspath() }.also { + logger.info("Migration will run using extra classpath: {}", it) + }.toTypedArray() return runCatching { ReflectiveMigrationRunner( - URLClassLoader(extraClasspath, classLoaders.buildscriptExclusive) + URLClassLoader(extraClasspath, classLoaders.buildscriptExclusive), ) }.onFailure { logger.debug("Failed to load Flyway from $CONFIGURATION_NAME classpath", it) @@ -45,7 +49,7 @@ internal class UniversalMigrationRunner( }.getOrElse { logger.info("Loaded Flyway from buildscript classpath") BuiltInMigrationRunner( - URLClassLoader(extraClasspath, classLoaders.buildscriptInclusive) + URLClassLoader(extraClasspath, classLoaders.buildscriptInclusive), ) }.migrateDb( schemas = schemas.get().toTypedArray(), diff --git a/src/main/kotlin/dev/monosoul/jooq/settings/Database.kt b/src/main/kotlin/dev/monosoul/jooq/settings/Database.kt index 27921ab..cc0e2f6 100644 --- a/src/main/kotlin/dev/monosoul/jooq/settings/Database.kt +++ b/src/main/kotlin/dev/monosoul/jooq/settings/Database.kt @@ -30,7 +30,10 @@ sealed class Database : JdbcAware, SettingsElement { override var port: Int = 5432, override val jdbc: Jdbc = Jdbc(), ) : Database() { - internal fun getJdbcUrl(host: String, port: Int) = "${jdbc.schema}://$host:$port/$name${jdbc.urlQueryParams}" + internal fun getJdbcUrl( + host: String, + port: Int, + ) = "${jdbc.schema}://$host:$port/$name${jdbc.urlQueryParams}" } data class External( diff --git a/src/main/kotlin/dev/monosoul/jooq/settings/Image.kt b/src/main/kotlin/dev/monosoul/jooq/settings/Image.kt index 7c0d8a8..4848aed 100644 --- a/src/main/kotlin/dev/monosoul/jooq/settings/Image.kt +++ b/src/main/kotlin/dev/monosoul/jooq/settings/Image.kt @@ -10,10 +10,11 @@ data class Image( @get:Input @get:Optional var command: String? = null, ) : SettingsElement { constructor(database: Database.Internal) : this( - envVars = mapOf( - "POSTGRES_USER" to database.username, - "POSTGRES_PASSWORD" to database.password, - "POSTGRES_DB" to database.name - ), + envVars = + mapOf( + "POSTGRES_USER" to database.username, + "POSTGRES_PASSWORD" to database.password, + "POSTGRES_DB" to database.name, + ), ) } diff --git a/src/main/kotlin/dev/monosoul/jooq/settings/JooqDockerPluginSettings.kt b/src/main/kotlin/dev/monosoul/jooq/settings/JooqDockerPluginSettings.kt index 65dd1dc..b95b951 100644 --- a/src/main/kotlin/dev/monosoul/jooq/settings/JooqDockerPluginSettings.kt +++ b/src/main/kotlin/dev/monosoul/jooq/settings/JooqDockerPluginSettings.kt @@ -10,9 +10,10 @@ import org.testcontainers.shaded.org.apache.commons.lang3.builder.HashCodeBuilde sealed class JooqDockerPluginSettings : SettingsElement { @get:Nested internal abstract val database: Database + internal abstract fun runWithDatabaseCredentials( classloaders: CodegenClasspathAwareClassLoaders, - block: (CodegenClasspathAwareClassLoaders, DatabaseCredentials) -> Unit + block: (CodegenClasspathAwareClassLoaders, DatabaseCredentials) -> Unit, ) internal abstract fun copy(): JooqDockerPluginSettings @@ -28,13 +29,14 @@ sealed class JooqDockerPluginSettings : SettingsElement { override fun runWithDatabaseCredentials( classloaders: CodegenClasspathAwareClassLoaders, - block: (CodegenClasspathAwareClassLoaders, DatabaseCredentials) -> Unit + block: (CodegenClasspathAwareClassLoaders, DatabaseCredentials) -> Unit, ) { - val dbContainer = GenericDatabaseContainer( - image = image, - database = database, - jdbcAwareClassLoader = classloaders.buildscriptInclusive, - ).also { it.start() } + val dbContainer = + GenericDatabaseContainer( + image = image, + database = database, + jdbcAwareClassLoader = classloaders.buildscriptInclusive, + ).also { it.start() } try { block( @@ -44,27 +46,30 @@ sealed class JooqDockerPluginSettings : SettingsElement { jdbcUrl = dbContainer.jdbcUrl, username = dbContainer.username, password = dbContainer.password, - ) + ), ) } finally { dbContainer.stop() } } - override fun copy(): WithContainer = WithContainer( - database = database.run { copy(jdbc = jdbc.copy()) }, - image = image.copy() - ) + override fun copy(): WithContainer = + WithContainer( + database = database.run { copy(jdbc = jdbc.copy()) }, + image = image.copy(), + ) override fun db(customizer: Action) = customizer.execute(database) + override fun image(customizer: Action) = customizer.execute(image) override fun equals(other: Any?) = reflectionEquals(this, other) + override fun hashCode(): Int = reflectionHashCode(this) } class WithoutContainer private constructor( - override val database: Database.External + override val database: Database.External, ) : JooqDockerPluginSettings(), DbAware { constructor(customizer: Action = Action { }) : this(Database.External()) { customizer.execute(this) @@ -72,7 +77,7 @@ sealed class JooqDockerPluginSettings : SettingsElement { override fun runWithDatabaseCredentials( classloaders: CodegenClasspathAwareClassLoaders, - block: (CodegenClasspathAwareClassLoaders, DatabaseCredentials) -> Unit + block: (CodegenClasspathAwareClassLoaders, DatabaseCredentials) -> Unit, ) { block( classloaders, @@ -80,18 +85,20 @@ sealed class JooqDockerPluginSettings : SettingsElement { jdbcDriverClassName = database.jdbc.driverClassName, jdbcUrl = database.getJdbcUrl(), username = database.username, - password = database.password - ) + password = database.password, + ), ) } - override fun copy(): WithoutContainer = WithoutContainer( - database = database.run { copy(jdbc = jdbc.copy()) } - ) + override fun copy(): WithoutContainer = + WithoutContainer( + database = database.run { copy(jdbc = jdbc.copy()) }, + ) override fun db(customizer: Action) = customizer.execute(database) override fun equals(other: Any?) = reflectionEquals(this, other) + override fun hashCode(): Int = reflectionHashCode(this) } } diff --git a/src/main/kotlin/dev/monosoul/jooq/settings/PropertiesReader.kt b/src/main/kotlin/dev/monosoul/jooq/settings/PropertiesReader.kt index 575b1b9..4f37f3d 100644 --- a/src/main/kotlin/dev/monosoul/jooq/settings/PropertiesReader.kt +++ b/src/main/kotlin/dev/monosoul/jooq/settings/PropertiesReader.kt @@ -23,16 +23,21 @@ internal object PropertiesReader { onlyApplyPropertiesFrom(pluginProperties) } - private fun WithContainer.onlyApplyPropertiesFrom(pluginProperties: Map) = apply { - image.applyPropertiesFrom(pluginProperties) - database.applyPropertiesFrom(pluginProperties) - } + private fun WithContainer.onlyApplyPropertiesFrom(pluginProperties: Map) = + apply { + image.applyPropertiesFrom(pluginProperties) + database.applyPropertiesFrom(pluginProperties) + } - fun WithoutContainer.applyPropertiesFrom(pluginProperties: Map): JooqDockerPluginSettings = apply { - database.applyPropertiesFrom(pluginProperties) - } + fun WithoutContainer.applyPropertiesFrom(pluginProperties: Map): JooqDockerPluginSettings = + apply { + database.applyPropertiesFrom(pluginProperties) + } - private fun Jdbc.applyPropertiesFrom(pluginProperties: Map, namespace: String) { + private fun Jdbc.applyPropertiesFrom( + pluginProperties: Map, + namespace: String, + ) { val prefix = "$namespace$JDBC_PREFIX" pluginProperties.findAndSetProperty(prefix, ::schema) pluginProperties.findAndSetProperty(prefix, ::driverClassName) @@ -76,7 +81,7 @@ internal object PropertiesReader { private fun Map.findAndSetProperty( prefix: String, property: KMutableProperty0, - mapper: (String) -> T = { it as T } + mapper: (String) -> T = { it as T }, ) { get("$prefix${property.name}")?.also { property.set(mapper(it)) diff --git a/src/main/kotlin/dev/monosoul/jooq/settings/SettingsElement.kt b/src/main/kotlin/dev/monosoul/jooq/settings/SettingsElement.kt index e9d0006..0808fdc 100644 --- a/src/main/kotlin/dev/monosoul/jooq/settings/SettingsElement.kt +++ b/src/main/kotlin/dev/monosoul/jooq/settings/SettingsElement.kt @@ -4,5 +4,6 @@ import java.io.Serializable internal interface SettingsElement : Serializable { override fun hashCode(): Int + override fun equals(other: Any?): Boolean } diff --git a/src/main/kotlin/dev/monosoul/jooq/util/CodegenClasspathAwareClassLoaders.kt b/src/main/kotlin/dev/monosoul/jooq/util/CodegenClasspathAwareClassLoaders.kt index 897641d..1a12924 100644 --- a/src/main/kotlin/dev/monosoul/jooq/util/CodegenClasspathAwareClassLoaders.kt +++ b/src/main/kotlin/dev/monosoul/jooq/util/CodegenClasspathAwareClassLoaders.kt @@ -8,13 +8,14 @@ internal class CodegenClasspathAwareClassLoaders( val buildscriptInclusive: URLClassLoader, ) { companion object { - fun from(classpath: FileCollection) = classpath.map { - it.toURI().toURL() - }.toTypedArray().let { - CodegenClasspathAwareClassLoaders( - buildscriptExclusive = URLClassLoader(it), - buildscriptInclusive = URLClassLoader(it, CodegenClasspathAwareClassLoaders::class.java.classLoader) - ) - } + fun from(classpath: FileCollection) = + classpath.map { + it.toURI().toURL() + }.toTypedArray().let { + CodegenClasspathAwareClassLoaders( + buildscriptExclusive = URLClassLoader(it), + buildscriptInclusive = URLClassLoader(it, CodegenClasspathAwareClassLoaders::class.java.classLoader), + ) + } } } diff --git a/src/main/kotlin/dev/monosoul/jooq/util/GetCodegenLogging.kt b/src/main/kotlin/dev/monosoul/jooq/util/GetCodegenLogging.kt index 5365a7c..bbd6249 100644 --- a/src/main/kotlin/dev/monosoul/jooq/util/GetCodegenLogging.kt +++ b/src/main/kotlin/dev/monosoul/jooq/util/GetCodegenLogging.kt @@ -4,9 +4,10 @@ import org.gradle.api.logging.Logger import org.jooq.meta.jaxb.Logging // covered by tests in artifact-tests module -fun Logger.getCodegenLogging(): Logging = when { - isQuietEnabled && !isWarnEnabled -> Logging.ERROR - isLifecycleEnabled && !isInfoEnabled -> Logging.ERROR - isWarnEnabled && !isInfoEnabled -> Logging.WARN - else -> Logging.DEBUG -} +fun Logger.getCodegenLogging(): Logging = + when { + isQuietEnabled && !isWarnEnabled -> Logging.ERROR + isLifecycleEnabled && !isInfoEnabled -> Logging.ERROR + isWarnEnabled && !isInfoEnabled -> Logging.WARN + else -> Logging.DEBUG + } diff --git a/src/test/kotlin/dev/monosoul/jooq/RecommendedVersionsTest.kt b/src/test/kotlin/dev/monosoul/jooq/RecommendedVersionsTest.kt index 9df2915..5762e68 100644 --- a/src/test/kotlin/dev/monosoul/jooq/RecommendedVersionsTest.kt +++ b/src/test/kotlin/dev/monosoul/jooq/RecommendedVersionsTest.kt @@ -6,7 +6,6 @@ import strikt.assertions.isNotBlank import strikt.assertions.isNotEqualTo class RecommendedVersionsTest { - @Test fun `should provide jooq version`() { expectThat(RecommendedVersions.JOOQ_VERSION).isNotBlank() isNotEqualTo "@jooq.version@" diff --git a/src/test/kotlin/dev/monosoul/jooq/container/GenericDatabaseContainerTest.kt b/src/test/kotlin/dev/monosoul/jooq/container/GenericDatabaseContainerTest.kt index 703655f..6472ef5 100644 --- a/src/test/kotlin/dev/monosoul/jooq/container/GenericDatabaseContainerTest.kt +++ b/src/test/kotlin/dev/monosoul/jooq/container/GenericDatabaseContainerTest.kt @@ -24,7 +24,6 @@ import kotlin.streams.asStream @ExtendWith(MockKExtension::class) class GenericDatabaseContainerTest { - private lateinit var image: Image private lateinit var database: Database.Internal @@ -39,11 +38,12 @@ class GenericDatabaseContainerTest { database = Database.Internal() image = Image() - container = GenericDatabaseContainer( - image = image, - database = database, - jdbcAwareClassLoader = jdbcAwareClassLoader, - ) + container = + GenericDatabaseContainer( + image = image, + database = database, + jdbcAwareClassLoader = jdbcAwareClassLoader, + ) } @Test @@ -62,21 +62,22 @@ class GenericDatabaseContainerTest { } @TestFactory - fun `should rethrow expected exceptions as no driver found exception`() = sequenceOf( - InstantiationException(), - IllegalAccessException(), - ClassNotFoundException(), - ).map { exception -> - dynamicTest("should rethrow ${exception::class.simpleName} as no driver found exception") { - // given - every { jdbcAwareClassLoader.loadClass(any()) } throws exception - - // when && then - expectThrows { - container.jdbcDriverInstance - }.message isEqualTo "Could not get Driver" - } - }.asStream() + fun `should rethrow expected exceptions as no driver found exception`() = + sequenceOf( + InstantiationException(), + IllegalAccessException(), + ClassNotFoundException(), + ).map { exception -> + dynamicTest("should rethrow ${exception::class.simpleName} as no driver found exception") { + // given + every { jdbcAwareClassLoader.loadClass(any()) } throws exception + + // when && then + expectThrows { + container.jdbcDriverInstance + }.message isEqualTo "Could not get Driver" + } + }.asStream() @Test fun `should rethrow unexpected exceptions as is`() { @@ -102,12 +103,13 @@ class GenericDatabaseContainerTest { } // when - val futures = (1..2).map { - threadPool.submit { - startLatch.countDown() - container.jdbcDriverInstance + val futures = + (1..2).map { + threadPool.submit { + startLatch.countDown() + container.jdbcDriverInstance + } } - } driverGetLatch.countDown() futures.forEach { it.get() } threadPool.shutdown() diff --git a/src/test/kotlin/dev/monosoul/jooq/container/PostgresContainer.kt b/src/test/kotlin/dev/monosoul/jooq/container/PostgresContainer.kt index fcc1782..f8c1e9c 100644 --- a/src/test/kotlin/dev/monosoul/jooq/container/PostgresContainer.kt +++ b/src/test/kotlin/dev/monosoul/jooq/container/PostgresContainer.kt @@ -4,5 +4,5 @@ import org.testcontainers.containers.PostgreSQLContainer import org.testcontainers.utility.DockerImageName internal class PostgresContainer( - image: String = "postgres:14.4-alpine" + image: String = "postgres:14.4-alpine", ) : PostgreSQLContainer(DockerImageName.parse(image)) diff --git a/src/test/kotlin/dev/monosoul/jooq/functional/CacheJooqDockerPluginFunctionalTest.kt b/src/test/kotlin/dev/monosoul/jooq/functional/CacheJooqDockerPluginFunctionalTest.kt index 473e2b9..eadb4ed 100644 --- a/src/test/kotlin/dev/monosoul/jooq/functional/CacheJooqDockerPluginFunctionalTest.kt +++ b/src/test/kotlin/dev/monosoul/jooq/functional/CacheJooqDockerPluginFunctionalTest.kt @@ -10,7 +10,6 @@ import strikt.java.exists import java.io.File class CacheJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalTestBase() { - @TempDir private lateinit var localBuildCacheDirectory: File @@ -20,17 +19,17 @@ class CacheJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalTestBase() configureLocalGradleCache() prepareBuildGradleFile { """ - plugins { - id("dev.monosoul.jooq-docker") - } + plugins { + id("dev.monosoul.jooq-docker") + } - repositories { - mavenCentral() - } + repositories { + mavenCentral() + } - dependencies { - jooqCodegen("org.postgresql:postgresql:42.3.6") - } + dependencies { + jooqCodegen("org.postgresql:postgresql:42.3.6") + } """.trimIndent() } copyResource(from = "/V01__init.sql", to = "src/main/resources/db/migration/V01__init.sql") @@ -54,10 +53,10 @@ class CacheJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalTestBase() that(resultAfterInputsChange).generateJooqClassesTask.outcome isEqualTo SUCCESS that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java"), ).exists() that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Bar.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Bar.java"), ).exists() } } @@ -65,11 +64,11 @@ class CacheJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalTestBase() private fun configureLocalGradleCache() { writeProjectFile("settings.gradle.kts") { """ - buildCache { - local { - directory = "${localBuildCacheDirectory.path}" - } + buildCache { + local { + directory = "${localBuildCacheDirectory.path}" } + } """.trimIndent() } } diff --git a/src/test/kotlin/dev/monosoul/jooq/functional/ConfigurabilityJooqDockerPluginFunctionalTest.kt b/src/test/kotlin/dev/monosoul/jooq/functional/ConfigurabilityJooqDockerPluginFunctionalTest.kt index 0fb6650..f24f21b 100644 --- a/src/test/kotlin/dev/monosoul/jooq/functional/ConfigurabilityJooqDockerPluginFunctionalTest.kt +++ b/src/test/kotlin/dev/monosoul/jooq/functional/ConfigurabilityJooqDockerPluginFunctionalTest.kt @@ -7,34 +7,33 @@ import strikt.assertions.isEqualTo import strikt.java.exists class ConfigurabilityJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalTestBase() { - @Test fun `should generate jooq classes for PostgreSQL db with default config for multiple schemas`() { // given prepareBuildGradleFile { """ - plugins { - id("dev.monosoul.jooq-docker") - } + plugins { + id("dev.monosoul.jooq-docker") + } - repositories { - mavenCentral() - } + repositories { + mavenCentral() + } - tasks { - generateJooqClasses { - schemas.set(listOf("public", "other")) - } + tasks { + generateJooqClasses { + schemas.set(listOf("public", "other")) } + } - dependencies { - jooqCodegen("org.postgresql:postgresql:42.3.6") - } + dependencies { + jooqCodegen("org.postgresql:postgresql:42.3.6") + } """.trimIndent() } copyResource( from = "/V01__init_multiple_schemas.sql", - to = "src/main/resources/db/migration/V01__init_multiple_schemas.sql" + to = "src/main/resources/db/migration/V01__init_multiple_schemas.sql", ) // when @@ -44,10 +43,10 @@ class ConfigurabilityJooqDockerPluginFunctionalTest : JooqDockerPluginFunctional expect { that(result).generateJooqClassesTask.outcome isEqualTo SUCCESS that( - projectFile("build/generated-jooq/org/jooq/generated/public_/tables/Foo.java") + projectFile("build/generated-jooq/org/jooq/generated/public_/tables/Foo.java"), ).exists() that( - projectFile("build/generated-jooq/org/jooq/generated/other/tables/Bar.java") + projectFile("build/generated-jooq/org/jooq/generated/other/tables/Bar.java"), ).exists() } } @@ -57,29 +56,29 @@ class ConfigurabilityJooqDockerPluginFunctionalTest : JooqDockerPluginFunctional // given prepareBuildGradleFile { """ - plugins { - id("dev.monosoul.jooq-docker") - } + plugins { + id("dev.monosoul.jooq-docker") + } - repositories { - mavenCentral() - } + repositories { + mavenCentral() + } - tasks { - generateJooqClasses { - schemas.set(listOf("public", "other")) - schemaToPackageMapping.put("public", "fancy_name") - } + tasks { + generateJooqClasses { + schemas.set(listOf("public", "other")) + schemaToPackageMapping.put("public", "fancy_name") } + } - dependencies { - jooqCodegen("org.postgresql:postgresql:42.3.6") - } + dependencies { + jooqCodegen("org.postgresql:postgresql:42.3.6") + } """.trimIndent() } copyResource( from = "/V01__init_multiple_schemas.sql", - to = "src/main/resources/db/migration/V01__init_multiple_schemas.sql" + to = "src/main/resources/db/migration/V01__init_multiple_schemas.sql", ) // when @@ -89,10 +88,10 @@ class ConfigurabilityJooqDockerPluginFunctionalTest : JooqDockerPluginFunctional expect { that(result).generateJooqClassesTask.outcome isEqualTo SUCCESS that( - projectFile("build/generated-jooq/org/jooq/generated/fancy_name/tables/Foo.java") + projectFile("build/generated-jooq/org/jooq/generated/fancy_name/tables/Foo.java"), ).exists() that( - projectFile("build/generated-jooq/org/jooq/generated/other/tables/Bar.java") + projectFile("build/generated-jooq/org/jooq/generated/other/tables/Bar.java"), ).exists() } } @@ -102,23 +101,23 @@ class ConfigurabilityJooqDockerPluginFunctionalTest : JooqDockerPluginFunctional // given prepareBuildGradleFile { """ - plugins { - id("dev.monosoul.jooq-docker") - } + plugins { + id("dev.monosoul.jooq-docker") + } - repositories { - mavenCentral() - } + repositories { + mavenCentral() + } - tasks { - generateJooqClasses { - basePackageName.set("com.example") - } + tasks { + generateJooqClasses { + basePackageName.set("com.example") } + } - dependencies { - jooqCodegen("org.postgresql:postgresql:42.3.6") - } + dependencies { + jooqCodegen("org.postgresql:postgresql:42.3.6") + } """.trimIndent() } copyResource(from = "/V01__init.sql", to = "src/main/resources/db/migration/V01__init.sql") @@ -130,7 +129,7 @@ class ConfigurabilityJooqDockerPluginFunctionalTest : JooqDockerPluginFunctional expect { that(result).generateJooqClassesTask.outcome isEqualTo SUCCESS that( - projectFile("build/generated-jooq/com/example/tables/Foo.java") + projectFile("build/generated-jooq/com/example/tables/Foo.java"), ).exists() } } @@ -140,28 +139,28 @@ class ConfigurabilityJooqDockerPluginFunctionalTest : JooqDockerPluginFunctional // given prepareBuildGradleFile { """ - plugins { - id("dev.monosoul.jooq-docker") - } + plugins { + id("dev.monosoul.jooq-docker") + } - repositories { - mavenCentral() - } + repositories { + mavenCentral() + } - tasks { - generateJooqClasses { - outputSchemaToDefault.add("public") - } + tasks { + generateJooqClasses { + outputSchemaToDefault.add("public") } + } - dependencies { - jooqCodegen("org.postgresql:postgresql:42.3.6") - } + dependencies { + jooqCodegen("org.postgresql:postgresql:42.3.6") + } """.trimIndent() } copyResource( from = "/V01__init_multiple_schemas.sql", - to = "src/main/resources/db/migration/V01__init_multiple_schemas.sql" + to = "src/main/resources/db/migration/V01__init_multiple_schemas.sql", ) // when @@ -171,10 +170,10 @@ class ConfigurabilityJooqDockerPluginFunctionalTest : JooqDockerPluginFunctional expect { that(result).generateJooqClassesTask.outcome isEqualTo SUCCESS that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java"), ).exists() that( - projectFile("build/generated-jooq/org/jooq/generated/DefaultSchema.java") + projectFile("build/generated-jooq/org/jooq/generated/DefaultSchema.java"), ).exists() } } @@ -184,28 +183,28 @@ class ConfigurabilityJooqDockerPluginFunctionalTest : JooqDockerPluginFunctional // given prepareBuildGradleFile { """ - plugins { - id("dev.monosoul.jooq-docker") - } + plugins { + id("dev.monosoul.jooq-docker") + } - repositories { - mavenCentral() - } + repositories { + mavenCentral() + } - tasks { - generateJooqClasses { - outputDirectory.set(project.layout.buildDirectory.dir("gen")) - } + tasks { + generateJooqClasses { + outputDirectory.set(project.layout.buildDirectory.dir("gen")) } + } - dependencies { - jooqCodegen("org.postgresql:postgresql:42.3.6") - } + dependencies { + jooqCodegen("org.postgresql:postgresql:42.3.6") + } """.trimIndent() } copyResource( from = "/V01__init_multiple_schemas.sql", - to = "src/main/resources/db/migration/V01__init_multiple_schemas.sql" + to = "src/main/resources/db/migration/V01__init_multiple_schemas.sql", ) // when @@ -215,7 +214,7 @@ class ConfigurabilityJooqDockerPluginFunctionalTest : JooqDockerPluginFunctional expect { that(result).generateJooqClassesTask.outcome isEqualTo SUCCESS that( - projectFile("build/gen/org/jooq/generated/tables/Foo.java") + projectFile("build/gen/org/jooq/generated/tables/Foo.java"), ).exists() } } diff --git a/src/test/kotlin/dev/monosoul/jooq/functional/ExcludeFlywayHistoryTableJooqDockerPluginFunctionalTest.kt b/src/test/kotlin/dev/monosoul/jooq/functional/ExcludeFlywayHistoryTableJooqDockerPluginFunctionalTest.kt index 35ae00b..17d9c1a 100644 --- a/src/test/kotlin/dev/monosoul/jooq/functional/ExcludeFlywayHistoryTableJooqDockerPluginFunctionalTest.kt +++ b/src/test/kotlin/dev/monosoul/jooq/functional/ExcludeFlywayHistoryTableJooqDockerPluginFunctionalTest.kt @@ -8,23 +8,22 @@ import strikt.java.exists import strikt.java.notExists class ExcludeFlywayHistoryTableJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalTestBase() { - @Test fun `should exclude flyway schema history by default`() { // given prepareBuildGradleFile { """ - plugins { - id("dev.monosoul.jooq-docker") - } + plugins { + id("dev.monosoul.jooq-docker") + } - repositories { - mavenCentral() - } + repositories { + mavenCentral() + } - dependencies { - jooqCodegen("org.postgresql:postgresql:42.3.6") - } + dependencies { + jooqCodegen("org.postgresql:postgresql:42.3.6") + } """.trimIndent() } copyResource(from = "/V01__init.sql", to = "src/main/resources/db/migration/V01__init.sql") @@ -36,10 +35,10 @@ class ExcludeFlywayHistoryTableJooqDockerPluginFunctionalTest : JooqDockerPlugin expect { that(result).generateJooqClassesTask.outcome isEqualTo SUCCESS that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java"), ).exists() that( - projectFile("build/generated-jooq/org/jooq/generated/tables/FlywaySchemaHistory.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/FlywaySchemaHistory.java"), ).notExists() } } @@ -49,23 +48,23 @@ class ExcludeFlywayHistoryTableJooqDockerPluginFunctionalTest : JooqDockerPlugin // given prepareBuildGradleFile { """ - plugins { - id("dev.monosoul.jooq-docker") - } + plugins { + id("dev.monosoul.jooq-docker") + } - repositories { - mavenCentral() - } + repositories { + mavenCentral() + } - tasks { - generateJooqClasses { - includeFlywayTable.set(true) - } + tasks { + generateJooqClasses { + includeFlywayTable.set(true) } + } - dependencies { - jooqCodegen("org.postgresql:postgresql:42.3.6") - } + dependencies { + jooqCodegen("org.postgresql:postgresql:42.3.6") + } """.trimIndent() } copyResource(from = "/V01__init.sql", to = "src/main/resources/db/migration/V01__init.sql") @@ -77,10 +76,10 @@ class ExcludeFlywayHistoryTableJooqDockerPluginFunctionalTest : JooqDockerPlugin expect { that(result).generateJooqClassesTask.outcome isEqualTo SUCCESS that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java"), ).exists() that( - projectFile("build/generated-jooq/org/jooq/generated/tables/FlywaySchemaHistory.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/FlywaySchemaHistory.java"), ).exists() } } @@ -90,23 +89,23 @@ class ExcludeFlywayHistoryTableJooqDockerPluginFunctionalTest : JooqDockerPlugin // given prepareBuildGradleFile { """ - plugins { - id("dev.monosoul.jooq-docker") - } + plugins { + id("dev.monosoul.jooq-docker") + } - repositories { - mavenCentral() - } + repositories { + mavenCentral() + } - tasks { - generateJooqClasses { - flywayProperties.put("flyway.table", "some_schema_table") - } + tasks { + generateJooqClasses { + flywayProperties.put("flyway.table", "some_schema_table") } + } - dependencies { - jooqCodegen("org.postgresql:postgresql:42.3.6") - } + dependencies { + jooqCodegen("org.postgresql:postgresql:42.3.6") + } """.trimIndent() } copyResource(from = "/V01__init.sql", to = "src/main/resources/db/migration/V01__init.sql") @@ -118,10 +117,10 @@ class ExcludeFlywayHistoryTableJooqDockerPluginFunctionalTest : JooqDockerPlugin expect { that(result).generateJooqClassesTask.outcome isEqualTo SUCCESS that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java"), ).exists() that( - projectFile("build/generated-jooq/org/jooq/generated/tables/SomeSchemaTable.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/SomeSchemaTable.java"), ).notExists() } } @@ -131,31 +130,31 @@ class ExcludeFlywayHistoryTableJooqDockerPluginFunctionalTest : JooqDockerPlugin // given prepareBuildGradleFile { """ - plugins { - id("dev.monosoul.jooq-docker") - } - - repositories { - mavenCentral() - } - - tasks { - generateJooqClasses { - schemas.set(listOf("public", "other")) - usingJavaConfig { - database.withExcludes("BAR") - } + plugins { + id("dev.monosoul.jooq-docker") + } + + repositories { + mavenCentral() + } + + tasks { + generateJooqClasses { + schemas.set(listOf("public", "other")) + usingJavaConfig { + database.withExcludes("BAR") } } + } - dependencies { - jooqCodegen("org.postgresql:postgresql:42.3.6") - } + dependencies { + jooqCodegen("org.postgresql:postgresql:42.3.6") + } """.trimIndent() } copyResource( from = "/V01__init_multiple_schemas.sql", - to = "src/main/resources/db/migration/V01__init_multiple_schemas.sql" + to = "src/main/resources/db/migration/V01__init_multiple_schemas.sql", ) // when @@ -165,13 +164,13 @@ class ExcludeFlywayHistoryTableJooqDockerPluginFunctionalTest : JooqDockerPlugin expect { that(result).generateJooqClassesTask.outcome isEqualTo SUCCESS that( - projectFile("build/generated-jooq/org/jooq/generated/public_/tables/Foo.java") + projectFile("build/generated-jooq/org/jooq/generated/public_/tables/Foo.java"), ).exists() that( - projectFile("build/generated-jooq/org/jooq/generated/other/tables/Bar.java") + projectFile("build/generated-jooq/org/jooq/generated/other/tables/Bar.java"), ).notExists() that( - projectFile("build/generated-jooq/org/jooq/generated/public_/tables/FlywaySchemaHistory.java") + projectFile("build/generated-jooq/org/jooq/generated/public_/tables/FlywaySchemaHistory.java"), ).notExists() } } diff --git a/src/test/kotlin/dev/monosoul/jooq/functional/ExternalDatabaseJooqDockerPluginFunctionalTest.kt b/src/test/kotlin/dev/monosoul/jooq/functional/ExternalDatabaseJooqDockerPluginFunctionalTest.kt index 0279089..02ac4df 100644 --- a/src/test/kotlin/dev/monosoul/jooq/functional/ExternalDatabaseJooqDockerPluginFunctionalTest.kt +++ b/src/test/kotlin/dev/monosoul/jooq/functional/ExternalDatabaseJooqDockerPluginFunctionalTest.kt @@ -10,7 +10,6 @@ import strikt.assertions.isEqualTo import strikt.java.exists class ExternalDatabaseJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalTestBase() { - private val postgresContainer = PostgresContainer() @BeforeEach @@ -28,29 +27,29 @@ class ExternalDatabaseJooqDockerPluginFunctionalTest : JooqDockerPluginFunctiona // given prepareBuildGradleFile { """ - plugins { - id("dev.monosoul.jooq-docker") - } + plugins { + id("dev.monosoul.jooq-docker") + } - repositories { - mavenCentral() - } - - jooq { - withoutContainer { - db { - username = "${postgresContainer.username}" - password = "${postgresContainer.password}" - name = "${postgresContainer.databaseName}" - host = "${postgresContainer.host}" - port = ${postgresContainer.firstMappedPort} - } + repositories { + mavenCentral() + } + + jooq { + withoutContainer { + db { + username = "${postgresContainer.username}" + password = "${postgresContainer.password}" + name = "${postgresContainer.databaseName}" + host = "${postgresContainer.host}" + port = ${postgresContainer.firstMappedPort} } } + } - dependencies { - jooqCodegen("org.postgresql:postgresql:42.3.6") - } + dependencies { + jooqCodegen("org.postgresql:postgresql:42.3.6") + } """.trimIndent() } copyResource(from = "/V01__init.sql", to = "src/main/resources/db/migration/V01__init.sql") @@ -62,7 +61,7 @@ class ExternalDatabaseJooqDockerPluginFunctionalTest : JooqDockerPluginFunctiona expect { that(result).generateJooqClassesTask.outcome isEqualTo SUCCESS that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java"), ).exists() } } diff --git a/src/test/kotlin/dev/monosoul/jooq/functional/FlywayConfigurationJooqDockerPluginFunctionalTest.kt b/src/test/kotlin/dev/monosoul/jooq/functional/FlywayConfigurationJooqDockerPluginFunctionalTest.kt index 0617eed..565fd39 100644 --- a/src/test/kotlin/dev/monosoul/jooq/functional/FlywayConfigurationJooqDockerPluginFunctionalTest.kt +++ b/src/test/kotlin/dev/monosoul/jooq/functional/FlywayConfigurationJooqDockerPluginFunctionalTest.kt @@ -7,34 +7,33 @@ import strikt.assertions.isEqualTo import strikt.java.exists class FlywayConfigurationJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalTestBase() { - @Test fun `should override flyway configuration with flywayProperties task input`() { // given prepareBuildGradleFile { """ - plugins { - id("dev.monosoul.jooq-docker") - } + plugins { + id("dev.monosoul.jooq-docker") + } - repositories { - mavenCentral() - } + repositories { + mavenCentral() + } - tasks { - generateJooqClasses { - flywayProperties.put("flyway.placeholderReplacement", "false") - } + tasks { + generateJooqClasses { + flywayProperties.put("flyway.placeholderReplacement", "false") } + } - dependencies { - jooqCodegen("org.postgresql:postgresql:42.3.6") - } + dependencies { + jooqCodegen("org.postgresql:postgresql:42.3.6") + } """.trimIndent() } copyResource( from = "/V01__init_with_placeholders.sql", - to = "src/main/resources/db/migration/V01__init_with_placeholders.sql" + to = "src/main/resources/db/migration/V01__init_with_placeholders.sql", ) // when @@ -44,7 +43,7 @@ class FlywayConfigurationJooqDockerPluginFunctionalTest : JooqDockerPluginFuncti expect { that(result).generateJooqClassesTask.outcome isEqualTo SUCCESS that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java"), ).exists() } } @@ -54,29 +53,29 @@ class FlywayConfigurationJooqDockerPluginFunctionalTest : JooqDockerPluginFuncti // given prepareBuildGradleFile { """ - plugins { - id("dev.monosoul.jooq-docker") - } + plugins { + id("dev.monosoul.jooq-docker") + } - repositories { - mavenCentral() - } + repositories { + mavenCentral() + } - tasks { - generateJooqClasses { - schemas.set(listOf("other", "public")) - includeFlywayTable.set(true) - } + tasks { + generateJooqClasses { + schemas.set(listOf("other", "public")) + includeFlywayTable.set(true) } + } - dependencies { - jooqCodegen("org.postgresql:postgresql:42.3.6") - } + dependencies { + jooqCodegen("org.postgresql:postgresql:42.3.6") + } """.trimIndent() } copyResource( from = "/V01__init_multiple_schemas.sql", - to = "src/main/resources/db/migration/V01__init_multiple_schemas.sql" + to = "src/main/resources/db/migration/V01__init_multiple_schemas.sql", ) // when @@ -86,13 +85,13 @@ class FlywayConfigurationJooqDockerPluginFunctionalTest : JooqDockerPluginFuncti expect { that(result).generateJooqClassesTask.outcome isEqualTo SUCCESS that( - projectFile("build/generated-jooq/org/jooq/generated/public_/tables/Foo.java") + projectFile("build/generated-jooq/org/jooq/generated/public_/tables/Foo.java"), ).exists() that( - projectFile("build/generated-jooq/org/jooq/generated/other/tables/Bar.java") + projectFile("build/generated-jooq/org/jooq/generated/other/tables/Bar.java"), ).exists() that( - projectFile("build/generated-jooq/org/jooq/generated/other/tables/FlywaySchemaHistory.java") + projectFile("build/generated-jooq/org/jooq/generated/other/tables/FlywaySchemaHistory.java"), ).exists() } } diff --git a/src/test/kotlin/dev/monosoul/jooq/functional/FlywayVersionConfigurationJooqDockerPluginFunctionalTest.kt b/src/test/kotlin/dev/monosoul/jooq/functional/FlywayVersionConfigurationJooqDockerPluginFunctionalTest.kt index 55cad06..33d5efd 100644 --- a/src/test/kotlin/dev/monosoul/jooq/functional/FlywayVersionConfigurationJooqDockerPluginFunctionalTest.kt +++ b/src/test/kotlin/dev/monosoul/jooq/functional/FlywayVersionConfigurationJooqDockerPluginFunctionalTest.kt @@ -10,27 +10,26 @@ import strikt.assertions.isEqualTo import strikt.java.exists class FlywayVersionConfigurationJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalTestBase() { - @Test fun `should provide recommended Flyway version`() { // given prepareBuildGradleFile { """ - import dev.monosoul.jooq.RecommendedVersions - - plugins { - id("dev.monosoul.jooq-docker") - } + import dev.monosoul.jooq.RecommendedVersions + + plugins { + id("dev.monosoul.jooq-docker") + } - repositories { - mavenCentral() - } + repositories { + mavenCentral() + } - dependencies { - jooqCodegen("org.flywaydb:flyway-core:${'$'}{RecommendedVersions.FLYWAY_VERSION}") - jooqCodegen("org.flywaydb:flyway-database-postgresql:${'$'}{RecommendedVersions.FLYWAY_VERSION}") - jooqCodegen("org.postgresql:postgresql:42.3.6") - } + dependencies { + jooqCodegen("org.flywaydb:flyway-core:${'$'}{RecommendedVersions.FLYWAY_VERSION}") + jooqCodegen("org.flywaydb:flyway-database-postgresql:${'$'}{RecommendedVersions.FLYWAY_VERSION}") + jooqCodegen("org.postgresql:postgresql:42.3.6") + } """.trimIndent() } copyResource(from = "/V01__init.sql", to = "src/main/resources/db/migration/V01__init.sql") @@ -42,7 +41,7 @@ class FlywayVersionConfigurationJooqDockerPluginFunctionalTest : JooqDockerPlugi expect { that(result).generateJooqClassesTask.outcome isEqualTo SUCCESS that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java"), ).exists() } } @@ -53,18 +52,18 @@ class FlywayVersionConfigurationJooqDockerPluginFunctionalTest : JooqDockerPlugi // given prepareBuildGradleFile { """ - plugins { - id("dev.monosoul.jooq-docker") - } + plugins { + id("dev.monosoul.jooq-docker") + } - repositories { - mavenCentral() - } + repositories { + mavenCentral() + } - dependencies { - jooqCodegen("org.flywaydb:flyway-core:$flywayVersion") - jooqCodegen("org.postgresql:postgresql:42.3.6") - } + dependencies { + jooqCodegen("org.flywaydb:flyway-core:$flywayVersion") + jooqCodegen("org.postgresql:postgresql:42.3.6") + } """.trimIndent() } copyResource(from = "/V01__init.sql", to = "src/main/resources/db/migration/V01__init.sql") @@ -79,7 +78,7 @@ class FlywayVersionConfigurationJooqDockerPluginFunctionalTest : JooqDockerPlugi get { output } contains "Flyway Community Edition $flywayVersion by Redgate" } that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java"), ).exists() } } diff --git a/src/test/kotlin/dev/monosoul/jooq/functional/GenerateForMySqlJooqDockerPluginFunctionalTest.kt b/src/test/kotlin/dev/monosoul/jooq/functional/GenerateForMySqlJooqDockerPluginFunctionalTest.kt index c09ec73..71ab9cd 100644 --- a/src/test/kotlin/dev/monosoul/jooq/functional/GenerateForMySqlJooqDockerPluginFunctionalTest.kt +++ b/src/test/kotlin/dev/monosoul/jooq/functional/GenerateForMySqlJooqDockerPluginFunctionalTest.kt @@ -7,49 +7,48 @@ import strikt.assertions.isEqualTo import strikt.java.exists class GenerateForMySqlJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalTestBase() { - @Test fun `should be able to generate jOOQ classes for MySQL`() { // given prepareBuildGradleFile { """ - import dev.monosoul.jooq.RecommendedVersions - - plugins { - id("dev.monosoul.jooq-docker") - } + import dev.monosoul.jooq.RecommendedVersions + + plugins { + id("dev.monosoul.jooq-docker") + } - repositories { - mavenCentral() - } + repositories { + mavenCentral() + } - jooq { - withContainer { - image { - name = "mysql:8.0.29" - envVars = mapOf( - "MYSQL_ROOT_PASSWORD" to "mysql", - "MYSQL_DATABASE" to "mysql" - ) - } - db { - username = "root" - password = "mysql" - name = "mysql" - port = 3306 - - jdbc { - schema = "jdbc:mysql" - driverClassName = "com.mysql.cj.jdbc.Driver" - } + jooq { + withContainer { + image { + name = "mysql:8.0.29" + envVars = mapOf( + "MYSQL_ROOT_PASSWORD" to "mysql", + "MYSQL_DATABASE" to "mysql" + ) + } + db { + username = "root" + password = "mysql" + name = "mysql" + port = 3306 + + jdbc { + schema = "jdbc:mysql" + driverClassName = "com.mysql.cj.jdbc.Driver" } } } + } - dependencies { - jooqCodegen("org.flywaydb:flyway-mysql:${'$'}{RecommendedVersions.FLYWAY_VERSION}") - jooqCodegen("mysql:mysql-connector-java:8.0.29") - } + dependencies { + jooqCodegen("org.flywaydb:flyway-mysql:${'$'}{RecommendedVersions.FLYWAY_VERSION}") + jooqCodegen("mysql:mysql-connector-java:8.0.29") + } """.trimIndent() } copyResource(from = "/V01__init_mysql.sql", to = "src/main/resources/db/migration/V01__init_mysql.sql") @@ -61,7 +60,7 @@ class GenerateForMySqlJooqDockerPluginFunctionalTest : JooqDockerPluginFunctiona expect { that(result).generateJooqClassesTask.outcome isEqualTo SUCCESS that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java"), ).exists() } } diff --git a/src/test/kotlin/dev/monosoul/jooq/functional/GroovyBuildscriptJooqDockerPluginFunctionalTest.kt b/src/test/kotlin/dev/monosoul/jooq/functional/GroovyBuildscriptJooqDockerPluginFunctionalTest.kt index ca4e00d..7726e3f 100644 --- a/src/test/kotlin/dev/monosoul/jooq/functional/GroovyBuildscriptJooqDockerPluginFunctionalTest.kt +++ b/src/test/kotlin/dev/monosoul/jooq/functional/GroovyBuildscriptJooqDockerPluginFunctionalTest.kt @@ -10,43 +10,42 @@ import strikt.java.exists import strikt.java.notExists class GroovyBuildscriptJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalTestBase() { - @Test fun `should respect global configuration regardless of declaration order`() { // given prepareBuildGradleFile("build.gradle") { // language=gradle """ - plugins { - id "dev.monosoul.jooq-docker" - } + plugins { + id "dev.monosoul.jooq-docker" + } - repositories { - mavenCentral() - } - - tasks { - generateJooqClasses { - flywayProperties.put("flyway.placeholderReplacement", "false") - } + repositories { + mavenCentral() + } + + tasks { + generateJooqClasses { + flywayProperties.put("flyway.placeholderReplacement", "false") } - - jooq { - withContainer { - image { - name = "postgres:13.4-alpine" - } + } + + jooq { + withContainer { + image { + name = "postgres:13.4-alpine" } } + } - dependencies { - jooqCodegen "org.postgresql:postgresql:42.3.6" - } + dependencies { + jooqCodegen "org.postgresql:postgresql:42.3.6" + } """.trimIndent() } copyResource( from = "/V01__init_with_placeholders.sql", - to = "src/main/resources/db/migration/V01__init_with_placeholders.sql" + to = "src/main/resources/db/migration/V01__init_with_placeholders.sql", ) // when @@ -59,7 +58,7 @@ class GroovyBuildscriptJooqDockerPluginFunctionalTest : JooqDockerPluginFunction get { output } contains "postgres:13.4-alpine" } that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java"), ).exists() } } @@ -70,51 +69,51 @@ class GroovyBuildscriptJooqDockerPluginFunctionalTest : JooqDockerPluginFunction prepareBuildGradleFile("build.gradle") { // language=gradle """ - plugins { - id "dev.monosoul.jooq-docker" - } + plugins { + id "dev.monosoul.jooq-docker" + } - repositories { - mavenCentral() - } - - jooq { - withContainer { - db { - username = "customusername" - password = "custompassword" - - jdbc { - schema = "jdbc:postgresql" - } - } - image { - envVars = [ - "POSTGRES_USER": "customusername", - "POSTGRES_PASSWORD": "custompassword", - "POSTGRES_DB": "postgres" - ] + repositories { + mavenCentral() + } + + jooq { + withContainer { + db { + username = "customusername" + password = "custompassword" + + jdbc { + schema = "jdbc:postgresql" } } + image { + envVars = [ + "POSTGRES_USER": "customusername", + "POSTGRES_PASSWORD": "custompassword", + "POSTGRES_DB": "postgres" + ] + } } + } - tasks { - generateJooqClasses { - flywayProperties.put("flyway.placeholderReplacement", "false") - usingJavaConfig { - database.withExcludes("BAR") - } + tasks { + generateJooqClasses { + flywayProperties.put("flyway.placeholderReplacement", "false") + usingJavaConfig { + database.withExcludes("BAR") } } + } - dependencies { - jooqCodegen "org.postgresql:postgresql:42.3.6" - } + dependencies { + jooqCodegen "org.postgresql:postgresql:42.3.6" + } """.trimIndent() } copyResource( from = "/V01__init_with_placeholders.sql", - to = "src/main/resources/db/migration/V01__init_with_placeholders.sql" + to = "src/main/resources/db/migration/V01__init_with_placeholders.sql", ) copyResource(from = "/V02__add_bar.sql", to = "src/main/resources/db/migration/V02__add_bar.sql") @@ -125,10 +124,10 @@ class GroovyBuildscriptJooqDockerPluginFunctionalTest : JooqDockerPluginFunction expect { that(result).generateJooqClassesTask.outcome isEqualTo SUCCESS that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java"), ).exists() that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Bar.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Bar.java"), ).notExists() } } @@ -140,65 +139,66 @@ class GroovyBuildscriptJooqDockerPluginFunctionalTest : JooqDockerPluginFunction prepareBuildGradleFile("build.gradle") { // language=gradle """ - plugins { - id "dev.monosoul.jooq-docker" - } + plugins { + id "dev.monosoul.jooq-docker" + } - repositories { - mavenCentral() - } - - jooq { - withoutContainer { - db { - username = "${postgresContainer.username}" - password = "${postgresContainer.password}" - name = "${postgresContainer.databaseName}" - host = "${postgresContainer.host}" - port = ${postgresContainer.firstMappedPort} - - jdbc { - schema = "jdbc:postgresql" - } + repositories { + mavenCentral() + } + + jooq { + withoutContainer { + db { + username = "${postgresContainer.username}" + password = "${postgresContainer.password}" + name = "${postgresContainer.databaseName}" + host = "${postgresContainer.host}" + port = ${postgresContainer.firstMappedPort} + + jdbc { + schema = "jdbc:postgresql" } } } + } - tasks { - generateJooqClasses { - flywayProperties.put("flyway.placeholderReplacement", "false") - usingJavaConfig { - database.withExcludes("BAR") - } + tasks { + generateJooqClasses { + flywayProperties.put("flyway.placeholderReplacement", "false") + usingJavaConfig { + database.withExcludes("BAR") } } + } - dependencies { - jooqCodegen "org.postgresql:postgresql:42.3.6" - } + dependencies { + jooqCodegen "org.postgresql:postgresql:42.3.6" + } """.trimIndent() } copyResource( from = "/V01__init_with_placeholders.sql", - to = "src/main/resources/db/migration/V01__init_with_placeholders.sql" + to = "src/main/resources/db/migration/V01__init_with_placeholders.sql", ) copyResource(from = "/V02__add_bar.sql", to = "src/main/resources/db/migration/V02__add_bar.sql") // when - val result = try { - runGradleWithArguments("generateJooqClasses") - } finally { - postgresContainer.stop() - } + val result = + try { + runGradleWithArguments("generateJooqClasses") + } finally { + postgresContainer.stop() + } // then expect { that(result).generateJooqClassesTask.outcome isEqualTo SUCCESS that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java"), ).exists() that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Bar.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Bar.java"), ).notExists() } } @@ -209,31 +209,31 @@ class GroovyBuildscriptJooqDockerPluginFunctionalTest : JooqDockerPluginFunction prepareBuildGradleFile("build.gradle") { // language=gradle """ - plugins { - id "dev.monosoul.jooq-docker" - } + plugins { + id "dev.monosoul.jooq-docker" + } - repositories { - mavenCentral() - } + repositories { + mavenCentral() + } - tasks { - generateJooqClasses { - flywayProperties.put("flyway.placeholderReplacement", "false") - usingXmlConfig(project.layout.projectDirectory.file("src/main/resources/db/jooq.xml")) { - database.withExcludes("BAR") - } + tasks { + generateJooqClasses { + flywayProperties.put("flyway.placeholderReplacement", "false") + usingXmlConfig(project.layout.projectDirectory.file("src/main/resources/db/jooq.xml")) { + database.withExcludes("BAR") } } + } - dependencies { - jooqCodegen "org.postgresql:postgresql:42.3.6" - } + dependencies { + jooqCodegen "org.postgresql:postgresql:42.3.6" + } """.trimIndent() } copyResource( from = "/V01__init_with_placeholders.sql", - to = "src/main/resources/db/migration/V01__init_with_placeholders.sql" + to = "src/main/resources/db/migration/V01__init_with_placeholders.sql", ) copyResource(from = "/V02__add_bar.sql", to = "src/main/resources/db/migration/V02__add_bar.sql") copyResource(from = "/jooq-generator.xml", to = "src/main/resources/db/jooq.xml") @@ -245,10 +245,10 @@ class GroovyBuildscriptJooqDockerPluginFunctionalTest : JooqDockerPluginFunction expect { that(result).generateJooqClassesTask.outcome isEqualTo SUCCESS that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java"), ).exists() that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Bar.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Bar.java"), ).notExists() } } @@ -260,46 +260,46 @@ class GroovyBuildscriptJooqDockerPluginFunctionalTest : JooqDockerPluginFunction prepareBuildGradleFile("build.gradle") { // language=gradle """ - import dev.monosoul.jooq.GenerateJooqClassesTask - import dev.monosoul.jooq.RecommendedVersions - - plugins { - id "org.jetbrains.kotlin.jvm" version "1.6.21" - id "dev.monosoul.jooq-docker" - } + import dev.monosoul.jooq.GenerateJooqClassesTask + import dev.monosoul.jooq.RecommendedVersions + + plugins { + id "org.jetbrains.kotlin.jvm" version "1.6.21" + id "dev.monosoul.jooq-docker" + } - repositories { - mavenCentral() - } - - tasks { - generateJooqClasses { - basePackageName.set("org.jooq.generated.local") - outputDirectory.set(project.layout.buildDirectory.dir("local")) - } + repositories { + mavenCentral() + } + + tasks { + generateJooqClasses { + basePackageName.set("org.jooq.generated.local") + outputDirectory.set(project.layout.buildDirectory.dir("local")) } + } + + tasks.register('generateJooqClassesForExternal', GenerateJooqClassesTask) { + basePackageName.set("org.jooq.generated.remote") + outputDirectory.set(project.layout.buildDirectory.dir("remote")) + includeFlywayTable.set(true) - tasks.register('generateJooqClassesForExternal', GenerateJooqClassesTask) { - basePackageName.set("org.jooq.generated.remote") - outputDirectory.set(project.layout.buildDirectory.dir("remote")) - includeFlywayTable.set(true) - - withoutContainer { - db { - username = "${postgresContainer.username}" - password = "${postgresContainer.password}" - name = "${postgresContainer.databaseName}" - host = "${postgresContainer.host}" - port = ${postgresContainer.firstMappedPort} - } + withoutContainer { + db { + username = "${postgresContainer.username}" + password = "${postgresContainer.password}" + name = "${postgresContainer.databaseName}" + host = "${postgresContainer.host}" + port = ${postgresContainer.firstMappedPort} } } + } - dependencies { - implementation("org.jetbrains.kotlin:kotlin-stdlib") - jooqCodegen("org.postgresql:postgresql:42.3.6") - implementation("org.jooq:jooq:" + RecommendedVersions.JOOQ_VERSION) - } + dependencies { + implementation("org.jetbrains.kotlin:kotlin-stdlib") + jooqCodegen("org.postgresql:postgresql:42.3.6") + implementation("org.jooq:jooq:" + RecommendedVersions.JOOQ_VERSION) + } """.trimIndent() } copyResource(from = "/V01__init.sql", to = "src/main/resources/db/migration/V01__init.sql") @@ -312,13 +312,13 @@ class GroovyBuildscriptJooqDockerPluginFunctionalTest : JooqDockerPluginFunction expect { that(result).generateJooqClassesTask.outcome isEqualTo SUCCESS that( - projectFile("build/local/org/jooq/generated/local/tables/Foo.java") + projectFile("build/local/org/jooq/generated/local/tables/Foo.java"), ).exists() that( - projectFile("build/remote/org/jooq/generated/remote/tables/Foo.java") + projectFile("build/remote/org/jooq/generated/remote/tables/Foo.java"), ).exists() that( - projectFile("build/remote/org/jooq/generated/remote/tables/FlywaySchemaHistory.java") + projectFile("build/remote/org/jooq/generated/remote/tables/FlywaySchemaHistory.java"), ).exists() } } diff --git a/src/test/kotlin/dev/monosoul/jooq/functional/ImmutableValueHolderJooqDockerPluginFunctionalTest.kt b/src/test/kotlin/dev/monosoul/jooq/functional/ImmutableValueHolderJooqDockerPluginFunctionalTest.kt index 1358255..dcbeb11 100644 --- a/src/test/kotlin/dev/monosoul/jooq/functional/ImmutableValueHolderJooqDockerPluginFunctionalTest.kt +++ b/src/test/kotlin/dev/monosoul/jooq/functional/ImmutableValueHolderJooqDockerPluginFunctionalTest.kt @@ -6,30 +6,29 @@ import strikt.api.expectThrows import strikt.assertions.contains class ImmutableValueHolderJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalTestBase() { - @Test fun `should not be possible to create an instance of ValueHolder by extending it from Groovy`() { // given prepareBuildGradleFile("build.gradle") { // language=gradle """ - import dev.monosoul.jooq.ValueHolder - - plugins { - id "dev.monosoul.jooq-docker" - } + import dev.monosoul.jooq.ValueHolder + + plugins { + id "dev.monosoul.jooq-docker" + } - repositories { - mavenCentral() - } + repositories { + mavenCentral() + } - dependencies { - jooqCodegen "org.postgresql:postgresql:42.3.6" - } - - class InternalValueHolder extends ValueHolder {} - - new InternalValueHolder() + dependencies { + jooqCodegen "org.postgresql:postgresql:42.3.6" + } + + class InternalValueHolder extends ValueHolder {} + + new InternalValueHolder() """.trimIndent() } @@ -38,8 +37,8 @@ class ImmutableValueHolderJooqDockerPluginFunctionalTest : JooqDockerPluginFunct runGradleWithArguments("tasks") }.get { stackTraceToString() }.contains( "Caused by: java.lang.IllegalAccessError: " + - "class InternalValueHolder tried to access private method " + - "'void dev.monosoul.jooq.ValueHolder.()'" + "class InternalValueHolder tried to access private method " + + "'void dev.monosoul.jooq.ValueHolder.()'", ) } } diff --git a/src/test/kotlin/dev/monosoul/jooq/functional/JavaBasedConfigJooqDockerPluginFunctionalTest.kt b/src/test/kotlin/dev/monosoul/jooq/functional/JavaBasedConfigJooqDockerPluginFunctionalTest.kt index 4724451..6ba87d6 100644 --- a/src/test/kotlin/dev/monosoul/jooq/functional/JavaBasedConfigJooqDockerPluginFunctionalTest.kt +++ b/src/test/kotlin/dev/monosoul/jooq/functional/JavaBasedConfigJooqDockerPluginFunctionalTest.kt @@ -8,42 +8,41 @@ import strikt.java.exists import strikt.java.notExists class JavaBasedConfigJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalTestBase() { - @Test fun `should respect the generator customizations`() { // given prepareBuildGradleFile { """ - import org.jooq.meta.jaxb.Strategy - - plugins { - id("dev.monosoul.jooq-docker") - } + import org.jooq.meta.jaxb.Strategy + + plugins { + id("dev.monosoul.jooq-docker") + } - repositories { - mavenCentral() - } + repositories { + mavenCentral() + } - tasks { - generateJooqClasses { - schemas.set(listOf("public", "other")) - usingJavaConfig { - database.withExcludes("BAR") - withStrategy( - Strategy().withName("org.jooq.codegen.KeepNamesGeneratorStrategy") - ) - } + tasks { + generateJooqClasses { + schemas.set(listOf("public", "other")) + usingJavaConfig { + database.withExcludes("BAR") + withStrategy( + Strategy().withName("org.jooq.codegen.KeepNamesGeneratorStrategy") + ) } } + } - dependencies { - jooqCodegen("org.postgresql:postgresql:42.3.6") - } + dependencies { + jooqCodegen("org.postgresql:postgresql:42.3.6") + } """.trimIndent() } copyResource( from = "/V01__init_multiple_schemas.sql", - to = "src/main/resources/db/migration/V01__init_multiple_schemas.sql" + to = "src/main/resources/db/migration/V01__init_multiple_schemas.sql", ) // when @@ -53,10 +52,10 @@ class JavaBasedConfigJooqDockerPluginFunctionalTest : JooqDockerPluginFunctional expect { that(result).generateJooqClassesTask.outcome isEqualTo SUCCESS that( - projectFile("build/generated-jooq/org/jooq/generated/public_/tables/foo.java") + projectFile("build/generated-jooq/org/jooq/generated/public_/tables/foo.java"), ).exists() that( - projectFile("build/generated-jooq/org/jooq/generated/other/tables/bar.java") + projectFile("build/generated-jooq/org/jooq/generated/other/tables/bar.java"), ).notExists() } } @@ -66,25 +65,25 @@ class JavaBasedConfigJooqDockerPluginFunctionalTest : JooqDockerPluginFunctional // given prepareBuildGradleFile { """ - plugins { - id("dev.monosoul.jooq-docker") - } + plugins { + id("dev.monosoul.jooq-docker") + } - repositories { - mavenCentral() - } + repositories { + mavenCentral() + } - tasks { - generateJooqClasses { - usingJavaConfig { - generate.setDeprecated(true) - } + tasks { + generateJooqClasses { + usingJavaConfig { + generate.setDeprecated(true) } } + } - dependencies { - jooqCodegen("org.postgresql:postgresql:42.3.6") - } + dependencies { + jooqCodegen("org.postgresql:postgresql:42.3.6") + } """.trimIndent() } copyResource(from = "/V01__init.sql", to = "src/main/resources/db/migration/V01__init.sql") @@ -96,7 +95,7 @@ class JavaBasedConfigJooqDockerPluginFunctionalTest : JooqDockerPluginFunctional expect { that(result).generateJooqClassesTask.outcome isEqualTo SUCCESS that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java"), ).exists() } } diff --git a/src/test/kotlin/dev/monosoul/jooq/functional/JavaBasedMigrationsFunctionalTest.kt b/src/test/kotlin/dev/monosoul/jooq/functional/JavaBasedMigrationsFunctionalTest.kt index a5437a8..6696868 100644 --- a/src/test/kotlin/dev/monosoul/jooq/functional/JavaBasedMigrationsFunctionalTest.kt +++ b/src/test/kotlin/dev/monosoul/jooq/functional/JavaBasedMigrationsFunctionalTest.kt @@ -8,29 +8,28 @@ import strikt.assertions.isEqualTo import strikt.java.exists class JavaBasedMigrationsFunctionalTest : JooqDockerPluginFunctionalTestBase() { - @Test fun `should be able to use a directory with compiled Java-based migrations for code gen`() { // given prepareBuildGradleFile { """ - plugins { - id("dev.monosoul.jooq-docker") - } + plugins { + id("dev.monosoul.jooq-docker") + } - repositories { - mavenCentral() - } - - tasks { - generateJooqClasses { - migrationLocations.setFromClasspath(provider { "java-based-migrations/" }) - } + repositories { + mavenCentral() + } + + tasks { + generateJooqClasses { + migrationLocations.setFromClasspath(provider { "java-based-migrations/" }) } + } - dependencies { - jooqCodegen("org.postgresql:postgresql:42.3.6") - } + dependencies { + jooqCodegen("org.postgresql:postgresql:42.3.6") + } """.trimIndent() } copyResource(from = "/classes/compiled/V01__init.class", to = "java-based-migrations/db/migration/V01__init.class") @@ -43,12 +42,12 @@ class JavaBasedMigrationsFunctionalTest : JooqDockerPluginFunctionalTestBase() { expect { that(result).generateJooqClassesTask.outcome isEqualTo SUCCESS that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java"), ).exists().and { get { readText() } contains "schema version:02" } that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Bar.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Bar.java"), ).exists().and { get { readText() } contains "schema version:02" } @@ -60,23 +59,23 @@ class JavaBasedMigrationsFunctionalTest : JooqDockerPluginFunctionalTestBase() { // given prepareBuildGradleFile { """ - plugins { - id("dev.monosoul.jooq-docker") - } + plugins { + id("dev.monosoul.jooq-docker") + } - repositories { - mavenCentral() - } - - tasks { - generateJooqClasses { - migrationLocations.setFromClasspath(project.files("java-based-migrations/")) - } + repositories { + mavenCentral() + } + + tasks { + generateJooqClasses { + migrationLocations.setFromClasspath(project.files("java-based-migrations/")) } + } - dependencies { - jooqCodegen("org.postgresql:postgresql:42.3.6") - } + dependencies { + jooqCodegen("org.postgresql:postgresql:42.3.6") + } """.trimIndent() } copyResource(from = "/jars/migrations.jar", to = "java-based-migrations/migrations.jar") @@ -88,12 +87,12 @@ class JavaBasedMigrationsFunctionalTest : JooqDockerPluginFunctionalTestBase() { expect { that(result).generateJooqClassesTask.outcome isEqualTo SUCCESS that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java"), ).exists().and { get { readText() } contains "schema version:02" } that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Bar.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Bar.java"), ).exists().and { get { readText() } contains "schema version:02" } @@ -105,50 +104,50 @@ class JavaBasedMigrationsFunctionalTest : JooqDockerPluginFunctionalTestBase() { // given writeProjectFile("settings.gradle.kts") { """ - include("migrations") + include("migrations") """.trimIndent() } writeProjectFile("migrations/build.gradle.kts") { """ - import dev.monosoul.jooq.RecommendedVersions.FLYWAY_VERSION - - plugins { - kotlin("jvm") - id("dev.monosoul.jooq-docker") apply false - } - - repositories { - mavenCentral() - } - - dependencies { - compileOnly("org.flywaydb:flyway-core:${'$'}FLYWAY_VERSION") - } + import dev.monosoul.jooq.RecommendedVersions.FLYWAY_VERSION + + plugins { + kotlin("jvm") + id("dev.monosoul.jooq-docker") apply false + } + + repositories { + mavenCentral() + } + + dependencies { + compileOnly("org.flywaydb:flyway-core:${'$'}FLYWAY_VERSION") + } """.trimIndent() } prepareBuildGradleFile { """ - plugins { - kotlin("jvm") version "1.6.21" - id("dev.monosoul.jooq-docker") - } + plugins { + kotlin("jvm") version "1.6.21" + id("dev.monosoul.jooq-docker") + } - repositories { - mavenCentral() - } - - val migrationClasspath by configurations.creating - - dependencies { - jooqCodegen("org.postgresql:postgresql:42.3.6") - migrationClasspath(project(":migrations")) - } - - tasks { - generateJooqClasses { - migrationLocations.setFromClasspath(migrationClasspath, "/some/pkg") - } + repositories { + mavenCentral() + } + + val migrationClasspath by configurations.creating + + dependencies { + jooqCodegen("org.postgresql:postgresql:42.3.6") + migrationClasspath(project(":migrations")) + } + + tasks { + generateJooqClasses { + migrationLocations.setFromClasspath(migrationClasspath, "/some/pkg") } + } """.trimIndent() } copyResource(from = "/classes/source/V01__init.txt", to = "migrations/src/main/kotlin/some/pkg/V01__init.kt") @@ -161,12 +160,12 @@ class JavaBasedMigrationsFunctionalTest : JooqDockerPluginFunctionalTestBase() { expect { that(result).generateJooqClassesTask.outcome isEqualTo SUCCESS that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java"), ).exists().and { get { readText() } contains "schema version:02" } that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Bar.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Bar.java"), ).exists().and { get { readText() } contains "schema version:02" } @@ -178,50 +177,50 @@ class JavaBasedMigrationsFunctionalTest : JooqDockerPluginFunctionalTestBase() { // given writeProjectFile("settings.gradle.kts") { """ - include("migrations") + include("migrations") """.trimIndent() } writeProjectFile("migrations/build.gradle.kts") { """ - import dev.monosoul.jooq.RecommendedVersions.FLYWAY_VERSION - - plugins { - kotlin("jvm") - id("dev.monosoul.jooq-docker") apply false - } - - repositories { - mavenCentral() - } - - dependencies { - implementation("org.flywaydb:flyway-core:${'$'}FLYWAY_VERSION") - } + import dev.monosoul.jooq.RecommendedVersions.FLYWAY_VERSION + + plugins { + kotlin("jvm") + id("dev.monosoul.jooq-docker") apply false + } + + repositories { + mavenCentral() + } + + dependencies { + implementation("org.flywaydb:flyway-core:${'$'}FLYWAY_VERSION") + } """.trimIndent() } prepareBuildGradleFile { """ - plugins { - kotlin("jvm") version "1.6.21" - id("dev.monosoul.jooq-docker") - } + plugins { + kotlin("jvm") version "1.6.21" + id("dev.monosoul.jooq-docker") + } - repositories { - mavenCentral() - } - - val migrationClasspath by configurations.creating - - dependencies { - jooqCodegen("org.postgresql:postgresql:42.3.6") - migrationClasspath(files("java-based-migrations/migrations.jar")) - } - - tasks { - generateJooqClasses { - migrationLocations.setFromClasspath(migrationClasspath) - } + repositories { + mavenCentral() + } + + val migrationClasspath by configurations.creating + + dependencies { + jooqCodegen("org.postgresql:postgresql:42.3.6") + migrationClasspath(files("java-based-migrations/migrations.jar")) + } + + tasks { + generateJooqClasses { + migrationLocations.setFromClasspath(migrationClasspath) } + } """.trimIndent() } copyResource(from = "/jars/migrations.jar", to = "java-based-migrations/migrations.jar") @@ -233,12 +232,12 @@ class JavaBasedMigrationsFunctionalTest : JooqDockerPluginFunctionalTestBase() { expect { that(result).generateJooqClassesTask.outcome isEqualTo SUCCESS that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java"), ).exists().and { get { readText() } contains "schema version:02" } that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Bar.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Bar.java"), ).exists().and { get { readText() } contains "schema version:02" } @@ -250,50 +249,50 @@ class JavaBasedMigrationsFunctionalTest : JooqDockerPluginFunctionalTestBase() { // given writeProjectFile("settings.gradle.kts") { """ - include("migrations") + include("migrations") """.trimIndent() } writeProjectFile("migrations/build.gradle.kts") { """ - import dev.monosoul.jooq.RecommendedVersions.FLYWAY_VERSION - - plugins { - kotlin("jvm") - id("dev.monosoul.jooq-docker") apply false - } - - repositories { - mavenCentral() - } - - dependencies { - implementation("org.flywaydb:flyway-core:${'$'}FLYWAY_VERSION") - } + import dev.monosoul.jooq.RecommendedVersions.FLYWAY_VERSION + + plugins { + kotlin("jvm") + id("dev.monosoul.jooq-docker") apply false + } + + repositories { + mavenCentral() + } + + dependencies { + implementation("org.flywaydb:flyway-core:${'$'}FLYWAY_VERSION") + } """.trimIndent() } prepareBuildGradleFile { """ - plugins { - kotlin("jvm") version "1.6.21" - id("dev.monosoul.jooq-docker") - } + plugins { + kotlin("jvm") version "1.6.21" + id("dev.monosoul.jooq-docker") + } - repositories { - mavenCentral() - } - - dependencies { - jooqCodegen("org.postgresql:postgresql:42.3.6") - } - - tasks { - generateJooqClasses { - migrationLocations.setFromClasspath( - project(":migrations").sourceSets.main.map { it.output }, - "/some/pkg" - ) - } + repositories { + mavenCentral() + } + + dependencies { + jooqCodegen("org.postgresql:postgresql:42.3.6") + } + + tasks { + generateJooqClasses { + migrationLocations.setFromClasspath( + project(":migrations").sourceSets.main.map { it.output }, + "/some/pkg" + ) } + } """.trimIndent() } copyResource(from = "/classes/source/V01__init.txt", to = "migrations/src/main/kotlin/some/pkg/V01__init.kt") @@ -306,12 +305,12 @@ class JavaBasedMigrationsFunctionalTest : JooqDockerPluginFunctionalTestBase() { expect { that(result).generateJooqClassesTask.outcome isEqualTo SUCCESS that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java"), ).exists().and { get { readText() } contains "schema version:02" } that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Bar.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Bar.java"), ).exists().and { get { readText() } contains "schema version:02" } diff --git a/src/test/kotlin/dev/monosoul/jooq/functional/JooqDockerPluginFunctionalTestBase.kt b/src/test/kotlin/dev/monosoul/jooq/functional/JooqDockerPluginFunctionalTestBase.kt index c880aed..9746613 100644 --- a/src/test/kotlin/dev/monosoul/jooq/functional/JooqDockerPluginFunctionalTestBase.kt +++ b/src/test/kotlin/dev/monosoul/jooq/functional/JooqDockerPluginFunctionalTestBase.kt @@ -3,7 +3,6 @@ package dev.monosoul.jooq.functional import org.junit.jupiter.api.BeforeEach abstract class JooqDockerPluginFunctionalTestBase : FunctionalTestBase() { - @BeforeEach fun setUp() { copyResource("/testkit-gradle.properties", "gradle.properties") diff --git a/src/test/kotlin/dev/monosoul/jooq/functional/JooqVersionConfigurationJooqDockerPluginFunctionalTest.kt b/src/test/kotlin/dev/monosoul/jooq/functional/JooqVersionConfigurationJooqDockerPluginFunctionalTest.kt index c3b8bf4..46ddefe 100644 --- a/src/test/kotlin/dev/monosoul/jooq/functional/JooqVersionConfigurationJooqDockerPluginFunctionalTest.kt +++ b/src/test/kotlin/dev/monosoul/jooq/functional/JooqVersionConfigurationJooqDockerPluginFunctionalTest.kt @@ -11,26 +11,25 @@ import strikt.java.exists import strikt.java.notExists class JooqVersionConfigurationJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalTestBase() { - @Test fun `should provide recommended jOOQ version`() { // given prepareBuildGradleFile { """ - import dev.monosoul.jooq.RecommendedVersions - - plugins { - id("dev.monosoul.jooq-docker") - } + import dev.monosoul.jooq.RecommendedVersions + + plugins { + id("dev.monosoul.jooq-docker") + } - repositories { - mavenCentral() - } + repositories { + mavenCentral() + } - dependencies { - jooqCodegen("org.jooq:jooq-codegen:${'$'}{RecommendedVersions.JOOQ_VERSION}") - jooqCodegen("org.postgresql:postgresql:42.3.6") - } + dependencies { + jooqCodegen("org.jooq:jooq-codegen:${'$'}{RecommendedVersions.JOOQ_VERSION}") + jooqCodegen("org.postgresql:postgresql:42.3.6") + } """.trimIndent() } copyResource(from = "/V01__init.sql", to = "src/main/resources/db/migration/V01__init.sql") @@ -42,7 +41,7 @@ class JooqVersionConfigurationJooqDockerPluginFunctionalTest : JooqDockerPluginF expect { that(result).generateJooqClassesTask.outcome isEqualTo SUCCESS that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java"), ).exists() } } @@ -53,37 +52,37 @@ class JooqVersionConfigurationJooqDockerPluginFunctionalTest : JooqDockerPluginF // given prepareBuildGradleFile { """ - import org.jooq.meta.jaxb.Strategy - - plugins { - id("dev.monosoul.jooq-docker") - } + import org.jooq.meta.jaxb.Strategy + + plugins { + id("dev.monosoul.jooq-docker") + } - repositories { - mavenCentral() - } - - tasks { - generateJooqClasses { - schemas.set(listOf("public", "other")) - usingJavaConfig { - database.withExcludes("BAR") - withStrategy( - Strategy().withName("org.jooq.codegen.KeepNamesGeneratorStrategy") - ) - } + repositories { + mavenCentral() + } + + tasks { + generateJooqClasses { + schemas.set(listOf("public", "other")) + usingJavaConfig { + database.withExcludes("BAR") + withStrategy( + Strategy().withName("org.jooq.codegen.KeepNamesGeneratorStrategy") + ) } } + } - dependencies { - jooqCodegen("org.jooq:jooq-codegen:$jooqVersion") - jooqCodegen("org.postgresql:postgresql:42.3.6") - } + dependencies { + jooqCodegen("org.jooq:jooq-codegen:$jooqVersion") + jooqCodegen("org.postgresql:postgresql:42.3.6") + } """.trimIndent() } copyResource( from = "/V01__init_multiple_schemas.sql", - to = "src/main/resources/db/migration/V01__init_multiple_schemas.sql" + to = "src/main/resources/db/migration/V01__init_multiple_schemas.sql", ) // when @@ -96,12 +95,12 @@ class JooqVersionConfigurationJooqDockerPluginFunctionalTest : JooqDockerPluginF get { output } contains "Thank you for using jOOQ $jooqVersion" } that( - projectFile("build/generated-jooq/org/jooq/generated/public_/tables/foo.java") + projectFile("build/generated-jooq/org/jooq/generated/public_/tables/foo.java"), ).exists().and { get { readText() } contains "jOOQ version:$jooqVersion" } that( - projectFile("build/generated-jooq/org/jooq/generated/other/tables/bar.java") + projectFile("build/generated-jooq/org/jooq/generated/other/tables/bar.java"), ).notExists() } } diff --git a/src/test/kotlin/dev/monosoul/jooq/functional/MultipleDatabasesJooqDockerPluginFunctionalTest.kt b/src/test/kotlin/dev/monosoul/jooq/functional/MultipleDatabasesJooqDockerPluginFunctionalTest.kt index 86b67a5..9dcb5e0 100644 --- a/src/test/kotlin/dev/monosoul/jooq/functional/MultipleDatabasesJooqDockerPluginFunctionalTest.kt +++ b/src/test/kotlin/dev/monosoul/jooq/functional/MultipleDatabasesJooqDockerPluginFunctionalTest.kt @@ -8,69 +8,68 @@ import strikt.assertions.isEqualTo import strikt.java.exists class MultipleDatabasesJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalTestBase() { - @Test fun `should generate jooq classes for PostgreSQL and MySQL`() { // given prepareBuildGradleFile { """ - import dev.monosoul.jooq.GenerateJooqClassesTask - import dev.monosoul.jooq.RecommendedVersions - import dev.monosoul.jooq.migration.MigrationLocation - - plugins { - kotlin("jvm") version "1.6.21" - id("dev.monosoul.jooq-docker") - } + import dev.monosoul.jooq.GenerateJooqClassesTask + import dev.monosoul.jooq.RecommendedVersions + import dev.monosoul.jooq.migration.MigrationLocation + + plugins { + kotlin("jvm") version "1.6.21" + id("dev.monosoul.jooq-docker") + } - repositories { - mavenCentral() + repositories { + mavenCentral() + } + + tasks { + generateJooqClasses { + basePackageName.set("org.jooq.generated.postgres") + migrationLocations.setFromFilesystem("src/main/resources/postgres/migration") + outputDirectory.set(project.layout.buildDirectory.dir("postgres")) } - tasks { - generateJooqClasses { - basePackageName.set("org.jooq.generated.postgres") - migrationLocations.setFromFilesystem("src/main/resources/postgres/migration") - outputDirectory.set(project.layout.buildDirectory.dir("postgres")) - } - - register("generateJooqClassesForMySql") { - basePackageName.set("org.jooq.generated.mysql") - migrationLocations.setFromFilesystem(project.files("src/main/resources/mysql/migration")) - outputDirectory.set(project.layout.buildDirectory.dir("mysql")) - includeFlywayTable.set(true) - - withContainer { - image { - name = "mysql:8.0.29" - envVars = mapOf( - "MYSQL_ROOT_PASSWORD" to "mysql", - "MYSQL_DATABASE" to "mysql" - ) - } - db { - username = "root" - password = "mysql" - name = "mysql" - port = 3306 - - jdbc { - schema = "jdbc:mysql" - driverClassName = "com.mysql.cj.jdbc.Driver" - } + register("generateJooqClassesForMySql") { + basePackageName.set("org.jooq.generated.mysql") + migrationLocations.setFromFilesystem(project.files("src/main/resources/mysql/migration")) + outputDirectory.set(project.layout.buildDirectory.dir("mysql")) + includeFlywayTable.set(true) + + withContainer { + image { + name = "mysql:8.0.29" + envVars = mapOf( + "MYSQL_ROOT_PASSWORD" to "mysql", + "MYSQL_DATABASE" to "mysql" + ) + } + db { + username = "root" + password = "mysql" + name = "mysql" + port = 3306 + + jdbc { + schema = "jdbc:mysql" + driverClassName = "com.mysql.cj.jdbc.Driver" } } } } + } - dependencies { - implementation(kotlin("stdlib")) - jooqCodegen("org.postgresql:postgresql:42.3.6") - jooqCodegen("mysql:mysql-connector-java:8.0.29") - jooqCodegen("org.flywaydb:flyway-mysql:${'$'}{RecommendedVersions.FLYWAY_VERSION}") - jooqCodegen("org.flywaydb:flyway-database-postgresql:${'$'}{RecommendedVersions.FLYWAY_VERSION}") - implementation("org.jooq:jooq:${'$'}{RecommendedVersions.JOOQ_VERSION}") - } + dependencies { + implementation(kotlin("stdlib")) + jooqCodegen("org.postgresql:postgresql:42.3.6") + jooqCodegen("mysql:mysql-connector-java:8.0.29") + jooqCodegen("org.flywaydb:flyway-mysql:${'$'}{RecommendedVersions.FLYWAY_VERSION}") + jooqCodegen("org.flywaydb:flyway-database-postgresql:${'$'}{RecommendedVersions.FLYWAY_VERSION}") + implementation("org.jooq:jooq:${'$'}{RecommendedVersions.JOOQ_VERSION}") + } """.trimIndent() } copyResource(from = "/V01__init.sql", to = "src/main/resources/postgres/migration/V01__init.sql") @@ -83,13 +82,13 @@ class MultipleDatabasesJooqDockerPluginFunctionalTest : JooqDockerPluginFunction expect { that(result).generateJooqClassesTask.outcome isEqualTo SUCCESS that( - projectFile("build/classes/java/main/org/jooq/generated/postgres/tables/Foo.class") + projectFile("build/classes/java/main/org/jooq/generated/postgres/tables/Foo.class"), ).exists() that( - projectFile("build/classes/java/main/org/jooq/generated/mysql/tables/Foo.class") + projectFile("build/classes/java/main/org/jooq/generated/mysql/tables/Foo.class"), ).exists() that( - projectFile("build/classes/java/main/org/jooq/generated/mysql/tables/FlywaySchemaHistory.class") + projectFile("build/classes/java/main/org/jooq/generated/mysql/tables/FlywaySchemaHistory.class"), ).exists() } } @@ -99,55 +98,55 @@ class MultipleDatabasesJooqDockerPluginFunctionalTest : JooqDockerPluginFunction // given prepareBuildGradleFile { """ - import dev.monosoul.jooq.RecommendedVersions - - plugins { - id("dev.monosoul.jooq-docker") - } + import dev.monosoul.jooq.RecommendedVersions + + plugins { + id("dev.monosoul.jooq-docker") + } - repositories { - mavenCentral() - } + repositories { + mavenCentral() + } - jooq { - withContainer { - image { - name = "mysql:8.0.29" - envVars = mapOf( - "MYSQL_ROOT_PASSWORD" to "mysql", - "MYSQL_DATABASE" to "mysql", - ) - } - db { - username = "root" - password = "mysql" - name = "mysql" - port = 6666 - - jdbc { - schema = "jdbc:mysql" - driverClassName = "com.mysql.cj.jdbc.Driver" - } + jooq { + withContainer { + image { + name = "mysql:8.0.29" + envVars = mapOf( + "MYSQL_ROOT_PASSWORD" to "mysql", + "MYSQL_DATABASE" to "mysql", + ) + } + db { + username = "root" + password = "mysql" + name = "mysql" + port = 6666 + + jdbc { + schema = "jdbc:mysql" + driverClassName = "com.mysql.cj.jdbc.Driver" } } } - - tasks { - generateJooqClasses { - withContainer { - image { - envVars = envVars + mapOf( - "MYSQL_TCP_PORT" to "6666" - ) - } + } + + tasks { + generateJooqClasses { + withContainer { + image { + envVars = envVars + mapOf( + "MYSQL_TCP_PORT" to "6666" + ) } } } + } - dependencies { - jooqCodegen("mysql:mysql-connector-java:8.0.29") - jooqCodegen("org.flywaydb:flyway-mysql:${'$'}{RecommendedVersions.FLYWAY_VERSION}") - } + dependencies { + jooqCodegen("mysql:mysql-connector-java:8.0.29") + jooqCodegen("org.flywaydb:flyway-mysql:${'$'}{RecommendedVersions.FLYWAY_VERSION}") + } """.trimIndent() } copyResource(from = "/V01__init_mysql.sql", to = "src/main/resources/db/migration/V01__init_mysql.sql") @@ -159,7 +158,7 @@ class MultipleDatabasesJooqDockerPluginFunctionalTest : JooqDockerPluginFunction expect { that(result).generateJooqClassesTask.outcome isEqualTo SUCCESS that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java"), ).exists() } } @@ -170,39 +169,39 @@ class MultipleDatabasesJooqDockerPluginFunctionalTest : JooqDockerPluginFunction val postgresContainer = PostgresContainer().also { it.start() } prepareBuildGradleFile { """ - plugins { - id("dev.monosoul.jooq-docker") - } + plugins { + id("dev.monosoul.jooq-docker") + } - repositories { - mavenCentral() - } + repositories { + mavenCentral() + } - jooq { - withoutContainer { - db { - username = "${postgresContainer.username}" - password = "${postgresContainer.password}" - name = "${postgresContainer.databaseName}" - host = "${postgresContainer.host}" - port = 6666 - } + jooq { + withoutContainer { + db { + username = "${postgresContainer.username}" + password = "${postgresContainer.password}" + name = "${postgresContainer.databaseName}" + host = "${postgresContainer.host}" + port = 6666 } } - - tasks { - generateJooqClasses { - withoutContainer { - db { - port = ${postgresContainer.firstMappedPort} - } + } + + tasks { + generateJooqClasses { + withoutContainer { + db { + port = ${postgresContainer.firstMappedPort} } } } + } - dependencies { - jooqCodegen("org.postgresql:postgresql:42.3.6") - } + dependencies { + jooqCodegen("org.postgresql:postgresql:42.3.6") + } """.trimIndent() } copyResource(from = "/V01__init_mysql.sql", to = "src/main/resources/db/migration/V01__init_mysql.sql") @@ -215,7 +214,7 @@ class MultipleDatabasesJooqDockerPluginFunctionalTest : JooqDockerPluginFunction expect { that(result).generateJooqClassesTask.outcome isEqualTo SUCCESS that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java"), ).exists() } } @@ -226,46 +225,46 @@ class MultipleDatabasesJooqDockerPluginFunctionalTest : JooqDockerPluginFunction val postgresContainer = PostgresContainer().also { it.start() } prepareBuildGradleFile { """ - import dev.monosoul.jooq.GenerateJooqClassesTask - import dev.monosoul.jooq.RecommendedVersions - - plugins { - kotlin("jvm") version "1.6.21" - id("dev.monosoul.jooq-docker") - } + import dev.monosoul.jooq.GenerateJooqClassesTask + import dev.monosoul.jooq.RecommendedVersions + + plugins { + kotlin("jvm") version "1.6.21" + id("dev.monosoul.jooq-docker") + } - repositories { - mavenCentral() + repositories { + mavenCentral() + } + + tasks { + generateJooqClasses { + basePackageName.set("org.jooq.generated.local") + outputDirectory.set(project.layout.buildDirectory.dir("local")) } - tasks { - generateJooqClasses { - basePackageName.set("org.jooq.generated.local") - outputDirectory.set(project.layout.buildDirectory.dir("local")) - } - - register("generateJooqClassesForExternal") { - basePackageName.set("org.jooq.generated.remote") - outputDirectory.set(project.layout.buildDirectory.dir("remote")) - includeFlywayTable.set(true) - - withoutContainer { - db { - username = "${postgresContainer.username}" - password = "${postgresContainer.password}" - name = "${postgresContainer.databaseName}" - host = "${postgresContainer.host}" - port = ${postgresContainer.firstMappedPort} - } + register("generateJooqClassesForExternal") { + basePackageName.set("org.jooq.generated.remote") + outputDirectory.set(project.layout.buildDirectory.dir("remote")) + includeFlywayTable.set(true) + + withoutContainer { + db { + username = "${postgresContainer.username}" + password = "${postgresContainer.password}" + name = "${postgresContainer.databaseName}" + host = "${postgresContainer.host}" + port = ${postgresContainer.firstMappedPort} } } } + } - dependencies { - implementation(kotlin("stdlib")) - jooqCodegen("org.postgresql:postgresql:42.3.6") - implementation("org.jooq:jooq:${'$'}{RecommendedVersions.JOOQ_VERSION}") - } + dependencies { + implementation(kotlin("stdlib")) + jooqCodegen("org.postgresql:postgresql:42.3.6") + implementation("org.jooq:jooq:${'$'}{RecommendedVersions.JOOQ_VERSION}") + } """.trimIndent() } copyResource(from = "/V01__init.sql", to = "src/main/resources/db/migration/V01__init.sql") @@ -278,13 +277,13 @@ class MultipleDatabasesJooqDockerPluginFunctionalTest : JooqDockerPluginFunction expect { that(result).generateJooqClassesTask.outcome isEqualTo SUCCESS that( - projectFile("build/classes/java/main/org/jooq/generated/local/tables/Foo.class") + projectFile("build/classes/java/main/org/jooq/generated/local/tables/Foo.class"), ).exists() that( - projectFile("build/classes/java/main/org/jooq/generated/remote/tables/Foo.class") + projectFile("build/classes/java/main/org/jooq/generated/remote/tables/Foo.class"), ).exists() that( - projectFile("build/classes/java/main/org/jooq/generated/remote/tables/FlywaySchemaHistory.class") + projectFile("build/classes/java/main/org/jooq/generated/remote/tables/FlywaySchemaHistory.class"), ).exists() } } diff --git a/src/test/kotlin/dev/monosoul/jooq/functional/NoMigrationsFunctionalTest.kt b/src/test/kotlin/dev/monosoul/jooq/functional/NoMigrationsFunctionalTest.kt index 814341d..4d7e1b9 100644 --- a/src/test/kotlin/dev/monosoul/jooq/functional/NoMigrationsFunctionalTest.kt +++ b/src/test/kotlin/dev/monosoul/jooq/functional/NoMigrationsFunctionalTest.kt @@ -6,23 +6,22 @@ import strikt.api.expect import strikt.assertions.isEqualTo class NoMigrationsFunctionalTest : JooqDockerPluginFunctionalTestBase() { - @Test fun `should not cause an exception when there are no migrations with built-in Flyway`() { // given prepareBuildGradleFile { """ - plugins { - id("dev.monosoul.jooq-docker") - } + plugins { + id("dev.monosoul.jooq-docker") + } - repositories { - mavenCentral() - } + repositories { + mavenCentral() + } - dependencies { - jooqCodegen("org.postgresql:postgresql:42.3.6") - } + dependencies { + jooqCodegen("org.postgresql:postgresql:42.3.6") + } """.trimIndent() } @@ -40,21 +39,21 @@ class NoMigrationsFunctionalTest : JooqDockerPluginFunctionalTestBase() { // given prepareBuildGradleFile { """ - import dev.monosoul.jooq.RecommendedVersions.FLYWAY_VERSION - - plugins { - id("dev.monosoul.jooq-docker") - } + import dev.monosoul.jooq.RecommendedVersions.FLYWAY_VERSION + + plugins { + id("dev.monosoul.jooq-docker") + } - repositories { - mavenCentral() - } + repositories { + mavenCentral() + } - dependencies { - jooqCodegen("org.flywaydb:flyway-core:${'$'}FLYWAY_VERSION") - jooqCodegen("org.flywaydb:flyway-database-postgresql:${'$'}FLYWAY_VERSION") - jooqCodegen("org.postgresql:postgresql:42.3.6") - } + dependencies { + jooqCodegen("org.flywaydb:flyway-core:${'$'}FLYWAY_VERSION") + jooqCodegen("org.flywaydb:flyway-database-postgresql:${'$'}FLYWAY_VERSION") + jooqCodegen("org.postgresql:postgresql:42.3.6") + } """.trimIndent() } diff --git a/src/test/kotlin/dev/monosoul/jooq/functional/PropertiesConfigurationJooqDockerPluginFunctionalTest.kt b/src/test/kotlin/dev/monosoul/jooq/functional/PropertiesConfigurationJooqDockerPluginFunctionalTest.kt index 58bdaf3..9cb812e 100644 --- a/src/test/kotlin/dev/monosoul/jooq/functional/PropertiesConfigurationJooqDockerPluginFunctionalTest.kt +++ b/src/test/kotlin/dev/monosoul/jooq/functional/PropertiesConfigurationJooqDockerPluginFunctionalTest.kt @@ -8,34 +8,33 @@ import strikt.assertions.isEqualTo import strikt.java.exists class PropertiesConfigurationJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalTestBase() { - @Test fun `should ignore non-string properties`() { // given writeProjectFile("gradle.properties") { """ - dev.monosoul.jooq.nonStringProperty=value-to-override + dev.monosoul.jooq.nonStringProperty=value-to-override """.trimIndent() } prepareBuildGradleFile { """ - project.setProperty("dev.monosoul.jooq.nonStringProperty", 123) - require(project.properties.get("dev.monosoul.jooq.nonStringProperty") !is String) { - "nonStringProperty should not be a string" - } - - plugins { - id("dev.monosoul.jooq-docker") - } - - - repositories { - mavenCentral() - } - - dependencies { - jooqCodegen("org.postgresql:postgresql:42.3.6") - } + project.setProperty("dev.monosoul.jooq.nonStringProperty", 123) + require(project.properties.get("dev.monosoul.jooq.nonStringProperty") !is String) { + "nonStringProperty should not be a string" + } + + plugins { + id("dev.monosoul.jooq-docker") + } + + + repositories { + mavenCentral() + } + + dependencies { + jooqCodegen("org.postgresql:postgresql:42.3.6") + } """.trimIndent() } copyResource(from = "/V01__init.sql", to = "src/main/resources/db/migration/V01__init.sql") @@ -47,7 +46,7 @@ class PropertiesConfigurationJooqDockerPluginFunctionalTest : JooqDockerPluginFu expect { that(result).generateJooqClassesTask.outcome isEqualTo SUCCESS that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java"), ).exists() } } @@ -58,44 +57,45 @@ class PropertiesConfigurationJooqDockerPluginFunctionalTest : JooqDockerPluginFu val postgresContainer = PostgresContainer().also { it.start() } prepareBuildGradleFile { """ - plugins { - id("dev.monosoul.jooq-docker") - } - - jooq { - withContainer { - image { - command = "postgres -p 6666" - } + plugins { + id("dev.monosoul.jooq-docker") + } + + jooq { + withContainer { + image { + command = "postgres -p 6666" } } + } - repositories { - mavenCentral() - } + repositories { + mavenCentral() + } - dependencies { - jooqCodegen("org.postgresql:postgresql:42.3.6") - } + dependencies { + jooqCodegen("org.postgresql:postgresql:42.3.6") + } """.trimIndent() } copyResource(from = "/V01__init.sql", to = "src/main/resources/db/migration/V01__init.sql") // when - val result = runGradleWithArguments( - "generateJooqClasses", - "-Pdev.monosoul.jooq.withoutContainer.db.username=${postgresContainer.username}", - "-Pdev.monosoul.jooq.withoutContainer.db.password=${postgresContainer.password}", - "-Pdev.monosoul.jooq.withoutContainer.db.name=${postgresContainer.databaseName}", - "-Pdev.monosoul.jooq.withoutContainer.db.port=${postgresContainer.firstMappedPort}" - ) + val result = + runGradleWithArguments( + "generateJooqClasses", + "-Pdev.monosoul.jooq.withoutContainer.db.username=${postgresContainer.username}", + "-Pdev.monosoul.jooq.withoutContainer.db.password=${postgresContainer.password}", + "-Pdev.monosoul.jooq.withoutContainer.db.name=${postgresContainer.databaseName}", + "-Pdev.monosoul.jooq.withoutContainer.db.port=${postgresContainer.firstMappedPort}", + ) postgresContainer.stop() // then expect { that(result).generateJooqClassesTask.outcome isEqualTo SUCCESS that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java"), ).exists() } } @@ -105,40 +105,41 @@ class PropertiesConfigurationJooqDockerPluginFunctionalTest : JooqDockerPluginFu // given prepareBuildGradleFile { """ - plugins { - id("dev.monosoul.jooq-docker") - } - - jooq { - withContainer { - image { - command = "postgres -p 6666" - } + plugins { + id("dev.monosoul.jooq-docker") + } + + jooq { + withContainer { + image { + command = "postgres -p 6666" } } + } - repositories { - mavenCentral() - } + repositories { + mavenCentral() + } - dependencies { - jooqCodegen("org.postgresql:postgresql:42.3.6") - } + dependencies { + jooqCodegen("org.postgresql:postgresql:42.3.6") + } """.trimIndent() } copyResource(from = "/V01__init.sql", to = "src/main/resources/db/migration/V01__init.sql") // when - val result = runGradleWithArguments( - "generateJooqClasses", - "-Pdev.monosoul.jooq.withContainer.db.port=6666", - ) + val result = + runGradleWithArguments( + "generateJooqClasses", + "-Pdev.monosoul.jooq.withContainer.db.port=6666", + ) // then expect { that(result).generateJooqClassesTask.outcome isEqualTo SUCCESS that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java"), ).exists() } } @@ -148,40 +149,41 @@ class PropertiesConfigurationJooqDockerPluginFunctionalTest : JooqDockerPluginFu // given prepareBuildGradleFile { """ - plugins { - id("dev.monosoul.jooq-docker") - } - - jooq { - withContainer { - image { - command = "postgres -p 6666" - } + plugins { + id("dev.monosoul.jooq-docker") + } + + jooq { + withContainer { + image { + command = "postgres -p 6666" } } + } - repositories { - mavenCentral() - } + repositories { + mavenCentral() + } - dependencies { - jooqCodegen("org.postgresql:postgresql:42.3.6") - } + dependencies { + jooqCodegen("org.postgresql:postgresql:42.3.6") + } """.trimIndent() } copyResource(from = "/V01__init.sql", to = "src/main/resources/db/migration/V01__init.sql") // when - val result = runGradleWithArguments( - "generateJooqClasses", - "-Pdev.monosoul.jooq.withContainer.image.command=", - ) + val result = + runGradleWithArguments( + "generateJooqClasses", + "-Pdev.monosoul.jooq.withContainer.image.command=", + ) // then expect { that(result).generateJooqClassesTask.outcome isEqualTo SUCCESS that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java"), ).exists() } } @@ -191,36 +193,36 @@ class PropertiesConfigurationJooqDockerPluginFunctionalTest : JooqDockerPluginFu // given writeProjectFile("gradle.properties") { """ - dev.monosoul.jooq.withContainer.db.username=root - dev.monosoul.jooq.withContainer.db.password=mysql - dev.monosoul.jooq.withContainer.db.name=mysql - dev.monosoul.jooq.withContainer.db.port=3306 - dev.monosoul.jooq.withContainer.db.jdbc.schema=jdbc:mysql - dev.monosoul.jooq.withContainer.db.jdbc.driverClassName=com.mysql.cj.jdbc.Driver - dev.monosoul.jooq.withContainer.db.jdbc.urlQueryParams=?useSSL=false - dev.monosoul.jooq.withContainer.image.name=mysql:8.0.29 - dev.monosoul.jooq.withContainer.image.testQuery=SELECT 2 - dev.monosoul.jooq.withContainer.image.command=--default-authentication-plugin=mysql_native_password - dev.monosoul.jooq.withContainer.image.envVars.MYSQL_ROOT_PASSWORD=mysql - dev.monosoul.jooq.withContainer.image.envVars.MYSQL_DATABASE=mysql + dev.monosoul.jooq.withContainer.db.username=root + dev.monosoul.jooq.withContainer.db.password=mysql + dev.monosoul.jooq.withContainer.db.name=mysql + dev.monosoul.jooq.withContainer.db.port=3306 + dev.monosoul.jooq.withContainer.db.jdbc.schema=jdbc:mysql + dev.monosoul.jooq.withContainer.db.jdbc.driverClassName=com.mysql.cj.jdbc.Driver + dev.monosoul.jooq.withContainer.db.jdbc.urlQueryParams=?useSSL=false + dev.monosoul.jooq.withContainer.image.name=mysql:8.0.29 + dev.monosoul.jooq.withContainer.image.testQuery=SELECT 2 + dev.monosoul.jooq.withContainer.image.command=--default-authentication-plugin=mysql_native_password + dev.monosoul.jooq.withContainer.image.envVars.MYSQL_ROOT_PASSWORD=mysql + dev.monosoul.jooq.withContainer.image.envVars.MYSQL_DATABASE=mysql """.trimIndent() } prepareBuildGradleFile { """ - import dev.monosoul.jooq.RecommendedVersions - - plugins { - id("dev.monosoul.jooq-docker") - } - - repositories { - mavenCentral() - } - - dependencies { - jooqCodegen("mysql:mysql-connector-java:8.0.29") - jooqCodegen("org.flywaydb:flyway-mysql:${'$'}{RecommendedVersions.FLYWAY_VERSION}") - } + import dev.monosoul.jooq.RecommendedVersions + + plugins { + id("dev.monosoul.jooq-docker") + } + + repositories { + mavenCentral() + } + + dependencies { + jooqCodegen("mysql:mysql-connector-java:8.0.29") + jooqCodegen("org.flywaydb:flyway-mysql:${'$'}{RecommendedVersions.FLYWAY_VERSION}") + } """.trimIndent() } copyResource(from = "/V01__init_mysql.sql", to = "src/main/resources/db/migration/V01__init_mysql.sql") @@ -232,7 +234,7 @@ class PropertiesConfigurationJooqDockerPluginFunctionalTest : JooqDockerPluginFu expect { that(result).generateJooqClassesTask.outcome isEqualTo SUCCESS that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java"), ).exists() } } @@ -243,28 +245,28 @@ class PropertiesConfigurationJooqDockerPluginFunctionalTest : JooqDockerPluginFu val postgresContainer = PostgresContainer().also { it.start() } writeProjectFile("gradle.properties") { """ - dev.monosoul.jooq.withoutContainer.db.username=${postgresContainer.username} - dev.monosoul.jooq.withoutContainer.db.password=${postgresContainer.password} - dev.monosoul.jooq.withoutContainer.db.name=${postgresContainer.databaseName} - dev.monosoul.jooq.withoutContainer.db.port=${postgresContainer.firstMappedPort} - dev.monosoul.jooq.withoutContainer.db.jdbc.schema=jdbc:postgresql - dev.monosoul.jooq.withoutContainer.db.jdbc.driverClassName=org.postgresql.Driver - dev.monosoul.jooq.withoutContainer.db.jdbc.urlQueryParams=?loggerLevel=OFF + dev.monosoul.jooq.withoutContainer.db.username=${postgresContainer.username} + dev.monosoul.jooq.withoutContainer.db.password=${postgresContainer.password} + dev.monosoul.jooq.withoutContainer.db.name=${postgresContainer.databaseName} + dev.monosoul.jooq.withoutContainer.db.port=${postgresContainer.firstMappedPort} + dev.monosoul.jooq.withoutContainer.db.jdbc.schema=jdbc:postgresql + dev.monosoul.jooq.withoutContainer.db.jdbc.driverClassName=org.postgresql.Driver + dev.monosoul.jooq.withoutContainer.db.jdbc.urlQueryParams=?loggerLevel=OFF """.trimIndent() } prepareBuildGradleFile { """ - plugins { - id("dev.monosoul.jooq-docker") - } + plugins { + id("dev.monosoul.jooq-docker") + } - repositories { - mavenCentral() - } + repositories { + mavenCentral() + } - dependencies { - jooqCodegen("org.postgresql:postgresql:42.3.6") - } + dependencies { + jooqCodegen("org.postgresql:postgresql:42.3.6") + } """.trimIndent() } copyResource(from = "/V01__init_mysql.sql", to = "src/main/resources/db/migration/V01__init_mysql.sql") @@ -277,7 +279,7 @@ class PropertiesConfigurationJooqDockerPluginFunctionalTest : JooqDockerPluginFu expect { that(result).generateJooqClassesTask.outcome isEqualTo SUCCESS that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java"), ).exists() } } diff --git a/src/test/kotlin/dev/monosoul/jooq/functional/RunContainerWithCommandJooqDockerPluginFunctionalTest.kt b/src/test/kotlin/dev/monosoul/jooq/functional/RunContainerWithCommandJooqDockerPluginFunctionalTest.kt index d23eadd..0174605 100644 --- a/src/test/kotlin/dev/monosoul/jooq/functional/RunContainerWithCommandJooqDockerPluginFunctionalTest.kt +++ b/src/test/kotlin/dev/monosoul/jooq/functional/RunContainerWithCommandJooqDockerPluginFunctionalTest.kt @@ -7,35 +7,34 @@ import strikt.assertions.isEqualTo import strikt.java.exists class RunContainerWithCommandJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalTestBase() { - @Test fun `should support running DB containers with command`() { // given prepareBuildGradleFile { """ - plugins { - id("dev.monosoul.jooq-docker") - } - - repositories { - mavenCentral() - } - - jooq { - withContainer { - image { - command = "postgres -p 6666" - } + plugins { + id("dev.monosoul.jooq-docker") + } + + repositories { + mavenCentral() + } + + jooq { + withContainer { + image { + command = "postgres -p 6666" + } - db { - port = 6666 - } + db { + port = 6666 } } + } - dependencies { - jooqCodegen("org.postgresql:postgresql:42.3.6") - } + dependencies { + jooqCodegen("org.postgresql:postgresql:42.3.6") + } """.trimIndent() } copyResource(from = "/V01__init.sql", to = "src/main/resources/db/migration/V01__init.sql") @@ -47,7 +46,7 @@ class RunContainerWithCommandJooqDockerPluginFunctionalTest : JooqDockerPluginFu expect { that(result).generateJooqClassesTask.outcome isEqualTo SUCCESS that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java"), ).exists() } } diff --git a/src/test/kotlin/dev/monosoul/jooq/functional/SchemaVersionJooqDockerPluginFunctionalTest.kt b/src/test/kotlin/dev/monosoul/jooq/functional/SchemaVersionJooqDockerPluginFunctionalTest.kt index 9de2969..585f45f 100644 --- a/src/test/kotlin/dev/monosoul/jooq/functional/SchemaVersionJooqDockerPluginFunctionalTest.kt +++ b/src/test/kotlin/dev/monosoul/jooq/functional/SchemaVersionJooqDockerPluginFunctionalTest.kt @@ -8,30 +8,29 @@ import strikt.assertions.isEqualTo import strikt.java.exists class SchemaVersionJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalTestBase() { - @Test fun `schema version provider should be aware of flyway table name override`() { // given prepareBuildGradleFile { """ - plugins { - id("dev.monosoul.jooq-docker") - } + plugins { + id("dev.monosoul.jooq-docker") + } - repositories { - mavenCentral() - } + repositories { + mavenCentral() + } - tasks { - generateJooqClasses { - flywayProperties.put("flyway.table", "some_schema_table") - includeFlywayTable.set(true) - } + tasks { + generateJooqClasses { + flywayProperties.put("flyway.table", "some_schema_table") + includeFlywayTable.set(true) } + } - dependencies { - jooqCodegen("org.postgresql:postgresql:42.3.6") - } + dependencies { + jooqCodegen("org.postgresql:postgresql:42.3.6") + } """.trimIndent() } copyResource(from = "/V01__init.sql", to = "src/main/resources/db/migration/V01__init.sql") @@ -43,7 +42,7 @@ class SchemaVersionJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalTe expect { that(result).generateJooqClassesTask.outcome isEqualTo SUCCESS that( - projectFile("build/generated-jooq/org/jooq/generated/tables/SomeSchemaTable.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/SomeSchemaTable.java"), ).exists().and { get { readText() } contains "schema version:01" } @@ -55,17 +54,17 @@ class SchemaVersionJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalTe // given prepareBuildGradleFile { """ - plugins { - id("dev.monosoul.jooq-docker") - } + plugins { + id("dev.monosoul.jooq-docker") + } - repositories { - mavenCentral() - } + repositories { + mavenCentral() + } - dependencies { - jooqCodegen("org.postgresql:postgresql:42.3.6") - } + dependencies { + jooqCodegen("org.postgresql:postgresql:42.3.6") + } """.trimIndent() } copyResource(from = "/V01__init.sql", to = "src/main/resources/db/migration/V01__init.sql") @@ -78,12 +77,12 @@ class SchemaVersionJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalTe expect { that(result).generateJooqClassesTask.outcome isEqualTo SUCCESS that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java"), ).exists().and { get { readText() } contains "schema version:02" } that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Bar.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Bar.java"), ).exists().and { get { readText() } contains "schema version:02" } diff --git a/src/test/kotlin/dev/monosoul/jooq/functional/SmokeJooqDockerPluginFunctionalTest.kt b/src/test/kotlin/dev/monosoul/jooq/functional/SmokeJooqDockerPluginFunctionalTest.kt index 247cb42..1aff74e 100644 --- a/src/test/kotlin/dev/monosoul/jooq/functional/SmokeJooqDockerPluginFunctionalTest.kt +++ b/src/test/kotlin/dev/monosoul/jooq/functional/SmokeJooqDockerPluginFunctionalTest.kt @@ -6,15 +6,14 @@ import strikt.api.expectThat import strikt.assertions.isEqualTo class SmokeJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalTestBase() { - @Test fun `plugin is applicable`() { // given prepareBuildGradleFile { """ - plugins { - id("dev.monosoul.jooq-docker") - } + plugins { + id("dev.monosoul.jooq-docker") + } """.trimIndent() } diff --git a/src/test/kotlin/dev/monosoul/jooq/functional/SourceSetsAndTasksConfigurationJooqDockerPluginFunctionalTest.kt b/src/test/kotlin/dev/monosoul/jooq/functional/SourceSetsAndTasksConfigurationJooqDockerPluginFunctionalTest.kt index 1176179..dbda3b3 100644 --- a/src/test/kotlin/dev/monosoul/jooq/functional/SourceSetsAndTasksConfigurationJooqDockerPluginFunctionalTest.kt +++ b/src/test/kotlin/dev/monosoul/jooq/functional/SourceSetsAndTasksConfigurationJooqDockerPluginFunctionalTest.kt @@ -9,73 +9,76 @@ import strikt.java.exists import kotlin.streams.asStream class SourceSetsAndTasksConfigurationJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalTestBase() { - @TestFactory - fun `should configure source sets and tasks for java project`() = sequenceOf( - "when jooq plugin is applied after java plugin" to """ - import dev.monosoul.jooq.RecommendedVersions - - plugins { - java - id("dev.monosoul.jooq-docker") - } + fun `should configure source sets and tasks for java project`() = + sequenceOf( + "when jooq plugin is applied after java plugin" to + """ + import dev.monosoul.jooq.RecommendedVersions + + plugins { + java + id("dev.monosoul.jooq-docker") + } - repositories { - mavenCentral() - } + repositories { + mavenCentral() + } - dependencies { - jooqCodegen("org.postgresql:postgresql:42.3.6") - implementation("org.jooq:jooq:${'$'}{RecommendedVersions.JOOQ_VERSION}") - implementation("javax.annotation:javax.annotation-api:1.3.2") - } - """.trimIndent(), - "when jooq plugin is applied before java plugin" to """ - import dev.monosoul.jooq.RecommendedVersions - - plugins { - id("dev.monosoul.jooq-docker") - } - apply(plugin = "java") + dependencies { + jooqCodegen("org.postgresql:postgresql:42.3.6") + implementation("org.jooq:jooq:${'$'}{RecommendedVersions.JOOQ_VERSION}") + implementation("javax.annotation:javax.annotation-api:1.3.2") + } + """.trimIndent(), + "when jooq plugin is applied before java plugin" to + """ + import dev.monosoul.jooq.RecommendedVersions + + plugins { + id("dev.monosoul.jooq-docker") + } + apply(plugin = "java") - repositories { - mavenCentral() - } + repositories { + mavenCentral() + } - dependencies { - jooqCodegen("org.postgresql:postgresql:42.3.6") - "implementation"("org.jooq:jooq:${'$'}{RecommendedVersions.JOOQ_VERSION}") - "implementation"("javax.annotation:javax.annotation-api:1.3.2") - } - """.trimIndent(), - "when jooq plugin is applied before java-library plugin" to """ - import dev.monosoul.jooq.RecommendedVersions - - plugins { - id("dev.monosoul.jooq-docker") - } - apply(plugin = "java-library") + dependencies { + jooqCodegen("org.postgresql:postgresql:42.3.6") + "implementation"("org.jooq:jooq:${'$'}{RecommendedVersions.JOOQ_VERSION}") + "implementation"("javax.annotation:javax.annotation-api:1.3.2") + } + """.trimIndent(), + "when jooq plugin is applied before java-library plugin" to + """ + import dev.monosoul.jooq.RecommendedVersions + + plugins { + id("dev.monosoul.jooq-docker") + } + apply(plugin = "java-library") - repositories { - mavenCentral() - } + repositories { + mavenCentral() + } - dependencies { - jooqCodegen("org.postgresql:postgresql:42.3.6") - "implementation"("org.jooq:jooq:${'$'}{RecommendedVersions.JOOQ_VERSION}") - "implementation"("javax.annotation:javax.annotation-api:1.3.2") - } - """.trimIndent() - ).onEach { - recreateProjectDir() - }.map { (caseName, buildScript) -> - dynamicTest("should configure source sets and tasks for java project $caseName") { - // given - prepareBuildGradleFile { buildScript } - copyResource(from = "/V01__init.sql", to = "src/main/resources/db/migration/V01__init.sql") - writeProjectFile("src/main/java/com/test/Main.java") { - // language=Java - """ + dependencies { + jooqCodegen("org.postgresql:postgresql:42.3.6") + "implementation"("org.jooq:jooq:${'$'}{RecommendedVersions.JOOQ_VERSION}") + "implementation"("javax.annotation:javax.annotation-api:1.3.2") + } + """.trimIndent(), + ).onEach { + recreateProjectDir() + }.map { (caseName, buildScript) -> + dynamicTest("should configure source sets and tasks for java project $caseName") { + // given + prepareBuildGradleFile { buildScript } + copyResource(from = "/V01__init.sql", to = "src/main/resources/db/migration/V01__init.sql") + writeProjectFile("src/main/java/com/test/Main.java") { + // language=Java + """ package com.test; import static org.jooq.generated.Tables.FOO; @@ -85,108 +88,111 @@ class SourceSetsAndTasksConfigurationJooqDockerPluginFunctionalTest : JooqDocker System.out.println(FOO.ID.getName()); } } - """.trimIndent() - } + """.trimIndent() + } + + // when + val result = runGradleWithArguments("classes") - // when - val result = runGradleWithArguments("classes") - - // then - expect { - that(result).apply { - generateJooqClassesTask.outcome isEqualTo SUCCESS - getTaskOutcome("classes") isEqualTo SUCCESS - } - that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java") - ).exists() - that( - projectFile("build/classes/java/main/com/test/Main.class") - ).exists() + // then + expect { + that(result).apply { + generateJooqClassesTask.outcome isEqualTo SUCCESS + getTaskOutcome("classes") isEqualTo SUCCESS + } + that( + projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java"), + ).exists() + that( + projectFile("build/classes/java/main/com/test/Main.class"), + ).exists() + } } - } - }.asStream() + }.asStream() @TestFactory - fun `should configure source sets and tasks for kotlin project`() = sequenceOf( - "when jooq plugin is applied after kotlin plugin" to """ - import dev.monosoul.jooq.RecommendedVersions - - plugins { - kotlin("jvm") version "1.6.21" - id("dev.monosoul.jooq-docker") - } + fun `should configure source sets and tasks for kotlin project`() = + sequenceOf( + "when jooq plugin is applied after kotlin plugin" to + """ + import dev.monosoul.jooq.RecommendedVersions + + plugins { + kotlin("jvm") version "1.6.21" + id("dev.monosoul.jooq-docker") + } - repositories { - mavenCentral() - } + repositories { + mavenCentral() + } - dependencies { - implementation(kotlin("stdlib")) - jooqCodegen("org.postgresql:postgresql:42.3.6") - implementation("org.jooq:jooq:${'$'}{RecommendedVersions.JOOQ_VERSION}") - implementation("javax.annotation:javax.annotation-api:1.3.2") - } - """.trimIndent(), - "when jooq plugin is applied before kotlin plugin" to """ - import dev.monosoul.jooq.RecommendedVersions - - buildscript { dependencies { - classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21") + implementation(kotlin("stdlib")) + jooqCodegen("org.postgresql:postgresql:42.3.6") + implementation("org.jooq:jooq:${'$'}{RecommendedVersions.JOOQ_VERSION}") + implementation("javax.annotation:javax.annotation-api:1.3.2") + } + """.trimIndent(), + "when jooq plugin is applied before kotlin plugin" to + """ + import dev.monosoul.jooq.RecommendedVersions + + buildscript { + dependencies { + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21") + } } - } - plugins { - id("dev.monosoul.jooq-docker") - } - apply(plugin = "org.jetbrains.kotlin.jvm") + plugins { + id("dev.monosoul.jooq-docker") + } + apply(plugin = "org.jetbrains.kotlin.jvm") - repositories { - mavenCentral() - } + repositories { + mavenCentral() + } - dependencies { - "implementation"(kotlin("stdlib")) - jooqCodegen("org.postgresql:postgresql:42.3.6") - "implementation"("org.jooq:jooq:${'$'}{RecommendedVersions.JOOQ_VERSION}") - "implementation"("javax.annotation:javax.annotation-api:1.3.2") - } - """.trimIndent() - ).onEach { - recreateProjectDir() - }.map { (caseName, buildScript) -> - dynamicTest("should configure source sets and tasks for kotlin project $caseName") { - // given - prepareBuildGradleFile { buildScript } - copyResource(from = "/V01__init.sql", to = "src/main/resources/db/migration/V01__init.sql") - writeProjectFile("src/main/kotlin/com/test/Main.kt") { - // language=kotlin - """ + dependencies { + "implementation"(kotlin("stdlib")) + jooqCodegen("org.postgresql:postgresql:42.3.6") + "implementation"("org.jooq:jooq:${'$'}{RecommendedVersions.JOOQ_VERSION}") + "implementation"("javax.annotation:javax.annotation-api:1.3.2") + } + """.trimIndent(), + ).onEach { + recreateProjectDir() + }.map { (caseName, buildScript) -> + dynamicTest("should configure source sets and tasks for kotlin project $caseName") { + // given + prepareBuildGradleFile { buildScript } + copyResource(from = "/V01__init.sql", to = "src/main/resources/db/migration/V01__init.sql") + writeProjectFile("src/main/kotlin/com/test/Main.kt") { + // language=kotlin + """ package com.test import org.jooq.generated.Tables.FOO fun main() = println(FOO.ID.name) - """.trimIndent() - } + """.trimIndent() + } - // when - val result = runGradleWithArguments("classes") - - // then - expect { - that(result).apply { - generateJooqClassesTask.outcome isEqualTo SUCCESS - getTaskOutcome("classes") isEqualTo SUCCESS - } - that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java") - ).exists() - that( - projectFile("build/classes/kotlin/main/com/test/MainKt.class") - ).exists() + // when + val result = runGradleWithArguments("classes") + + // then + expect { + that(result).apply { + generateJooqClassesTask.outcome isEqualTo SUCCESS + getTaskOutcome("classes") isEqualTo SUCCESS + } + that( + projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java"), + ).exists() + that( + projectFile("build/classes/kotlin/main/com/test/MainKt.class"), + ).exists() + } } - } - }.asStream() + }.asStream() } diff --git a/src/test/kotlin/dev/monosoul/jooq/functional/UpToDateChecksJooqDockerPluginFunctionalTest.kt b/src/test/kotlin/dev/monosoul/jooq/functional/UpToDateChecksJooqDockerPluginFunctionalTest.kt index 6fadbc3..5b23f29 100644 --- a/src/test/kotlin/dev/monosoul/jooq/functional/UpToDateChecksJooqDockerPluginFunctionalTest.kt +++ b/src/test/kotlin/dev/monosoul/jooq/functional/UpToDateChecksJooqDockerPluginFunctionalTest.kt @@ -10,23 +10,22 @@ import strikt.java.exists import strikt.java.notExists class UpToDateChecksJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalTestBase() { - @Test fun `up to date check should work for output dir`() { // given prepareBuildGradleFile { """ - plugins { - id("dev.monosoul.jooq-docker") - } + plugins { + id("dev.monosoul.jooq-docker") + } - repositories { - mavenCentral() - } + repositories { + mavenCentral() + } - dependencies { - jooqCodegen("org.postgresql:postgresql:42.3.6") - } + dependencies { + jooqCodegen("org.postgresql:postgresql:42.3.6") + } """.trimIndent() } copyResource(from = "/V01__init.sql", to = "src/main/resources/db/migration/V01__init.sql") @@ -51,17 +50,17 @@ class UpToDateChecksJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalT // given prepareBuildGradleFile { """ - plugins { - id("dev.monosoul.jooq-docker") - } + plugins { + id("dev.monosoul.jooq-docker") + } - repositories { - mavenCentral() - } + repositories { + mavenCentral() + } - dependencies { - jooqCodegen("org.postgresql:postgresql:42.3.6") - } + dependencies { + jooqCodegen("org.postgresql:postgresql:42.3.6") + } """.trimIndent() } copyResource(from = "/V01__init.sql", to = "src/main/resources/db/migration/V01__init.sql") @@ -84,7 +83,8 @@ class UpToDateChecksJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalT @Test fun `up to date check should work for extension changes`() { // given - val initialBuildScript = """ + val initialBuildScript = + """ plugins { id("dev.monosoul.jooq-docker") } @@ -104,9 +104,10 @@ class UpToDateChecksJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalT dependencies { jooqCodegen("org.postgresql:postgresql:42.3.6") } - """.trimIndent() + """.trimIndent() - val extensionValueChangedBuildScript = """ + val extensionValueChangedBuildScript = + """ plugins { id("dev.monosoul.jooq-docker") } @@ -126,7 +127,7 @@ class UpToDateChecksJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalT dependencies { jooqCodegen("org.postgresql:postgresql:42.3.6") } - """.trimIndent() + """.trimIndent() prepareBuildGradleFile { initialBuildScript } copyResource(from = "/V01__init.sql", to = "src/main/resources/db/migration/V01__init.sql") @@ -150,7 +151,8 @@ class UpToDateChecksJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalT @Test fun `up to date check should work for generator customizations`() { // given - val initialBuildScript = """ + val initialBuildScript = + """ plugins { id("dev.monosoul.jooq-docker") } @@ -171,9 +173,10 @@ class UpToDateChecksJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalT dependencies { jooqCodegen("org.postgresql:postgresql:42.3.6") } - """.trimIndent() + """.trimIndent() - val updatedBuildScript = """ + val updatedBuildScript = + """ plugins { id("dev.monosoul.jooq-docker") } @@ -194,12 +197,12 @@ class UpToDateChecksJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalT dependencies { jooqCodegen("org.postgresql:postgresql:42.3.6") } - """.trimIndent() + """.trimIndent() prepareBuildGradleFile { initialBuildScript } copyResource( from = "/V01__init_multiple_schemas.sql", - to = "src/main/resources/db/migration/V01__init_multiple_schemas.sql" + to = "src/main/resources/db/migration/V01__init_multiple_schemas.sql", ) // when @@ -217,10 +220,10 @@ class UpToDateChecksJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalT that(finalResultNoChanges).generateJooqClassesTask.outcome isEqualTo UP_TO_DATE that( - projectFile("build/generated-jooq/org/jooq/generated/public_/tables/Foo.java") + projectFile("build/generated-jooq/org/jooq/generated/public_/tables/Foo.java"), ).notExists() that( - projectFile("build/generated-jooq/org/jooq/generated/other/tables/Bar.java") + projectFile("build/generated-jooq/org/jooq/generated/other/tables/Bar.java"), ).notExists() } } @@ -228,7 +231,8 @@ class UpToDateChecksJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalT @Test fun `should regenerate jooq classes when out of date even if output directory already has classes generated`() { // given - val initialBuildScript = """ + val initialBuildScript = + """ import org.jooq.meta.jaxb.ForcedType plugins { @@ -253,9 +257,10 @@ class UpToDateChecksJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalT dependencies { jooqCodegen("org.postgresql:postgresql:42.3.6") } - """.trimIndent() + """.trimIndent() - val updatedBuildScript = """ + val updatedBuildScript = + """ import org.jooq.meta.jaxb.ForcedType plugins { @@ -280,7 +285,7 @@ class UpToDateChecksJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalT dependencies { jooqCodegen("org.postgresql:postgresql:42.3.6") } - """.trimIndent() + """.trimIndent() prepareBuildGradleFile { initialBuildScript } copyResource(from = "/V01__init.sql", to = "src/main/resources/db/migration/V01__init.sql") @@ -292,7 +297,7 @@ class UpToDateChecksJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalT expect { that(initialResult).generateJooqClassesTask.outcome isEqualTo SUCCESS that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java"), ).exists().get { readText() }.contains("com.example.UniqueClassForFirstGeneration") } @@ -304,7 +309,7 @@ class UpToDateChecksJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalT expect { that(resultAfterUpdate).generateJooqClassesTask.outcome isEqualTo SUCCESS that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java"), ).exists().get { readText() }.contains("com.example.UniqueClassForSecondGeneration") } } @@ -312,7 +317,8 @@ class UpToDateChecksJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalT @Test fun `up to date check should work for dependency version changes`() { // given - val initialBuildScript = """ + val initialBuildScript = + """ plugins { id("dev.monosoul.jooq-docker") } @@ -324,9 +330,10 @@ class UpToDateChecksJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalT dependencies { jooqCodegen("org.postgresql:postgresql:42.3.0") } - """.trimIndent() + """.trimIndent() - val extensionValueChangedBuildScript = """ + val extensionValueChangedBuildScript = + """ plugins { id("dev.monosoul.jooq-docker") } @@ -338,7 +345,7 @@ class UpToDateChecksJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalT dependencies { jooqCodegen("org.postgresql:postgresql:42.3.6") } - """.trimIndent() + """.trimIndent() prepareBuildGradleFile { initialBuildScript } copyResource(from = "/V01__init.sql", to = "src/main/resources/db/migration/V01__init.sql") diff --git a/src/test/kotlin/dev/monosoul/jooq/functional/XmlBasedConfigJooqDockerPluginFunctionalTest.kt b/src/test/kotlin/dev/monosoul/jooq/functional/XmlBasedConfigJooqDockerPluginFunctionalTest.kt index 0d6a43b..7dc6d44 100644 --- a/src/test/kotlin/dev/monosoul/jooq/functional/XmlBasedConfigJooqDockerPluginFunctionalTest.kt +++ b/src/test/kotlin/dev/monosoul/jooq/functional/XmlBasedConfigJooqDockerPluginFunctionalTest.kt @@ -8,35 +8,34 @@ import strikt.java.exists import strikt.java.notExists class XmlBasedConfigJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalTestBase() { - @Test fun `should generate jOOQ classes using XML generator definition`() { // given prepareBuildGradleFile { """ - plugins { - id("dev.monosoul.jooq-docker") - } - - repositories { - mavenCentral() + plugins { + id("dev.monosoul.jooq-docker") + } + + repositories { + mavenCentral() + } + + tasks { + generateJooqClasses { + schemas.set(listOf("public", "other")) + usingXmlConfig() } + } - tasks { - generateJooqClasses { - schemas.set(listOf("public", "other")) - usingXmlConfig() - } - } - - dependencies { - jooqCodegen("org.postgresql:postgresql:42.3.6") - } + dependencies { + jooqCodegen("org.postgresql:postgresql:42.3.6") + } """.trimIndent() } copyResource( from = "/V01__init_multiple_schemas.sql", - to = "src/main/resources/db/migration/V01__init_multiple_schemas.sql" + to = "src/main/resources/db/migration/V01__init_multiple_schemas.sql", ) copyResource(from = "/jooq-generator.xml", to = "src/main/resources/db/jooq.xml") @@ -47,10 +46,10 @@ class XmlBasedConfigJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalT expect { that(result).generateJooqClassesTask.outcome isEqualTo SUCCESS that( - projectFile("build/generated-jooq/org/jooq/generated/public_/tables/Foo.java") + projectFile("build/generated-jooq/org/jooq/generated/public_/tables/Foo.java"), ).exists() that( - projectFile("build/generated-jooq/org/jooq/generated/other/tables/Bar.java") + projectFile("build/generated-jooq/org/jooq/generated/other/tables/Bar.java"), ).notExists() } } @@ -60,31 +59,31 @@ class XmlBasedConfigJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalT // given prepareBuildGradleFile { """ - plugins { - id("dev.monosoul.jooq-docker") - } - - repositories { - mavenCentral() - } - - tasks { - generateJooqClasses { - schemas.set(listOf("public", "other")) - usingXmlConfig { - database.withExcludes("BAR") - } + plugins { + id("dev.monosoul.jooq-docker") + } + + repositories { + mavenCentral() + } + + tasks { + generateJooqClasses { + schemas.set(listOf("public", "other")) + usingXmlConfig { + database.withExcludes("BAR") } } + } - dependencies { - jooqCodegen("org.postgresql:postgresql:42.3.6") - } + dependencies { + jooqCodegen("org.postgresql:postgresql:42.3.6") + } """.trimIndent() } copyResource( from = "/V01__init_multiple_schemas.sql", - to = "src/main/resources/db/migration/V01__init_multiple_schemas.sql" + to = "src/main/resources/db/migration/V01__init_multiple_schemas.sql", ) copyResource(from = "/jooq-generator-without-excludes.xml", to = "src/main/resources/db/jooq.xml") @@ -95,10 +94,10 @@ class XmlBasedConfigJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalT expect { that(result).getTaskOutcome("generateJooqClasses") isEqualTo SUCCESS that( - projectFile("build/generated-jooq/org/jooq/generated/public_/tables/Foo.java") + projectFile("build/generated-jooq/org/jooq/generated/public_/tables/Foo.java"), ).exists() that( - projectFile("build/generated-jooq/org/jooq/generated/other/tables/Bar.java") + projectFile("build/generated-jooq/org/jooq/generated/other/tables/Bar.java"), ).notExists() } } @@ -108,30 +107,30 @@ class XmlBasedConfigJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalT // given prepareBuildGradleFile { """ - plugins { - id("dev.monosoul.jooq-docker") - } - - repositories { - mavenCentral() + plugins { + id("dev.monosoul.jooq-docker") + } + + repositories { + mavenCentral() + } + + tasks { + generateJooqClasses { + schemas.set(listOf("public", "other")) + schemaToPackageMapping.put("public", "fancy_name") + usingXmlConfig() } + } - tasks { - generateJooqClasses { - schemas.set(listOf("public", "other")) - schemaToPackageMapping.put("public", "fancy_name") - usingXmlConfig() - } - } - - dependencies { - jooqCodegen("org.postgresql:postgresql:42.3.6") - } + dependencies { + jooqCodegen("org.postgresql:postgresql:42.3.6") + } """.trimIndent() } copyResource( from = "/V01__init_multiple_schemas.sql", - to = "src/main/resources/db/migration/V01__init_multiple_schemas.sql" + to = "src/main/resources/db/migration/V01__init_multiple_schemas.sql", ) copyResource(from = "/jooq-generator-with-mappings.xml", to = "src/main/resources/db/jooq.xml") @@ -142,10 +141,10 @@ class XmlBasedConfigJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalT expect { that(result).getTaskOutcome("generateJooqClasses") isEqualTo SUCCESS that( - projectFile("build/generated-jooq/org/jooq/generated/fancy_name/tables/PrefixedFoo.java") + projectFile("build/generated-jooq/org/jooq/generated/fancy_name/tables/PrefixedFoo.java"), ).exists() that( - projectFile("build/generated-jooq/org/jooq/generated/other/tables/PrefixedBar.java") + projectFile("build/generated-jooq/org/jooq/generated/other/tables/PrefixedBar.java"), ).exists() } } diff --git a/src/test/kotlin/dev/monosoul/jooq/functional/ZeroConfigurationJooqDockerPluginFunctionalTest.kt b/src/test/kotlin/dev/monosoul/jooq/functional/ZeroConfigurationJooqDockerPluginFunctionalTest.kt index 13aa8ba..0a320df 100644 --- a/src/test/kotlin/dev/monosoul/jooq/functional/ZeroConfigurationJooqDockerPluginFunctionalTest.kt +++ b/src/test/kotlin/dev/monosoul/jooq/functional/ZeroConfigurationJooqDockerPluginFunctionalTest.kt @@ -7,23 +7,22 @@ import strikt.assertions.isEqualTo import strikt.java.exists class ZeroConfigurationJooqDockerPluginFunctionalTest : JooqDockerPluginFunctionalTestBase() { - @Test fun `should generate jooq classes for PostgreSQL db with default config`() { // given prepareBuildGradleFile { """ - plugins { - id("dev.monosoul.jooq-docker") - } + plugins { + id("dev.monosoul.jooq-docker") + } - repositories { - mavenCentral() - } + repositories { + mavenCentral() + } - dependencies { - jooqCodegen("org.postgresql:postgresql:42.3.6") - } + dependencies { + jooqCodegen("org.postgresql:postgresql:42.3.6") + } """.trimIndent() } copyResource(from = "/V01__init.sql", to = "src/main/resources/db/migration/V01__init.sql") @@ -35,7 +34,7 @@ class ZeroConfigurationJooqDockerPluginFunctionalTest : JooqDockerPluginFunction expect { that(result).generateJooqClassesTask.outcome isEqualTo SUCCESS that( - projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java") + projectFile("build/generated-jooq/org/jooq/generated/tables/Foo.java"), ).exists() } } diff --git a/src/test/kotlin/dev/monosoul/jooq/migration/ClasspathTest.kt b/src/test/kotlin/dev/monosoul/jooq/migration/ClasspathTest.kt index 4186c13..2365bef 100644 --- a/src/test/kotlin/dev/monosoul/jooq/migration/ClasspathTest.kt +++ b/src/test/kotlin/dev/monosoul/jooq/migration/ClasspathTest.kt @@ -16,7 +16,6 @@ import strikt.assertions.withElementAt import kotlin.streams.asStream class ClasspathTest { - private lateinit var project: Project @BeforeEach @@ -49,22 +48,23 @@ class ClasspathTest { } @TestFactory - fun `given a files collection, when getting path, then return the collection as is`() = sequenceOf( - "multiple dirs" to project.files("someDir", "someOtherDir"), - "single dir" to project.files("someDir"), - "project dir" to project.files(), - ).map { (description, paths) -> - dynamicTest("given $description, should return path as is") { - // when - val actual = MigrationLocation.Classpath(paths) + fun `given a files collection, when getting path, then return the collection as is`() = + sequenceOf( + "multiple dirs" to project.files("someDir", "someOtherDir"), + "single dir" to project.files("someDir"), + "project dir" to project.files(), + ).map { (description, paths) -> + dynamicTest("given $description, should return path as is") { + // when + val actual = MigrationLocation.Classpath(paths) - // then - expectThat(actual) { - get { path } isEqualTo paths - get { locations } isEqualTo listOf("classpath:/db/migration") + // then + expectThat(actual) { + get { path } isEqualTo paths + get { locations } isEqualTo listOf("classpath:/db/migration") + } } - } - }.asStream() + }.asStream() @Test fun `given a file collection, when getting locations, then should prefix them all with classpath`() { diff --git a/src/test/kotlin/dev/monosoul/jooq/migration/FilesystemTest.kt b/src/test/kotlin/dev/monosoul/jooq/migration/FilesystemTest.kt index b48a0ba..ecd0e55 100644 --- a/src/test/kotlin/dev/monosoul/jooq/migration/FilesystemTest.kt +++ b/src/test/kotlin/dev/monosoul/jooq/migration/FilesystemTest.kt @@ -16,7 +16,6 @@ import strikt.assertions.withElementAt import kotlin.streams.asStream class FilesystemTest { - private lateinit var project: Project @BeforeEach @@ -49,32 +48,34 @@ class FilesystemTest { } @TestFactory - fun `given a files collection, when getting path, then return the collection as is`() = sequenceOf( - "multiple dirs" to project.files("someDir", "someOtherDir"), - "single dir" to project.files("someDir"), - "project dir" to project.files(), - ).map { (description, paths) -> - dynamicTest("given $description, should return path as is") { - // when - val actual = MigrationLocation.Filesystem(paths).path + fun `given a files collection, when getting path, then return the collection as is`() = + sequenceOf( + "multiple dirs" to project.files("someDir", "someOtherDir"), + "single dir" to project.files("someDir"), + "project dir" to project.files(), + ).map { (description, paths) -> + dynamicTest("given $description, should return path as is") { + // when + val actual = MigrationLocation.Filesystem(paths).path - // then - expectThat(actual) isEqualTo paths - } - }.asStream() + // then + expectThat(actual) isEqualTo paths + } + }.asStream() @TestFactory - fun `given a files collection, when getting extraClasspath, then return an empty list`() = sequenceOf( - "multiple dirs" to project.files("someDir", "someOtherDir"), - "single dir" to project.files("someDir"), - "project dir" to project.files(), - ).map { (description, paths) -> - dynamicTest("given $description, should return empty extra classpath") { - // when - val actual = MigrationLocation.Filesystem(paths).extraClasspath() + fun `given a files collection, when getting extraClasspath, then return an empty list`() = + sequenceOf( + "multiple dirs" to project.files("someDir", "someOtherDir"), + "single dir" to project.files("someDir"), + "project dir" to project.files(), + ).map { (description, paths) -> + dynamicTest("given $description, should return empty extra classpath") { + // when + val actual = MigrationLocation.Filesystem(paths).extraClasspath() - // then - expectThat(actual).isEmpty() - } - }.asStream() + // then + expectThat(actual).isEmpty() + } + }.asStream() } diff --git a/src/test/kotlin/dev/monosoul/jooq/settings/JooqDockerPluginSettingsTest.kt b/src/test/kotlin/dev/monosoul/jooq/settings/JooqDockerPluginSettingsTest.kt index 03d1e42..76dc7f8 100644 --- a/src/test/kotlin/dev/monosoul/jooq/settings/JooqDockerPluginSettingsTest.kt +++ b/src/test/kotlin/dev/monosoul/jooq/settings/JooqDockerPluginSettingsTest.kt @@ -10,46 +10,46 @@ import strikt.assertions.isTrue import kotlin.streams.asStream class JooqDockerPluginSettingsTest { - @TestFactory - fun `JooqDockerPluginSettings implementations should implement equals and hashcode`() = sequenceOf( - WithContainer().let { - Triple( - it, - it.copy(), - WithContainer().apply { - database.apply { - name = "dbname" - } - image.apply { - name = "imagename" - } - }, - ) - }, - WithoutContainer().let { - Triple( - it, - it.copy(), - WithoutContainer().apply { - database.apply { - name = "dbname" - } - }, - ) - } - ).map { (instance, instanceCopy, differentInstance) -> - dynamicTest("${instance::class.simpleName} should implement equals and hashcode") { - expect { - @Suppress("KotlinConstantConditions") - that(instance == instance).isTrue() - that(instance == instanceCopy).isTrue() - that(instance == differentInstance).isFalse() + fun `JooqDockerPluginSettings implementations should implement equals and hashcode`() = + sequenceOf( + WithContainer().let { + Triple( + it, + it.copy(), + WithContainer().apply { + database.apply { + name = "dbname" + } + image.apply { + name = "imagename" + } + }, + ) + }, + WithoutContainer().let { + Triple( + it, + it.copy(), + WithoutContainer().apply { + database.apply { + name = "dbname" + } + }, + ) + }, + ).map { (instance, instanceCopy, differentInstance) -> + dynamicTest("${instance::class.simpleName} should implement equals and hashcode") { + expect { + @Suppress("KotlinConstantConditions") + that(instance == instance).isTrue() + that(instance == instanceCopy).isTrue() + that(instance == differentInstance).isFalse() - that(instance.hashCode() == instance.hashCode()).isTrue() - that(instance.hashCode() == instanceCopy.hashCode()).isTrue() - that(instance.hashCode() == differentInstance.hashCode()).isFalse() + that(instance.hashCode() == instance.hashCode()).isTrue() + that(instance.hashCode() == instanceCopy.hashCode()).isTrue() + that(instance.hashCode() == differentInstance.hashCode()).isFalse() + } } - } - }.asStream() + }.asStream() } diff --git a/src/testFixtures/kotlin/dev/monosoul/jooq/functional/FunctionalTestBase.kt b/src/testFixtures/kotlin/dev/monosoul/jooq/functional/FunctionalTestBase.kt index 80678c9..a8e9bcb 100644 --- a/src/testFixtures/kotlin/dev/monosoul/jooq/functional/FunctionalTestBase.kt +++ b/src/testFixtures/kotlin/dev/monosoul/jooq/functional/FunctionalTestBase.kt @@ -10,7 +10,6 @@ import java.io.File import java.io.FileOutputStream abstract class FunctionalTestBase { - @TempDir private lateinit var projectDir: File @@ -19,14 +18,18 @@ abstract class FunctionalTestBase { projectDir.mkdirs() } - protected fun runGradleWithArguments(vararg arguments: String): BuildResult = GradleRunner.create() - .withProjectDir(projectDir) - .withPluginClasspath() - .forwardOutput() - .withArguments(*arguments, "--stacktrace", "--info") - .build() - - protected fun copyResource(from: String, to: String) { + protected fun runGradleWithArguments(vararg arguments: String): BuildResult = + GradleRunner.create() + .withProjectDir(projectDir) + .withPluginClasspath() + .forwardOutput() + .withArguments(*arguments, "--stacktrace", "--info") + .build() + + protected fun copyResource( + from: String, + to: String, + ) { val destinationFile = projectFile(to) javaClass.getResourceAsStream(from)?.use { sourceStream -> FileOutputStream(destinationFile).use { destinationStream -> @@ -35,16 +38,22 @@ abstract class FunctionalTestBase { } ?: throw IllegalStateException("Resource not found: $from") } - protected fun prepareBuildGradleFile(scriptName: String = "build.gradle.kts", scriptSupplier: () -> String) = - writeProjectFile(scriptName, scriptSupplier) + protected fun prepareBuildGradleFile( + scriptName: String = "build.gradle.kts", + scriptSupplier: () -> String, + ) = writeProjectFile(scriptName, scriptSupplier) - protected fun writeProjectFile(fileName: String, bodySupplier: () -> String) = projectFile(fileName) + protected fun writeProjectFile( + fileName: String, + bodySupplier: () -> String, + ) = projectFile(fileName) .writeText(bodySupplier()) protected fun projectFile(fileName: String) = File(projectDir, fileName).also { it.parentFile.mkdirs() } - protected fun Assertion.Builder.getTask(taskName: String) = get { task(":$taskName") } - .describedAs("Task $taskName") + protected fun Assertion.Builder.getTask(taskName: String) = + get { task(":$taskName") } + .describedAs("Task $taskName") protected val Assertion.Builder.outcome get() = isNotNull().get { outcome }