From 0794697f0c3e315d6ea6491ca00abb4084a40c77 Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Wed, 10 Jan 2024 13:33:08 +0100 Subject: [PATCH] refactor(model): Handle `UnknownProvenance` in `toPurlExtras()` Make `toPurlExtras()` more symmetric to `toProvenance()` by also hanlding `UnknownProvenance`, which simply results in empty `PurlExtras`. Signed-off-by: Sebastian Schuberth --- model/src/main/kotlin/utils/PurlExtensions.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/model/src/main/kotlin/utils/PurlExtensions.kt b/model/src/main/kotlin/utils/PurlExtensions.kt index e9b27f04c60d7..277f0f5c3bb77 100644 --- a/model/src/main/kotlin/utils/PurlExtensions.kt +++ b/model/src/main/kotlin/utils/PurlExtensions.kt @@ -24,7 +24,6 @@ import java.net.URLDecoder import org.ossreviewtoolkit.model.ArtifactProvenance import org.ossreviewtoolkit.model.Hash import org.ossreviewtoolkit.model.Identifier -import org.ossreviewtoolkit.model.KnownProvenance import org.ossreviewtoolkit.model.Package import org.ossreviewtoolkit.model.Provenance import org.ossreviewtoolkit.model.RemoteArtifact @@ -77,9 +76,9 @@ fun Identifier.toPurl(qualifiers: Map = emptyMap(), subpath: Str fun Identifier.toPurl(extras: PurlExtras) = toPurl(extras.qualifiers, extras.subpath) /** - * Encode a [KnownProvenance] to extra qualifying data / a subpath of PURL. + * Encode a [Provenance] to extra qualifying data / a subpath of PURL. */ -fun KnownProvenance.toPurlExtras(): PurlExtras = +fun Provenance.toPurlExtras(): PurlExtras = when (this) { is ArtifactProvenance -> with(sourceArtifact) { val checksum = "${hash.algorithm.name.lowercase()}:${hash.value}" @@ -98,6 +97,8 @@ fun KnownProvenance.toPurlExtras(): PurlExtras = subpath = vcsInfo.path ) } + + is UnknownProvenance -> PurlExtras() } /**