Skip to content

Commit

Permalink
refactor(node): Port the parsing of Yarn2 package infos to KxS
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Viernau <frank_viernau@epam.com>
  • Loading branch information
fviernau committed Sep 11, 2024
1 parent e84d43a commit 77590e3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
5 changes: 5 additions & 0 deletions plugins/package-managers/node/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 @@ -44,6 +47,8 @@ dependencies {
implementation(libs.jackson.dataformat.yaml)
implementation(libs.jackson.module.kotlin)
implementation(libs.kotlinx.coroutines)
implementation(libs.kotlinx.serialization.core)
implementation(libs.kotlinx.serialization.json)

funTestImplementation(testFixtures(projects.analyzer))

Expand Down
28 changes: 15 additions & 13 deletions plugins/package-managers/node/src/main/kotlin/yarn2/PackageInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,40 @@

package org.ossreviewtoolkit.plugins.packagemanagers.node.yarn2

import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.module.kotlin.readValues
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.decodeToSequence

import org.ossreviewtoolkit.model.jsonMapper
private val JSON = Json { ignoreUnknownKeys = true }

internal fun parsePackageInfos(info: String): List<PackageInfo> =
jsonMapper.createParser(info).use { parser ->
jsonMapper.readValues<PackageInfo>(parser).readAll()
}
info.byteInputStream().use { JSON.decodeToSequence<PackageInfo>(it) }.toList()

@Serializable
internal data class PackageInfo(
val value: String,
val children: Children
) {
@JsonIgnoreProperties(ignoreUnknown = true)
@Serializable
data class Children(
@JsonProperty("Version")
@SerialName("Version")
val version: String,
@JsonProperty("Manifest")
@SerialName("Manifest")
val manifest: Manifest,
@JsonProperty("Dependencies")
@SerialName("Dependencies")
val dependencies: List<Dependency> = emptyList()
)

@Serializable
data class Manifest(
@JsonProperty("License")
@SerialName("License")
val license: String? = null,
@JsonProperty("Homepage")
@SerialName("Homepage")
val homepage: String? = null
)

@Serializable
data class Dependency(
val descriptor: String,
val locator: String
Expand Down

0 comments on commit 77590e3

Please sign in to comment.