Skip to content

Commit

Permalink
Formatting with ktlint
Browse files Browse the repository at this point in the history
  • Loading branch information
eygraber committed Sep 11, 2023
1 parent 8a1f33a commit e1865df
Show file tree
Hide file tree
Showing 49 changed files with 2,616 additions and 2,614 deletions.
16 changes: 5 additions & 11 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
# noinspection EditorConfigKeyCorrectness
[*.{kt,kts}]
root=true
ij_kotlin_allow_trailing_comma = true
ij_kotlin_allow_trailing_comma_on_call_site = true
ij_kotlin_imports_layout=*,java.**,javax.**,kotlin.**,^
indent_size = 2
indent_style = space
insert_final_newline = true
ktlint_code_style = intellij_idea
ktlint_experimental = enabled
# ktlint_standard_annotation = disabled
# ktlint_standard_class-signature = disabled
# ktlint_standard_comment-wrapping = disabled
# ktlint_standard_filename = disabled
# ktlint_standard_function-naming = disabled
# ktlint_standard_function-signature = disabled
# ktlint_standard_package-name = disabled
# ktlint_standard_property-naming = disabled
# ktlint_standard_spacing-between-declarations-with-annotations = disabled
# ktlint_standard_trailing-comma-on-call-site = disabled
# ktlint_standard_trailing-comma-on-declaration-site = disabled
ktlint_standard_class-signature = disabled
ktlint_standard_function-signature = disabled
max_line_length = 120
22 changes: 11 additions & 11 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ import com.eygraber.conventions.tasks.deleteRootBuildDirWhenCleaning
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

buildscript {
dependencies {
classpath(libs.buildscript.detekt)
classpath(libs.buildscript.dokka)
classpath(libs.buildscript.kotlin)
classpath(libs.buildscript.publish)
}
dependencies {
classpath(libs.buildscript.detekt)
classpath(libs.buildscript.dokka)
classpath(libs.buildscript.kotlin)
classpath(libs.buildscript.publish)
}
}

plugins {
base
alias(libs.plugins.conventions)
base
alias(libs.plugins.conventions)
}

deleteRootBuildDirWhenCleaning()

gradleConventionsDefaults {
kotlin {
jvmTargetVersion = JvmTarget.JVM_11
}
kotlin {
jvmTargetVersion = JvmTarget.JVM_11
}
}
279 changes: 139 additions & 140 deletions jsonpath/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,187 +3,186 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmCompilation
import org.jetbrains.kotlin.konan.target.KonanTarget

plugins {
java
jacoco
id("com.eygraber.conventions-kotlin-multiplatform")
id("com.eygraber.conventions-detekt")
id("com.eygraber.conventions-publish-maven-central")
alias(libs.plugins.kotlinx.serialization)
java
jacoco
id("com.eygraber.conventions-kotlin-multiplatform")
id("com.eygraber.conventions-detekt")
id("com.eygraber.conventions-publish-maven-central")
alias(libs.plugins.kotlinx.serialization)
}

kotlin {
targets {
kmpTargets(
project = project,
android = false,
jvm = true,
ios = true,
macos = true,
wasm = false,
js = true
)

presets.withType<AbstractKotlinNativeTargetPreset<*>>().forEach {
if(!it.konanTarget.family.isAppleFamily && it.konanTarget !in KonanTarget.deprecatedTargets) {
targetFromPreset(it)
}
}
targets {
kmpTargets(
project = project,
android = false,
jvm = true,
ios = true,
macos = true,
wasm = false,
js = true,
)

jvm {
compilations.registerBenchmarkCompilation()
}
presets.withType<AbstractKotlinNativeTargetPreset<*>>().forEach {
if (!it.konanTarget.family.isAppleFamily && it.konanTarget !in KonanTarget.deprecatedTargets) {
targetFromPreset(it)
}
}

sourceSets {
commonMain {
dependencies {
implementation(libs.kotlinx.serialization.json)
}
}

getByName("jvmBenchmark") {
dependsOn(commonMain.get())
}

getByName("commonTest") {
dependencies {
implementation(libs.test.kotest.assertions)
implementation(kotlin("test"))
}
}
jvm {
compilations.registerBenchmarkCompilation()
}
}
}

tasks.withType<Test> {
testLogging {
// show test results for following events
events("PASSED", "FAILED", "SKIPPED")
sourceSets {
commonMain {
dependencies {
implementation(libs.kotlinx.serialization.json)
}
}

// show printlines
showStandardStreams = true
getByName("jvmBenchmark") {
dependsOn(commonMain.get())
}

addTestListener(
object : TestListener {
override fun beforeSuite(suite: TestDescriptor?) {}
override fun afterTest(testDescriptor: TestDescriptor?, result: TestResult?) {}
override fun beforeTest(testDescriptor: TestDescriptor?) {}

override fun afterSuite(suite: TestDescriptor?, result: TestResult?) {
val parent = suite?.parent
if (parent != null && result != null) {
println("\nTest result: ${result.resultType}")
println(
"""
|Test summary: ${result.testCount} tests,
| ${result.successfulTestCount} succeeded,
| ${result.failedTestCount} failed,
| ${result.skippedTestCount} skipped
""".trimMargin().replace("\n", "")
)
}
}
getByName("commonTest") {
dependencies {
implementation(libs.test.kotest.assertions)
implementation(kotlin("test"))
}
}
}
}

tasks.withType<Test> {
testLogging {
// show test results for following events
events("PASSED", "FAILED", "SKIPPED")

// show printlines
showStandardStreams = true
}

addTestListener(
object : TestListener {
override fun beforeSuite(suite: TestDescriptor?) {}
override fun afterTest(testDescriptor: TestDescriptor?, result: TestResult?) {}
override fun beforeTest(testDescriptor: TestDescriptor?) {}

override fun afterSuite(suite: TestDescriptor?, result: TestResult?) {
val parent = suite?.parent
if (parent != null && result != null) {
println("\nTest result: ${result.resultType}")
println(
"""
|Test summary: ${result.testCount} tests,
| ${result.successfulTestCount} succeeded,
| ${result.failedTestCount} failed,
| ${result.skippedTestCount} skipped
""".trimMargin().replace("\n", ""),
)
}
)
}
},
)

configure<JacocoTaskExtension> {
setDestinationFile(
layout.buildDirectory.file("jacoco/junitPlatformTest.exec").map { it.asFile })
isIncludeNoLocationClasses = true
excludes = listOf(
"*/LRUCache\$LRUMap*",
"*/JsonNodeKt*",
"jdk.internal.*"
)
}
configure<JacocoTaskExtension> {
setDestinationFile(
layout.buildDirectory.file("jacoco/junitPlatformTest.exec").map { it.asFile },
)
isIncludeNoLocationClasses = true
excludes = listOf(
"*/LRUCache\$LRUMap*",
"*/JsonNodeKt*",
"jdk.internal.*",
)
}

// Make this task never up to date, thus forcing rerun of all tests whenever task is run
outputs.upToDateWhen { false }
// Make this task never up to date, thus forcing rerun of all tests whenever task is run
outputs.upToDateWhen { false }
}

jacoco {
toolVersion = "0.8.10"
reportsDirectory.set(rootProject.layout.buildDirectory.dir("reports"))
toolVersion = "0.8.10"
reportsDirectory.set(rootProject.layout.buildDirectory.dir("reports"))
}

tasks.jacocoTestReport.configure {
dependsOn(tasks.named("jvmTest"))
dependsOn(tasks.named("jvmTest"))

val buildDirPath = layout.buildDirectory.asFile.get().absolutePath
val buildDirPath = layout.buildDirectory.asFile.get().absolutePath

val coverageSourceDirs = listOf("src/commonMain")
val classFiles = File("$buildDirPath/classes/kotlin/jvm").walkBottomUp().toSet()
val coverageSourceDirs = listOf("src/commonMain")
val classFiles = File("$buildDirPath/classes/kotlin/jvm").walkBottomUp().toSet()

classDirectories.setFrom(classFiles)
sourceDirectories.setFrom(files(coverageSourceDirs))
classDirectories.setFrom(classFiles)
sourceDirectories.setFrom(files(coverageSourceDirs))

executionData.setFrom(files("$buildDirPath/jacoco/junitPlatformTest.exec"))
executionData.setFrom(files("$buildDirPath/jacoco/junitPlatformTest.exec"))

reports {
xml.required.set(true)
html.required.set(true)
csv.required.set(false)
}
reports {
xml.required.set(true)
html.required.set(true)
csv.required.set(false)
}
}

tasks.jacocoTestCoverageVerification {
dependsOn(tasks.named("jvmTest"))
violationRules {
rule {
limit {
counter = "LINE"
value = "COVEREDRATIO"
minimum = BigDecimal(0.90)
}
}
dependsOn(tasks.named("jvmTest"))
violationRules {
rule {
limit {
counter = "LINE"
value = "COVEREDRATIO"
minimum = BigDecimal(0.90)
}
}
}
}

tasks.check.configure {
dependsOn(tasks.jacocoTestReport)
dependsOn(tasks.jacocoTestCoverageVerification)
dependsOn(tasks.jacocoTestReport)
dependsOn(tasks.jacocoTestCoverageVerification)
}

fun NamedDomainObjectContainer<KotlinJvmCompilation>.registerBenchmarkCompilation() {
val main = getByName("main")
val test = getByName("test")
create("benchmark") {
defaultSourceSet {
dependencies {
implementation(main.compileDependencyFiles + main.output.classesDirs)
implementation(test.compileDependencyFiles + test.output.classesDirs)

implementation(libs.jayway.jsonPath)
implementation(libs.json.org)
implementation(libs.test.junit)
implementation(libs.jackson.core)
implementation(libs.jackson.databind)
implementation(libs.jackson.moduleKotlin)
implementation(libs.slf4j)

}
}
val main = getByName("main")
val test = getByName("test")
create("benchmark") {
defaultSourceSet {
dependencies {
implementation(main.compileDependencyFiles + main.output.classesDirs)
implementation(test.compileDependencyFiles + test.output.classesDirs)

implementation(libs.jayway.jsonPath)
implementation(libs.json.org)
implementation(libs.test.junit)
implementation(libs.jackson.core)
implementation(libs.jackson.databind)
implementation(libs.jackson.moduleKotlin)
implementation(libs.slf4j)
}
}

// pass -PreadmeFormat to format benchmark results to update readme
val readmeFormat = hasProperty("readmeFormat")
// pass -PreadmeFormat to format benchmark results to update readme
val readmeFormat = hasProperty("readmeFormat")

tasks.register<Test>("benchmark") {
classpath = compileDependencyFiles + runtimeDependencyFiles + output.allOutputs
testClassesDirs = output.classesDirs
tasks.register<Test>("benchmark") {
classpath = compileDependencyFiles + runtimeDependencyFiles + output.allOutputs
testClassesDirs = output.classesDirs

useJUnitPlatform()
useJUnitPlatform()

if (readmeFormat) {
jvmArgs("-DreadmeFormat=true")
}
if (readmeFormat) {
jvmArgs("-DreadmeFormat=true")
}

testLogging {
showStandardStreams = true
}
testLogging {
showStandardStreams = true
}

// Make this task never up to date, thus forcing rerun of all tests whenever task is run
outputs.upToDateWhen { false }
}
// Make this task never up to date, thus forcing rerun of all tests whenever task is run
outputs.upToDateWhen { false }
}
}
}
Loading

0 comments on commit e1865df

Please sign in to comment.