Skip to content

Commit

Permalink
refactor(conan): Port parsing package info from Jackson to KxS
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Viernau <[email protected]>
  • Loading branch information
fviernau committed Jul 17, 2024
1 parent 3181191 commit abe7a89
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
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

0 comments on commit abe7a89

Please sign in to comment.