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

refactor(conan): Port parsing package info from Jackson to KxS #8900

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions plugins/package-managers/conan/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
plugins {
// Apply precompiled plugins.
id("ort-library-conventions")

// Apply third-party plugins.
alias(libs.plugins.kotlinSerialization)
}

dependencies {
Expand All @@ -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))
}
17 changes: 9 additions & 8 deletions plugins/package-managers/conan/src/main/kotlin/PackageInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<PackageInfo> = mapper.readValue<List<PackageInfo>>(file)
internal fun parsePackageInfos(file: File): List<PackageInfo> = JSON.decodeFromString(file.readText())

@JsonIgnoreProperties(ignoreUnknown = true)
@Serializable
internal data class PackageInfo(
val reference: String? = null,
val author: String? = null,
Expand Down
Loading