Skip to content

Commit

Permalink
apply detekt rules
Browse files Browse the repository at this point in the history
  • Loading branch information
osoykan committed Apr 22, 2024
1 parent f7ed466 commit 3dad99d
Show file tree
Hide file tree
Showing 54 changed files with 373 additions and 285 deletions.
230 changes: 119 additions & 111 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,153 +2,161 @@ import org.jetbrains.dokka.gradle.DokkaMultiModuleTask
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
kotlin("jvm").version(libs.versions.kotlin)
alias(libs.plugins.dokka)
alias(libs.plugins.spotless)
alias(libs.plugins.gitVersioning)
`test-report-aggregation`
id("stove-publishing") apply false
alias(testLibs.plugins.testLogger)
alias(libs.plugins.kover)
java
kotlin("jvm").version(libs.versions.kotlin)
alias(libs.plugins.dokka)
alias(libs.plugins.spotless)
alias(libs.plugins.gitVersioning)
`test-report-aggregation`
id("stove-publishing") apply false
alias(testLibs.plugins.testLogger)
alias(libs.plugins.kover)
alias(libs.plugins.detekt)
java
}
group = "com.trendyol"
val versionDetails: groovy.lang.Closure<com.palantir.gradle.gitversion.VersionDetails> by extra
val details = versionDetails()
version = details.lastTag

allprojects {
extra.set("dokka.outputDirectory", rootDir.resolve("docs"))
extra.set("dokka.outputDirectory", rootDir.resolve("docs"))
}

koverReport {
filters {
excludes {
classes(
"com.trendyol.stove.functional.*",
"com.trendyol.stove.testing.e2e.system.abstractions.*",
"com.trendyol.stove.testing.e2e.system.annotations.*",
"com.trendyol.stove.testing.e2e.serialization.*",
"com.trendyol.stove.testing.e2e.standalone.*",
"stove.spring.example.*",
"stove.ktor.example.*",
)
}
filters {
excludes {
classes(
"com.trendyol.stove.functional.*",
"com.trendyol.stove.testing.e2e.system.abstractions.*",
"com.trendyol.stove.testing.e2e.system.annotations.*",
"com.trendyol.stove.testing.e2e.serialization.*",
"com.trendyol.stove.testing.e2e.standalone.*",
"stove.spring.example.*",
"stove.ktor.example.*"
)
}
}
}
val related = subprojects.of("lib", "spring", "examples", "ktor")
dependencies {
related.forEach {
kover(it)
}
related.forEach {
kover(it)
}
}

subprojects.of("lib", "spring", "examples", "ktor") {
apply {
plugin("kotlin")
plugin(rootProject.libs.plugins.spotless.get().pluginId)
plugin(rootProject.libs.plugins.dokka.get().pluginId)
plugin("test-report-aggregation")
plugin(rootProject.testLibs.plugins.testLogger.get().pluginId)
plugin(rootProject.libs.plugins.kover.get().pluginId)
}
apply {
plugin("kotlin")
plugin(rootProject.libs.plugins.spotless.get().pluginId)
plugin(rootProject.libs.plugins.dokka.get().pluginId)
plugin("test-report-aggregation")
plugin(rootProject.testLibs.plugins.testLogger.get().pluginId)
plugin(rootProject.libs.plugins.kover.get().pluginId)
plugin(rootProject.libs.plugins.detekt.get().pluginId)
}

val testImplementation by configurations
val libs = rootProject.libs
val testLibs = rootProject.testLibs
val testImplementation by configurations
val libs = rootProject.libs
val testLibs = rootProject.testLibs

dependencies {
api(libs.arrow.core)
}
dependencies {
api(libs.arrow.core)
}

dependencies {
testImplementation(kotlin("test"))
testImplementation(testLibs.kotest.runner.junit5)
testImplementation(testLibs.kotest.framework.api.jvm)
testImplementation(testLibs.kotest.property.jvm)
}
detekt {
buildUponDefaultConfig = true
parallel = true
config.from(rootProject.file("detekt.yml"))
}
dependencies {
testImplementation(kotlin("test"))
testImplementation(testLibs.kotest.runner.junit5)
testImplementation(testLibs.kotest.framework.api.jvm)
testImplementation(testLibs.kotest.property.jvm)
detektPlugins(libs.detekt.formatting)
}

spotless {
kotlin {
ktlint().setEditorConfigPath(rootProject.layout.projectDirectory.file(".editorconfig"))
}
spotless {
kotlin {
ktlint().setEditorConfigPath(rootProject.layout.projectDirectory.file(".editorconfig"))
}
}

tasks {
test {
dependsOn(spotlessApply)
useJUnitPlatform()
testlogger {
setTheme("mocha")
showStandardStreams = true
showExceptions = true
showCauses = true
}
reports {
junitXml.required.set(true)
}
}
kotlin {
jvmToolchain(17)
}
tasks {
test {
dependsOn(spotlessApply)
useJUnitPlatform()
testlogger {
setTheme("mocha")
showStandardStreams = true
showExceptions = true
showCauses = true
}
reports {
junitXml.required.set(true)
}
}
kotlin {
jvmToolchain(17)
}

withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
dependsOn(spotlessApply)
compilerOptions {
jvmTarget.set(JvmTarget.JVM_17)
allWarningsAsErrors = true
freeCompilerArgs.addAll(
"-Xjsr305=strict",
"-Xcontext-receivers",
"-Xsuppress-version-warnings"
)
}
}
withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
dependsOn(spotlessApply)
compilerOptions {
jvmTarget.set(JvmTarget.JVM_17)
allWarningsAsErrors = true
freeCompilerArgs.addAll(
"-Xjsr305=strict",
"-Xcontext-receivers",
"-Xsuppress-version-warnings"
)
}
}
}
}

tasks.register<Copy>("testAggregateXmlReports") {
group = "Reporting"
related.forEach {
dependsOn(it.tasks.testAggregateTestReport)
mustRunAfter(it.tasks.testAggregateTestReport)
}
val testResults = related.map { it.tasks.test.get().outputs.files }
duplicatesStrategy = DuplicatesStrategy.WARN
from(testResults)
include("*.xml")
into(rootProject.layout.buildDirectory.dir("reports/xml"))
group = "Reporting"
related.forEach {
dependsOn(it.tasks.testAggregateTestReport)
mustRunAfter(it.tasks.testAggregateTestReport)
}
val testResults = related.map { it.tasks.test.get().outputs.files }
duplicatesStrategy = DuplicatesStrategy.WARN
from(testResults)
include("*.xml")
into(rootProject.layout.buildDirectory.dir("reports/xml"))
}

val publishedProjects = listOf(
"stove-testing-e2e",
"stove-testing-e2e-couchbase",
"stove-testing-e2e-elasticsearch",
"stove-testing-e2e-http",
"stove-testing-e2e-kafka",
"stove-testing-e2e-mongodb",
"stove-testing-e2e-rdbms",
"stove-testing-e2e-rdbms-postgres",
"stove-testing-e2e-rdbms-mssql",
"stove-testing-e2e-wiremock",
"stove-testing-e2e-redis",
"stove-ktor-testing-e2e",
"stove-spring-testing-e2e",
"stove-spring-testing-e2e-kafka"
"stove-testing-e2e",
"stove-testing-e2e-couchbase",
"stove-testing-e2e-elasticsearch",
"stove-testing-e2e-http",
"stove-testing-e2e-kafka",
"stove-testing-e2e-mongodb",
"stove-testing-e2e-rdbms",
"stove-testing-e2e-rdbms-postgres",
"stove-testing-e2e-rdbms-mssql",
"stove-testing-e2e-wiremock",
"stove-testing-e2e-redis",
"stove-ktor-testing-e2e",
"stove-spring-testing-e2e",
"stove-spring-testing-e2e-kafka"
)

subprojects.of("lib", "spring", "ktor", filter = { p -> publishedProjects.contains(p.name) }) {
apply {
plugin("java")
plugin("stove-publishing")
}
apply {
plugin("java")
plugin("stove-publishing")
}

java {
withSourcesJar()
withJavadocJar()
}
java {
withSourcesJar()
withJavadocJar()
}
}

tasks.withType<DokkaMultiModuleTask>().configureEach {
outputDirectory.set(file(rootDir.resolve("docs/source")))
outputDirectory.set(file(rootDir.resolve("docs/source")))
}
18 changes: 17 additions & 1 deletion detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,23 @@ output-reports:

formatting:
Indentation:
active: true
active: false
indentSize: 2
autoCorrect: true
NoWildcardImports:
active: false
MaximumLineLength:
active: true
maxLineLength: 140
excludes: [ '**/test/**', '**/test-e2e/**' ]
ArgumentListWrapping:
maxLineLength: 140
autoCorrect: true
active: true
indentSize: 2
Filename:
active: false

comments:
active: true
AbsentOrWrongFileLicense:
Expand Down Expand Up @@ -674,3 +687,6 @@ style:
ignoreLateinitVar: false
WildcardImport:
active: false
excludes: [ '**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**' ]
excludeImports:
- 'java.util.*'
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,26 @@ package stove.ktor.example
import io.ktor.http.*
import io.ktor.serialization.kotlinx.json.*
import io.ktor.server.application.*
import io.ktor.server.config.*
import io.ktor.server.engine.*
import io.ktor.server.netty.*
import io.ktor.server.plugins.callloging.*
import io.ktor.server.plugins.contentnegotiation.*
import io.ktor.server.request.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import io.r2dbc.postgresql.PostgresqlConnectionConfiguration
import io.r2dbc.postgresql.PostgresqlConnectionFactory
import io.r2dbc.postgresql.*
import kotlinx.serialization.Serializable
import org.koin.core.module.Module
import org.koin.core.module.dsl.bind
import org.koin.core.module.dsl.singleOf
import org.koin.core.module.dsl.*
import org.koin.dsl.module
import org.koin.ktor.ext.get
import org.koin.ktor.plugin.Koin
import org.koin.logger.SLF4JLogger
import org.slf4j.event.*
import stove.ktor.example.domain.JediRepository
import stove.ktor.example.domain.JediService
import stove.ktor.example.domain.*
import java.time.Duration

const val CONNECT_TIMEOUT_SECONDS = 10L

fun main(args: Array<String>) {
run(args)
}
Expand Down Expand Up @@ -75,7 +72,9 @@ fun Application.mainModule(
val request = call.receive<UpdateJediRequest>()
call.get<JediService>().update(id, request)
call.respond(HttpStatusCode.OK)
} catch (ex: Exception) {
} catch (
@Suppress("TooGenericExceptionCaught") ex: Exception
) {
ex.printStackTrace()
call.respond(HttpStatusCode.BadRequest)
}
Expand All @@ -95,7 +94,8 @@ fun dataModule(args: Array<String>) =
password(map["database.password"]!!)
username(map["database.username"]!!)
}
PostgresqlConnectionFactory(builder.connectTimeout(Duration.ofSeconds(10)).build())

PostgresqlConnectionFactory(builder.connectTimeout(Duration.ofSeconds(CONNECT_TIMEOUT_SECONDS)).build())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ class JediRepository(private val postgresqlConnectionFactory: PostgresqlConnecti
try {
invoke(this)
connection.commitTransaction().awaitFirstOrNull()
} catch (ex: Exception) {
} catch (
@Suppress("TooGenericExceptionCaught") ex: Exception
) {
connection.rollbackTransaction().awaitFirstOrNull()
throw ex
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ class TestSystemConfig : AbstractProjectConfig() {
)
}
ktor(
withParameters =
listOf(
"ktor.server.port=8001"
),
withParameters = listOf(
"ktor.server.port=8001"
),
runner = { parameters ->
stove.ktor.example.run(parameters) {
addTestSystemDependencies()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ class NoOpLockProvider : LockProvider {
return true
}

override suspend fun releaseLock(name: String) {}
override suspend fun releaseLock(name: String) = Unit
}
Loading

0 comments on commit 3dad99d

Please sign in to comment.