From e7f0e1e4fcacf214f885d16d51389c4be7f73673 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Tue, 30 Nov 2021 21:27:08 +0300 Subject: [PATCH] Workarround serialization bug --- build.gradle.kts | 4 +-- .../main/kotlin/ru/mipt/npm/sat/satServer.kt | 4 +-- gradle.properties | 5 +++- gradle/wrapper/gradle-wrapper.properties | 2 +- .../space/kscience/visionforge/VisionBase.kt | 4 +-- .../kscience/visionforge/VisionGroupBase.kt | 25 +++++++++---------- .../kscience/visionforge/VisionManager.kt | 3 +++ .../kscience/visionforge/html/HtmlTagTest.kt | 3 +-- .../kscience/visionforge/VisionClient.kt | 2 ++ .../visionforge/plotly/VisionOfPlotly.kt | 1 + .../visionforge/three/server/VisionServer.kt | 3 ++- 11 files changed, 32 insertions(+), 24 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 551ef7df..62f608e4 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,7 +4,7 @@ plugins { // kotlin("js") version "1.5.30" apply false } -val dataforgeVersion by extra("0.5.2-dev-3") +val dataforgeVersion by extra("0.5.2") val fxVersion by extra("11") allprojects { @@ -16,7 +16,7 @@ allprojects { } group = "space.kscience" - version = "0.2.0-dev-25" + version = "0.2.0" } subprojects { diff --git a/demo/sat-demo/src/main/kotlin/ru/mipt/npm/sat/satServer.kt b/demo/sat-demo/src/main/kotlin/ru/mipt/npm/sat/satServer.kt index 8b286e07..3a360ce7 100644 --- a/demo/sat-demo/src/main/kotlin/ru/mipt/npm/sat/satServer.kt +++ b/demo/sat-demo/src/main/kotlin/ru/mipt/npm/sat/satServer.kt @@ -7,7 +7,7 @@ import kotlinx.coroutines.isActive import kotlinx.coroutines.launch import kotlinx.html.div import kotlinx.html.h1 -import space.kscience.dataforge.context.Global +import space.kscience.dataforge.context.Context import space.kscience.dataforge.names.Name import space.kscience.visionforge.solid.* import space.kscience.visionforge.three.server.* @@ -15,7 +15,7 @@ import space.kscience.visionforge.visionManager import kotlin.random.Random fun main() { - val satContext = Global.buildContext ("sat") { + val satContext = Context("sat") { plugin(Solids) } diff --git a/gradle.properties b/gradle.properties index 0443442f..41982482 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,4 +4,7 @@ kotlin.mpp.stability.nowarn=true kotlin.jupyter.add.scanner=false org.gradle.jvmargs=-XX:MaxMetaspaceSize=1G -org.gradle.parallel=true \ No newline at end of file +org.gradle.parallel=true + +publishing.github=false +publishing.sonatype=false \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ffed3a25..e750102e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/VisionBase.kt b/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/VisionBase.kt index e7865a24..6e2e95d0 100644 --- a/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/VisionBase.kt +++ b/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/VisionBase.kt @@ -1,5 +1,6 @@ package space.kscience.visionforge +import kotlinx.serialization.EncodeDefault import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlinx.serialization.Transient @@ -29,7 +30,7 @@ internal data class MetaListener( @SerialName("vision") public open class VisionBase( @Transient override var parent: VisionGroup? = null, - protected var properties: MutableMeta? = null + @EncodeDefault protected var properties: MutableMeta? = null, ) : Vision { @Synchronized @@ -131,7 +132,6 @@ public open class VisionBase( override val descriptor: MetaDescriptor? get() = null - override fun invalidateProperty(propertyName: Name) { if (propertyName == STYLE_KEY) { styles.mapNotNull { getStyle(it) }.asSequence() diff --git a/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/VisionGroupBase.kt b/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/VisionGroupBase.kt index d4af712d..e8594df2 100644 --- a/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/VisionGroupBase.kt +++ b/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/VisionGroupBase.kt @@ -1,5 +1,6 @@ package space.kscience.visionforge +import kotlinx.serialization.EncodeDefault import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlinx.serialization.Transient @@ -16,7 +17,7 @@ private class StructureChangeListener(val owner: Any?, val callback: VisionGroup @Serializable @SerialName("vision.group") public open class VisionGroupBase( - @SerialName("children") protected val childrenInternal: MutableMap = LinkedHashMap(), + @EncodeDefault @SerialName("children") protected val childrenInternal: MutableMap = LinkedHashMap(), ) : VisionBase(), MutableVisionGroup { /** @@ -102,21 +103,19 @@ public open class VisionGroupBase( /** * Recursively create a child group */ - private fun createGroups(name: Name): VisionGroupBase { - return when { - name.isEmpty() -> error("Should be unreachable") - name.length == 1 -> { - val token = name.tokens.first() - when (val current = children[token]) { - null -> createGroup().also { child -> - attachChild(token, child) - } - is VisionGroupBase -> current - else -> error("Can't create group with name $name because it exists and not a group") + private fun createGroups(name: Name): VisionGroupBase = when { + name.isEmpty() -> error("Should be unreachable") + name.length == 1 -> { + val token = name.tokens.first() + when (val current = children[token]) { + null -> createGroup().also { child -> + attachChild(token, child) } + is VisionGroupBase -> current + else -> error("Can't create group with name $name because it exists and not a group") } - else -> createGroups(name.tokens.first().asName()).createGroups(name.cutFirst()) } + else -> createGroups(name.tokens.first().asName()).createGroups(name.cutFirst()) } /** diff --git a/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/VisionManager.kt b/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/VisionManager.kt index 3f9bfaa8..ff4c29e1 100644 --- a/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/VisionManager.kt +++ b/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/VisionManager.kt @@ -1,5 +1,6 @@ package space.kscience.visionforge +import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.PolymorphicSerializer import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonElement @@ -68,12 +69,14 @@ public class VisionManager(meta: Meta) : AbstractPlugin(meta) { } } + @OptIn(ExperimentalSerializationApi::class) public val defaultJson: Json = Json { serializersModule = defaultSerialModule prettyPrint = true useArrayPolymorphism = false encodeDefaults = false ignoreUnknownKeys = true + explicitNulls = false } internal val visionSerializer: PolymorphicSerializer = PolymorphicSerializer(Vision::class) diff --git a/visionforge-core/src/commonTest/kotlin/space/kscience/visionforge/html/HtmlTagTest.kt b/visionforge-core/src/commonTest/kotlin/space/kscience/visionforge/html/HtmlTagTest.kt index 3572dd42..d6cd8dd1 100644 --- a/visionforge-core/src/commonTest/kotlin/space/kscience/visionforge/html/HtmlTagTest.kt +++ b/visionforge-core/src/commonTest/kotlin/space/kscience/visionforge/html/HtmlTagTest.kt @@ -37,8 +37,7 @@ fun FlowContent.renderVisionFragment( @DFExperimental class HtmlTagTest { - fun VisionOutput.base(block: VisionBase.() -> Unit) = - VisionBase().apply(block) + fun VisionOutput.base(block: VisionBase.() -> Unit) = VisionBase().apply(block) val fragment: HtmlVisionFragment = { div { diff --git a/visionforge-core/src/jsMain/kotlin/space/kscience/visionforge/VisionClient.kt b/visionforge-core/src/jsMain/kotlin/space/kscience/visionforge/VisionClient.kt index 7c118233..63f9a882 100644 --- a/visionforge-core/src/jsMain/kotlin/space/kscience/visionforge/VisionClient.kt +++ b/visionforge-core/src/jsMain/kotlin/space/kscience/visionforge/VisionClient.kt @@ -18,6 +18,7 @@ import space.kscience.visionforge.html.VisionTagConsumer.Companion.OUTPUT_FETCH_ import space.kscience.visionforge.html.VisionTagConsumer.Companion.OUTPUT_NAME_ATTRIBUTE import kotlin.reflect.KClass import kotlin.time.Duration.Companion.milliseconds +import kotlin.time.ExperimentalTime public class VisionClient : AbstractPlugin() { override val tag: PluginTag get() = Companion.tag @@ -56,6 +57,7 @@ public class VisionClient : AbstractPlugin() { private fun Element.getFlag(attribute: String): Boolean = attributes[attribute]?.value != null + @OptIn(ExperimentalTime::class) private fun renderVision(name: String, element: Element, vision: Vision?, outputMeta: Meta) { if (vision != null) { val renderer = findRendererFor(vision) ?: error("Could nof find renderer for $vision") diff --git a/visionforge-plotly/src/commonMain/kotlin/space/kscience/visionforge/plotly/VisionOfPlotly.kt b/visionforge-plotly/src/commonMain/kotlin/space/kscience/visionforge/plotly/VisionOfPlotly.kt index 1b20b95f..eaa94573 100644 --- a/visionforge-plotly/src/commonMain/kotlin/space/kscience/visionforge/plotly/VisionOfPlotly.kt +++ b/visionforge-plotly/src/commonMain/kotlin/space/kscience/visionforge/plotly/VisionOfPlotly.kt @@ -15,6 +15,7 @@ public class VisionOfPlotly private constructor() : VisionBase() { public constructor(plot: Plot) : this() { properties = plot.meta } + public val plot: Plot get() = Plot(meta) } diff --git a/visionforge-server/src/main/kotlin/space/kscience/visionforge/three/server/VisionServer.kt b/visionforge-server/src/main/kotlin/space/kscience/visionforge/three/server/VisionServer.kt index b5693aa7..0018ab83 100644 --- a/visionforge-server/src/main/kotlin/space/kscience/visionforge/three/server/VisionServer.kt +++ b/visionforge-server/src/main/kotlin/space/kscience/visionforge/three/server/VisionServer.kt @@ -44,6 +44,7 @@ import java.net.URI import kotlin.collections.set import kotlin.time.Duration import kotlin.time.Duration.Companion.milliseconds +import kotlin.time.ExperimentalTime /** @@ -121,7 +122,7 @@ public class VisionServer internal constructor( /** * Server a map of visions without providing explicit html page for them */ - @OptIn(DFExperimental::class) + @OptIn(DFExperimental::class, ExperimentalTime::class) public fun serveVisions(route: Route, visions: Map): Unit = route { application.log.info("Serving visions $visions at $route")