diff --git a/AndroidCLI/build.gradle.kts b/AndroidCLI/build.gradle.kts index c3fa58ed93..965a843171 100644 --- a/AndroidCLI/build.gradle.kts +++ b/AndroidCLI/build.gradle.kts @@ -17,8 +17,8 @@ plugins { id("com.android.application") id("kotlin-android") - id("io.gitlab.arturbosch.detekt") - id("org.jlleitschuh.gradle.ktlint") + alias(libs.plugins.detekt) + alias(libs.plugins.ktlint) } repositories { @@ -28,7 +28,7 @@ repositories { android { compileSdk = Versions.ANDROID_SDK.version.toInt() - buildToolsVersion = Versions.ANDROID_BUILD_TOOLS.version + buildToolsVersion = libs.android.tools.gradle.get().version!! namespace = "com.bloomberg.selekt.cli" defaultConfig { applicationId = "com.bloomberg.selekt.cli" @@ -59,9 +59,9 @@ android { dependencies { implementation(projects.selektAndroid) - implementation(androidX("appcompat", version = "1.0.2")) - implementation(androidX("core", "ktx", version = "1.0.2")) - implementation(androidX("paging", "runtime", "2.1.0")) - implementation(androidX("constraintlayout", version = "1.1.3")) + implementation(libs.androidx.appcompat) + implementation(libs.androidx.constraintlayout) + implementation(libs.androidx.core.ktx) + implementation(libs.androidx.paging) runtimeOnly(projects.selektAndroidSqlcipher) } diff --git a/AndroidLibBenchmark/build.gradle.kts b/AndroidLibBenchmark/build.gradle.kts index bceeeea131..7b019c1399 100644 --- a/AndroidLibBenchmark/build.gradle.kts +++ b/AndroidLibBenchmark/build.gradle.kts @@ -17,9 +17,9 @@ plugins { id("com.android.library") id("kotlin-android") - id("androidx.benchmark") version Versions.ANDROID_BENCHMARK.version - id("io.gitlab.arturbosch.detekt") - id("org.jlleitschuh.gradle.ktlint") + alias(libs.plugins.androidx.benchmark) + alias(libs.plugins.detekt) + alias(libs.plugins.ktlint) } repositories { @@ -29,7 +29,7 @@ repositories { android { compileSdkVersion(Versions.ANDROID_SDK.version.toInt()) - buildToolsVersion(Versions.ANDROID_BUILD_TOOLS.version) + buildToolsVersion(libs.android.tools.gradle.get().version!!) namespace = "com.bloomberg.selekt.android.benchmark" defaultConfig { minSdkVersion(21) @@ -49,13 +49,12 @@ android { dependencies { androidTestImplementation(projects.selektAndroid) - androidTestImplementation("junit:junit:${Versions.JUNIT4}") - androidTestImplementation("androidx.test:runner:1.5.2") - androidTestImplementation("androidx.test:rules:1.5.0") - androidTestImplementation("androidx.test.ext:junit:1.1.5") - androidTestImplementation(androidX("benchmark", "junit4", Versions.ANDROID_BENCHMARK.version)) - androidTestImplementation(kotlin("test", Versions.KOTLIN.version)) - androidTestImplementation(kotlin("test-junit", Versions.KOTLIN.version)) - androidTestImplementation(kotlinX("coroutines-core", Versions.KOTLINX_COROUTINES.version)) - testImplementation(kotlinX("coroutines-core", Versions.KOTLINX_COROUTINES.version)) + androidTestImplementation(libs.androidx.benchmark) + androidTestImplementation(libs.androidx.test.rules) + androidTestImplementation(libs.androidx.test.runner) + androidTestImplementation(libs.junit.junit) + androidTestImplementation(libs.kotlin.test) + androidTestImplementation(libs.kotlin.test.junit) + androidTestImplementation(libs.kotlinx.coroutines.core) + testImplementation(libs.kotlinx.coroutines.core) } diff --git a/AndroidLibBenchmark/src/androidTest/kotlin/com/bloomberg/selekt/android/benchmark/SQLiteDatabaseCacheBenchmark.kt b/AndroidLibBenchmark/src/androidTest/kotlin/com/bloomberg/selekt/android/benchmark/SQLiteDatabaseCacheBenchmark.kt index ef71ee062d..b04683c3bb 100644 --- a/AndroidLibBenchmark/src/androidTest/kotlin/com/bloomberg/selekt/android/benchmark/SQLiteDatabaseCacheBenchmark.kt +++ b/AndroidLibBenchmark/src/androidTest/kotlin/com/bloomberg/selekt/android/benchmark/SQLiteDatabaseCacheBenchmark.kt @@ -91,10 +91,13 @@ internal class SQLiteDatabaseCacheBenchmark(private val inputs: CacheInputs) { CacheInputs("reuse", Array(10_000) { Pair("SELECT * FROM 'Foo' WHERE bar=?", arrayOf("$it")) }.asIterable()), - CacheInputs("waste", Array(10_000) { - Pair("SELECT * FROM 'Foo' WHERE bar=$it", arrayOf()) - }.asIterable() - )).asIterable() + CacheInputs( + "waste", + Array(10_000) { + Pair("SELECT * FROM 'Foo' WHERE bar=$it", arrayOf()) + }.asIterable() + ) + ).asIterable() } @After diff --git a/OpenSSL/build.gradle.kts b/OpenSSL/build.gradle.kts index 97cd7d9b46..dd6fd3ddc2 100644 --- a/OpenSSL/build.gradle.kts +++ b/OpenSSL/build.gradle.kts @@ -24,7 +24,7 @@ repositories { plugins { base - id("de.undercouch.download") version Versions.GRADLE_DOWNLOAD_TASK_PLUGIN.version + alias(libs.plugins.undercouch.download) } fun Project.openSslVersion() = property("openssl.version").toString() diff --git a/build.gradle.kts b/build.gradle.kts index 719f8e07b3..6dcf797525 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -16,7 +16,6 @@ import com.android.build.api.dsl.ApplicationExtension import com.android.build.api.dsl.LibraryExtension -import io.github.gradlenexus.publishplugin.NexusRepositoryContainer import io.gitlab.arturbosch.detekt.Detekt import io.gitlab.arturbosch.detekt.extensions.DetektExtension import java.net.URL @@ -34,13 +33,13 @@ import org.jlleitschuh.gradle.ktlint.tasks.GenerateReportsTask plugins { base - id("io.gitlab.arturbosch.detekt") version Versions.DETEKT.version - id("io.github.gradle-nexus.publish-plugin") version Versions.NEXUS_PLUGIN.version - id("org.jetbrains.dokka") version Versions.DOKKA.version - id("org.jetbrains.kotlinx.kover") version Versions.KOTLINX_KOVER.version - id("org.jetbrains.qodana") version Versions.QODANA_PLUGIN.version - id("org.jlleitschuh.gradle.ktlint") version Versions.KTLINT_GRADLE_PLUGIN.version - id("org.jetbrains.gradle.plugin.idea-ext") version Versions.IDE_EXT_GRADLE_PLUGIN.version + alias(libs.plugins.dokka) + alias(libs.plugins.kover) + alias(libs.plugins.nexus) + alias(libs.plugins.detekt) + alias(libs.plugins.ktlint) + alias(libs.plugins.ideaExt) + alias(libs.plugins.qodana) } repositories { @@ -52,12 +51,12 @@ version = selektVersionName logger.quiet("Group: {}; Version: {}", group, version) nexusPublishing { - repositories(Action { + repositories { sonatype() - }) + } transitionCheckOptions { - maxRetries.set(180) - delayBetween.set(Duration.ofSeconds(10L)) + maxRetries = 180 + delayBetween = Duration.ofSeconds(10L) } } @@ -66,7 +65,6 @@ dependencies { kover(projects.selektApi) kover(projects.selektJava) kover(projects.selektSqlite3Classes) - ktlint("com.pinterest:ktlint:${Versions.KTLINT}") } subprojects { @@ -83,16 +81,17 @@ subprojects { plugins.withId(it) { dependencies { configurations.getByName("compileOnly").apply { - add(name, "com.google.code.findbugs:jsr305:[2.0.2, ${Versions.JSR_305}]") + add(name, "com.google.code.findbugs:jsr305:[2.0.2, ${libs.findbugs.jsr305.get().version}]") } configurations.getByName("implementation").apply { - platform(kotlinX("coroutines-bom", version = Versions.KOTLINX_COROUTINES.version)) + add(name, platform(libs.kotlin.bom)) + add(name, platform(libs.kotlinx.coroutines.bom)) } configurations.getByName("testImplementation") { - add(name, kotlin("test", Versions.KOTLIN_TEST.version)) - add(name, kotlinX("coroutines-core", version = Versions.KOTLINX_COROUTINES.version)) - add(name, "org.mockito:mockito-core:${Versions.MOCKITO}") - add(name, "org.mockito.kotlin:mockito-kotlin:${Versions.MOCKITO_KOTLIN}") + add(name, libs.kotlin.test) + add(name, libs.kotlinx.coroutines.core) + add(name, libs.mockito.core) + add(name, libs.mockito.kotlin) } } } @@ -161,7 +160,6 @@ subprojects { } plugins.withId("io.gitlab.arturbosch.detekt") { configure { - toolVersion = Versions.DETEKT.version source = files("src") config = files("${rootProject.projectDir}/config/detekt/config.yml") buildUponDefaultConfig = true @@ -193,9 +191,10 @@ subprojects { moduleName.set("Selekt") dokkaSourceSets.named("main") { sourceLink { - remoteUrl.set(URL("https://github.com/bloomberg/selekt/tree/master/" + - "${this@configureEach.project.name}/src/main/kotlin")) - localDirectory.set(file("src/main/kotlin")) + remoteUrl = URL( + "https://github.com/bloomberg/selekt/tree/master/${this@configureEach.project.name}/src/main/kotlin" + ) + localDirectory = file("src/main/kotlin") } includeNonPublic.set(false) jdkVersion.set(JavaVersion.VERSION_17.majorVersion.toInt()) @@ -209,7 +208,6 @@ subprojects { allprojects { plugins.withId("org.jlleitschuh.gradle.ktlint") { configure { - version.set(Versions.KTLINT.version) disabledRules.set(setOf("import-ordering", "indent", "wrapping")) reporters { reporter(ReporterType.HTML) @@ -273,5 +271,5 @@ limitations under the License. } qodana { - saveReport.set(true) + saveReport = true } diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 615b5bab04..6c47a90a22 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -14,9 +14,6 @@ * limitations under the License. */ -// TODO Move me. -val kotlinVersion = "1.9.23" - plugins { `kotlin-dsl` `java-gradle-plugin` @@ -37,6 +34,6 @@ gradlePlugin { } dependencies { - implementation(kotlin("gradle-plugin", version = kotlinVersion)) - implementation("com.android.tools.build:gradle:8.3.2") + implementation(kotlin("gradle-plugin", version = libs.versions.kotlin.get())) + implementation(libs.android.tools.gradle) } diff --git a/buildSrc/settings.gradle.kts b/buildSrc/settings.gradle.kts index 8fa633c866..57277961a5 100644 --- a/buildSrc/settings.gradle.kts +++ b/buildSrc/settings.gradle.kts @@ -15,3 +15,11 @@ */ rootProject.name = "buildSrc" + +dependencyResolutionManagement { + versionCatalogs { + create("libs") { + from(files("../gradle/libs.versions.toml")) + } + } +} diff --git a/buildSrc/src/main/kotlin/SelektExtensions.kt b/buildSrc/src/main/kotlin/SelektExtensions.kt index b3e77635fe..2ab82d9c8b 100644 --- a/buildSrc/src/main/kotlin/SelektExtensions.kt +++ b/buildSrc/src/main/kotlin/SelektExtensions.kt @@ -16,25 +16,17 @@ import org.gradle.api.NamedDomainObjectContainer import org.gradle.api.Project -import org.gradle.api.artifacts.DependencySubstitutions -import org.gradle.api.artifacts.dsl.DependencyHandler import org.gradle.api.provider.Provider import org.gradle.api.publish.maven.MavenPom import org.gradle.kotlin.dsl.withType import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import java.net.URI -fun DependencyHandler.androidX(module: String, suffix: String? = null, version: String? = null): Any = - "androidx.$module:$module${suffix?.let { "-$it" }.orEmpty()}${version?.let { ":$it" }.orEmpty()}" +val NamedDomainObjectContainer.debug: T get() = getByName("debug") -fun DependencyHandler.kotlinX(module: String, version: String? = null): Any = - "org.jetbrains.kotlinx:kotlinx-$module${version?.let { ":$version" }.orEmpty()}" +fun NamedDomainObjectContainer.debug(configure: T.() -> Unit) = getByName("debug", configure) -val NamedDomainObjectContainer.debug: T get() = requireNotNull(getByName("debug")) - -fun NamedDomainObjectContainer.debug(configure: T.() -> Unit) = requireNotNull(getByName("debug", configure)) - -fun NamedDomainObjectContainer.release(configure: T.() -> Unit) = requireNotNull(getByName("release", configure)) +fun NamedDomainObjectContainer.release(configure: T.() -> Unit) = getByName("release", configure) fun Project.gitCommit(): Provider = providers.exec { commandLine("git", "rev-parse", "HEAD") diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index 148bb9d846..f5bce0704b 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -20,35 +20,8 @@ enum class Versions( val version: String, private val url: URL ) { - ANDROID_BENCHMARK("1.2.0-alpha13", URL("https://developer.android.com/studio/profile/benchmark")), - ANDROID_BUILD_TOOLS("34.0.0", URL("https://developer.android.com/studio/releases/build-tools")), - ANDROID_GRADLE_PLUGIN("8.3.2", URL("https://developer.android.com/tools/revisions/gradle-plugin.html")), - ANDROID_LINT("30.0.2", URL("https://github.com/googlesamples/android-custom-lint-rules")), - ANDROID_NDK("26.3.11579264", URL("https://developer.android.com/ndk")), ANDROID_SDK("34", URL("https://developer.android.com/sdk")), - ANDROIDX_LIVE_DATA("2.5.1", URL("https://developer.android.com/topic/libraries/architecture/livedata")), - ANDROIDX_ROOM("2.6.1", URL("https://developer.android.com/jetpack/androidx/releases/room")), - CMAKE("3.22.1", URL("https://cmake.org")), - DETEKT("1.22.0", URL("https://github.com/arturbosch/detekt")), - DOKKA("1.9.10", URL("https://github.com/Kotlin/dokka")), - GRADLE_DOWNLOAD_TASK_PLUGIN("5.4.0", URL("https://github.com/michel-kraemer/gradle-download-task")), - GRADLE_LICENSEE_PLUGIN("1.6.0", URL("https://github.com/cashapp/licensee")), - IDE_EXT_GRADLE_PLUGIN("1.1.7", URL("https://github.com/JetBrains/gradle-idea-ext-plugin")), - JMH("1.36", URL("https://openjdk.java.net/projects/code-tools/jmh/")), - JSR_305("3.0.2", URL("https://code.google.com/archive/p/jsr-305/")), - JUNIT4("4.13.2", URL("https://github.com/junit-team/junit4")), - JUNIT5("5.10.2", URL("https://junit.org/junit5/")), - KOTLIN("1.9.23", URL("https://github.com/JetBrains/kotlin")), - KOTLIN_TEST(KOTLIN.version, URL("https://github.com/JetBrains/kotlin")), - KOTLINX_COROUTINES("1.7.3", URL("https://github.com/Kotlin/kotlinx.coroutines")), - KOTLINX_KOVER("0.7.6", URL("https://github.com/Kotlin/kotlinx-kover")), - KTLINT("0.45.2", URL("https://github.com/pinterest/ktlint")), - KTLINT_GRADLE_PLUGIN("11.5.0", URL("https://github.com/JLLeitschuh/ktlint-gradle")), - MOCKITO("5.11.0", URL("https://github.com/mockito/mockito")), - MOCKITO_KOTLIN("5.3.1", URL("https://github.com/mockito/mockito-kotlin")), - NEXUS_PLUGIN("1.3.0", URL("https://github.com/gradle-nexus/publish-plugin")), - QODANA_PLUGIN("0.1.12", URL("https://www.jetbrains.com/help/qodana/qodana-gradle-plugin.html")), - ROBOLECTRIC_ANDROID_ALL("12.1-robolectric-8229987", URL("https://github.com/robolectric/robolectric")); + JMH("1.36", URL("https://openjdk.java.net/projects/code-tools/jmh/")); override fun toString() = version diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 0000000000..2273709797 --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,49 @@ +# https://docs.gradle.org/current/userguide/platforms.html#sub:conventional-dependencies-toml + +[versions] +room = "2.6.1" + +[libraries] +android-tools-lint = { group = "com.android.tools.lint", name = "lint", version = "31.3.2" } +android-tools-lint-api = { group = "com.android.tools.lint", name = "lint-api", version = "31.3.2" } +android-tools-gradle = { group = "com.android.tools.build", name = "gradle", version = "8.3.2" } +androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version = "1.0.2" } +androidx-benchmark = { group = "androidx.benchmark", name = "benchmark-junit4" } +androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version = "1.1.3" } +androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version = "1.0.2" } +androidx-paging = { group = "androidx.paging", name = "paging-runtime", version = "2.1.0" } +androidx-lifecycle-livedata-ktx = { group = "androidx.lifecycle", name = "lifecycle-livedata-ktx", version = "2.5.1" } +androidx-room-compiler = { group = "androidx.room", name = "room-compiler", version.ref = "room" } +androidx-room-runtime = { group = "androidx.room", name = "room-runtime", version.ref = "room" } +androidx-room-ktx = { group = "androidx.room", name = "room-ktx", version.ref = "room" } +androidx-test-ext = { group = "androidx.test.ext", name = "junit", version = "1.1.5" } +androidx-test-rules = { group = "androidx.test", name = "rules", version = "1.5.0" } +androidx-test-runner = { group = "androidx.test", name = "runner", version = "1.5.2" } +findbugs-jsr305 = { group = "com.google.code.findbugs", name = "jsr305", version = "3.0.2" } +jmh-core = { group = "org.openjdk.jmh", name = "jmh-core", version = "1.36" } +jmh-generator-annprocess = { group = "org.openjdk.jmh", name = "jmh-generator-annprocess", version = "1.36" } +junit-junit = { group = "junit", name = "junit", version = "4.13.2" } +junit-jupiter-params = { group = "org.junit.jupiter", name = "junit-jupiter-params", version = "5.10.2" } +kotlin-bom = { group = "org.jetbrains.kotlin", name = "kotlin-bom", version = "1.9.23" } +kotlin-reflect = { group = "org.jetbrains.kotlin", name = "kotlin-reflect" } +kotlin-test = { group = "org.jetbrains.kotlin", name = "kotlin-test" } +kotlin-test-junit = { group = "org.jetbrains.kotlin", name = "kotlin-test-junit" } +kotlinx-coroutines-bom = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-bom", version = "1.7.3" } +kotlinx-coroutines-core = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core" } +mockito-core = { group = "org.mockito", name = "mockito-core", version = "5.11.0" } +mockito-kotlin = { group = "org.mockito.kotlin", name = "mockito-kotlin", version = "5.3.1" } +robolectric-android-all = { group = "org.robolectric", name = "android-all", version = "12.1-robolectric-8229987" } + +[bundles] + +[plugins] +androidx-benchmark = { id = "androidx.benchmark", version = "1.2.0-alpha13" } +cash-licensee = { id = "app.cash.licensee", version = "1.6.0" } +detekt = { id = "io.gitlab.arturbosch.detekt", version = "1.22.0" } +dokka = { id = "org.jetbrains.dokka", version = "1.9.10" } +ideaExt = { id = "org.jetbrains.gradle.plugin.idea-ext", version = "1.1.7" } +kover = { id = "org.jetbrains.kotlinx.kover", version = "0.7.6" } +ktlint = { id = "org.jlleitschuh.gradle.ktlint", version = "11.5.0" } +nexus = { id = "io.github.gradle-nexus.publish-plugin", version = "1.3.0" } +qodana = { id = "org.jetbrains.qodana", version = "0.1.12" } +undercouch-download = { id = "de.undercouch.download", version = "5.4.0" } diff --git a/selekt-android-lint/build.gradle.kts b/selekt-android-lint/build.gradle.kts index af64605a90..f6ac1d8120 100644 --- a/selekt-android-lint/build.gradle.kts +++ b/selekt-android-lint/build.gradle.kts @@ -23,8 +23,8 @@ plugins { kotlin("jvm") `maven-publish` signing - id("io.gitlab.arturbosch.detekt") - id("org.jlleitschuh.gradle.ktlint") + alias(libs.plugins.detekt) + alias(libs.plugins.ktlint) } java { @@ -33,9 +33,9 @@ java { } dependencies { - compileOnly("com.android.tools.lint:lint:${Versions.ANDROID_LINT}") - compileOnly("com.android.tools.lint:lint-api:${Versions.ANDROID_LINT}") - implementation(kotlin("reflect", Versions.KOTLIN.version)) + compileOnly(libs.android.tools.lint.asProvider()) + compileOnly(libs.android.tools.lint.api) + implementation(libs.kotlin.reflect) } tasks.withType().configureEach { diff --git a/selekt-android-sqlcipher/build.gradle.kts b/selekt-android-sqlcipher/build.gradle.kts index 21fad9fdf8..8f61a3c6ae 100644 --- a/selekt-android-sqlcipher/build.gradle.kts +++ b/selekt-android-sqlcipher/build.gradle.kts @@ -24,7 +24,8 @@ plugins { id("kotlin-android") `maven-publish` signing - id("io.gitlab.arturbosch.detekt") + alias(libs.plugins.detekt) + alias(libs.plugins.ktlint) } repositories { @@ -37,9 +38,9 @@ val allABIs = listOf("armeabi-v7a", "arm64-v8a", "x86", "x86_64") android { compileSdk = Versions.ANDROID_SDK.version.toInt() - buildToolsVersion = Versions.ANDROID_BUILD_TOOLS.version + buildToolsVersion = libs.android.tools.gradle.get().version!! namespace = "com.bloomberg.selekt.android.sqlcipher" - ndkVersion = Versions.ANDROID_NDK.version + ndkVersion = "26.3.11579264" defaultConfig { minSdk = 21 } @@ -59,7 +60,7 @@ android { externalNativeBuild { cmake { path("$rootDir/SQLite3/CMakeLists.txt") - version = Versions.CMAKE.version + version = "3.22.1" } } publishing { diff --git a/selekt-android/build.gradle.kts b/selekt-android/build.gradle.kts index bb8ffa769f..a1abea789d 100644 --- a/selekt-android/build.gradle.kts +++ b/selekt-android/build.gradle.kts @@ -20,14 +20,14 @@ import com.android.build.gradle.internal.lint.LintModelWriterTask plugins { id("com.android.library") id("kotlin-android") - id("org.jetbrains.dokka") - id("app.cash.licensee") version Versions.GRADLE_LICENSEE_PLUGIN.version + alias(libs.plugins.dokka) + alias(libs.plugins.cash.licensee) kotlin("kapt") `maven-publish` signing - id("org.jetbrains.kotlinx.kover") - id("io.gitlab.arturbosch.detekt") - id("org.jlleitschuh.gradle.ktlint") + alias(libs.plugins.kover) + alias(libs.plugins.detekt) + alias(libs.plugins.ktlint) } repositories { @@ -37,8 +37,7 @@ repositories { android { compileSdk = Versions.ANDROID_SDK.version.toInt() - @Suppress("UnstableApiUsage") - buildToolsVersion = Versions.ANDROID_BUILD_TOOLS.version + buildToolsVersion = libs.android.tools.gradle.get().version!! namespace = "com.bloomberg.selekt.android" defaultConfig { minSdk = 21 @@ -62,16 +61,16 @@ android { dependencies { api(projects.selektApi) compileOnly(projects.selektAndroidSqlcipher) - compileOnly(androidX("room", "runtime", Versions.ANDROIDX_ROOM.version)) + compileOnly(libs.androidx.room.runtime) implementation(projects.selektJava) implementation(projects.selektSqlite3Classes) - kaptTest(androidX("room", "compiler", Versions.ANDROIDX_ROOM.version)) - testImplementation(androidX("lifecycle", "livedata-ktx", Versions.ANDROIDX_LIVE_DATA.version)) - testImplementation(androidX("room", "runtime", Versions.ANDROIDX_ROOM.version)) - testImplementation(androidX("room", "ktx", Versions.ANDROIDX_ROOM.version)) - testImplementation("org.junit.jupiter:junit-jupiter-params:${Versions.JUNIT5}") + kaptTest(libs.androidx.room.compiler) + testImplementation(libs.androidx.lifecycle.livedata.ktx) + testImplementation(libs.androidx.room.runtime) + testImplementation(libs.androidx.room.ktx) + testImplementation(libs.junit.jupiter.params) testRuntimeOnly(projects.selektAndroidSqlcipher) - testRuntimeOnly("org.robolectric:android-all:${Versions.ROBOLECTRIC_ANDROID_ALL}") + testRuntimeOnly(libs.robolectric.android.all) } koverReport { diff --git a/selekt-android/src/main/kotlin/com/bloomberg/selekt/android/support/SupportSQLiteDatabase.kt b/selekt-android/src/main/kotlin/com/bloomberg/selekt/android/support/SupportSQLiteDatabase.kt index 4768b7b18d..f4ee8e5f29 100644 --- a/selekt-android/src/main/kotlin/com/bloomberg/selekt/android/support/SupportSQLiteDatabase.kt +++ b/selekt-android/src/main/kotlin/com/bloomberg/selekt/android/support/SupportSQLiteDatabase.kt @@ -55,7 +55,7 @@ private class WrappedSQLiteTransactionListener( } @DelicateApi -private class SupportSQLiteDatabase constructor( +private class SupportSQLiteDatabase( private val database: SQLiteDatabase ) : SupportSQLiteDatabase { override fun beginTransaction() = database.beginExclusiveTransaction() diff --git a/selekt-api/build.gradle.kts b/selekt-api/build.gradle.kts index d489128c8c..c0a968359f 100644 --- a/selekt-api/build.gradle.kts +++ b/selekt-api/build.gradle.kts @@ -22,12 +22,12 @@ repositories { plugins { kotlin("jvm") - id("org.jetbrains.dokka") + alias(libs.plugins.dokka) `maven-publish` signing - id("org.jetbrains.kotlinx.kover") - id("io.gitlab.arturbosch.detekt") - id("org.jlleitschuh.gradle.ktlint") + alias(libs.plugins.detekt) + alias(libs.plugins.kover) + alias(libs.plugins.ktlint) } java { diff --git a/selekt-api/src/main/kotlin/com/bloomberg/selekt/DatabaseConfiguration.kt b/selekt-api/src/main/kotlin/com/bloomberg/selekt/DatabaseConfiguration.kt index 30e45775af..8e9c9e20e4 100644 --- a/selekt-api/src/main/kotlin/com/bloomberg/selekt/DatabaseConfiguration.kt +++ b/selekt-api/src/main/kotlin/com/bloomberg/selekt/DatabaseConfiguration.kt @@ -16,7 +16,7 @@ package com.bloomberg.selekt -data class DatabaseConfiguration constructor( +data class DatabaseConfiguration( val borrowWaitTimeoutMillis: Long = -1L, val busyTimeoutMillis: Int = 0, val evictionDelayMillis: Long, diff --git a/selekt-api/src/main/kotlin/com/bloomberg/selekt/SQLiteAutoVacuumMode.kt b/selekt-api/src/main/kotlin/com/bloomberg/selekt/SQLiteAutoVacuumMode.kt index d6637232d3..153bca4296 100644 --- a/selekt-api/src/main/kotlin/com/bloomberg/selekt/SQLiteAutoVacuumMode.kt +++ b/selekt-api/src/main/kotlin/com/bloomberg/selekt/SQLiteAutoVacuumMode.kt @@ -24,6 +24,7 @@ enum class SQLiteAutoVacuumMode(private val value: Int) { * the entire database file and thus reclaim unused disk space. */ NONE(0), + /** * The freelist pages are moved to the end of the database file and the database file is truncated to remove the * freelist pages at every transaction commit. Note, however, that auto-vacuum only truncates the freelist pages from @@ -31,6 +32,7 @@ enum class SQLiteAutoVacuumMode(private val value: Int) { * In fact, because it moves pages around within the file, auto-vacuum can actually make fragmentation worse. */ FULL(1), + /** * The additional information needed to do auto-vacuuming is stored in the database file but auto-vacuuming does not * occur automatically at each commit as it does with "full". In incremental mode, the separate incremental vacuum diff --git a/selekt-api/src/main/kotlin/com/bloomberg/selekt/SQLiteJournalMode.kt b/selekt-api/src/main/kotlin/com/bloomberg/selekt/SQLiteJournalMode.kt index b110fe576f..b229c3a760 100644 --- a/selekt-api/src/main/kotlin/com/bloomberg/selekt/SQLiteJournalMode.kt +++ b/selekt-api/src/main/kotlin/com/bloomberg/selekt/SQLiteJournalMode.kt @@ -30,12 +30,14 @@ enum class SQLiteJournalMode( * conclusion of each transaction. Indeed, the delete operation is the action that causes the transaction to commit. */ DELETE, + /** * The MEMORY journaling mode stores the rollback journal in volatile RAM. This saves disk I/O but at the expense of * database safety and integrity. If the application using SQLite crashes in the middle of a transaction when the MEMORY * journaling mode is set, then the database file will very likely go corrupt. */ MEMORY(commonInMemoryConfiguration), + /** * The OFF journaling mode disables the rollback journal completely. No rollback journal is ever created and hence there * is never a rollback journal to delete. The OFF journaling mode disables the atomic commit and rollback capabilities @@ -46,6 +48,7 @@ enum class SQLiteJournalMode( * in a corrupted state. */ OFF, + /** * The PERSIST journaling mode prevents the rollback journal from being deleted at the end of each transaction. Instead, * the header of the journal is overwritten with zeros. This will prevent other database connections from rolling the @@ -53,12 +56,14 @@ enum class SQLiteJournalMode( * file is much more expensive than overwriting the first block of a file with zeros. */ PERSIST, + /** * The TRUNCATE journaling mode commits transactions by truncating the rollback journal to zero-length instead of * deleting it. On many systems, truncating a file is much faster than deleting the file since the containing directory * does not need to be changed. */ TRUNCATE, + /** * The WAL journaling mode uses a write-ahead log instead of a rollback journal to implement transactions. The WAL * journaling mode is persistent; after being set it stays in effect across multiple database connections and after diff --git a/selekt-api/src/main/kotlin/com/bloomberg/selekt/SQLiteThreadingMode.kt b/selekt-api/src/main/kotlin/com/bloomberg/selekt/SQLiteThreadingMode.kt index 9a0b1798de..c502a38ced 100644 --- a/selekt-api/src/main/kotlin/com/bloomberg/selekt/SQLiteThreadingMode.kt +++ b/selekt-api/src/main/kotlin/com/bloomberg/selekt/SQLiteThreadingMode.kt @@ -24,6 +24,7 @@ enum class SQLiteThreadingMode(private val value: Int) { * as long as no two threads attempt to use the same database connection at the same time. */ MULTITHREAD(2), + /** * This option sets the threading mode to "serialized". In other words, this option enables all mutexes including the * recursive mutexes on database connection and prepared statement objects. In this mode the SQLite library will itself @@ -31,6 +32,7 @@ enum class SQLiteThreadingMode(private val value: Int) { * database connection or the same prepared statement in different threads at the same time. */ SERIALIZED(1), + /** * This option sets the threading mode to "single-thread". In other words, it disables all mutexing and puts SQLite into * a mode where it can only be used by a single thread. diff --git a/selekt-java/build.gradle.kts b/selekt-java/build.gradle.kts index 92b36bfa6a..8776a4a5e3 100644 --- a/selekt-java/build.gradle.kts +++ b/selekt-java/build.gradle.kts @@ -26,13 +26,13 @@ repositories { plugins { kotlin("jvm") kotlin("kapt") - id("org.jetbrains.kotlinx.kover") - id("org.jetbrains.dokka") + alias(libs.plugins.kover) + alias(libs.plugins.dokka) `maven-publish` signing id("bb-jmh") - id("io.gitlab.arturbosch.detekt") - id("org.jlleitschuh.gradle.ktlint") + alias(libs.plugins.detekt) + alias(libs.plugins.ktlint) } disableKotlinCompilerAssertions() @@ -60,7 +60,7 @@ val integrationTestRuntimeOnly: Configuration by configurations.getting { dependencies { implementation(projects.selektApi) implementation(projects.selektSqlite3Classes) - jmhImplementation(kotlinX("coroutines-core", version = Versions.KOTLINX_COROUTINES.version)) + jmhImplementation(libs.kotlinx.coroutines.core) } publishing { diff --git a/selekt-java/src/integrationTest/kotlin/com/bloomberg/selekt/jvm/SQLiteDatabaseChurnTest.kt b/selekt-java/src/integrationTest/kotlin/com/bloomberg/selekt/jvm/SQLiteDatabaseChurnTest.kt index b9e3d6b46b..940cef82b8 100644 --- a/selekt-java/src/integrationTest/kotlin/com/bloomberg/selekt/jvm/SQLiteDatabaseChurnTest.kt +++ b/selekt-java/src/integrationTest/kotlin/com/bloomberg/selekt/jvm/SQLiteDatabaseChurnTest.kt @@ -45,7 +45,8 @@ internal class SQLiteDatabaseChurnTest { file, SQLiteJournalMode.WAL.databaseConfiguration.copy( evictionDelayMillis = 50L, - timeBetweenEvictionRunsMillis = 100L), + timeBetweenEvictionRunsMillis = 100L + ), null ).apply { pragma("journal_mode", SQLiteJournalMode.WAL) diff --git a/selekt-java/src/integrationTest/kotlin/com/bloomberg/selekt/jvm/SQLiteDatabaseEvictionTest.kt b/selekt-java/src/integrationTest/kotlin/com/bloomberg/selekt/jvm/SQLiteDatabaseEvictionTest.kt index 60ef2f7019..33fbf6d76a 100644 --- a/selekt-java/src/integrationTest/kotlin/com/bloomberg/selekt/jvm/SQLiteDatabaseEvictionTest.kt +++ b/selekt-java/src/integrationTest/kotlin/com/bloomberg/selekt/jvm/SQLiteDatabaseEvictionTest.kt @@ -45,7 +45,8 @@ internal class SQLiteDatabaseEvictionTest { file, SQLiteJournalMode.WAL.databaseConfiguration.copy( evictionDelayMillis = 25L, - timeBetweenEvictionRunsMillis = 50L), + timeBetweenEvictionRunsMillis = 50L + ), null ).apply { pragma("journal_mode", SQLiteJournalMode.WAL) diff --git a/selekt-java/src/integrationTest/kotlin/com/bloomberg/selekt/jvm/SQLiteDatabaseLargeTransactionTest.kt b/selekt-java/src/integrationTest/kotlin/com/bloomberg/selekt/jvm/SQLiteDatabaseLargeTransactionTest.kt index ad44dddd0f..b7666dea4a 100644 --- a/selekt-java/src/integrationTest/kotlin/com/bloomberg/selekt/jvm/SQLiteDatabaseLargeTransactionTest.kt +++ b/selekt-java/src/integrationTest/kotlin/com/bloomberg/selekt/jvm/SQLiteDatabaseLargeTransactionTest.kt @@ -49,7 +49,8 @@ internal class SQLiteDatabaseLargeTransactionTest { file, SQLiteJournalMode.WAL.databaseConfiguration.copy( evictionDelayMillis = 50L, - timeBetweenEvictionRunsMillis = 100L), + timeBetweenEvictionRunsMillis = 100L + ), null ).apply { pragma("journal_mode", SQLiteJournalMode.WAL) diff --git a/selekt-java/src/integrationTest/kotlin/com/bloomberg/selekt/jvm/SQLiteDatabaseThunderingHerdTest.kt b/selekt-java/src/integrationTest/kotlin/com/bloomberg/selekt/jvm/SQLiteDatabaseThunderingHerdTest.kt index fd53be3a48..da076e9421 100644 --- a/selekt-java/src/integrationTest/kotlin/com/bloomberg/selekt/jvm/SQLiteDatabaseThunderingHerdTest.kt +++ b/selekt-java/src/integrationTest/kotlin/com/bloomberg/selekt/jvm/SQLiteDatabaseThunderingHerdTest.kt @@ -44,7 +44,8 @@ internal class SQLiteDatabaseThunderingHerdTest { file, SQLiteJournalMode.WAL.databaseConfiguration.copy( evictionDelayMillis = 100L, - timeBetweenEvictionRunsMillis = 250L), + timeBetweenEvictionRunsMillis = 250L + ), null ).apply { pragma("journal_mode", SQLiteJournalMode.WAL) diff --git a/selekt-java/src/jmh/kotlin/com/bloomberg/selekt/pools/benchmarks/CommonObjectPoolBenchmark.kt b/selekt-java/src/jmh/kotlin/com/bloomberg/selekt/pools/benchmarks/CommonObjectPoolBenchmark.kt index dac155e943..ea1391538a 100644 --- a/selekt-java/src/jmh/kotlin/com/bloomberg/selekt/pools/benchmarks/CommonObjectPoolBenchmark.kt +++ b/selekt-java/src/jmh/kotlin/com/bloomberg/selekt/pools/benchmarks/CommonObjectPoolBenchmark.kt @@ -127,12 +127,14 @@ open class MultipleObjectInput { } open class CommonObjectPoolBenchmark { - @Benchmark @BenchmarkMode(Mode.Throughput) + @Benchmark + @BenchmarkMode(Mode.Throughput) fun borrowThenReturnSingleObject(input: SingleObjectInput) = input.pool.run { borrowObject("").also { returnObject(it) } } - @Benchmark @BenchmarkMode(Mode.AverageTime) + @Benchmark + @BenchmarkMode(Mode.AverageTime) fun sequentialExactBorrowMultipleObjects( input: MultipleObjectInput ) = input.pool.run { @@ -153,7 +155,8 @@ open class CommonObjectPoolBenchmark { } } - @Benchmark @BenchmarkMode(Mode.AverageTime) + @Benchmark + @BenchmarkMode(Mode.AverageTime) fun exactBorrowThenReturnMultipleObjects(input: MultipleObjectInput) = input.pool.run { runBlocking(Dispatchers.IO) { coroutineScope { @@ -176,7 +179,8 @@ open class CommonObjectPoolBenchmark { } } - @Benchmark @BenchmarkMode(Mode.AverageTime) + @Benchmark + @BenchmarkMode(Mode.AverageTime) fun excessiveBorrowThenReturnMultipleObjects(input: MultipleObjectInput) = input.pool.run { runBlocking(Dispatchers.IO) { coroutineScope { diff --git a/selekt-java/src/jmh/kotlin/com/bloomberg/selekt/pools/benchmarks/SingleObjectPoolBenchmark.kt b/selekt-java/src/jmh/kotlin/com/bloomberg/selekt/pools/benchmarks/SingleObjectPoolBenchmark.kt index feb17b6393..828ae64acc 100644 --- a/selekt-java/src/jmh/kotlin/com/bloomberg/selekt/pools/benchmarks/SingleObjectPoolBenchmark.kt +++ b/selekt-java/src/jmh/kotlin/com/bloomberg/selekt/pools/benchmarks/SingleObjectPoolBenchmark.kt @@ -58,7 +58,8 @@ open class PoolInput { } open class SingleObjectPoolBenchmark { - @Benchmark @BenchmarkMode(Mode.Throughput) + @Benchmark + @BenchmarkMode(Mode.Throughput) fun borrowThenReturnObject(input: PoolInput) = input.pool.run { borrowObject("").also { returnObject(it) } } diff --git a/selekt-java/src/main/kotlin/com/bloomberg/selekt/Databases.kt b/selekt-java/src/main/kotlin/com/bloomberg/selekt/Databases.kt index d41673f058..bd1074a3ba 100644 --- a/selekt-java/src/main/kotlin/com/bloomberg/selekt/Databases.kt +++ b/selekt-java/src/main/kotlin/com/bloomberg/selekt/Databases.kt @@ -47,7 +47,7 @@ private object SharedSqlBuilder { * @see Android's SQLiteDatabase */ @ThreadSafe -class SQLDatabase constructor( +class SQLDatabase( val path: String, sqlite: SQLite, configuration: DatabaseConfiguration, @@ -187,7 +187,13 @@ class SQLDatabase constructor( ): ICursor = query(SQLQuery.create(session, sql, sql.resolvedSqlStatementType(), selectionArgs)) override fun query(query: ISQLQuery): ICursor = query( - SQLQuery.create(session, query.sql, query.sql.resolvedSqlStatementType(), query.argCount).also { query.bindTo(it) }) + SQLQuery.create( + session, + query.sql, + query.sql.resolvedSqlStatementType(), + query.argCount + ).also { query.bindTo(it) } + ) @Suppress("Detekt.LongParameterList") fun readFromBlob( diff --git a/selekt-java/src/main/kotlin/com/bloomberg/selekt/Key.kt b/selekt-java/src/main/kotlin/com/bloomberg/selekt/Key.kt index a581296e6a..5cfd106822 100644 --- a/selekt-java/src/main/kotlin/com/bloomberg/selekt/Key.kt +++ b/selekt-java/src/main/kotlin/com/bloomberg/selekt/Key.kt @@ -21,8 +21,10 @@ import javax.annotation.concurrent.GuardedBy internal class Key(value: ByteArray) { private val lock = Any() + @GuardedBy("lock") private val value: ByteArray = value.copyOf() + @GuardedBy("lock") private var isDestroyed = false diff --git a/selekt-java/src/main/kotlin/com/bloomberg/selekt/Caches.kt b/selekt-java/src/main/kotlin/com/bloomberg/selekt/LruCache.kt similarity index 100% rename from selekt-java/src/main/kotlin/com/bloomberg/selekt/Caches.kt rename to selekt-java/src/main/kotlin/com/bloomberg/selekt/LruCache.kt diff --git a/selekt-java/src/main/kotlin/com/bloomberg/selekt/Pools.kt b/selekt-java/src/main/kotlin/com/bloomberg/selekt/Pools.kt index f8575b037e..dfa94e2dc2 100644 --- a/selekt-java/src/main/kotlin/com/bloomberg/selekt/Pools.kt +++ b/selekt-java/src/main/kotlin/com/bloomberg/selekt/Pools.kt @@ -53,7 +53,8 @@ internal fun openConnectionPool( ) = createObjectPool( SQLConnectionFactory(path, sqlite, configuration, random, key?.let { Key(it) }), sharedExecutor, - configuration.toPoolConfiguration()) + configuration.toPoolConfiguration() +) internal interface CloseableSQLExecutor : SQLExecutor, Closeable, IPooledObject diff --git a/selekt-java/src/main/kotlin/com/bloomberg/selekt/SQLBlob.kt b/selekt-java/src/main/kotlin/com/bloomberg/selekt/SQLBlob.kt index af2b847b67..f4552a5e69 100644 --- a/selekt-java/src/main/kotlin/com/bloomberg/selekt/SQLBlob.kt +++ b/selekt-java/src/main/kotlin/com/bloomberg/selekt/SQLBlob.kt @@ -28,7 +28,7 @@ internal fun SQLBlob.inputStream(offset: Int, limit: Int): InputStream = BlobInp internal fun SQLBlob.outputStream(offset: Int): OutputStream = BlobOutputStream(this, offset) @NotThreadSafe -internal class SQLBlob constructor( +internal class SQLBlob( private val pointer: Long, private val sqlite: SQLite, val readOnly: Boolean @@ -98,7 +98,8 @@ internal class BlobInputStream( minOf(it, length).also { len -> if (offset + len > destination.size) { throw ArrayIndexOutOfBoundsException( - "Size: ${destination.size}; offset: $offset; length: $length; truncated length: $len") + "Size: ${destination.size}; offset: $offset; length: $length; truncated length: $len" + ) } blob.read(index, destination, offset, len) index += len diff --git a/selekt-java/src/main/kotlin/com/bloomberg/selekt/SQLConnection.kt b/selekt-java/src/main/kotlin/com/bloomberg/selekt/SQLConnection.kt index 2dbf0c0d97..3bbb97edbb 100644 --- a/selekt-java/src/main/kotlin/com/bloomberg/selekt/SQLConnection.kt +++ b/selekt-java/src/main/kotlin/com/bloomberg/selekt/SQLConnection.kt @@ -21,7 +21,7 @@ import com.bloomberg.selekt.commons.forUntil import javax.annotation.concurrent.NotThreadSafe @NotThreadSafe -internal class SQLConnection constructor( +internal class SQLConnection( path: String, private val sqlite: SQLite, private val configuration: DatabaseConfiguration, diff --git a/selekt-java/src/main/kotlin/com/bloomberg/selekt/SQLite.kt b/selekt-java/src/main/kotlin/com/bloomberg/selekt/SQLite.kt index 30990cba2c..9f5d4951ee 100644 --- a/selekt-java/src/main/kotlin/com/bloomberg/selekt/SQLite.kt +++ b/selekt-java/src/main/kotlin/com/bloomberg/selekt/SQLite.kt @@ -85,7 +85,8 @@ open class SQLite( row, flags, holder - )) + ) + ) fun blobRead( blob: Long, diff --git a/selekt-java/src/main/kotlin/com/bloomberg/selekt/Sessions.kt b/selekt-java/src/main/kotlin/com/bloomberg/selekt/Sessions.kt index 04b0abca6c..25f3f5f4ce 100644 --- a/selekt-java/src/main/kotlin/com/bloomberg/selekt/Sessions.kt +++ b/selekt-java/src/main/kotlin/com/bloomberg/selekt/Sessions.kt @@ -227,7 +227,7 @@ interface ISQLTransactor { } @NotThreadSafe -internal open class Session> constructor( +internal open class Session>( private val pool: TieredObjectPool ) { private var obj: T? = null diff --git a/selekt-java/src/main/kotlin/com/bloomberg/selekt/SharedCloseable.kt b/selekt-java/src/main/kotlin/com/bloomberg/selekt/SharedCloseable.kt index c931323868..bffbb82022 100644 --- a/selekt-java/src/main/kotlin/com/bloomberg/selekt/SharedCloseable.kt +++ b/selekt-java/src/main/kotlin/com/bloomberg/selekt/SharedCloseable.kt @@ -51,6 +51,8 @@ abstract class SharedCloseable : Closeable { private companion object { val retainCountUpdater: AtomicIntegerFieldUpdater = AtomicIntegerFieldUpdater.newUpdater( - SharedCloseable::class.java, "retainCount") + SharedCloseable::class.java, + "retainCount" + ) } } diff --git a/selekt-java/src/main/kotlin/com/bloomberg/selekt/commons/ManagedStringBuilder.kt b/selekt-java/src/main/kotlin/com/bloomberg/selekt/commons/ManagedStringBuilder.kt index 4872a9c83c..354330c3a8 100644 --- a/selekt-java/src/main/kotlin/com/bloomberg/selekt/commons/ManagedStringBuilder.kt +++ b/selekt-java/src/main/kotlin/com/bloomberg/selekt/commons/ManagedStringBuilder.kt @@ -43,13 +43,19 @@ class ManagedStringBuilder( } } - @JvmSynthetic @PublishedApi internal fun validate() = builder.length <= maxRetainedLength + @JvmSynthetic + @PublishedApi + internal fun validate() = builder.length <= maxRetainedLength - @JvmSynthetic @PublishedApi internal fun passivate() { + @JvmSynthetic + @PublishedApi + internal fun passivate() { builder.clear() } - @JvmSynthetic @PublishedApi internal fun reset() { + @JvmSynthetic + @PublishedApi + internal fun reset() { builder = StringBuilder(defaultLength) } } diff --git a/selekt-java/src/main/kotlin/com/bloomberg/selekt/commons/NativeResources.kt b/selekt-java/src/main/kotlin/com/bloomberg/selekt/commons/NativeResources.kt index a93ef145e4..9d9e617544 100644 --- a/selekt-java/src/main/kotlin/com/bloomberg/selekt/commons/NativeResources.kt +++ b/selekt-java/src/main/kotlin/com/bloomberg/selekt/commons/NativeResources.kt @@ -65,6 +65,7 @@ fun loadEmbeddedLibrary(loader: ClassLoader, parentDirectory: String, name: Stri val url = checkNotNull(libraryNames(parentDirectory, name).firstNotNullOfOrNull { loader.getResource(it) }) { "Failed to find resource with name: $name in directory: $parentDirectory" } + @Suppress("NewApi") // Not used by Android. val file = createTempFile("lib$name", "lib").toFile() try { diff --git a/selekt-java/src/main/kotlin/com/bloomberg/selekt/pools/CommonObjectPool.kt b/selekt-java/src/main/kotlin/com/bloomberg/selekt/pools/CommonObjectPool.kt index 8fe311fbaa..f70b2eafc3 100644 --- a/selekt-java/src/main/kotlin/com/bloomberg/selekt/pools/CommonObjectPool.kt +++ b/selekt-java/src/main/kotlin/com/bloomberg/selekt/pools/CommonObjectPool.kt @@ -48,10 +48,13 @@ class CommonObjectPool>( @GuardedBy("lock") private val idleObjects = LinkedDeque() + @GuardedBy("lock") private var count = 0 + @GuardedBy("lock") private var future: Future<*>? = null + @GuardedBy("lock") private var tag = false diff --git a/selekt-java/src/main/kotlin/com/bloomberg/selekt/pools/Mutex.kt b/selekt-java/src/main/kotlin/com/bloomberg/selekt/pools/Mutex.kt index d606aac0c9..84af2a73cd 100644 --- a/selekt-java/src/main/kotlin/com/bloomberg/selekt/pools/Mutex.kt +++ b/selekt-java/src/main/kotlin/com/bloomberg/selekt/pools/Mutex.kt @@ -25,8 +25,11 @@ import java.util.concurrent.locks.LockSupport */ internal class Mutex { @Suppress("unused") - @Volatile private var isLocked = 0 - @Volatile private var isCancelled = 0 + @Volatile + private var isLocked = 0 + + @Volatile + private var isCancelled = 0 private val waiters = ConcurrentLinkedQueue() fun lock() { @@ -159,10 +162,14 @@ internal class Mutex { private val ensureLoaded: Class<*> = LockSupport::class.java val isLockedUpdater: AtomicIntegerFieldUpdater = AtomicIntegerFieldUpdater.newUpdater( - Mutex::class.java, "isLocked") + Mutex::class.java, + "isLocked" + ) val isCancelledUpdater: AtomicIntegerFieldUpdater = AtomicIntegerFieldUpdater.newUpdater( - Mutex::class.java, "isCancelled") + Mutex::class.java, + "isCancelled" + ) fun cancellationError(): Nothing = error("Mutex received cancellation signal.") } diff --git a/selekt-java/src/main/kotlin/com/bloomberg/selekt/pools/SingleObjectPool.kt b/selekt-java/src/main/kotlin/com/bloomberg/selekt/pools/SingleObjectPool.kt index b45e9f4f44..eed41aaeaa 100644 --- a/selekt-java/src/main/kotlin/com/bloomberg/selekt/pools/SingleObjectPool.kt +++ b/selekt-java/src/main/kotlin/com/bloomberg/selekt/pools/SingleObjectPool.kt @@ -30,10 +30,13 @@ class SingleObjectPool>( private val evictionIntervalMillis: Long ) : IObjectPool { private val mutex = Mutex() + @GuardedBy("mutex") private var obj: T? = null + @GuardedBy("mutex") private var canEvict = false + @GuardedBy("mutex") private var future: Future<*>? = null diff --git a/selekt-java/src/test/kotlin/com/bloomberg/selekt/QueriesKtTest.kt b/selekt-java/src/test/kotlin/com/bloomberg/selekt/QueriesKtTest.kt index b2241a4144..868d7ec991 100644 --- a/selekt-java/src/test/kotlin/com/bloomberg/selekt/QueriesKtTest.kt +++ b/selekt-java/src/test/kotlin/com/bloomberg/selekt/QueriesKtTest.kt @@ -39,14 +39,16 @@ internal class QueriesKtTest { fun appendGroupByHaving() { assertEquals( "SELECT * FROM Foo GROUP BY bar HAVING COUNT(id) > 42", - StringBuilder("SELECT * FROM Foo").groupBy("bar").having("COUNT(id) > 42").toString()) + StringBuilder("SELECT * FROM Foo").groupBy("bar").having("COUNT(id) > 42").toString() + ) } @Test fun appendGroupByHavingNull() { assertEquals( "SELECT * FROM Foo GROUP BY bar", - StringBuilder("SELECT * FROM Foo").groupBy("bar").having(null).toString()) + StringBuilder("SELECT * FROM Foo").groupBy("bar").having(null).toString() + ) } @Test diff --git a/selekt-java/src/test/kotlin/com/bloomberg/selekt/pools/CommonObjectPoolTest.kt b/selekt-java/src/test/kotlin/com/bloomberg/selekt/pools/CommonObjectPoolTest.kt index 20c0f6e707..69a6b64ba0 100644 --- a/selekt-java/src/test/kotlin/com/bloomberg/selekt/pools/CommonObjectPoolTest.kt +++ b/selekt-java/src/test/kotlin/com/bloomberg/selekt/pools/CommonObjectPoolTest.kt @@ -432,8 +432,10 @@ internal class CommonObjectPoolTest { } }.forEach { it.join() } assertTrue(objects.isNotEmpty()) - assertTrue(objects.size <= configuration.maxTotal, - "Expected at most ${configuration.maxTotal}, found ${objects.size}.") + assertTrue( + objects.size <= configuration.maxTotal, + "Expected at most ${configuration.maxTotal}, found ${objects.size}." + ) } @Test diff --git a/selekt-sqlite3-classes/build.gradle.kts b/selekt-sqlite3-classes/build.gradle.kts index 5c9fdeee2e..a1f74cffaa 100644 --- a/selekt-sqlite3-classes/build.gradle.kts +++ b/selekt-sqlite3-classes/build.gradle.kts @@ -22,8 +22,8 @@ plugins { kotlin("jvm") `maven-publish` signing - id("io.gitlab.arturbosch.detekt") - id("org.jlleitschuh.gradle.ktlint") + alias(libs.plugins.detekt) + alias(libs.plugins.ktlint) } disableKotlinCompilerAssertions()