Skip to content

Commit

Permalink
refactor(git): Migrate from Jackson to KxS
Browse files Browse the repository at this point in the history
Use xmlutil as a serializer for KxS to parse git-repo manifests.

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
  • Loading branch information
sschuberth committed Jul 3, 2024
1 parent dd09f54 commit 2c3d0a8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
3 changes: 2 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ springCore = "5.3.37"
svnkit = "1.10.11"
sw360Client = "17.0.1-m2"
wiremock = "3.8.0"
xmlutil = "0.90.1"
xz = "1.9"

[plugins]
Expand Down Expand Up @@ -107,7 +108,6 @@ hoplite-yaml = { module = "com.sksamuel.hoplite:hoplite-yaml", version.ref = "ho
jackson-annotations = { module = "com.fasterxml.jackson.core:jackson-annotations", version.ref = "jackson" }
jackson-core = { module = "com.fasterxml.jackson.core:jackson-core", version.ref = "jackson" }
jackson-databind = { module = "com.fasterxml.jackson.core:jackson-databind", version.ref = "jackson" }
jackson-dataformat-xml = { module = "com.fasterxml.jackson.dataformat:jackson-dataformat-xml", version.ref = "jackson" }
jackson-dataformat-yaml = { module = "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml", version.ref = "jackson" }
jackson-datatype-jsr310 = { module = "com.fasterxml.jackson.datatype:jackson-datatype-jsr310", version.ref = "jackson" }
jackson-module-kotlin = { module = "com.fasterxml.jackson.module:jackson-module-kotlin", version.ref = "jackson" }
Expand All @@ -132,6 +132,7 @@ kotlinx-html = { module = "org.jetbrains.kotlinx:kotlinx-html-jvm", version.ref
kotlinx-serialization-core = { module = "org.jetbrains.kotlinx:kotlinx-serialization-core", version.ref = "kotlinxSerialization" }
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinxSerialization" }
kotlinx-serialization-toml = { module = "net.peanuuutz.tomlkt:tomlkt", version.ref = "tomlkt" }
kotlinx-serialization-xml = { module = "io.github.pdvrieze.xmlutil:serialization", version.ref = "xmlutil" }
kotlinx-serialization-yaml = { module = "com.charleskorn.kaml:kaml", version.ref = "kaml" }
ks3-jdk = { module = "io.ks3:ks3-jdk", version.ref = "ks3" }
ks3-standard = { module = "io.ks3:ks3-standard", version.ref = "ks3" }
Expand Down
8 changes: 5 additions & 3 deletions plugins/version-control-systems/git/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 @@ -35,11 +38,10 @@ dependencies {

implementation(projects.utils.ortUtils)

implementation(libs.jackson.core)
implementation(libs.jackson.databind)
implementation(libs.jackson.dataformat.xml)
implementation(libs.jgit)
implementation(libs.jgit.ssh.apache)
implementation(libs.kotlinx.serialization.core)
implementation(libs.kotlinx.serialization.xml)

runtimeOnly(libs.jgit.ssh.apache.agent) {
exclude(group = "org.apache.sshd", module = "sshd-sftp")
Expand Down
16 changes: 11 additions & 5 deletions plugins/version-control-systems/git/src/main/kotlin/GitRepo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@

package org.ossreviewtoolkit.plugins.versioncontrolsystems.git

import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty

import java.io.File
import java.io.IOException

import kotlinx.serialization.Serializable
import kotlinx.serialization.decodeFromString

import nl.adaptivity.xmlutil.serialization.XML
import nl.adaptivity.xmlutil.serialization.XmlSerialName

import org.apache.logging.log4j.kotlin.logger

import org.eclipse.jgit.lib.SymbolicRef
Expand All @@ -32,7 +36,6 @@ import org.ossreviewtoolkit.downloader.VersionControlSystem
import org.ossreviewtoolkit.downloader.WorkingTree
import org.ossreviewtoolkit.model.VcsInfo
import org.ossreviewtoolkit.model.VcsType
import org.ossreviewtoolkit.model.readValue
import org.ossreviewtoolkit.model.utils.parseRepoManifestPath
import org.ossreviewtoolkit.utils.common.CommandLineTool
import org.ossreviewtoolkit.utils.common.Os
Expand All @@ -53,16 +56,18 @@ private const val GIT_REPO_REV = "v2.39"
* The minimal manifest structure as used by the wrapping "manifest.xml" file as of repo version 2.4. For the full
* structure see https://gerrit.googlesource.com/git-repo/+/refs/heads/master/docs/manifest-format.md.
*/
@Serializable
private data class Manifest(
@XmlSerialName("include")
val include: Include
)

/**
* The "include" tag of a "manifest.xml" file, see
* https://gerrit.googlesource.com/git-repo/+/refs/heads/master/docs/manifest-format.md#Element-include.
*/
@Serializable
private data class Include(
@JacksonXmlProperty(isAttribute = true)
val name: String
)

Expand Down Expand Up @@ -116,7 +121,8 @@ class GitRepo : VersionControlSystem(GitRepoCommand) {
} else {
// As of repo 2.4, the active manifest is a real file with an include directive instead of a
// symbolic link, see https://gerrit-review.googlesource.com/c/git-repo/+/256313.
val manifest = manifestWrapper.readValue<Manifest>()
val manifestText = manifestWrapper.readText()
val manifest = XML().decodeFromString<Manifest>(manifestText)
workingDir.resolve(manifest.include.name)
}

Expand Down

0 comments on commit 2c3d0a8

Please sign in to comment.