[Build, IGS] Deserialize setup json using kotlinx-serialization-json

#KTI-1223 In Progress
This commit is contained in:
Alexander.Likhachev
2023-04-26 14:43:58 +02:00
committed by Space Team
parent 188203197b
commit e30b72fa8f
5 changed files with 121 additions and 1 deletions
@@ -1,6 +1,7 @@
plugins {
`kotlin-dsl`
id("org.jetbrains.kotlin.jvm")
kotlin("jvm")
kotlin("plugin.serialization")
}
repositories {
@@ -8,8 +9,19 @@ repositories {
gradlePluginPortal()
}
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.0")
implementation(kotlin("test-junit5"))
}
kotlin.jvmToolchain(8)
tasks {
test {
useJUnitPlatform()
}
}
gradlePlugin {
plugins {
create("internal-gradle-setup") {
@@ -0,0 +1,23 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.build
import kotlinx.serialization.Serializable
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import kotlin.streams.asSequence
@Serializable
internal data class SetupFile(
val properties: Map<String, String>,
)
// can't use decodeFromStream: https://github.com/Kotlin/kotlinx.serialization/issues/2218
internal fun parseSetupFile(inputStream: InputStream): SetupFile =
Json.decodeFromString(BufferedReader(InputStreamReader(inputStream)).lines().asSequence().joinToString("\n"))
@@ -0,0 +1,29 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.build
import kotlin.test.*
class SetupFileParseTest {
private fun openPropertiesJsonStream() =
SetupFileParseTest::class.java.classLoader.getResourceAsStream("properties.json")
?: error("No properties.json file found in test resources")
@Test
fun testSimpleParsing() {
val setupFile = openPropertiesJsonStream().use {
parseSetupFile(it)
}
assertEquals(
mapOf(
"newProperty1" to "someValue",
"newProperty2" to "someOtherValue",
"alreadySetProperty" to "newValue",
),
setupFile.properties
)
}
}
@@ -0,0 +1,7 @@
{
"properties": {
"newProperty1": "someValue",
"newProperty2": "someOtherValue",
"alreadySetProperty": "newValue"
}
}