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

chore(opossum reporter): Migrate serialization to kotlinx #9484

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
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")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit message nits:

  • We prefer imperative mood, i.e. "Migrates" should say "Migrate".
  • We usually start capitalized after ":" in the title.

// 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