From 09de0215188af6c2e35120ba2249df344f8b9de6 Mon Sep 17 00:00:00 2001 From: monosoul Date: Sun, 9 Jun 2024 15:25:11 +0200 Subject: [PATCH] refactor(formatting): apply new linter rules --- artifact-tests/build.gradle.kts | 6 ++-- build.gradle.kts | 3 +- .../monosoul/jooq/GenerateJooqClassesTask.kt | 33 +++++++++++-------- .../dev/monosoul/jooq/JooqDockerPlugin.kt | 11 ++++--- .../kotlin/dev/monosoul/jooq/JooqExtension.kt | 6 ++-- .../jooq/codegen/ConfigurationProvider.kt | 11 +++---- .../codegen/ReflectiveJooqCodegenRunner.kt | 19 ++++++----- .../container/GenericDatabaseContainer.kt | 6 ++-- .../jooq/migration/BuiltInMigrationRunner.kt | 4 ++- .../jooq/migration/MigrationLocation.kt | 6 ++-- .../migration/ReflectiveMigrationRunner.kt | 8 +++-- .../monosoul/jooq/migration/SchemaVersion.kt | 4 ++- .../migration/UniversalMigrationRunner.kt | 8 +++-- .../dev/monosoul/jooq/settings/Database.kt | 4 ++- .../jooq/settings/JooqDockerPluginSettings.kt | 7 ++-- .../jooq/settings/PropertiesReader.kt | 13 +++++--- .../util/CodegenClasspathAwareClassLoaders.kt | 18 +++++----- .../monosoul/jooq/util/ConfigurationCopy.kt | 11 ++++--- .../container/GenericDatabaseContainerTest.kt | 4 ++- .../jooq/functional/FunctionalTestBase.kt | 3 +- 20 files changed, 111 insertions(+), 74 deletions(-) diff --git a/artifact-tests/build.gradle.kts b/artifact-tests/build.gradle.kts index c427fe0..83c5efb 100644 --- a/artifact-tests/build.gradle.kts +++ b/artifact-tests/build.gradle.kts @@ -46,7 +46,8 @@ tasks { withType { filesMatching("**/build.gradle.kts") { filter { - it.replace("@plugin.version@", rootProject.version.toString()) + it + .replace("@plugin.version@", rootProject.version.toString()) .replace("@testcontainers.version@", libs.versions.testcontainers.get()) } } @@ -54,7 +55,8 @@ tasks { processTestTemplates { filter { - it.replace("@gradle.version@", gradle.gradleVersion) + it + .replace("@gradle.version@", gradle.gradleVersion) .replace("@plugin.version@", rootProject.version.toString()) } } diff --git a/build.gradle.kts b/build.gradle.kts index 5157776..bcd23d1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -41,7 +41,8 @@ tasks { processTemplates { filter { - it.replace("@jooq.version@", libs.versions.jooq.get()) + it + .replace("@jooq.version@", libs.versions.jooq.get()) .replace("@flyway.version@", libs.versions.flyway.get()) } } diff --git a/src/main/kotlin/dev/monosoul/jooq/GenerateJooqClassesTask.kt b/src/main/kotlin/dev/monosoul/jooq/GenerateJooqClassesTask.kt index 7d381f0..769b236 100644 --- a/src/main/kotlin/dev/monosoul/jooq/GenerateJooqClassesTask.kt +++ b/src/main/kotlin/dev/monosoul/jooq/GenerateJooqClassesTask.kt @@ -52,7 +52,8 @@ open class GenerateJooqClassesTask private val providerFactory: ProviderFactory, private val fsOperations: FileSystemOperations, private val projectLayout: ProjectLayout, - ) : DefaultTask(), SettingsAware { + ) : DefaultTask(), + SettingsAware { /** * List of schemas to take into account when running migrations and generating code. */ @@ -91,9 +92,10 @@ open class GenerateJooqClassesTask private val _generatorConfig = objectFactory.property>().convention( - providerFactory.provider { - configurationProvider.defaultConfiguration() - }.map(::PrivateValueHolder), + providerFactory + .provider { + configurationProvider.defaultConfiguration() + }.map(::PrivateValueHolder), ) /** @@ -199,9 +201,11 @@ open class GenerateJooqClassesTask customizer: Action = Action { }, ) { _generatorConfig.set( - configurationProvider.fromXml(providerFactory.fileContents(file)).map { config -> - config.also { customizer.execute(it.generator) } - }.map(::PrivateValueHolder), + configurationProvider + .fromXml(providerFactory.fileContents(file)) + .map { config -> + config.also { customizer.execute(it.generator) } + }.map(::PrivateValueHolder), ) } @@ -220,11 +224,12 @@ open class GenerateJooqClassesTask @Suppress("unused") fun usingJavaConfig(customizer: Action) { _generatorConfig.set( - providerFactory.provider { - configurationProvider.defaultConfiguration().also { - customizer.execute(it.generator) - } - }.map(::PrivateValueHolder), + providerFactory + .provider { + configurationProvider.defaultConfiguration().also { + customizer.execute(it.generator) + } + }.map(::PrivateValueHolder), ) } @@ -236,7 +241,9 @@ open class GenerateJooqClassesTask @TaskAction fun generateClasses() { - _pluginSettings.get().value + _pluginSettings + .get() + .value .runWithDatabaseCredentials(classLoaders()) { classLoaders, credentials -> val schemaVersion = migrationRunner.migrateDb(classLoaders, credentials) generateJooqClasses(classLoaders, credentials, schemaVersion) diff --git a/src/main/kotlin/dev/monosoul/jooq/JooqDockerPlugin.kt b/src/main/kotlin/dev/monosoul/jooq/JooqDockerPlugin.kt index 752f61f..14f79cf 100644 --- a/src/main/kotlin/dev/monosoul/jooq/JooqDockerPlugin.kt +++ b/src/main/kotlin/dev/monosoul/jooq/JooqDockerPlugin.kt @@ -31,11 +31,12 @@ open class JooqDockerPlugin "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() + project.properties.entries + .filter { (key, _) -> + key.startsWith(PropertiesReader.PREFIX) + }.mapNotNull { (key, value) -> + (value as? String)?.let { key to it } + }.toMap() }, ) tasks.register("generateJooqClasses") diff --git a/src/main/kotlin/dev/monosoul/jooq/JooqExtension.kt b/src/main/kotlin/dev/monosoul/jooq/JooqExtension.kt index b7791f9..aab8385 100644 --- a/src/main/kotlin/dev/monosoul/jooq/JooqExtension.kt +++ b/src/main/kotlin/dev/monosoul/jooq/JooqExtension.kt @@ -18,9 +18,11 @@ open class JooqExtension constructor( private val propertiesProvider: Provider>, objectFactory: ObjectFactory, - ) : Serializable, SettingsAware { + ) : Serializable, + SettingsAware { internal val pluginSettings: Property = - objectFactory.property() + objectFactory + .property() .convention( propertiesProvider.map { WithContainer().applyPropertiesFrom(it) diff --git a/src/main/kotlin/dev/monosoul/jooq/codegen/ConfigurationProvider.kt b/src/main/kotlin/dev/monosoul/jooq/codegen/ConfigurationProvider.kt index 62318cc..de9aa99 100644 --- a/src/main/kotlin/dev/monosoul/jooq/codegen/ConfigurationProvider.kt +++ b/src/main/kotlin/dev/monosoul/jooq/codegen/ConfigurationProvider.kt @@ -42,12 +42,10 @@ internal class ConfigurationProvider( .withSchemata(schemas.get().map(this::toSchemaMappingType)) .withIncludes(".*") .withExcludes(""), - ) - .withGenerate(Generate()) + ).withGenerate(Generate()) .let { Configuration().withGenerator(it) - } - .applyCommonConfiguration() + }.applyCommonConfiguration() private fun Configuration.applyCommonConfiguration() = also { config -> @@ -68,11 +66,10 @@ internal class ConfigurationProvider( .withEncoding("UTF-8") .withClean(true) - private fun toSchemaMappingType(schemaName: String): SchemaMappingType { - return SchemaMappingType() + private fun toSchemaMappingType(schemaName: String): SchemaMappingType = + SchemaMappingType() .withInputSchema(schemaName) .withOutputSchemaToDefault(outputSchemaToDefault.get().contains(schemaName)) - } private fun Map.toMappingApplier(): (Strategy) -> Unit = { strategy -> diff --git a/src/main/kotlin/dev/monosoul/jooq/codegen/ReflectiveJooqCodegenRunner.kt b/src/main/kotlin/dev/monosoul/jooq/codegen/ReflectiveJooqCodegenRunner.kt index fc7f11c..6177b33 100644 --- a/src/main/kotlin/dev/monosoul/jooq/codegen/ReflectiveJooqCodegenRunner.kt +++ b/src/main/kotlin/dev/monosoul/jooq/codegen/ReflectiveJooqCodegenRunner.kt @@ -23,7 +23,9 @@ internal class ReflectiveJooqCodegenRunner( * Wrapper for jOOQ code generation tool object obtained via reflection. * @see GenerationTool */ - private class ReflectiveGenerationTool(codegenAwareClassLoader: ClassLoader) { + private class ReflectiveGenerationTool( + codegenAwareClassLoader: ClassLoader, + ) { private val toolClass = codegenAwareClassLoader.loadClass(GenerationTool::class.jvmName) private val configurationClass = codegenAwareClassLoader.loadClass(Configuration::class.jvmName) private val tool = toolClass.getDeclaredConstructor().newInstance() @@ -61,13 +63,14 @@ internal class ReflectiveJooqCodegenRunner( } private fun Configuration.toXmlByteArray() = - ByteArrayOutputStream().also { stream -> - stream.writer().use { writer -> - @Suppress("UnstableApiUsage") - MiniJAXB.marshal(this, writer) - writer.flush() - } - }.toByteArray() + 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/container/GenericDatabaseContainer.kt b/src/main/kotlin/dev/monosoul/jooq/container/GenericDatabaseContainer.kt index c6af65a..c5d1f62 100644 --- a/src/main/kotlin/dev/monosoul/jooq/container/GenericDatabaseContainer.kt +++ b/src/main/kotlin/dev/monosoul/jooq/container/GenericDatabaseContainer.kt @@ -83,13 +83,13 @@ class GenericDatabaseContainer( * Workaround for https://github.com/testcontainers/testcontainers-java/issues/6441 */ val failFastAlways = - DockerClientProviderStrategy::class.declaredMembers + DockerClientProviderStrategy::class + .declaredMembers .single { it.name == "FAIL_FAST_ALWAYS" } .apply { isAccessible = true } .let { @Suppress("UNCHECKED_CAST") it as KCallable - } - .call() + }.call() } } diff --git a/src/main/kotlin/dev/monosoul/jooq/migration/BuiltInMigrationRunner.kt b/src/main/kotlin/dev/monosoul/jooq/migration/BuiltInMigrationRunner.kt index 4f29730..3ec9378 100644 --- a/src/main/kotlin/dev/monosoul/jooq/migration/BuiltInMigrationRunner.kt +++ b/src/main/kotlin/dev/monosoul/jooq/migration/BuiltInMigrationRunner.kt @@ -3,7 +3,9 @@ package dev.monosoul.jooq.migration import dev.monosoul.jooq.settings.DatabaseCredentials import org.flywaydb.core.Flyway -internal class BuiltInMigrationRunner(codegenAwareClassLoader: ClassLoader) : MigrationRunner { +internal class BuiltInMigrationRunner( + codegenAwareClassLoader: ClassLoader, +) : MigrationRunner { private val flyway = Flyway.configure(codegenAwareClassLoader) override fun migrateDb( diff --git a/src/main/kotlin/dev/monosoul/jooq/migration/MigrationLocation.kt b/src/main/kotlin/dev/monosoul/jooq/migration/MigrationLocation.kt index deb70cc..08508d0 100644 --- a/src/main/kotlin/dev/monosoul/jooq/migration/MigrationLocation.kt +++ b/src/main/kotlin/dev/monosoul/jooq/migration/MigrationLocation.kt @@ -129,13 +129,13 @@ sealed class MigrationLocation { constructor(path: FileCollection) : this(path, "/db/migration") override fun extraClasspath(): List = - path.asSequence() + path + .asSequence() .flatMap { file -> listOf(file).plus( file.listFiles { _, name -> name.endsWith(".jar") }?.asList() ?: emptyList(), ) - } - .map { it.toURI().toURL() } + }.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 c958f0b..a44bba5 100644 --- a/src/main/kotlin/dev/monosoul/jooq/migration/ReflectiveMigrationRunner.kt +++ b/src/main/kotlin/dev/monosoul/jooq/migration/ReflectiveMigrationRunner.kt @@ -9,7 +9,9 @@ import kotlin.reflect.KFunction2 import kotlin.reflect.KFunction4 import kotlin.reflect.jvm.jvmName -internal class ReflectiveMigrationRunner(codegenAwareClassLoader: ClassLoader) : MigrationRunner { +internal class ReflectiveMigrationRunner( + codegenAwareClassLoader: ClassLoader, +) : MigrationRunner { private val flyway = ReflectiveFlywayConfiguration(codegenAwareClassLoader) override fun migrateDb( @@ -33,7 +35,9 @@ internal class ReflectiveMigrationRunner(codegenAwareClassLoader: ClassLoader) : * Wrapper for Flyway configuration object obtained via reflection. * @see FluentConfiguration */ - private class ReflectiveFlywayConfiguration(private val codegenAwareClassLoader: ClassLoader) { + private class ReflectiveFlywayConfiguration( + private val codegenAwareClassLoader: ClassLoader, + ) { private val flywayClass = codegenAwareClassLoader.loadClass(Flyway::class.jvmName) private val configurationClass = codegenAwareClassLoader.loadClass(FluentConfiguration::class.jvmName) diff --git a/src/main/kotlin/dev/monosoul/jooq/migration/SchemaVersion.kt b/src/main/kotlin/dev/monosoul/jooq/migration/SchemaVersion.kt index d2b5962..7d746df 100644 --- a/src/main/kotlin/dev/monosoul/jooq/migration/SchemaVersion.kt +++ b/src/main/kotlin/dev/monosoul/jooq/migration/SchemaVersion.kt @@ -1,3 +1,5 @@ package dev.monosoul.jooq.migration -internal data class SchemaVersion(val value: String) +internal data class SchemaVersion( + val value: String, +) diff --git a/src/main/kotlin/dev/monosoul/jooq/migration/UniversalMigrationRunner.kt b/src/main/kotlin/dev/monosoul/jooq/migration/UniversalMigrationRunner.kt index ef82da7..b8745c3 100644 --- a/src/main/kotlin/dev/monosoul/jooq/migration/UniversalMigrationRunner.kt +++ b/src/main/kotlin/dev/monosoul/jooq/migration/UniversalMigrationRunner.kt @@ -34,9 +34,11 @@ internal class UniversalMigrationRunner( logger.info("Migration locations: {}", resolvedMigrationLocations) val extraClasspath = - resolvedMigrationLocations.flatMap { it.extraClasspath() }.also { - logger.info("Migration will run using extra classpath: {}", it) - }.toTypedArray() + resolvedMigrationLocations + .flatMap { it.extraClasspath() } + .also { + logger.info("Migration will run using extra classpath: {}", it) + }.toTypedArray() return runCatching { ReflectiveMigrationRunner( diff --git a/src/main/kotlin/dev/monosoul/jooq/settings/Database.kt b/src/main/kotlin/dev/monosoul/jooq/settings/Database.kt index cc0e2f6..e8235f5 100644 --- a/src/main/kotlin/dev/monosoul/jooq/settings/Database.kt +++ b/src/main/kotlin/dev/monosoul/jooq/settings/Database.kt @@ -5,7 +5,9 @@ import org.gradle.api.tasks.Input import org.gradle.api.tasks.Nested import org.gradle.api.tasks.Internal as GradleInternal -sealed class Database : JdbcAware, SettingsElement { +sealed class Database : + JdbcAware, + SettingsElement { @get:Input abstract var username: String diff --git a/src/main/kotlin/dev/monosoul/jooq/settings/JooqDockerPluginSettings.kt b/src/main/kotlin/dev/monosoul/jooq/settings/JooqDockerPluginSettings.kt index b95b951..25fbd6b 100644 --- a/src/main/kotlin/dev/monosoul/jooq/settings/JooqDockerPluginSettings.kt +++ b/src/main/kotlin/dev/monosoul/jooq/settings/JooqDockerPluginSettings.kt @@ -21,7 +21,9 @@ sealed class JooqDockerPluginSettings : SettingsElement { class WithContainer private constructor( override val database: Database.Internal, @get:Nested internal val image: Image, - ) : JooqDockerPluginSettings(), DbAware, ImageAware { + ) : JooqDockerPluginSettings(), + DbAware, + ImageAware { private constructor(database: Database.Internal) : this(database, Image(database)) constructor(customizer: Action = Action { }) : this(Database.Internal()) { customizer.execute(this) @@ -70,7 +72,8 @@ sealed class JooqDockerPluginSettings : SettingsElement { class WithoutContainer private constructor( override val database: Database.External, - ) : JooqDockerPluginSettings(), DbAware { + ) : JooqDockerPluginSettings(), + DbAware { constructor(customizer: Action = Action { }) : this(Database.External()) { customizer.execute(this) } diff --git a/src/main/kotlin/dev/monosoul/jooq/settings/PropertiesReader.kt b/src/main/kotlin/dev/monosoul/jooq/settings/PropertiesReader.kt index 4f37f3d..4b40a23 100644 --- a/src/main/kotlin/dev/monosoul/jooq/settings/PropertiesReader.kt +++ b/src/main/kotlin/dev/monosoul/jooq/settings/PropertiesReader.kt @@ -70,11 +70,14 @@ internal object PropertiesReader { pluginProperties.findAndSetProperty(prefix, ::testQuery) val envVarsPrefix = "$prefix${::envVars.name}." - pluginProperties.filterKeys { it.startsWith(envVarsPrefix) }.map { (key, value) -> - key.removePrefix(envVarsPrefix) to value.toString() - }.takeIf { it.isNotEmpty() }?.also { - envVars = it.toMap() - } + pluginProperties + .filterKeys { it.startsWith(envVarsPrefix) } + .map { (key, value) -> + key.removePrefix(envVarsPrefix) to value.toString() + }.takeIf { it.isNotEmpty() } + ?.also { + envVars = it.toMap() + } } @Suppress("UNCHECKED_CAST") diff --git a/src/main/kotlin/dev/monosoul/jooq/util/CodegenClasspathAwareClassLoaders.kt b/src/main/kotlin/dev/monosoul/jooq/util/CodegenClasspathAwareClassLoaders.kt index 1a12924..6ae7369 100644 --- a/src/main/kotlin/dev/monosoul/jooq/util/CodegenClasspathAwareClassLoaders.kt +++ b/src/main/kotlin/dev/monosoul/jooq/util/CodegenClasspathAwareClassLoaders.kt @@ -9,13 +9,15 @@ internal class CodegenClasspathAwareClassLoaders( ) { companion object { fun from(classpath: FileCollection) = - classpath.map { - it.toURI().toURL() - }.toTypedArray().let { - CodegenClasspathAwareClassLoaders( - buildscriptExclusive = URLClassLoader(it), - buildscriptInclusive = URLClassLoader(it, CodegenClasspathAwareClassLoaders::class.java.classLoader), - ) - } + 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/ConfigurationCopy.kt b/src/main/kotlin/dev/monosoul/jooq/util/ConfigurationCopy.kt index a7ff37d..10c88f3 100644 --- a/src/main/kotlin/dev/monosoul/jooq/util/ConfigurationCopy.kt +++ b/src/main/kotlin/dev/monosoul/jooq/util/ConfigurationCopy.kt @@ -8,11 +8,12 @@ import java.io.ObjectOutputStream internal fun Configuration.copy(): Configuration { val serialized = - ByteArrayOutputStream().apply { - ObjectOutputStream(this).use { oos -> - oos.writeObject(this@copy) - } - }.toByteArray() + ByteArrayOutputStream() + .apply { + ObjectOutputStream(this).use { oos -> + oos.writeObject(this@copy) + } + }.toByteArray() return ObjectInputStream(ByteArrayInputStream(serialized)).use { ois -> ois.readObject() as Configuration diff --git a/src/test/kotlin/dev/monosoul/jooq/container/GenericDatabaseContainerTest.kt b/src/test/kotlin/dev/monosoul/jooq/container/GenericDatabaseContainerTest.kt index 6472ef5..13d2f4d 100644 --- a/src/test/kotlin/dev/monosoul/jooq/container/GenericDatabaseContainerTest.kt +++ b/src/test/kotlin/dev/monosoul/jooq/container/GenericDatabaseContainerTest.kt @@ -156,5 +156,7 @@ class GenericDatabaseContainerTest { expectThat(actual) isEqualTo database.password } - private class TestDriver(val mockDriver: Driver = mockk()) : Driver by mockDriver + private class TestDriver( + val mockDriver: Driver = mockk(), + ) : Driver by mockDriver } diff --git a/src/testFixtures/kotlin/dev/monosoul/jooq/functional/FunctionalTestBase.kt b/src/testFixtures/kotlin/dev/monosoul/jooq/functional/FunctionalTestBase.kt index 9b3af21..1d255f1 100644 --- a/src/testFixtures/kotlin/dev/monosoul/jooq/functional/FunctionalTestBase.kt +++ b/src/testFixtures/kotlin/dev/monosoul/jooq/functional/FunctionalTestBase.kt @@ -21,7 +21,8 @@ abstract class FunctionalTestBase { vararg arguments: String, projectDirectory: File = projectDir, ): BuildResult = - GradleRunner.create() + GradleRunner + .create() .withProjectDir(projectDirectory) .withPluginClasspath() .forwardOutput()