Skip to content
Merged
Show file tree
Hide file tree
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
9 changes: 4 additions & 5 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import io.gitlab.arturbosch.detekt.Detekt
import dev.detekt.gradle.Detekt
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
`kotlin-dsl`
`java-gradle-plugin`
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.detekt)
}

Expand All @@ -22,15 +23,13 @@ detekt {
source.from(files("src/"))
config.from(files("../detekt.yml"))
buildUponDefaultConfig = true
allRules = true
parallel = true
}

tasks.withType<Detekt>().configureEach {
jvmTarget = JvmTarget.JVM_11.target
reports {
xml.required.set(false)
txt.required.set(false)
sarif.required.set(false)
md.required.set(false)
}
Expand All @@ -51,7 +50,7 @@ dependencies {
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))

// enable Ktlint formatting
add("detektPlugins", libs.plugin.detektFormatting)
add("detektPlugins", libs.plugin.detektKtlintWrapper)

implementation(libs.plugin.kotlin)
implementation(libs.plugin.dokka)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,14 @@ package io.github.reactivecircus.cache4k.buildlogic.convention

import com.vanniktech.maven.publish.MavenPublishBaseExtension
import com.vanniktech.maven.publish.MavenPublishPlugin
import io.gitlab.arturbosch.detekt.Detekt
import io.gitlab.arturbosch.detekt.DetektPlugin
import io.gitlab.arturbosch.detekt.extensions.DetektExtension
import dev.detekt.gradle.Detekt
import dev.detekt.gradle.extensions.DetektExtension
import dev.detekt.gradle.plugin.DetektPlugin
import kotlinx.validation.BinaryCompatibilityValidatorPlugin
import org.gradle.accessors.dm.LibrariesForLibs
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.tasks.testing.Test
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.creating
import org.gradle.kotlin.dsl.getValue
import org.gradle.kotlin.dsl.getting
import org.gradle.kotlin.dsl.invoke
import org.gradle.kotlin.dsl.register
import org.gradle.kotlin.dsl.the
import org.gradle.kotlin.dsl.withType
import org.jetbrains.dokka.gradle.DokkaExtension
import org.jetbrains.dokka.gradle.DokkaPlugin
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
Expand All @@ -42,9 +34,9 @@ internal class ConventionPlugin : Plugin<Project> {

private fun Project.configureRootProject() {
plugins.withId("org.jetbrains.dokka") {
extensions.configure<DokkaExtension> {
dokkaPublications.configureEach {
outputDirectory.set(layout.buildDirectory.dir("docs/api"))
extensions.configure(DokkaExtension::class.java) {
it.dokkaPublications.configureEach {
it.outputDirectory.set(layout.buildDirectory.dir("docs/api"))
}
}
}
Expand All @@ -60,11 +52,11 @@ private fun Project.configureSubproject() {
version = property("VERSION_NAME") as String

plugins.withId("org.jetbrains.kotlin.multiplatform") {
extensions.configure<KotlinMultiplatformExtension> {
explicitApi()
configureTargets(this@configureSubproject)
sourceSets.configureEach {
languageSettings.apply {
extensions.configure(KotlinMultiplatformExtension::class.java) {
it.explicitApi()
it.configureTargets(this@configureSubproject)
it.sourceSets.configureEach {
it.languageSettings.apply {
progressiveMode = true
}
}
Expand All @@ -73,82 +65,81 @@ private fun Project.configureSubproject() {

// configure detekt
pluginManager.apply(DetektPlugin::class.java)
dependencies.add("detektPlugins", the<LibrariesForLibs>().plugin.detektFormatting)
plugins.withType<DetektPlugin> {
extensions.configure<DetektExtension> {
source.from(files("src/"))
config.from(files("${project.rootDir}/detekt.yml"))
buildUponDefaultConfig = true
allRules = true
parallel = true
dependencies.add("detektPlugins", (extensions.getByName("libs") as LibrariesForLibs).plugin.detektKtlintWrapper)
plugins.withType(DetektPlugin::class.java) {
extensions.configure(DetektExtension::class.java) {
it.source.from(files("src/"))
it.config.from(files("${project.rootDir}/detekt.yml"))
it.buildUponDefaultConfig.set(true)
it.parallel.set(true)
}
tasks.withType<Detekt>().configureEach {
jvmTarget = JvmTarget.JVM_11.target
reports {
xml.required.set(false)
txt.required.set(false)
sarif.required.set(false)
md.required.set(false)
tasks.withType(Detekt::class.java).configureEach {
it.jvmTarget.set(JvmTarget.JVM_11.target)
it.reports { report ->
report.xml.required.set(false)
report.sarif.required.set(false)
report.md.required.set(false)
}
}
}

// configure test
tasks.withType<Test>().configureEach {
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed")
tasks.withType(Test::class.java).configureEach { test ->
test.useJUnitPlatform()
test.testLogging {
it.events("passed", "skipped", "failed")
}
}

// configure publishing
pluginManager.apply(MavenPublishPlugin::class.java)
extensions.configure<MavenPublishBaseExtension> {
publishToMavenCentral(automaticRelease = true)
signAllPublications()
extensions.configure(MavenPublishBaseExtension::class.java) {
it.publishToMavenCentral(automaticRelease = true)
it.signAllPublications()
}
}

@Suppress("LongMethod", "MagicNumber")
private fun KotlinMultiplatformExtension.configureTargets(project: Project) {
targets.configureEach {
compilations.configureEach {
compileTaskProvider.configure {
it.compilations.configureEach {
it.compileTaskProvider.configure {
compilerOptions {
freeCompilerArgs.add("-Xexpect-actual-classes")
}
}
}
}
project.tasks.withType<KotlinJvmCompile>().configureEach {
compilerOptions {
project.tasks.withType(KotlinJvmCompile::class.java).configureEach {
it.compilerOptions {
jvmTarget.set(JvmTarget.JVM_11)
freeCompilerArgs.addAll(
"-Xjvm-default=all"
)
}
}
project.tasks.withType<KotlinJsCompile>().configureEach {
compilerOptions {
project.tasks.withType(KotlinJsCompile::class.java).configureEach {
it.compilerOptions {
moduleKind.set(JsModuleKind.MODULE_COMMONJS)
}
}
jvm {
val main = compilations.getByName("main")
compilations.create("lincheck") {
defaultSourceSet {
compilations.create("lincheck") { compilation ->
compilation.defaultSourceSet {
dependencies {
implementation(main.compileDependencyFiles + main.output.classesDirs)
}
}
project.tasks.register<Test>("jvmLincheck") {
classpath = compileDependencyFiles + runtimeDependencyFiles + output.allOutputs
testClassesDirs = output.classesDirs
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed")
project.tasks.register("jvmLincheck", Test::class.java) {
it.classpath = compilation.compileDependencyFiles +
compilation.runtimeDependencyFiles + compilation.output.allOutputs
it.testClassesDirs = compilation.output.classesDirs
it.useJUnitPlatform()
it.testLogging {
it.events("passed", "skipped", "failed")
}
jvmArgs(
it.jvmArgs(
"--add-opens", "java.base/jdk.internal.misc=ALL-UNNAMED",
"--add-opens", "java.base/java.lang=ALL-UNNAMED",
"--add-exports", "java.base/jdk.internal.util=ALL-UNNAMED",
Expand Down Expand Up @@ -183,20 +174,19 @@ private fun KotlinMultiplatformExtension.configureTargets(project: Project) {
mingwX64()
applyDefaultHierarchyTemplate()

@Suppress("UnusedPrivateProperty")
sourceSets {
val nonJvmMain by creating {
dependsOn(commonMain.get())
with(sourceSets) {
create("nonJvmMain") {
it.dependsOn(commonMain.get())
}
val jvmLincheck by getting {
dependsOn(jvmMain.get())
getByName("jvmLincheck") {
it.dependsOn(jvmMain.get())
}
jsMain.get().dependsOn(nonJvmMain)
val wasmJsMain by getting {
dependsOn(nonJvmMain)
jsMain.get().dependsOn(getByName("nonJvmMain"))
getByName("wasmJsMain") {
it.dependsOn(getByName("nonJvmMain"))
}
appleMain.get().dependsOn(nonJvmMain)
linuxMain.get().dependsOn(nonJvmMain)
mingwMain.get().dependsOn(nonJvmMain)
appleMain.get().dependsOn(getByName("nonJvmMain"))
linuxMain.get().dependsOn(getByName("nonJvmMain"))
mingwMain.get().dependsOn(getByName("nonJvmMain"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import kotlin.time.TimeSource
* An in-memory key-value cache with support for time-based (expiration) and size-based evictions.
*/
public interface Cache<in Key : Any, Value : Any> {

/**
* Returns the value associated with [key] in this cache, or null if there is no
* cached value for [key].
Expand Down Expand Up @@ -48,7 +47,6 @@ public interface Cache<in Key : Any, Value : Any> {
* Main entry point for creating a [Cache].
*/
public interface Builder<K : Any, V : Any> {

/**
* Specifies that each entry should be automatically removed from the cache once a fixed duration
* has elapsed after the entry's creation or the most recent replacement of its value.
Expand Down Expand Up @@ -95,7 +93,6 @@ public interface Cache<in Key : Any, Value : Any> {
public fun build(): Cache<K, V>

public companion object {

/**
* Returns a new [Cache.Builder] instance.
*/
Expand All @@ -108,7 +105,6 @@ public interface Cache<in Key : Any, Value : Any> {
* A default implementation of [Cache.Builder].
*/
internal class CacheBuilderImpl<K : Any, V : Any> : Cache.Builder<K, V> {

private var expireAfterWriteDuration = Duration.INFINITE

private var expireAfterAccessDuration = Duration.INFINITE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ package io.github.reactivecircus.cache4k

internal expect class ConcurrentMutableMap<Key : Any, Value : Any>() {
val size: Int

val values: Collection<Value>

operator fun get(key: Key): Value?

fun put(key: Key, value: Value): Value?

fun remove(key: Key): Value?

fun clear()
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import kotlin.time.DurationUnit
* Implementation is identical to [kotlin.time.TestTimeSource] except the internal [reading] is an [AtomicLong].
*/
public class FakeTimeSource : AbstractLongTimeSource(unit = DurationUnit.NANOSECONDS) {

private val reading = atomic(0L)

override fun read(): Long = reading.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import kotlinx.coroutines.sync.withLock
* Provides a mechanism for performing key-based synchronization.
*/
internal class KeyedSynchronizer<Key : Any> {

private val keyBasedMutexes = ConcurrentMutableMap<Key, MutexEntry>()

private val mapLock = reentrantLock()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ internal class RealCache<Key : Any, Value : Any>(
val timeSource: TimeSource,
private val eventListener: CacheEventListener<Key, Value>?,
) : Cache<Key, Value> {

private val cacheEntries = ConcurrentMutableMap<Key, CacheEntry<Key, Value>>()

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import kotlin.time.Duration.Companion.nanoseconds
import kotlin.time.TimeSource

class CacheBuilderTest {

@Test
fun expireAfterWrite_zeroDuration() {
val exception = assertFailsWith<IllegalArgumentException> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import kotlin.test.assertEquals
import kotlin.test.assertNull

class CacheEvictionTest {

@Test
fun maxSizeLimitReached_addNewEntry_oldEntryEvicted() {
val cache = Cache.Builder<Long, String>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import kotlin.time.Duration.Companion.minutes
import kotlin.time.Duration.Companion.nanoseconds

class CacheExpiryTest {

private val fakeTimeSource = FakeTimeSource()

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import kotlin.test.assertNull
import kotlin.time.Duration.Companion.minutes

class CacheInvalidationTest {

@Test
fun invalidateByKey_associatedEntryEvicted() {
val cache = Cache.Builder<Long, String>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import kotlin.time.Duration.Companion.minutes
import kotlin.time.Duration.Companion.nanoseconds

class CacheLoaderTest {

private val fakeTimeSource = FakeTimeSource()
private val expiryDuration = 1.minutes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import kotlin.test.assertEquals
import kotlin.test.assertNull

class DefaultCacheTest {

@Test
fun noEntryWithAssociatedKeyExists_get_returnsNull() {
val cache = Cache.Builder<Long, String>().build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import kotlin.test.assertFalse
import kotlin.test.assertTrue

class ReorderingIsoMutableSetTest {

private val set = ReorderingIsoMutableSet<String>()

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import org.junit.jupiter.api.Test
import kotlin.time.Duration.Companion.seconds

class Cache4kLincheckTest {

private val cache = Cache.Builder<Long, String>()
.expireAfterWrite(5.seconds)
.expireAfterAccess(2.seconds)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import org.jetbrains.kotlinx.lincheck.strategy.stress.StressOptions
import org.junit.jupiter.api.Test

class ReorderingIsoMutableSetLincheckTest {

private val reorderingIsoMutableSet = ReorderingIsoMutableSet<Int>()

@Operation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import org.junit.jupiter.api.RepeatedTest
import kotlin.time.Duration.Companion.seconds

class JvmConcurrencyTest {

private val fakeTimeSource = FakeTimeSource()

@RepeatedTest(100)
Expand Down
Loading