From 556d2f04aa67127dab1d501a69e11e7cbcbf93c4 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 6 Mar 2024 12:06:31 +0300 Subject: [PATCH] Update Kotlin core dependencies (#2844) - removed deprecated api - fixed actual\expected classes - fixed test for JS - @OptIn(ExperimentalNativeApi::class) - fixed import @JsModule("@react-sigma/*") --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Nariman Abdullin --- .../karma.config.d/custom-config.js | 10 ++++---- gradle/libs.versions.toml | 8 +++--- .../com/saveourtool/save/agent/SaveAgent.kt | 6 ++--- .../saveourtool/save/agent/utils/HttpUtils.kt | 4 +-- .../saveourtool/save/utils/PlatformUtils.kt | 25 +++++++++++++------ .../saveourtool/save/utils/PlatformUtils.kt | 20 ++++++--------- .../saveourtool/save/utils/PlatformUtils.kt | 20 +++++++++++---- .../saveourtool/save/utils/PlatformUtils.kt | 17 ++++++------- .../save/demo/agent/ServerTest.kt | 2 ++ save-frontend/karma.config.d/custom-config.js | 8 +++--- .../graph/sigma/layouts/LayoutCircular.kt | 7 ++---- .../graph/sigma/layouts/LayoutForceAtlas2.kt | 8 +++--- .../graph/sigma/layouts/LayoutRandom.kt | 7 ++---- 13 files changed, 75 insertions(+), 67 deletions(-) diff --git a/frontend-common/karma.config.d/custom-config.js b/frontend-common/karma.config.d/custom-config.js index 0c88d3dc9c..25274c721d 100644 --- a/frontend-common/karma.config.d/custom-config.js +++ b/frontend-common/karma.config.d/custom-config.js @@ -8,7 +8,7 @@ test: /\.js$/, use: {loader: 'istanbul-instrumenter-loader'}, // fixme: need to exclude Kotlin dependencies - include: [path.resolve(__dirname, '../save-cloud-save-frontend-common/kotlin/')] + include: [path.resolve(__dirname, '../save-cloud-frontend-common/kotlin/')] } ) config.coverageIstanbulReporter = { @@ -24,12 +24,12 @@ config.set({ } }, proxies: { - // serving mockServiceWorker.js.js from location relative to base url + // serving mockServiceWorker.js from location relative to base url // the file should be included into Karma's `files` to be served by server at all - '/mockServiceWorker.js': '/base/mockServiceWorker.js', + '/mockServiceWorker.js': '/base/node_modules/mockServiceWorker.js', }, }) // http://karma-runner.github.io/6.3/config/files.html -// 'All of the relative patterns will get resolved using the basePath first.', where basePath is set by KGP to `node_modules` -config.files.push('./mockServiceWorker.js') +// 'All of the relative patterns will get resolved using the basePath first.', where basePath is NOT set by KGP to `node_modules` after migration to 1.9 +config.files.push('./node_modules/mockServiceWorker.js') diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 8c3b1d6d20..1228d24b4a 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,12 +1,12 @@ [versions] -kotlin = "1.9.10" +kotlin = "1.9.22" jetbrains-annotations = "24.0.1" save-cli = "0.3.10" ktor = "2.3.6" okio = "3.3.0" -serialization = "1.6.0" -kotlinx-datetime = "0.4.1" -kotlinx-coroutines = "1.7.3" +serialization = "1.6.3" +kotlinx-datetime = "0.5.0" +kotlinx-coroutines = "1.8.0" kotlin-wrappers = "1.0.0-pre.634" spring-boot = "2.7.17" spring-cloud = "3.1.9" diff --git a/save-agent/src/commonMain/kotlin/com/saveourtool/save/agent/SaveAgent.kt b/save-agent/src/commonMain/kotlin/com/saveourtool/save/agent/SaveAgent.kt index 11e66b4276..afefa47c1e 100644 --- a/save-agent/src/commonMain/kotlin/com/saveourtool/save/agent/SaveAgent.kt +++ b/save-agent/src/commonMain/kotlin/com/saveourtool/save/agent/SaveAgent.kt @@ -51,12 +51,12 @@ class SaveAgent( /** * The current [AgentState] of this agent. Initial value corresponds to the period when agent needs to finish its configuration. */ - val state = GenericAtomicReference(AgentState.BUSY) + val state = createGenericAtomicReference(AgentState.BUSY) // fixme (limitation of old MM): can't use atomic reference to Instant here, because when using `Clock.System.now()` as an assigned value // Kotlin throws `kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen kotlinx.datetime.Instant...` - private val executionStartSeconds = AtomicLong(0L) - private val saveProcessJob: GenericAtomicReference = GenericAtomicReference(null) + private val executionStartSeconds = createAtomicLong(0L) + private val saveProcessJob: GenericAtomicReference = createGenericAtomicReference(null) private val backgroundContext = newSingleThreadContext("background") private val saveProcessContext = newSingleThreadContext("save-process") private val reportFormat = Json { diff --git a/save-agent/src/commonMain/kotlin/com/saveourtool/save/agent/utils/HttpUtils.kt b/save-agent/src/commonMain/kotlin/com/saveourtool/save/agent/utils/HttpUtils.kt index 19d82dd1bd..b3477fa756 100644 --- a/save-agent/src/commonMain/kotlin/com/saveourtool/save/agent/utils/HttpUtils.kt +++ b/save-agent/src/commonMain/kotlin/com/saveourtool/save/agent/utils/HttpUtils.kt @@ -8,7 +8,7 @@ import com.saveourtool.save.agent.AgentState import com.saveourtool.save.agent.SaveAgent import com.saveourtool.save.core.logging.logWarn import com.saveourtool.save.core.utils.runIf -import com.saveourtool.save.utils.AtomicLong +import com.saveourtool.save.utils.createAtomicLong import com.saveourtool.save.utils.failureOrNotOk import com.saveourtool.save.utils.fs import com.saveourtool.save.utils.notOk @@ -82,7 +82,7 @@ internal suspend fun HttpClient.download(url: String, file: Path): Result if (httpResponse.status.isSuccess()) { val channel: ByteReadChannel = httpResponse.body() - val totalBytes = AtomicLong(0L) + val totalBytes = createAtomicLong(0L) while (!channel.isClosedForRead) { val packet = channel.readRemaining(DEFAULT_HTTP_BUFFER_SIZE.toLong()) while (!packet.isEmpty) { diff --git a/save-cloud-common/src/commonMain/kotlin/com/saveourtool/save/utils/PlatformUtils.kt b/save-cloud-common/src/commonMain/kotlin/com/saveourtool/save/utils/PlatformUtils.kt index 53b2cc1a3f..bd1ce5f44e 100644 --- a/save-cloud-common/src/commonMain/kotlin/com/saveourtool/save/utils/PlatformUtils.kt +++ b/save-cloud-common/src/commonMain/kotlin/com/saveourtool/save/utils/PlatformUtils.kt @@ -13,7 +13,7 @@ import kotlinx.datetime.Clock /** * Atomic values */ -expect class AtomicLong(value: Long) { +interface AtomicLong { /** * @return value */ @@ -32,12 +32,9 @@ expect class AtomicLong(value: Long) { } /** - * Class that holds value and shares atomic reference to the value - * - * @param valueToStore value to store + * Class that holds value and shares atomic reference to the value */ -@Suppress("USE_DATA_CLASS") -expect class GenericAtomicReference(valueToStore: T) { +interface GenericAtomicReference { /** * @return stored value */ @@ -61,8 +58,8 @@ class ExpiringValueWrapper( private val valueGetter: () -> T, ) { private val expirationTimeSeconds = expirationTime.toLong(DurationUnit.SECONDS) - private val lastUpdateTimeSeconds = AtomicLong(0) - private val value: GenericAtomicReference = GenericAtomicReference(valueGetter()) + private val lastUpdateTimeSeconds = createAtomicLong(0) + private val value: GenericAtomicReference = createGenericAtomicReference(valueGetter()) /** * @return cached value or refreshes the value and returns it @@ -77,6 +74,18 @@ class ExpiringValueWrapper( } } +/** + * @param value + * @return [AtomicLong] with initial value [value] + */ +expect fun createAtomicLong(value: Long): AtomicLong + +/** + * @param valueToStore + * @return create [GenericAtomicReference] with initial value [valueToStore] + */ +expect fun createGenericAtomicReference(valueToStore: T): GenericAtomicReference + /** * @param envName * @return env variable name diff --git a/save-cloud-common/src/jsMain/kotlin/com/saveourtool/save/utils/PlatformUtils.kt b/save-cloud-common/src/jsMain/kotlin/com/saveourtool/save/utils/PlatformUtils.kt index 5648366b5c..efd5fa26c9 100644 --- a/save-cloud-common/src/jsMain/kotlin/com/saveourtool/save/utils/PlatformUtils.kt +++ b/save-cloud-common/src/jsMain/kotlin/com/saveourtool/save/utils/PlatformUtils.kt @@ -4,22 +4,18 @@ package com.saveourtool.save.utils -actual class AtomicLong actual constructor(value: Long) { - actual fun get(): Long = throw NotImplementedError(NOT_IMPLEMENTED_ON_JS) +actual fun createAtomicLong(value: Long): AtomicLong = object : AtomicLong { + override fun get(): Long = throw NotImplementedError(NOT_IMPLEMENTED_ON_JS) - actual fun set(newValue: Long) { - throw NotImplementedError(NOT_IMPLEMENTED_ON_JS) - } + override fun set(newValue: Long) = throw NotImplementedError(NOT_IMPLEMENTED_ON_JS) - actual fun addAndGet(delta: Long): Long = throw NotImplementedError(NOT_IMPLEMENTED_ON_JS) + override fun addAndGet(delta: Long): Long = throw NotImplementedError(NOT_IMPLEMENTED_ON_JS) } -@Suppress("USE_DATA_CLASS") -actual class GenericAtomicReference actual constructor(valueToStore: T) { - actual fun get(): T = throw NotImplementedError(NOT_IMPLEMENTED_ON_JS) - actual fun set(newValue: T) { - throw NotImplementedError(NOT_IMPLEMENTED_ON_JS) - } +actual fun createGenericAtomicReference(valueToStore: T): GenericAtomicReference = object : GenericAtomicReference { + override fun get(): T = throw NotImplementedError(NOT_IMPLEMENTED_ON_JS) + + override fun set(newValue: T) = throw NotImplementedError(NOT_IMPLEMENTED_ON_JS) } actual fun getenv(envName: String): String? = throw NotImplementedError(NOT_IMPLEMENTED_ON_JS) diff --git a/save-cloud-common/src/jvmMain/kotlin/com/saveourtool/save/utils/PlatformUtils.kt b/save-cloud-common/src/jvmMain/kotlin/com/saveourtool/save/utils/PlatformUtils.kt index 5edfb454cd..fd23413b5a 100644 --- a/save-cloud-common/src/jvmMain/kotlin/com/saveourtool/save/utils/PlatformUtils.kt +++ b/save-cloud-common/src/jvmMain/kotlin/com/saveourtool/save/utils/PlatformUtils.kt @@ -1,3 +1,7 @@ +/** + * Platform utils + */ + @file:Suppress("FILE_NAME_MATCH_CLASS") /** * Platform dependent utility methods @@ -7,13 +11,19 @@ package com.saveourtool.save.utils -actual typealias AtomicLong = java.util.concurrent.atomic.AtomicLong +actual fun createAtomicLong(value: Long): AtomicLong = object : AtomicLong { + private val holder = java.util.concurrent.atomic.AtomicLong(value) + override fun get(): Long = holder.get() + + override fun set(newValue: Long) = holder.set(newValue) + + override fun addAndGet(delta: Long): Long = holder.addAndGet(delta) +} -@Suppress("USE_DATA_CLASS") -actual class GenericAtomicReference actual constructor(valueToStore: T) { +actual fun createGenericAtomicReference(valueToStore: T): GenericAtomicReference = object : GenericAtomicReference { 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) { + override fun get(): T = holder.get() + override fun set(newValue: T) { holder.set(newValue) } } diff --git a/save-cloud-common/src/nativeMain/kotlin/com/saveourtool/save/utils/PlatformUtils.kt b/save-cloud-common/src/nativeMain/kotlin/com/saveourtool/save/utils/PlatformUtils.kt index 0d5ff19117..a48a4b361b 100644 --- a/save-cloud-common/src/nativeMain/kotlin/com/saveourtool/save/utils/PlatformUtils.kt +++ b/save-cloud-common/src/nativeMain/kotlin/com/saveourtool/save/utils/PlatformUtils.kt @@ -7,23 +7,22 @@ package com.saveourtool.save.utils import kotlinx.cinterop.ExperimentalForeignApi import kotlinx.cinterop.toKString -actual class AtomicLong actual constructor(value: Long) { - private val kotlinAtomicLong = kotlin.native.concurrent.AtomicLong(value) +actual fun createAtomicLong(value: Long): AtomicLong = object : AtomicLong { + private val kotlinAtomicLong = kotlin.concurrent.AtomicLong(value) - actual fun get(): Long = kotlinAtomicLong.value + override fun get(): Long = kotlinAtomicLong.value - actual fun set(newValue: Long) { + override fun set(newValue: Long) { kotlinAtomicLong.value = newValue } - actual fun addAndGet(delta: Long): Long = kotlinAtomicLong.addAndGet(delta) + override fun addAndGet(delta: Long): Long = kotlinAtomicLong.addAndGet(delta) } -@Suppress("USE_DATA_CLASS") -actual class GenericAtomicReference actual constructor(valueToStore: T) { +actual fun createGenericAtomicReference(valueToStore: T): GenericAtomicReference = object : GenericAtomicReference { private val holder: kotlin.concurrent.AtomicReference = kotlin.concurrent.AtomicReference(valueToStore) - actual fun get(): T = holder.value - actual fun set(newValue: T) { + override fun get(): T = holder.value + override fun set(newValue: T) { holder.value = newValue } } diff --git a/save-demo-agent/src/nativeTest/kotlin/com/saveoourtool/save/demo/agent/ServerTest.kt b/save-demo-agent/src/nativeTest/kotlin/com/saveoourtool/save/demo/agent/ServerTest.kt index cf82d3c44f..63dfb52d8d 100644 --- a/save-demo-agent/src/nativeTest/kotlin/com/saveoourtool/save/demo/agent/ServerTest.kt +++ b/save-demo-agent/src/nativeTest/kotlin/com/saveoourtool/save/demo/agent/ServerTest.kt @@ -10,6 +10,7 @@ import io.ktor.utils.io.core.* import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch +import kotlin.experimental.ExperimentalNativeApi import kotlin.test.* class ServerTest { @@ -27,6 +28,7 @@ class ServerTest { server.stop() } + @OptIn(ExperimentalNativeApi::class) @Test fun testServerStartup() { httpClient().use { client -> diff --git a/save-frontend/karma.config.d/custom-config.js b/save-frontend/karma.config.d/custom-config.js index 89c1081706..f84f21137a 100644 --- a/save-frontend/karma.config.d/custom-config.js +++ b/save-frontend/karma.config.d/custom-config.js @@ -24,12 +24,12 @@ config.set({ } }, proxies: { - // serving mockServiceWorker.js.js from location relative to base url + // serving mockServiceWorker.js from location relative to base url // the file should be included into Karma's `files` to be served by server at all - '/mockServiceWorker.js': '/base/mockServiceWorker.js', + '/mockServiceWorker.js': '/base/node_modules/mockServiceWorker.js', }, }) // http://karma-runner.github.io/6.3/config/files.html -// 'All of the relative patterns will get resolved using the basePath first.', where basePath is set by KGP to `node_modules` -config.files.push('./mockServiceWorker.js') +// 'All of the relative patterns will get resolved using the basePath first.', where basePath is NOT set by KGP to `node_modules` after migration to 1.9 +config.files.push('./node_modules/mockServiceWorker.js') diff --git a/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/externals/graph/sigma/layouts/LayoutCircular.kt b/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/externals/graph/sigma/layouts/LayoutCircular.kt index e032f7ee0b..e02f3ffa18 100644 --- a/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/externals/graph/sigma/layouts/LayoutCircular.kt +++ b/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/externals/graph/sigma/layouts/LayoutCircular.kt @@ -1,15 +1,12 @@ @file:Suppress("FILE_NAME_MATCH_CLASS", "HEADER_MISSING_IN_NON_SINGLE_CLASS_FILE") -@file:JsModule("@react-sigma/layout-circular") -@file:JsNonModule package com.saveourtool.save.frontend.externals.graph.sigma.layouts -import react.* - /** * @param settings * @return [LayoutInstance] with positions and assign functions */ -@JsName("useLayoutCircular") +@JsModule("@react-sigma/layout-circular") +@JsNonModule @JsExport external fun useLayoutCircular(settings: dynamic = definedExternally): LayoutInstance diff --git a/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/externals/graph/sigma/layouts/LayoutForceAtlas2.kt b/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/externals/graph/sigma/layouts/LayoutForceAtlas2.kt index 2a1b490b77..76008bc9c1 100644 --- a/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/externals/graph/sigma/layouts/LayoutForceAtlas2.kt +++ b/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/externals/graph/sigma/layouts/LayoutForceAtlas2.kt @@ -1,14 +1,12 @@ @file:Suppress("FILE_NAME_MATCH_CLASS", "HEADER_MISSING_IN_NON_SINGLE_CLASS_FILE") -@file:JsModule("@react-sigma/layout-forceatlas2") -@file:JsNonModule package com.saveourtool.save.frontend.externals.graph.sigma.layouts -import react.* - /** * @param settings * @return [LayoutInstance] with positions and assign functions */ -@JsName("useLayoutForceAtlas2") +@JsModule("@react-sigma/layout-forceatlas2") +@JsNonModule +@JsExport external fun useLayoutForceAtlas2(settings: dynamic = definedExternally): LayoutInstance diff --git a/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/externals/graph/sigma/layouts/LayoutRandom.kt b/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/externals/graph/sigma/layouts/LayoutRandom.kt index 8b229d530a..305b38a7da 100644 --- a/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/externals/graph/sigma/layouts/LayoutRandom.kt +++ b/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/externals/graph/sigma/layouts/LayoutRandom.kt @@ -1,15 +1,12 @@ @file:Suppress("FILE_NAME_MATCH_CLASS", "HEADER_MISSING_IN_NON_SINGLE_CLASS_FILE") -@file:JsModule("@react-sigma/layout-random") -@file:JsNonModule package com.saveourtool.save.frontend.externals.graph.sigma.layouts -import react.* - /** * @param settings * @return [LayoutInstance] with positions and assign functions */ -@JsName("useLayoutRandom") +@JsModule("@react-sigma/layout-random") +@JsNonModule @JsExport external fun useLayoutRandom(settings: dynamic = definedExternally): LayoutInstance