mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-08 09:23:50 +00:00
downgrade kotlin and fix build
This commit is contained in:
parent
d94cd7ea94
commit
19bbfd4916
@ -1,6 +1,6 @@
|
|||||||
[versions]
|
[versions]
|
||||||
|
|
||||||
kt = "2.0.20-Beta2"
|
kt = "2.0.0"
|
||||||
kt-serialization = "1.7.1"
|
kt-serialization = "1.7.1"
|
||||||
kt-coroutines = "1.8.1"
|
kt-coroutines = "1.8.1"
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ koin = "3.5.6"
|
|||||||
|
|
||||||
okio = "3.9.0"
|
okio = "3.9.0"
|
||||||
|
|
||||||
ksp = "2.0.20-Beta2-1.0.23"
|
ksp = "2.0.0-1.0.23"
|
||||||
kotlin-poet = "1.18.0"
|
kotlin-poet = "1.18.0"
|
||||||
|
|
||||||
versions = "0.51.0"
|
versions = "0.51.0"
|
||||||
|
@ -13,6 +13,7 @@ kotlin {
|
|||||||
api libs.kslog
|
api libs.kslog
|
||||||
api libs.kt.reflect
|
api libs.kt.reflect
|
||||||
api project(":micro_utils.coroutines")
|
api project(":micro_utils.coroutines")
|
||||||
|
api libs.uuid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
jsMain {
|
jsMain {
|
||||||
|
@ -1,5 +1,42 @@
|
|||||||
package dev.inmo.micro_utils.startup.plugin
|
package dev.inmo.micro_utils.startup.plugin
|
||||||
|
|
||||||
|
import com.benasher44.uuid.uuid4
|
||||||
import kotlinx.serialization.KSerializer
|
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<StartPlugin>
|
object StartPluginSerializer : KSerializer<StartPlugin> {
|
||||||
|
private val registeredPlugins = mutableMapOf<String, StartPlugin>()
|
||||||
|
private val registeredPluginsByPlugin = mutableMapOf<StartPlugin, String>()
|
||||||
|
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
|
||||||
|
13
startup/plugin/src/jsMain/kotlin/StartPluginSerializer.js.kt
Normal file
13
startup/plugin/src/jsMain/kotlin/StartPluginSerializer.js.kt
Normal file
@ -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
|
@ -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<StartPlugin> {
|
|
||||||
private val registeredPlugins = mutableMapOf<String, StartPlugin>()
|
|
||||||
private val registeredPluginsByPlugin = mutableMapOf<StartPlugin, String>()
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
@ -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
|
||||||
|
}
|
@ -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<StartPlugin> {
|
|
||||||
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
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
@ -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<StartPlugin> {
|
|
||||||
private val registeredPlugins = mutableMapOf<String, StartPlugin>()
|
|
||||||
private val registeredPluginsByPlugin = mutableMapOf<StartPlugin, String>()
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
@ -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<StartPlugin> {
|
|
||||||
private val registeredPlugins = mutableMapOf<String, StartPlugin>()
|
|
||||||
private val registeredPluginsByPlugin = mutableMapOf<StartPlugin, String>()
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
@ -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
|
Loading…
Reference in New Issue
Block a user