From acb18cbd7f709690f93f9b6af01d1e61a7a76b39 Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Fri, 5 Apr 2024 14:28:41 +0200 Subject: [PATCH] refactor(cargo): Move serializers to their respective model classes Model classes and serializers are tightly coupled, e.g. because of the naming strategy, so put them together. Signed-off-by: Sebastian Schuberth --- .../package-managers/cargo/src/main/kotlin/Cargo.kt | 11 ----------- .../cargo/src/main/kotlin/CargoLockfile.kt | 4 ++++ .../cargo/src/main/kotlin/CargoMetadata.kt | 7 +++++++ 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/plugins/package-managers/cargo/src/main/kotlin/Cargo.kt b/plugins/package-managers/cargo/src/main/kotlin/Cargo.kt index 25ae853e7e71e..f608d55a33519 100644 --- a/plugins/package-managers/cargo/src/main/kotlin/Cargo.kt +++ b/plugins/package-managers/cargo/src/main/kotlin/Cargo.kt @@ -23,10 +23,6 @@ package org.ossreviewtoolkit.plugins.packagemanagers.cargo import java.io.File -import kotlinx.serialization.json.Json -import kotlinx.serialization.json.JsonNamingStrategy - -import net.peanuuutz.tomlkt.Toml import net.peanuuutz.tomlkt.decodeFromNativeReader import org.apache.logging.log4j.kotlin.logger @@ -57,13 +53,6 @@ import org.ossreviewtoolkit.utils.ort.ProcessedDeclaredLicense import org.ossreviewtoolkit.utils.spdx.SpdxConstants import org.ossreviewtoolkit.utils.spdx.SpdxOperator -private val json = Json { - ignoreUnknownKeys = true - namingStrategy = JsonNamingStrategy.SnakeCase -} - -private val toml = Toml { ignoreUnknownKeys = true } - private const val DEV_KIND_NAME = "dev" private const val BUILD_KIND_NAME = "build" diff --git a/plugins/package-managers/cargo/src/main/kotlin/CargoLockfile.kt b/plugins/package-managers/cargo/src/main/kotlin/CargoLockfile.kt index bed72c195864b..d9659fbc88898 100644 --- a/plugins/package-managers/cargo/src/main/kotlin/CargoLockfile.kt +++ b/plugins/package-managers/cargo/src/main/kotlin/CargoLockfile.kt @@ -22,6 +22,10 @@ package org.ossreviewtoolkit.plugins.packagemanagers.cargo import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +import net.peanuuutz.tomlkt.Toml + +internal val toml = Toml { ignoreUnknownKeys = true } + /** * See https://docs.rs/cargo-lock/latest/cargo_lock/struct.Lockfile.html. */ diff --git a/plugins/package-managers/cargo/src/main/kotlin/CargoMetadata.kt b/plugins/package-managers/cargo/src/main/kotlin/CargoMetadata.kt index c2e51450f356b..5585a850c3a87 100644 --- a/plugins/package-managers/cargo/src/main/kotlin/CargoMetadata.kt +++ b/plugins/package-managers/cargo/src/main/kotlin/CargoMetadata.kt @@ -20,6 +20,13 @@ package org.ossreviewtoolkit.plugins.packagemanagers.cargo import kotlinx.serialization.Serializable +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.JsonNamingStrategy + +internal val json = Json { + ignoreUnknownKeys = true + namingStrategy = JsonNamingStrategy.SnakeCase +} /** * See https://doc.rust-lang.org/cargo/commands/cargo-metadata.html.