Skip to content

Commit

Permalink
chore(opossum reporter): migrate serialization to kotlinx
Browse files Browse the repository at this point in the history
Migrates the OpossumReporter plugin away from Jackson serialization
to use kotlinx serialization. To get properly typed data structures for
serialization the previous untyped Map<*, *> are substituted by
properly typed data classes. This leads to the creation of an
OpossumInputCreator class that holds intermediate data structures
needed for processing of the Reporter input.

Signed-off-by: alexzurbonsen <[email protected]>
  • Loading branch information
alexzurbonsen committed Nov 21, 2024
1 parent 9103ac2 commit 7b1a948
Show file tree
Hide file tree
Showing 4 changed files with 258 additions and 189 deletions.
7 changes: 5 additions & 2 deletions plugins/reporters/opossum/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-plugin-conventions")

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

dependencies {
Expand All @@ -33,6 +36,6 @@ dependencies {
implementation(projects.utils.ortUtils)
implementation(projects.utils.spdxUtils)

implementation(libs.jackson.annotations)
implementation(libs.jackson.databind)
implementation(libs.kotlinx.serialization.core)
implementation(libs.kotlinx.serialization.json)
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@

package org.ossreviewtoolkit.plugins.reporters.opossum

import com.fasterxml.jackson.databind.json.JsonMapper
import kotlinx.serialization.json.Json

import io.kotest.core.TestConfiguration
import io.kotest.core.spec.style.WordSpec
import io.kotest.engine.spec.tempdir
import io.kotest.matchers.sequences.shouldContain
import io.kotest.matchers.collections.shouldContain
import io.kotest.matchers.shouldBe
import io.kotest.matchers.string.shouldContain
import kotlinx.serialization.json.jsonArray
import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive

import org.ossreviewtoolkit.model.OrtResult
import org.ossreviewtoolkit.plugins.api.PluginConfig
Expand All @@ -45,15 +48,24 @@ class OpossumReporterFunTest : WordSpec({
}

"create a parseable result and contain some expected values" {
with(JsonMapper().readTree(reportStr)) {
isObject shouldBe true
get("metadata").get("projectId").asText() shouldBe "0"
get("attributionBreakpoints").size() shouldBe 4
get("externalAttributionSources").size() shouldBe 7
get("resourcesToAttributions").fieldNames().asSequence() shouldContain
"/analyzer/src/funTest/assets/projects/synthetic/gradle/lib/build.gradle/" +
"compile/org.apache.commons/[email protected]/dependencies/org.apache.commons/[email protected]"
}
val json = Json.parseToJsonElement(reportStr).jsonObject

json["metadata"]?.jsonObject?.get("projectId")?.jsonPrimitive?.content shouldBe "0"
json["resources"]?.jsonObject?.size shouldBe 2
json["attributionBreakpoints"]?.jsonArray?.size shouldBe 4
json["externalAttributionSources"]?.jsonObject?.size shouldBe 7
json["frequentLicenses"]?.jsonArray?.size shouldBe 666
json["resourcesToAttributions"]?.jsonObject?.size shouldBe 13

val resourceRoots = json["resources"]?.jsonObject?.keys ?: emptySet()
resourceRoots shouldBe setOf("analyzer", "project")
val projectResource = json["resources"]?.jsonObject?.get("project")
projectResource?.jsonObject?.size shouldBe 5
projectResource?.jsonObject?.get("file.kt")?.jsonPrimitive?.content shouldBe "1"

val resourcePaths = json["resourcesToAttributions"]?.jsonObject?.keys ?: emptySet()
resourcePaths shouldContain "/analyzer/src/funTest/assets/projects/synthetic/gradle/lib/build.gradle/" +
"compile/org.apache.commons/[email protected]/dependencies/org.apache.commons/[email protected]"
}
}
})
Expand Down
Loading

0 comments on commit 7b1a948

Please sign in to comment.