Skip to content

Commit 8e5c4c4

Browse files
authored
Detekt 2.0.0-alpha.0. (#52)
1 parent 66402ed commit 8e5c4c4

File tree

19 files changed

+82
-96
lines changed

19 files changed

+82
-96
lines changed

build-logic/build.gradle.kts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import io.gitlab.arturbosch.detekt.Detekt
1+
import dev.detekt.gradle.Detekt
22
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
33
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
44

55
plugins {
6-
`kotlin-dsl`
6+
`java-gradle-plugin`
7+
alias(libs.plugins.kotlin.jvm)
78
alias(libs.plugins.detekt)
89
}
910

@@ -22,15 +23,13 @@ detekt {
2223
source.from(files("src/"))
2324
config.from(files("../detekt.yml"))
2425
buildUponDefaultConfig = true
25-
allRules = true
2626
parallel = true
2727
}
2828

2929
tasks.withType<Detekt>().configureEach {
3030
jvmTarget = JvmTarget.JVM_11.target
3131
reports {
3232
xml.required.set(false)
33-
txt.required.set(false)
3433
sarif.required.set(false)
3534
md.required.set(false)
3635
}
@@ -51,7 +50,7 @@ dependencies {
5150
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
5251

5352
// enable Ktlint formatting
54-
add("detektPlugins", libs.plugin.detektFormatting)
53+
add("detektPlugins", libs.plugin.detektKtlintWrapper)
5554

5655
implementation(libs.plugin.kotlin)
5756
implementation(libs.plugin.dokka)

build-logic/src/main/kotlin/io/github/reactivecircus/cache4k/buildlogic/convention/ConventionPlugin.kt

Lines changed: 58 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,14 @@ package io.github.reactivecircus.cache4k.buildlogic.convention
22

33
import com.vanniktech.maven.publish.MavenPublishBaseExtension
44
import com.vanniktech.maven.publish.MavenPublishPlugin
5-
import io.gitlab.arturbosch.detekt.Detekt
6-
import io.gitlab.arturbosch.detekt.DetektPlugin
7-
import io.gitlab.arturbosch.detekt.extensions.DetektExtension
5+
import dev.detekt.gradle.Detekt
6+
import dev.detekt.gradle.extensions.DetektExtension
7+
import dev.detekt.gradle.plugin.DetektPlugin
88
import kotlinx.validation.BinaryCompatibilityValidatorPlugin
99
import org.gradle.accessors.dm.LibrariesForLibs
1010
import org.gradle.api.Plugin
1111
import org.gradle.api.Project
1212
import org.gradle.api.tasks.testing.Test
13-
import org.gradle.kotlin.dsl.configure
14-
import org.gradle.kotlin.dsl.creating
15-
import org.gradle.kotlin.dsl.getValue
16-
import org.gradle.kotlin.dsl.getting
17-
import org.gradle.kotlin.dsl.invoke
18-
import org.gradle.kotlin.dsl.register
19-
import org.gradle.kotlin.dsl.the
20-
import org.gradle.kotlin.dsl.withType
2113
import org.jetbrains.dokka.gradle.DokkaExtension
2214
import org.jetbrains.dokka.gradle.DokkaPlugin
2315
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
@@ -42,9 +34,9 @@ internal class ConventionPlugin : Plugin<Project> {
4234

4335
private fun Project.configureRootProject() {
4436
plugins.withId("org.jetbrains.dokka") {
45-
extensions.configure<DokkaExtension> {
46-
dokkaPublications.configureEach {
47-
outputDirectory.set(layout.buildDirectory.dir("docs/api"))
37+
extensions.configure(DokkaExtension::class.java) {
38+
it.dokkaPublications.configureEach {
39+
it.outputDirectory.set(layout.buildDirectory.dir("docs/api"))
4840
}
4941
}
5042
}
@@ -60,11 +52,11 @@ private fun Project.configureSubproject() {
6052
version = property("VERSION_NAME") as String
6153

6254
plugins.withId("org.jetbrains.kotlin.multiplatform") {
63-
extensions.configure<KotlinMultiplatformExtension> {
64-
explicitApi()
65-
configureTargets(this@configureSubproject)
66-
sourceSets.configureEach {
67-
languageSettings.apply {
55+
extensions.configure(KotlinMultiplatformExtension::class.java) {
56+
it.explicitApi()
57+
it.configureTargets(this@configureSubproject)
58+
it.sourceSets.configureEach {
59+
it.languageSettings.apply {
6860
progressiveMode = true
6961
}
7062
}
@@ -73,82 +65,81 @@ private fun Project.configureSubproject() {
7365

7466
// configure detekt
7567
pluginManager.apply(DetektPlugin::class.java)
76-
dependencies.add("detektPlugins", the<LibrariesForLibs>().plugin.detektFormatting)
77-
plugins.withType<DetektPlugin> {
78-
extensions.configure<DetektExtension> {
79-
source.from(files("src/"))
80-
config.from(files("${project.rootDir}/detekt.yml"))
81-
buildUponDefaultConfig = true
82-
allRules = true
83-
parallel = true
68+
dependencies.add("detektPlugins", (extensions.getByName("libs") as LibrariesForLibs).plugin.detektKtlintWrapper)
69+
plugins.withType(DetektPlugin::class.java) {
70+
extensions.configure(DetektExtension::class.java) {
71+
it.source.from(files("src/"))
72+
it.config.from(files("${project.rootDir}/detekt.yml"))
73+
it.buildUponDefaultConfig.set(true)
74+
it.parallel.set(true)
8475
}
85-
tasks.withType<Detekt>().configureEach {
86-
jvmTarget = JvmTarget.JVM_11.target
87-
reports {
88-
xml.required.set(false)
89-
txt.required.set(false)
90-
sarif.required.set(false)
91-
md.required.set(false)
76+
tasks.withType(Detekt::class.java).configureEach {
77+
it.jvmTarget.set(JvmTarget.JVM_11.target)
78+
it.reports { report ->
79+
report.xml.required.set(false)
80+
report.sarif.required.set(false)
81+
report.md.required.set(false)
9282
}
9383
}
9484
}
9585

9686
// configure test
97-
tasks.withType<Test>().configureEach {
98-
useJUnitPlatform()
99-
testLogging {
100-
events("passed", "skipped", "failed")
87+
tasks.withType(Test::class.java).configureEach { test ->
88+
test.useJUnitPlatform()
89+
test.testLogging {
90+
it.events("passed", "skipped", "failed")
10191
}
10292
}
10393

10494
// configure publishing
10595
pluginManager.apply(MavenPublishPlugin::class.java)
106-
extensions.configure<MavenPublishBaseExtension> {
107-
publishToMavenCentral(automaticRelease = true)
108-
signAllPublications()
96+
extensions.configure(MavenPublishBaseExtension::class.java) {
97+
it.publishToMavenCentral(automaticRelease = true)
98+
it.signAllPublications()
10999
}
110100
}
111101

112102
@Suppress("LongMethod", "MagicNumber")
113103
private fun KotlinMultiplatformExtension.configureTargets(project: Project) {
114104
targets.configureEach {
115-
compilations.configureEach {
116-
compileTaskProvider.configure {
105+
it.compilations.configureEach {
106+
it.compileTaskProvider.configure {
117107
compilerOptions {
118108
freeCompilerArgs.add("-Xexpect-actual-classes")
119109
}
120110
}
121111
}
122112
}
123-
project.tasks.withType<KotlinJvmCompile>().configureEach {
124-
compilerOptions {
113+
project.tasks.withType(KotlinJvmCompile::class.java).configureEach {
114+
it.compilerOptions {
125115
jvmTarget.set(JvmTarget.JVM_11)
126116
freeCompilerArgs.addAll(
127117
"-Xjvm-default=all"
128118
)
129119
}
130120
}
131-
project.tasks.withType<KotlinJsCompile>().configureEach {
132-
compilerOptions {
121+
project.tasks.withType(KotlinJsCompile::class.java).configureEach {
122+
it.compilerOptions {
133123
moduleKind.set(JsModuleKind.MODULE_COMMONJS)
134124
}
135125
}
136126
jvm {
137127
val main = compilations.getByName("main")
138-
compilations.create("lincheck") {
139-
defaultSourceSet {
128+
compilations.create("lincheck") { compilation ->
129+
compilation.defaultSourceSet {
140130
dependencies {
141131
implementation(main.compileDependencyFiles + main.output.classesDirs)
142132
}
143133
}
144-
project.tasks.register<Test>("jvmLincheck") {
145-
classpath = compileDependencyFiles + runtimeDependencyFiles + output.allOutputs
146-
testClassesDirs = output.classesDirs
147-
useJUnitPlatform()
148-
testLogging {
149-
events("passed", "skipped", "failed")
134+
project.tasks.register("jvmLincheck", Test::class.java) {
135+
it.classpath = compilation.compileDependencyFiles +
136+
compilation.runtimeDependencyFiles + compilation.output.allOutputs
137+
it.testClassesDirs = compilation.output.classesDirs
138+
it.useJUnitPlatform()
139+
it.testLogging {
140+
it.events("passed", "skipped", "failed")
150141
}
151-
jvmArgs(
142+
it.jvmArgs(
152143
"--add-opens", "java.base/jdk.internal.misc=ALL-UNNAMED",
153144
"--add-opens", "java.base/java.lang=ALL-UNNAMED",
154145
"--add-exports", "java.base/jdk.internal.util=ALL-UNNAMED",
@@ -183,20 +174,19 @@ private fun KotlinMultiplatformExtension.configureTargets(project: Project) {
183174
mingwX64()
184175
applyDefaultHierarchyTemplate()
185176

186-
@Suppress("UnusedPrivateProperty")
187-
sourceSets {
188-
val nonJvmMain by creating {
189-
dependsOn(commonMain.get())
177+
with(sourceSets) {
178+
create("nonJvmMain") {
179+
it.dependsOn(commonMain.get())
190180
}
191-
val jvmLincheck by getting {
192-
dependsOn(jvmMain.get())
181+
getByName("jvmLincheck") {
182+
it.dependsOn(jvmMain.get())
193183
}
194-
jsMain.get().dependsOn(nonJvmMain)
195-
val wasmJsMain by getting {
196-
dependsOn(nonJvmMain)
184+
jsMain.get().dependsOn(getByName("nonJvmMain"))
185+
getByName("wasmJsMain") {
186+
it.dependsOn(getByName("nonJvmMain"))
197187
}
198-
appleMain.get().dependsOn(nonJvmMain)
199-
linuxMain.get().dependsOn(nonJvmMain)
200-
mingwMain.get().dependsOn(nonJvmMain)
188+
appleMain.get().dependsOn(getByName("nonJvmMain"))
189+
linuxMain.get().dependsOn(getByName("nonJvmMain"))
190+
mingwMain.get().dependsOn(getByName("nonJvmMain"))
201191
}
202192
}

cache4k/src/commonMain/kotlin/io/github/reactivecircus/cache4k/Cache.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import kotlin.time.TimeSource
77
* An in-memory key-value cache with support for time-based (expiration) and size-based evictions.
88
*/
99
public interface Cache<in Key : Any, Value : Any> {
10-
1110
/**
1211
* Returns the value associated with [key] in this cache, or null if there is no
1312
* cached value for [key].
@@ -48,7 +47,6 @@ public interface Cache<in Key : Any, Value : Any> {
4847
* Main entry point for creating a [Cache].
4948
*/
5049
public interface Builder<K : Any, V : Any> {
51-
5250
/**
5351
* Specifies that each entry should be automatically removed from the cache once a fixed duration
5452
* has elapsed after the entry's creation or the most recent replacement of its value.
@@ -95,7 +93,6 @@ public interface Cache<in Key : Any, Value : Any> {
9593
public fun build(): Cache<K, V>
9694

9795
public companion object {
98-
9996
/**
10097
* Returns a new [Cache.Builder] instance.
10198
*/
@@ -108,7 +105,6 @@ public interface Cache<in Key : Any, Value : Any> {
108105
* A default implementation of [Cache.Builder].
109106
*/
110107
internal class CacheBuilderImpl<K : Any, V : Any> : Cache.Builder<K, V> {
111-
112108
private var expireAfterWriteDuration = Duration.INFINITE
113109

114110
private var expireAfterAccessDuration = Duration.INFINITE

cache4k/src/commonMain/kotlin/io/github/reactivecircus/cache4k/ConcurrentMutableMap.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@ package io.github.reactivecircus.cache4k
22

33
internal expect class ConcurrentMutableMap<Key : Any, Value : Any>() {
44
val size: Int
5+
56
val values: Collection<Value>
7+
68
operator fun get(key: Key): Value?
9+
710
fun put(key: Key, value: Value): Value?
11+
812
fun remove(key: Key): Value?
13+
914
fun clear()
1015
}

cache4k/src/commonMain/kotlin/io/github/reactivecircus/cache4k/FakeTimeSource.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import kotlin.time.DurationUnit
1313
* Implementation is identical to [kotlin.time.TestTimeSource] except the internal [reading] is an [AtomicLong].
1414
*/
1515
public class FakeTimeSource : AbstractLongTimeSource(unit = DurationUnit.NANOSECONDS) {
16-
1716
private val reading = atomic(0L)
1817

1918
override fun read(): Long = reading.value

cache4k/src/commonMain/kotlin/io/github/reactivecircus/cache4k/KeyedSynchronizer.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import kotlinx.coroutines.sync.withLock
99
* Provides a mechanism for performing key-based synchronization.
1010
*/
1111
internal class KeyedSynchronizer<Key : Any> {
12-
1312
private val keyBasedMutexes = ConcurrentMutableMap<Key, MutexEntry>()
1413

1514
private val mapLock = reentrantLock()

cache4k/src/commonMain/kotlin/io/github/reactivecircus/cache4k/RealCache.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ internal class RealCache<Key : Any, Value : Any>(
3636
val timeSource: TimeSource,
3737
private val eventListener: CacheEventListener<Key, Value>?,
3838
) : Cache<Key, Value> {
39-
4039
private val cacheEntries = ConcurrentMutableMap<Key, CacheEntry<Key, Value>>()
4140

4241
/**

cache4k/src/commonTest/kotlin/io/github/reactivecircus/cache4k/CacheBuilderTest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import kotlin.time.Duration.Companion.nanoseconds
1010
import kotlin.time.TimeSource
1111

1212
class CacheBuilderTest {
13-
1413
@Test
1514
fun expireAfterWrite_zeroDuration() {
1615
val exception = assertFailsWith<IllegalArgumentException> {

cache4k/src/commonTest/kotlin/io/github/reactivecircus/cache4k/CacheEvictionTest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import kotlin.test.assertEquals
55
import kotlin.test.assertNull
66

77
class CacheEvictionTest {
8-
98
@Test
109
fun maxSizeLimitReached_addNewEntry_oldEntryEvicted() {
1110
val cache = Cache.Builder<Long, String>()

cache4k/src/commonTest/kotlin/io/github/reactivecircus/cache4k/CacheExpiryTest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import kotlin.time.Duration.Companion.minutes
77
import kotlin.time.Duration.Companion.nanoseconds
88

99
class CacheExpiryTest {
10-
1110
private val fakeTimeSource = FakeTimeSource()
1211

1312
@Test

0 commit comments

Comments
 (0)