Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Update dependency com.pinterest.ktlint:ktlint-cli to v1.3.0 #205

Merged
merged 2 commits into from
Jun 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions artifact-tests/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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())
}
}
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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())
}
}
2 changes: 1 addition & 1 deletion libs.versions.toml
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ junit-jupiter = { module = "org.junit.jupiter:junit-jupiter" }
strikt = "io.strikt:strikt-jvm:0.34.1"
mockk = "io.mockk:mockk-jvm:1.13.11"

ktlint = "com.pinterest.ktlint:ktlint-cli:1.2.1"
ktlint = "com.pinterest.ktlint:ktlint-cli:1.3.0"

# plugins
gradle-plugin-publish = "com.gradle.publish:plugin-publish-plugin:1.2.1"
33 changes: 20 additions & 13 deletions src/main/kotlin/dev/monosoul/jooq/GenerateJooqClassesTask.kt
Original file line number Diff line number Diff line change
@@ -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<PrivateValueHolder<Configuration>>().convention(
providerFactory.provider {
configurationProvider.defaultConfiguration()
}.map(::PrivateValueHolder),
providerFactory
.provider {
configurationProvider.defaultConfiguration()
}.map(::PrivateValueHolder),
)

/**
@@ -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),
)
}

@@ -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),
)
}

@@ -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)
11 changes: 6 additions & 5 deletions src/main/kotlin/dev/monosoul/jooq/JooqDockerPlugin.kt
Original file line number Diff line number Diff line change
@@ -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")
6 changes: 4 additions & 2 deletions src/main/kotlin/dev/monosoul/jooq/JooqExtension.kt
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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<String, String>.toMappingApplier(): (Strategy) -> Unit =
{ strategy ->
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
@@ -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(
Original file line number Diff line number Diff line change
@@ -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
@@ -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)

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
@@ -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(
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
@@ -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

Original file line number Diff line number Diff line change
@@ -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)
@@ -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)
}
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
@@ -70,11 +70,14 @@
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()

Check warning on line 76 in src/main/kotlin/dev/monosoul/jooq/settings/PropertiesReader.kt

Codecov / codecov/patch

src/main/kotlin/dev/monosoul/jooq/settings/PropertiesReader.kt#L76

Added line #L76 was not covered by tests
}.takeIf { it.isNotEmpty() }
?.also {
envVars = it.toMap()

Check warning on line 79 in src/main/kotlin/dev/monosoul/jooq/settings/PropertiesReader.kt

Codecov / codecov/patch

src/main/kotlin/dev/monosoul/jooq/settings/PropertiesReader.kt#L79

Added line #L79 was not covered by tests
}
}

@Suppress("UNCHECKED_CAST")
Original file line number Diff line number Diff line change
@@ -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
@@ -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
Original file line number Diff line number Diff line change
@@ -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
}
Loading
Oops, something went wrong.
Loading
Oops, something went wrong.