diff --git a/build.gradle b/build.gradle index 96797a98..25c077f0 100644 --- a/build.gradle +++ b/build.gradle @@ -24,14 +24,14 @@ buildscript { description = "The basic interfaces for DataForge meta-data" -group 'hep.dataforge' -version '0.1.1-SNAPSHOT' +group = 'hep.dataforge' +version = '0.1.1-SNAPSHOT' allprojects { repositories { jcenter() maven { url = "http://dl.bintray.com/kotlin/kotlin-eap" } - maven { url "https://kotlin.bintray.com/kotlinx" } + maven { url = "https://kotlin.bintray.com/kotlinx" } //maven { url 'https://jitpack.io' } } } diff --git a/dataforge-meta-io/build.gradle b/dataforge-meta-io/build.gradle new file mode 100644 index 00000000..51ffa452 --- /dev/null +++ b/dataforge-meta-io/build.gradle @@ -0,0 +1,65 @@ +plugins { + id 'kotlin-multiplatform'// version '1.3.0-rc-57' + id 'kotlinx-serialization' +} +repositories { + maven { url = 'http://dl.bintray.com/kotlin/kotlin-eap' } + mavenCentral() +} +kotlin { + targets { + fromPreset(presets.jvm, 'jvm') + fromPreset(presets.js, 'js') + // For ARM, preset should be changed to presets.iosArm32 or presets.iosArm64 + // For Linux, preset should be changed to e.g. presets.linuxX64 + // For MacOS, preset should be changed to e.g. presets.macosX64 + //fromPreset(presets.iosX64, 'ios') + } + sourceSets { + commonMain { + dependencies { + implementation project(":dataforge-meta") + implementation "org.jetbrains.kotlin:kotlin-stdlib-common" + implementation 'org.jetbrains.kotlin:kotlin-reflect' + implementation "org.jetbrains.kotlinx:kotlinx-io:$kotlinx_io_version" + implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$serialization_version" + } + } + commonTest { + dependencies { + implementation 'org.jetbrains.kotlin:kotlin-test-common' + implementation 'org.jetbrains.kotlin:kotlin-test-annotations-common' + implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$serialization_version" + } + } + jvmMain { + dependencies { + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" + implementation "org.jetbrains.kotlinx:kotlinx-io-jvm:$kotlinx_io_version" + implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$serialization_version" + } + } + jvmTest { + dependencies { + implementation 'org.jetbrains.kotlin:kotlin-test' + implementation 'org.jetbrains.kotlin:kotlin-test-junit' + } + } + jsMain { + dependencies { + implementation 'org.jetbrains.kotlin:kotlin-stdlib-js' + implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$serialization_version" + } + } + jsTest { + dependencies { + implementation 'org.jetbrains.kotlin:kotlin-test-js' + implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$serialization_version" + } + } +// iosMain { +// } +// iosTest { +// } + } +} \ No newline at end of file diff --git a/dataforge-meta/dataforge-meta-io/src/main/kotlin/hep/dataforge/meta/io/MetaFormat.kt b/dataforge-meta-io/src/commonMain/kotlin/hep/dataforge/meta/io/MetaFormat.kt similarity index 56% rename from dataforge-meta/dataforge-meta-io/src/main/kotlin/hep/dataforge/meta/io/MetaFormat.kt rename to dataforge-meta-io/src/commonMain/kotlin/hep/dataforge/meta/io/MetaFormat.kt index 75cd9773..7eb3b641 100644 --- a/dataforge-meta/dataforge-meta-io/src/main/kotlin/hep/dataforge/meta/io/MetaFormat.kt +++ b/dataforge-meta-io/src/commonMain/kotlin/hep/dataforge/meta/io/MetaFormat.kt @@ -15,12 +15,12 @@ interface MetaFormat { suspend fun read(input: Input): Meta } -/** - * Resolve format by its name. Null if not provided - */ -expect fun resolveFormat(name: String): MetaFormat? - -/** - * Resolve format by its binary key. Null if not provided - */ -expect fun resolveFormat(key: Short): MetaFormat? \ No newline at end of file +///** +// * Resolve format by its name. Null if not provided +// */ +//expect fun resolveFormat(name: String): MetaFormat? +// +///** +// * Resolve format by its binary key. Null if not provided +// */ +//expect fun resolveFormat(key: Short): MetaFormat? \ No newline at end of file diff --git a/dataforge-meta-io/src/commonMain/kotlin/hep/dataforge/meta/io/MetaProxy.kt b/dataforge-meta-io/src/commonMain/kotlin/hep/dataforge/meta/io/MetaProxy.kt new file mode 100644 index 00000000..3e1e1681 --- /dev/null +++ b/dataforge-meta-io/src/commonMain/kotlin/hep/dataforge/meta/io/MetaProxy.kt @@ -0,0 +1,51 @@ +package hep.dataforge.meta.io + +import hep.dataforge.meta.Meta +import hep.dataforge.meta.MetaItem +import hep.dataforge.meta.ValueType +import hep.dataforge.meta.boolean +import kotlinx.serialization.Polymorphic +import kotlinx.serialization.Serializable + +/*Universal serialization*/ + +@Serializable +class MetaProxy(val map: Map) + + +@Serializable +sealed class MetaItemProxy { + @Serializable + class NumberValueProxy(val number: Number) : MetaItemProxy() + + @Serializable + class StringValueProxy(val string: String) : MetaItemProxy() + + @Serializable + class BooleanValueProxy(val boolean: Boolean) : MetaItemProxy() + + @Serializable + object NullValueProxy : MetaItemProxy() + + @Serializable + class SingleMetaProxy(val node: MetaProxy) : MetaItemProxy() + + @Serializable + class MetaListProxy(val list: List<@Polymorphic MetaProxy>) : MetaItemProxy() +} + + +fun Meta.toMap(): MetaProxy { + return MetaProxy(this.items.mapValues { (_, value) -> + when (value) { + is MetaItem.ValueItem<*> -> when (value.value.type) { + ValueType.NUMBER -> MetaItemProxy.NumberValueProxy(value.value.number) + ValueType.STRING -> MetaItemProxy.StringValueProxy(value.value.string) + ValueType.BOOLEAN -> MetaItemProxy.BooleanValueProxy(value.value.boolean) + ValueType.NULL -> MetaItemProxy.NullValueProxy + } + is MetaItem.SingleNodeItem<*> -> MetaItemProxy.SingleMetaProxy(value.node.toMap()) + is MetaItem.MultiNodeItem<*> -> MetaItemProxy.MetaListProxy(value.nodes.map { it.toMap() }) + } + }) +} diff --git a/dataforge-meta/dataforge-meta-io/src/main/kotlin/hep/dataforge/meta/io/Serializers.kt b/dataforge-meta-io/src/commonMain/kotlin/hep/dataforge/meta/io/Serializers.kt similarity index 77% rename from dataforge-meta/dataforge-meta-io/src/main/kotlin/hep/dataforge/meta/io/Serializers.kt rename to dataforge-meta-io/src/commonMain/kotlin/hep/dataforge/meta/io/Serializers.kt index 2297673e..d52b7be1 100644 --- a/dataforge-meta/dataforge-meta-io/src/main/kotlin/hep/dataforge/meta/io/Serializers.kt +++ b/dataforge-meta-io/src/commonMain/kotlin/hep/dataforge/meta/io/Serializers.kt @@ -1,47 +1,7 @@ package hep.dataforge.meta.io import hep.dataforge.meta.* -import kotlinx.serialization.Serializable - - -/*Universal serialization*/ - -sealed class MetaItemProxy { - - @Serializable - class NumberValueProxy(val number: Number) : MetaItemProxy() - - @Serializable - class StringValueProxy(val string: String) : MetaItemProxy() - - @Serializable - class BooleanValueProxy(val boolean: Boolean) : MetaItemProxy() - - @Serializable - object NullValueProxy : MetaItemProxy() - - @Serializable - class MetaProxy(@Serializable val map: Map) : MetaItemProxy() - - @Serializable - class MetaListProxy(@Serializable val nodes: List) : MetaItemProxy() -} - - -fun Meta.toMap(): Map { - return this.items.mapValues { (_, value) -> - when (value) { - is MetaItem.ValueItem<*> -> when (value.value.type) { - ValueType.NUMBER -> MetaItemProxy.NumberValueProxy(value.value.number) - ValueType.STRING -> MetaItemProxy.StringValueProxy(value.value.string) - ValueType.BOOLEAN -> MetaItemProxy.BooleanValueProxy(value.value.boolean) - ValueType.NULL -> MetaItemProxy.NullValueProxy - } - is MetaItem.SingleNodeItem<*> -> MetaItemProxy.MetaProxy(value.node.toMap()) - is MetaItem.MultiNodeItem<*> -> MetaItemProxy.MetaListProxy(value.nodes.map { MetaItemProxy.MetaProxy(it.toMap()) }) - } - } -} +import kotlinx.serialization.json.* /*Direct JSON serialization*/ diff --git a/dataforge-meta-io/src/commonTest/kotlin/io/MetaItemProxyTest.kt b/dataforge-meta-io/src/commonTest/kotlin/io/MetaItemProxyTest.kt new file mode 100644 index 00000000..cd12d611 --- /dev/null +++ b/dataforge-meta-io/src/commonTest/kotlin/io/MetaItemProxyTest.kt @@ -0,0 +1,47 @@ +package io + +import hep.dataforge.meta.buildMeta +import hep.dataforge.meta.io.MetaItemProxy +import hep.dataforge.meta.io.toMap +import kotlinx.serialization.json.JSON +import kotlinx.serialization.serializer +import kotlin.test.Test + +class MetaItemProxyTest { + @Test + fun testGeneration() { + MetaItemProxy::class.serializer() + } + + + @Test + fun testProxySerialization() { + val meta = buildMeta { + "a" to 2 + "b" to { + "c" to "ddd" + "d" to 2.2 + } + } + val json = JSON.indented.stringify(meta.toMap()) + println(json) +// val result: Map = JSON.parse(json) +// assertEquals(meta,result.to) + } + +// @Test +// fun testJSONSerialization() { +// val meta = buildMeta { +// "a" to 2 +// "b" to { +// "c" to "ddd" +// "d" to 2.2 +// } +// } +// val json = meta.toJSON() +// println(json) +// val result = json.toMeta() +// assertEquals(meta, result) +// } + +} \ No newline at end of file diff --git a/dataforge-meta/build.gradle b/dataforge-meta/build.gradle index e13aef58..34599174 100644 --- a/dataforge-meta/build.gradle +++ b/dataforge-meta/build.gradle @@ -1,10 +1,63 @@ -plugins{ - id 'kotlin-platform-common' +plugins { + id 'kotlin-multiplatform'// version '1.3.0-rc-57' + id 'kotlinx-serialization' } - -dependencies { - compile "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlin_version" - - testCompile "org.jetbrains.kotlin:kotlin-test-annotations-common" - testCompile "org.jetbrains.kotlin:kotlin-test-common" +repositories { + maven { url = 'http://dl.bintray.com/kotlin/kotlin-eap' } + mavenCentral() +} +kotlin { + targets { + fromPreset(presets.jvm, 'jvm') + fromPreset(presets.js, 'js') + // For ARM, preset should be changed to presets.iosArm32 or presets.iosArm64 + // For Linux, preset should be changed to e.g. presets.linuxX64 + // For MacOS, preset should be changed to e.g. presets.macosX64 + //fromPreset(presets.iosX64, 'ios') + } + sourceSets { + commonMain { + dependencies { + implementation "org.jetbrains.kotlin:kotlin-stdlib-common" + implementation 'org.jetbrains.kotlin:kotlin-reflect' + implementation "org.jetbrains.kotlinx:kotlinx-io:$kotlinx_io_version" + implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$serialization_version" + } + } + commonTest { + dependencies { + implementation 'org.jetbrains.kotlin:kotlin-test-common' + implementation 'org.jetbrains.kotlin:kotlin-test-annotations-common' + implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$serialization_version" + } + } + jvmMain { + dependencies { + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" + implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$serialization_version" + } + } + jvmTest { + dependencies { + implementation 'org.jetbrains.kotlin:kotlin-test' + implementation 'org.jetbrains.kotlin:kotlin-test-junit' + } + } + jsMain { + dependencies { + implementation 'org.jetbrains.kotlin:kotlin-stdlib-js' + implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$serialization_version" + } + } + jsTest { + dependencies { + implementation 'org.jetbrains.kotlin:kotlin-test-js' + implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$serialization_version" + } + } +// iosMain { +// } +// iosTest { +// } + } } \ No newline at end of file diff --git a/dataforge-meta/dataforge-meta-io/build.gradle b/dataforge-meta/dataforge-meta-io/build.gradle deleted file mode 100644 index e56fdc44..00000000 --- a/dataforge-meta/dataforge-meta-io/build.gradle +++ /dev/null @@ -1,19 +0,0 @@ -plugins{ - id 'kotlin-platform-common' -} - -dependencies { - compile project(":dataforge-meta") - - - compile "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlin_version" - compile "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$serialization_version" - compile "org.jetbrains.kotlinx:kotlinx-io:$kotlinx_io_version" - - testCompile "org.jetbrains.kotlin:kotlin-test-annotations-common" - testCompile "org.jetbrains.kotlin:kotlin-test-common" -} - -allprojects { - apply plugin: 'kotlinx-serialization' -} \ No newline at end of file diff --git a/dataforge-meta/dataforge-meta-js/build.gradle b/dataforge-meta/dataforge-meta-js/build.gradle deleted file mode 100644 index af0d28ca..00000000 --- a/dataforge-meta/dataforge-meta-js/build.gradle +++ /dev/null @@ -1,10 +0,0 @@ -plugins{ - id 'kotlin-platform-js' -} - -dependencies { - expectedBy project(":dataforge-meta") - - compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version" - testCompile "org.jetbrains.kotlin:kotlin-test-js" -} diff --git a/dataforge-meta/dataforge-meta-jvm/build.gradle b/dataforge-meta/dataforge-meta-jvm/build.gradle deleted file mode 100644 index 1f4379b0..00000000 --- a/dataforge-meta/dataforge-meta-jvm/build.gradle +++ /dev/null @@ -1,19 +0,0 @@ -plugins{ - id 'kotlin-platform-jvm' -} - -dependencies { - expectedBy project(":dataforge-meta") - - compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" - testCompile "org.jetbrains.kotlin:kotlin-test" - testCompile "org.jetbrains.kotlin:kotlin-test-junit" -} - -compileKotlin { - kotlinOptions.jvmTarget = "1.8" -} -compileTestKotlin { - kotlinOptions.jvmTarget = "1.8" -} -sourceCompatibility = "1.8" \ No newline at end of file diff --git a/dataforge-meta/src/main/kotlin/hep/dataforge/meta/Config.kt b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Config.kt similarity index 100% rename from dataforge-meta/src/main/kotlin/hep/dataforge/meta/Config.kt rename to dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Config.kt diff --git a/dataforge-meta/src/main/kotlin/hep/dataforge/meta/Delegates.kt b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Delegates.kt similarity index 100% rename from dataforge-meta/src/main/kotlin/hep/dataforge/meta/Delegates.kt rename to dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Delegates.kt diff --git a/dataforge-meta/src/main/kotlin/hep/dataforge/meta/Meta.kt b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Meta.kt similarity index 100% rename from dataforge-meta/src/main/kotlin/hep/dataforge/meta/Meta.kt rename to dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Meta.kt diff --git a/dataforge-meta/src/main/kotlin/hep/dataforge/meta/MetaBuilder.kt b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/MetaBuilder.kt similarity index 100% rename from dataforge-meta/src/main/kotlin/hep/dataforge/meta/MetaBuilder.kt rename to dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/MetaBuilder.kt diff --git a/dataforge-meta/src/main/kotlin/hep/dataforge/meta/MutableMetaNode.kt b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/MutableMetaNode.kt similarity index 100% rename from dataforge-meta/src/main/kotlin/hep/dataforge/meta/MutableMetaNode.kt rename to dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/MutableMetaNode.kt diff --git a/dataforge-meta/src/main/kotlin/hep/dataforge/meta/Specification.kt b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Specification.kt similarity index 100% rename from dataforge-meta/src/main/kotlin/hep/dataforge/meta/Specification.kt rename to dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Specification.kt diff --git a/dataforge-meta/src/main/kotlin/hep/dataforge/meta/Styleable.kt b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Styleable.kt similarity index 100% rename from dataforge-meta/src/main/kotlin/hep/dataforge/meta/Styleable.kt rename to dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Styleable.kt diff --git a/dataforge-meta/src/main/kotlin/hep/dataforge/meta/Value.kt b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Value.kt similarity index 100% rename from dataforge-meta/src/main/kotlin/hep/dataforge/meta/Value.kt rename to dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Value.kt diff --git a/dataforge-meta/src/main/kotlin/hep/dataforge/names/Name.kt b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/names/Name.kt similarity index 100% rename from dataforge-meta/src/main/kotlin/hep/dataforge/names/Name.kt rename to dataforge-meta/src/commonMain/kotlin/hep/dataforge/names/Name.kt diff --git a/dataforge-meta/src/test/kotlin/hep/dataforge/meta/MetaBuilderTest.kt b/dataforge-meta/src/commonTest/kotlin/hep/dataforge/meta/MetaBuilderTest.kt similarity index 100% rename from dataforge-meta/src/test/kotlin/hep/dataforge/meta/MetaBuilderTest.kt rename to dataforge-meta/src/commonTest/kotlin/hep/dataforge/meta/MetaBuilderTest.kt diff --git a/dataforge-meta/src/test/kotlin/hep/dataforge/meta/MetaDelegateTest.kt b/dataforge-meta/src/commonTest/kotlin/hep/dataforge/meta/MetaDelegateTest.kt similarity index 100% rename from dataforge-meta/src/test/kotlin/hep/dataforge/meta/MetaDelegateTest.kt rename to dataforge-meta/src/commonTest/kotlin/hep/dataforge/meta/MetaDelegateTest.kt diff --git a/dataforge-meta/src/test/kotlin/hep/dataforge/names/NameTest.kt b/dataforge-meta/src/commonTest/kotlin/hep/dataforge/names/NameTest.kt similarity index 100% rename from dataforge-meta/src/test/kotlin/hep/dataforge/names/NameTest.kt rename to dataforge-meta/src/commonTest/kotlin/hep/dataforge/names/NameTest.kt diff --git a/dataforge-meta/src/test/kotlin/hep/dataforge/meta/SerializationTest.kt b/dataforge-meta/src/test/kotlin/hep/dataforge/meta/SerializationTest.kt deleted file mode 100644 index b1e28ab7..00000000 --- a/dataforge-meta/src/test/kotlin/hep/dataforge/meta/SerializationTest.kt +++ /dev/null @@ -1,52 +0,0 @@ -package hep.dataforge.meta - -import kotlin.test.Test -import kotlin.test.assertEquals - -class SerializationTest { - - @Test - fun testJSONSerialization() { - val meta = buildMeta { - "a" to 2 - "b" to { - "c" to "ddd" - "d" to 2.2 - } - } - val json = meta.toJSON() - println(json) - val result = json.toMeta() - assertEquals(meta, result) - } - -// @Test -// fun testIndirectSerialization() { -// val meta = buildMeta { -// "a" to 2 -// "b" to { -// "c" to "ddd" -// "d" to 2.2 -// } -// } -// val json = JSON.stringify(meta.toMap()) -// println(json) -//// val result = json.toMeta() -//// assertEquals(meta, result) -// } - -// @Test -// fun testWeirdSerialization() { -// val meta = buildMeta { -// "a" to 2 -// "b" to { -// "c" to "ddd" -// "d" to 2.2 -// } -// } -// val json = JSON.stringify(meta.toJSON()) -// println(json) -// val result: JsonObject = JSON.parse(json) -// assertEquals(meta, result.toMeta()) -// } -} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 3cd11386..665278b9 100644 --- a/settings.gradle +++ b/settings.gradle @@ -10,16 +10,23 @@ pluginManagement { if (requested.id.id == "kotlin-platform-js") { useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:${requested.version}") } + if (requested.id.id == "kotlin-multiplatform") { + useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:${requested.version}") + } } } + + repositories { + maven { url = 'http://dl.bintray.com/kotlin/kotlin-eap' } + mavenCentral() + maven { url = 'https://plugins.gradle.org/m2/' } + } } + rootProject.name = 'dataforge-core' include ":dataforge-meta" -include ":dataforge-meta:dataforge-meta-jvm" -include ":dataforge-meta:dataforge-meta-js" - -include ":dataforge-meta:dataforge-meta-io" +include ":dataforge-meta-io" include ":dataforge-envelope" \ No newline at end of file