Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate from kaml to yamlkt #5490

Closed
wants to merge 8 commits into from
Closed
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ dependencies {

// serialization
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.2")
implementation("com.charleskorn.kaml:kaml:0.57.0")
implementation("net.mamoe.yamlkt:yamlkt:0.13.0")

// map and location
implementation("com.mapzen.tangram:tangram:0.17.1")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
package de.westnordost.streetcomplete.data.meta

import android.content.res.AssetManager
import com.charleskorn.kaml.Yaml
import com.charleskorn.kaml.YamlConfiguration
import com.charleskorn.kaml.decodeFromStream
import de.westnordost.countryboundaries.CountryBoundaries
import kotlinx.serialization.decodeFromString
import net.mamoe.yamlkt.Yaml
import java.io.File
import java.io.SequenceInputStream

class CountryInfos(private val assetManager: AssetManager) {
private val yaml = Yaml(configuration = YamlConfiguration(
strictMode = false, // ignore unknown properties
))

private val countryInfoMap = HashMap<String, IncompleteCountryInfo?>()
private val defaultCountryInfo: IncompleteCountryInfo by lazy {
loadCountryInfo("default")
Expand Down Expand Up @@ -43,9 +37,9 @@ class CountryInfos(private val assetManager: AssetManager) {
val filename = "$countryCodeIso3166.yml"
assetManager.open(BASEPATH + File.separator + filename).use { inputStream ->
val countryCode = countryCodeIso3166.split("-").first()
val stream = SequenceInputStream("countryCode: $countryCode\n".byteInputStream(), inputStream)
val countryInfo = "countryCode: $countryCode\n" + inputStream.bufferedReader().readText()

return yaml.decodeFromStream(stream)
return Yaml.decodeFromString(countryInfo)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import androidx.annotation.DrawableRes
import androidx.annotation.RawRes
import com.charleskorn.kaml.Yaml
import com.charleskorn.kaml.decodeFromStream
import de.westnordost.streetcomplete.view.DrawableImage
import de.westnordost.streetcomplete.view.Image
import de.westnordost.streetcomplete.view.ResImage
import kotlinx.serialization.decodeFromString
import net.mamoe.yamlkt.Yaml

inline fun <reified T> Resources.getYamlObject(@RawRes id: Int): T =
Yaml.default.decodeFromStream(openRawResource(id))
Yaml.decodeFromString(openRawResource(id).bufferedReader().readText())

/** shortcut for [getYamlObject] with included type information */
fun Resources.getYamlStringMap(@RawRes id: Int): Map<String, String> = this.getYamlObject(id)
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies {
implementation("com.esotericsoftware.yamlbeans:yamlbeans:1.15")
implementation("org.jsoup:jsoup:1.15.3")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2")
implementation("com.charleskorn.kaml:kaml:0.55.0")
implementation("net.mamoe.yamlkt:yamlkt:0.13.0")
implementation("org.jetbrains:markdown:0.5.0")
}

Expand Down
12 changes: 6 additions & 6 deletions buildSrc/src/main/java/UpdateContributorStatisticsTask.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import com.charleskorn.kaml.Yaml
import com.charleskorn.kaml.YamlConfiguration
import com.charleskorn.kaml.encodeToStream
import kotlinx.serialization.Serializable
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import net.mamoe.yamlkt.Yaml
import net.mamoe.yamlkt.YamlBuilder
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.TaskAction
Expand Down Expand Up @@ -161,10 +160,11 @@ open class UpdateContributorStatisticsTask : DefaultTask() {
}

private fun writeContributors(contributors: List<Contributor>) {
File(targetFile).outputStream().use {
val yamlFormat = Yaml(configuration = YamlConfiguration(encodeDefaults = false))
yamlFormat.encodeToStream(contributors, it)
val yamlFormat = Yaml {
stringSerialization = YamlBuilder.StringSerialization.DOUBLE_QUOTATION
encodeDefaultValues = false
}
File(targetFile).writeText(yamlFormat.encodeToString(contributors) + "\n")
}
}

Expand Down