From abe7a89af1c67a892df79c92f9894ea9dbce7b12 Mon Sep 17 00:00:00 2001 From: Frank Viernau Date: Wed, 17 Jul 2024 17:10:53 +0200 Subject: [PATCH] refactor(conan): Port parsing package info from Jackson to KxS Signed-off-by: Frank Viernau --- plugins/package-managers/conan/build.gradle.kts | 6 ++++++ .../conan/src/main/kotlin/PackageInfo.kt | 17 +++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/plugins/package-managers/conan/build.gradle.kts b/plugins/package-managers/conan/build.gradle.kts index 80b56d94cfbfd..af71c27846c9a 100644 --- a/plugins/package-managers/conan/build.gradle.kts +++ b/plugins/package-managers/conan/build.gradle.kts @@ -20,6 +20,9 @@ plugins { // Apply precompiled plugins. id("ort-library-conventions") + + // Apply third-party plugins. + alias(libs.plugins.kotlinSerialization) } dependencies { @@ -42,5 +45,8 @@ dependencies { implementation(libs.jackson.dataformat.yaml) implementation(libs.jackson.module.kotlin) + implementation(libs.kotlinx.serialization.core) + implementation(libs.kotlinx.serialization.json) + funTestImplementation(testFixtures(projects.analyzer)) } diff --git a/plugins/package-managers/conan/src/main/kotlin/PackageInfo.kt b/plugins/package-managers/conan/src/main/kotlin/PackageInfo.kt index d85e5d5d7c7bb..c6b6176304a4b 100644 --- a/plugins/package-managers/conan/src/main/kotlin/PackageInfo.kt +++ b/plugins/package-managers/conan/src/main/kotlin/PackageInfo.kt @@ -19,19 +19,20 @@ package org.ossreviewtoolkit.plugins.packagemanagers.conan -import com.fasterxml.jackson.annotation.JsonIgnoreProperties -import com.fasterxml.jackson.databind.PropertyNamingStrategies -import com.fasterxml.jackson.module.kotlin.readValue - import java.io.File -import org.ossreviewtoolkit.model.jsonMapper +import kotlinx.serialization.Serializable +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.JsonNamingStrategy -private val mapper = jsonMapper.copy().setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE) +private val JSON = Json { + ignoreUnknownKeys = true + namingStrategy = JsonNamingStrategy.SnakeCase +} -internal fun parsePackageInfos(file: File): List = mapper.readValue>(file) +internal fun parsePackageInfos(file: File): List = JSON.decodeFromString(file.readText()) -@JsonIgnoreProperties(ignoreUnknown = true) +@Serializable internal data class PackageInfo( val reference: String? = null, val author: String? = null,