From 5ab159ae44203812ad74e8e79fb8fa1bf29ca53d Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Wed, 8 Nov 2023 17:59:48 +0300 Subject: [PATCH] Upgraded kotlin to 1.9.20 ### WHat's done: - upgraded kotlin - removed actual\expected class - added required OptIn It handles of #554 --- gradle/libs.versions.toml | 2 +- .../saveourtool/save/core/logging/Logger.kt | 3 ++- .../save/core/utils/PlatformUtils.kt | 12 ++++++++---- .../save/core/utils/PlatformUtils.kt | 16 ++++++++-------- .../save/core/utils/PlatformUtils.kt | 16 ++++++++-------- .../save/core/utils/PlatformUtils.kt | 18 ++++++++++-------- 6 files changed, 37 insertions(+), 30 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 419f9b782..1fabb948b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,5 @@ [versions] -kotlin = "1.9.10" +kotlin = "1.9.20" okio = "3.6.0" serialization = "1.6.0" diktat = "1.2.5" diff --git a/save-common/src/commonMain/kotlin/com/saveourtool/save/core/logging/Logger.kt b/save-common/src/commonMain/kotlin/com/saveourtool/save/core/logging/Logger.kt index 5f5471cd1..3bfaeb720 100644 --- a/save-common/src/commonMain/kotlin/com/saveourtool/save/core/logging/Logger.kt +++ b/save-common/src/commonMain/kotlin/com/saveourtool/save/core/logging/Logger.kt @@ -10,6 +10,7 @@ package com.saveourtool.save.core.logging import com.saveourtool.save.core.config.LogType import com.saveourtool.save.core.config.OutputStreamType import com.saveourtool.save.core.utils.GenericAtomicReference +import com.saveourtool.save.core.utils.createGenericAtomicReference import com.saveourtool.save.core.utils.writeToStream import kotlin.native.concurrent.SharedImmutable @@ -21,7 +22,7 @@ import kotlinx.datetime.toLocalDateTime * Logging mode */ @SharedImmutable -val logType: GenericAtomicReference = GenericAtomicReference(LogType.WARN) +val logType: GenericAtomicReference = createGenericAtomicReference(LogType.WARN) /** * Whether to add time stamps to log messages diff --git a/save-common/src/commonMain/kotlin/com/saveourtool/save/core/utils/PlatformUtils.kt b/save-common/src/commonMain/kotlin/com/saveourtool/save/core/utils/PlatformUtils.kt index 6341f3674..a3851979e 100644 --- a/save-common/src/commonMain/kotlin/com/saveourtool/save/core/utils/PlatformUtils.kt +++ b/save-common/src/commonMain/kotlin/com/saveourtool/save/core/utils/PlatformUtils.kt @@ -16,12 +16,10 @@ enum class CurrentOs { } /** - * Class that holds value and shares atomic reference to the value (native only) + * Interface that holds value and shares atomic reference to the value (native only) * - * @param valueToStore value to store */ -@Suppress("USE_DATA_CLASS") -expect class GenericAtomicReference(valueToStore: T) { +interface GenericAtomicReference { /** * @return stored value */ @@ -33,6 +31,12 @@ expect class GenericAtomicReference(valueToStore: T) { fun set(newValue: T) } +/** + * @param valueToStore value to store + * @return a new [GenericAtomicReference] with default value [valueToStore] + */ +expect fun createGenericAtomicReference(valueToStore: T): GenericAtomicReference + /** * Get type of current OS * diff --git a/save-common/src/jsMain/kotlin/com/saveourtool/save/core/utils/PlatformUtils.kt b/save-common/src/jsMain/kotlin/com/saveourtool/save/core/utils/PlatformUtils.kt index e41698b4f..949ce40de 100644 --- a/save-common/src/jsMain/kotlin/com/saveourtool/save/core/utils/PlatformUtils.kt +++ b/save-common/src/jsMain/kotlin/com/saveourtool/save/core/utils/PlatformUtils.kt @@ -13,14 +13,14 @@ package com.saveourtool.save.core.utils import com.saveourtool.save.core.config.OutputStreamType -@Suppress("USE_DATA_CLASS") -actual class GenericAtomicReference actual constructor(valueToStore: T) { - private var value: T = valueToStore - actual fun get(): T = value - actual fun set(newValue: T) { - value = newValue - } -} +actual fun createGenericAtomicReference(valueToStore: T): GenericAtomicReference = + object : GenericAtomicReference { + private var value: T = valueToStore + override fun get(): T = value + override fun set(newValue: T) { + value = newValue + } + } actual fun getCurrentOs(): CurrentOs = error("Not implemented for JS") diff --git a/save-common/src/jvmMain/kotlin/com/saveourtool/save/core/utils/PlatformUtils.kt b/save-common/src/jvmMain/kotlin/com/saveourtool/save/core/utils/PlatformUtils.kt index 2fb595b59..c41cf8617 100644 --- a/save-common/src/jvmMain/kotlin/com/saveourtool/save/core/utils/PlatformUtils.kt +++ b/save-common/src/jvmMain/kotlin/com/saveourtool/save/core/utils/PlatformUtils.kt @@ -10,14 +10,14 @@ package com.saveourtool.save.core.utils import com.saveourtool.save.core.config.OutputStreamType -@Suppress("USE_DATA_CLASS") -actual class GenericAtomicReference actual constructor(valueToStore: T) { - private val holder: java.util.concurrent.atomic.AtomicReference = java.util.concurrent.atomic.AtomicReference(valueToStore) - actual fun get(): T = holder.get() - actual fun set(newValue: T) { - holder.set(newValue) - } -} +actual fun createGenericAtomicReference(valueToStore: T): GenericAtomicReference = + object : GenericAtomicReference { + private val holder = java.util.concurrent.atomic.AtomicReference(valueToStore) + override fun get(): T = holder.get() + override fun set(newValue: T) { + holder.set(newValue) + } + } actual fun getCurrentOs() = when { System.getProperty("os.name").startsWith("Linux", ignoreCase = true) -> CurrentOs.LINUX diff --git a/save-common/src/nativeMain/kotlin/com/saveourtool/save/core/utils/PlatformUtils.kt b/save-common/src/nativeMain/kotlin/com/saveourtool/save/core/utils/PlatformUtils.kt index f2ce29902..650210826 100644 --- a/save-common/src/nativeMain/kotlin/com/saveourtool/save/core/utils/PlatformUtils.kt +++ b/save-common/src/nativeMain/kotlin/com/saveourtool/save/core/utils/PlatformUtils.kt @@ -16,15 +16,16 @@ import platform.posix.stderr import platform.posix.stdout import kotlinx.cinterop.ExperimentalForeignApi +import kotlin.experimental.ExperimentalNativeApi -@Suppress("USE_DATA_CLASS") -actual class GenericAtomicReference actual constructor(valueToStore: T) { - private val holder: kotlin.concurrent.AtomicReference = kotlin.concurrent.AtomicReference(valueToStore) - actual fun get(): T = holder.value - actual fun set(newValue: T) { - holder.value = newValue - } -} +actual fun createGenericAtomicReference(valueToStore: T): GenericAtomicReference = + object : GenericAtomicReference { + private val holder = kotlin.concurrent.AtomicReference(valueToStore) + override fun get(): T = holder.value + override fun set(newValue: T) { + holder.value = newValue + } + } /** * Escaping percent symbol in the string in case it is not escaped already @@ -51,6 +52,7 @@ fun String.escapePercent(): String { return stringBuilder.toString() } +@OptIn(ExperimentalNativeApi::class) actual fun getCurrentOs() = when (Platform.osFamily) { OsFamily.LINUX -> CurrentOs.LINUX OsFamily.MACOSX -> CurrentOs.MACOS