From 19bbfd49162a9ee4c81d8e4bec6804c751af8429 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 25 Jul 2024 18:53:47 +0600 Subject: [PATCH] downgrade kotlin and fix build --- gradle/libs.versions.toml | 4 +- startup/plugin/build.gradle | 1 + .../kotlin/StartPluginSerializer.kt | 39 ++++++++++++++++++- .../jsMain/kotlin/StartPluginSerializer.js.kt | 13 +++++++ .../jsMain/kotlin/StartPluginSerializer.kt | 35 ----------------- .../kotlin/StartPluginSerializer.jvm.kt | 17 ++++++++ .../jvmMain/kotlin/StartPluginSerializer.kt | 23 ----------- .../kotlin/StartPluginSerializer.kt | 36 ----------------- .../kotlin/StartPluginSerializer.kt | 36 ----------------- .../kotlin/StartPluginSerializer.native.kt | 13 +++++++ 10 files changed, 84 insertions(+), 133 deletions(-) create mode 100644 startup/plugin/src/jsMain/kotlin/StartPluginSerializer.js.kt delete mode 100644 startup/plugin/src/jsMain/kotlin/StartPluginSerializer.kt create mode 100644 startup/plugin/src/jvmMain/kotlin/StartPluginSerializer.jvm.kt delete mode 100644 startup/plugin/src/jvmMain/kotlin/StartPluginSerializer.kt delete mode 100644 startup/plugin/src/linuxX64Main/kotlin/StartPluginSerializer.kt delete mode 100644 startup/plugin/src/mingwX64Main/kotlin/StartPluginSerializer.kt create mode 100644 startup/plugin/src/nativeMain/kotlin/StartPluginSerializer.native.kt diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 172ab0a38b1..214fd3c041b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,6 +1,6 @@ [versions] -kt = "2.0.20-Beta2" +kt = "2.0.0" kt-serialization = "1.7.1" kt-coroutines = "1.8.1" @@ -21,7 +21,7 @@ koin = "3.5.6" okio = "3.9.0" -ksp = "2.0.20-Beta2-1.0.23" +ksp = "2.0.0-1.0.23" kotlin-poet = "1.18.0" versions = "0.51.0" diff --git a/startup/plugin/build.gradle b/startup/plugin/build.gradle index 6da68fd5aec..0aef62701a0 100644 --- a/startup/plugin/build.gradle +++ b/startup/plugin/build.gradle @@ -13,6 +13,7 @@ kotlin { api libs.kslog api libs.kt.reflect api project(":micro_utils.coroutines") + api libs.uuid } } jsMain { diff --git a/startup/plugin/src/commonMain/kotlin/StartPluginSerializer.kt b/startup/plugin/src/commonMain/kotlin/StartPluginSerializer.kt index 15e4a6be604..6dfe08987c7 100644 --- a/startup/plugin/src/commonMain/kotlin/StartPluginSerializer.kt +++ b/startup/plugin/src/commonMain/kotlin/StartPluginSerializer.kt @@ -1,5 +1,42 @@ package dev.inmo.micro_utils.startup.plugin +import com.benasher44.uuid.uuid4 import kotlinx.serialization.KSerializer +import kotlinx.serialization.builtins.serializer +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder -expect object StartPluginSerializer : KSerializer +object StartPluginSerializer : KSerializer { + private val registeredPlugins = mutableMapOf() + private val registeredPluginsByPlugin = mutableMapOf() + override val descriptor: SerialDescriptor = String.serializer().descriptor + + override fun deserialize(decoder: Decoder): StartPlugin { + alternativeDeserialize(decoder) ?.let { return it } + val name = decoder.decodeString() + return registeredPlugins[name] ?: error("Unable to find startup plugin for $name") + } + + override fun serialize(encoder: Encoder, value: StartPlugin) { + if (alternativeSerialize(encoder, value)) { + return + } + val name = registeredPluginsByPlugin[value] ?: uuid4().toString().also { + registeredPlugins[it] = value + registeredPluginsByPlugin[value] = it + } + encoder.encodeString(name) + } + + /** + * Register plugin inside of this [KSerializer]. Since plugin has been registered, you may use its [name] in any + * serialized [dev.inmo.micro_utils.startup.launcher.Config] to retrieve [plugin] you passed here + */ + fun registerPlugin(name: String, plugin: StartPlugin) { + registeredPlugins[name] = plugin + } +} + +internal expect fun alternativeDeserialize(decoder: Decoder): StartPlugin? +internal expect fun alternativeSerialize(encoder: Encoder, value: StartPlugin): Boolean diff --git a/startup/plugin/src/jsMain/kotlin/StartPluginSerializer.js.kt b/startup/plugin/src/jsMain/kotlin/StartPluginSerializer.js.kt new file mode 100644 index 00000000000..db3d48e3e5e --- /dev/null +++ b/startup/plugin/src/jsMain/kotlin/StartPluginSerializer.js.kt @@ -0,0 +1,13 @@ +package dev.inmo.micro_utils.startup.plugin + +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +internal actual fun alternativeDeserialize(decoder: Decoder): StartPlugin? { + return null +} + +internal actual fun alternativeSerialize( + encoder: Encoder, + value: StartPlugin +): Boolean = false \ No newline at end of file diff --git a/startup/plugin/src/jsMain/kotlin/StartPluginSerializer.kt b/startup/plugin/src/jsMain/kotlin/StartPluginSerializer.kt deleted file mode 100644 index b8eda302903..00000000000 --- a/startup/plugin/src/jsMain/kotlin/StartPluginSerializer.kt +++ /dev/null @@ -1,35 +0,0 @@ -package dev.inmo.micro_utils.startup.plugin - -import com.benasher44.uuid.uuid4 -import kotlinx.serialization.KSerializer -import kotlinx.serialization.builtins.serializer -import kotlinx.serialization.descriptors.SerialDescriptor -import kotlinx.serialization.encoding.Decoder -import kotlinx.serialization.encoding.Encoder - -actual object StartPluginSerializer : KSerializer { - private val registeredPlugins = mutableMapOf() - private val registeredPluginsByPlugin = mutableMapOf() - override val descriptor: SerialDescriptor = String.serializer().descriptor - - override fun deserialize(decoder: Decoder): StartPlugin { - val name = decoder.decodeString() - return registeredPlugins[name] ?: error("Unable to find startup plugin for $name") - } - - override fun serialize(encoder: Encoder, value: StartPlugin) { - val name = registeredPluginsByPlugin[value] ?: uuid4().toString().also { - registeredPlugins[it] = value - registeredPluginsByPlugin[value] = it - } - encoder.encodeString(name) - } - - /** - * Register plugin inside of this [KSerializer]. Since plugin has been registered, you may use its [name] in any - * serialized [dev.inmo.micro_utils.startup.launcher.Config] to retrieve [plugin] you passed here - */ - fun registerPlugin(name: String, plugin: StartPlugin) { - registeredPlugins[name] = plugin - } -} diff --git a/startup/plugin/src/jvmMain/kotlin/StartPluginSerializer.jvm.kt b/startup/plugin/src/jvmMain/kotlin/StartPluginSerializer.jvm.kt new file mode 100644 index 00000000000..ad53c7cf590 --- /dev/null +++ b/startup/plugin/src/jvmMain/kotlin/StartPluginSerializer.jvm.kt @@ -0,0 +1,17 @@ +package dev.inmo.micro_utils.startup.plugin + +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +internal actual fun alternativeDeserialize(decoder: Decoder): StartPlugin? { + val kclass = Class.forName(decoder.decodeString()).kotlin + return (kclass.objectInstance ?: kclass.constructors.first { it.parameters.isEmpty() }.call()) as StartPlugin +} + +internal actual fun alternativeSerialize( + encoder: Encoder, + value: StartPlugin +): Boolean { + encoder.encodeString(value::class.java.canonicalName ?: return false) + return true +} \ No newline at end of file diff --git a/startup/plugin/src/jvmMain/kotlin/StartPluginSerializer.kt b/startup/plugin/src/jvmMain/kotlin/StartPluginSerializer.kt deleted file mode 100644 index 0e650c70df5..00000000000 --- a/startup/plugin/src/jvmMain/kotlin/StartPluginSerializer.kt +++ /dev/null @@ -1,23 +0,0 @@ -package dev.inmo.micro_utils.startup.plugin - -import kotlinx.serialization.KSerializer -import kotlinx.serialization.builtins.serializer -import kotlinx.serialization.descriptors.SerialDescriptor -import kotlinx.serialization.encoding.Decoder -import kotlinx.serialization.encoding.Encoder - -actual object StartPluginSerializer : KSerializer { - override val descriptor: SerialDescriptor - get() = String.serializer().descriptor - - override fun deserialize(decoder: Decoder): StartPlugin { - val kclass = Class.forName(decoder.decodeString()).kotlin - return (kclass.objectInstance ?: kclass.constructors.first { it.parameters.isEmpty() }.call()) as StartPlugin - } - - override fun serialize(encoder: Encoder, value: StartPlugin) { - encoder.encodeString( - value::class.java.canonicalName - ) - } -} diff --git a/startup/plugin/src/linuxX64Main/kotlin/StartPluginSerializer.kt b/startup/plugin/src/linuxX64Main/kotlin/StartPluginSerializer.kt deleted file mode 100644 index 176d0995bcb..00000000000 --- a/startup/plugin/src/linuxX64Main/kotlin/StartPluginSerializer.kt +++ /dev/null @@ -1,36 +0,0 @@ -package dev.inmo.micro_utils.startup.plugin - -import com.benasher44.uuid.uuid4 -import kotlinx.serialization.KSerializer -import kotlinx.serialization.builtins.serializer -import kotlinx.serialization.descriptors.SerialDescriptor -import kotlinx.serialization.encoding.Decoder -import kotlinx.serialization.encoding.Encoder -import kotlin.reflect.KClass - -actual object StartPluginSerializer : KSerializer { - private val registeredPlugins = mutableMapOf() - private val registeredPluginsByPlugin = mutableMapOf() - override val descriptor: SerialDescriptor = String.serializer().descriptor - - override fun deserialize(decoder: Decoder): StartPlugin { - val name = decoder.decodeString() - return registeredPlugins[name] ?: error("Unable to find startup plugin for $name") - } - - override fun serialize(encoder: Encoder, value: StartPlugin) { - val name = registeredPluginsByPlugin[value] ?: uuid4().toString().also { - registeredPlugins[it] = value - registeredPluginsByPlugin[value] = it - } - encoder.encodeString(name) - } - - /** - * Register plugin inside of this [KSerializer]. Since plugin has been registered, you may use its [name] in any - * serialized [dev.inmo.micro_utils.startup.launcher.Config] to retrieve [plugin] you passed here - */ - fun registerPlugin(name: String, plugin: StartPlugin) { - registeredPlugins[name] = plugin - } -} diff --git a/startup/plugin/src/mingwX64Main/kotlin/StartPluginSerializer.kt b/startup/plugin/src/mingwX64Main/kotlin/StartPluginSerializer.kt deleted file mode 100644 index 176d0995bcb..00000000000 --- a/startup/plugin/src/mingwX64Main/kotlin/StartPluginSerializer.kt +++ /dev/null @@ -1,36 +0,0 @@ -package dev.inmo.micro_utils.startup.plugin - -import com.benasher44.uuid.uuid4 -import kotlinx.serialization.KSerializer -import kotlinx.serialization.builtins.serializer -import kotlinx.serialization.descriptors.SerialDescriptor -import kotlinx.serialization.encoding.Decoder -import kotlinx.serialization.encoding.Encoder -import kotlin.reflect.KClass - -actual object StartPluginSerializer : KSerializer { - private val registeredPlugins = mutableMapOf() - private val registeredPluginsByPlugin = mutableMapOf() - override val descriptor: SerialDescriptor = String.serializer().descriptor - - override fun deserialize(decoder: Decoder): StartPlugin { - val name = decoder.decodeString() - return registeredPlugins[name] ?: error("Unable to find startup plugin for $name") - } - - override fun serialize(encoder: Encoder, value: StartPlugin) { - val name = registeredPluginsByPlugin[value] ?: uuid4().toString().also { - registeredPlugins[it] = value - registeredPluginsByPlugin[value] = it - } - encoder.encodeString(name) - } - - /** - * Register plugin inside of this [KSerializer]. Since plugin has been registered, you may use its [name] in any - * serialized [dev.inmo.micro_utils.startup.launcher.Config] to retrieve [plugin] you passed here - */ - fun registerPlugin(name: String, plugin: StartPlugin) { - registeredPlugins[name] = plugin - } -} diff --git a/startup/plugin/src/nativeMain/kotlin/StartPluginSerializer.native.kt b/startup/plugin/src/nativeMain/kotlin/StartPluginSerializer.native.kt new file mode 100644 index 00000000000..db3d48e3e5e --- /dev/null +++ b/startup/plugin/src/nativeMain/kotlin/StartPluginSerializer.native.kt @@ -0,0 +1,13 @@ +package dev.inmo.micro_utils.startup.plugin + +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +internal actual fun alternativeDeserialize(decoder: Decoder): StartPlugin? { + return null +} + +internal actual fun alternativeSerialize( + encoder: Encoder, + value: StartPlugin +): Boolean = false \ No newline at end of file