Skip to content

Commit

Permalink
refactor(formatting): apply new linter rules
Browse files Browse the repository at this point in the history
  • Loading branch information
monosoul authored and renovate[bot] committed Jun 9, 2024
1 parent 7bac14f commit 09de021
Show file tree
Hide file tree
Showing 20 changed files with 111 additions and 74 deletions.
6 changes: 4 additions & 2 deletions artifact-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,17 @@ tasks {
withType<ProcessResources> {
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())
}
}
}

processTestTemplates {
filter {
it.replace("@gradle.version@", gradle.gradleVersion)
it
.replace("@gradle.version@", gradle.gradleVersion)
.replace("@plugin.version@", rootProject.version.toString())
}
}
Expand Down
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
Expand Down
33 changes: 20 additions & 13 deletions src/main/kotlin/dev/monosoul/jooq/GenerateJooqClassesTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -91,9 +92,10 @@ open class GenerateJooqClassesTask

private val _generatorConfig =
objectFactory.property<PrivateValueHolder<Configuration>>().convention(
providerFactory.provider {
configurationProvider.defaultConfiguration()
}.map(::PrivateValueHolder),
providerFactory
.provider {
configurationProvider.defaultConfiguration()
}.map(::PrivateValueHolder),
)

/**
Expand Down Expand Up @@ -199,9 +201,11 @@ open class GenerateJooqClassesTask
customizer: Action<Generator> = Action<Generator> { },
) {
_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),
)
}

Expand All @@ -220,11 +224,12 @@ open class GenerateJooqClassesTask
@Suppress("unused")
fun usingJavaConfig(customizer: Action<Generator>) {
_generatorConfig.set(
providerFactory.provider {
configurationProvider.defaultConfiguration().also {
customizer.execute(it.generator)
}
}.map(::PrivateValueHolder),
providerFactory
.provider {
configurationProvider.defaultConfiguration().also {
customizer.execute(it.generator)
}
}.map(::PrivateValueHolder),
)
}

Expand All @@ -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)
Expand Down
11 changes: 6 additions & 5 deletions src/main/kotlin/dev/monosoul/jooq/JooqDockerPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<GenerateJooqClassesTask>("generateJooqClasses")
Expand Down
6 changes: 4 additions & 2 deletions src/main/kotlin/dev/monosoul/jooq/JooqExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ open class JooqExtension
constructor(
private val propertiesProvider: Provider<Map<String, String>>,
objectFactory: ObjectFactory,
) : Serializable, SettingsAware {
) : Serializable,
SettingsAware {
internal val pluginSettings: Property<JooqDockerPluginSettings> =
objectFactory.property<JooqDockerPluginSettings>()
objectFactory
.property<JooqDockerPluginSettings>()
.convention(
propertiesProvider.map {
WithContainer().applyPropertiesFrom(it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand All @@ -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<String, String>.toMappingApplier(): (Strategy) -> Unit =
{ strategy ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<AtomicBoolean>
}
.call()
}.call()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ sealed class MigrationLocation {
constructor(path: FileCollection) : this(path, "/db/migration")

override fun extraClasspath(): List<URL> =
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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)

Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/dev/monosoul/jooq/migration/SchemaVersion.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package dev.monosoul.jooq.migration

internal data class SchemaVersion(val value: String)
internal data class SchemaVersion(
val value: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/dev/monosoul/jooq/settings/Database.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Database.Internal>, ImageAware {
) : JooqDockerPluginSettings(),
DbAware<Database.Internal>,
ImageAware {
private constructor(database: Database.Internal) : this(database, Image(database))
constructor(customizer: Action<WithContainer> = Action<WithContainer> { }) : this(Database.Internal()) {
customizer.execute(this)
Expand Down Expand Up @@ -70,7 +72,8 @@ sealed class JooqDockerPluginSettings : SettingsElement {

class WithoutContainer private constructor(
override val database: Database.External,
) : JooqDockerPluginSettings(), DbAware<Database.External> {
) : JooqDockerPluginSettings(),
DbAware<Database.External> {
constructor(customizer: Action<WithoutContainer> = Action<WithoutContainer> { }) : this(Database.External()) {
customizer.execute(this)
}
Expand Down
13 changes: 8 additions & 5 deletions src/main/kotlin/dev/monosoul/jooq/settings/PropertiesReader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
}
}
}
11 changes: 6 additions & 5 deletions src/main/kotlin/dev/monosoul/jooq/util/ConfigurationCopy.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ abstract class FunctionalTestBase {
vararg arguments: String,
projectDirectory: File = projectDir,
): BuildResult =
GradleRunner.create()
GradleRunner
.create()
.withProjectDir(projectDirectory)
.withPluginClasspath()
.forwardOutput()
Expand Down

0 comments on commit 09de021

Please sign in to comment.