From d4557a52244b08424ab29d1bad237715035297bd Mon Sep 17 00:00:00 2001 From: Jens Keim Date: Wed, 12 Jun 2024 17:02:57 +0200 Subject: [PATCH] feat(Provenance): Add `matches(KnownProvenance)` method In preparation of replacing `VcsInfo` in `Repository` with `KnownProvenances`, we add a method to match `KnownProvenances` against each other. Signed-off-by: Jens Keim --- model/src/main/kotlin/Provenance.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/model/src/main/kotlin/Provenance.kt b/model/src/main/kotlin/Provenance.kt index e71b0652786fb..cdea2aa391201 100644 --- a/model/src/main/kotlin/Provenance.kt +++ b/model/src/main/kotlin/Provenance.kt @@ -35,10 +35,12 @@ sealed interface Provenance { * True if this [Provenance] refers to the same source code as [pkg], assuming that it belongs to the package id. */ fun matches(pkg: Package): Boolean + fun matches(other: KnownProvenance): Boolean } data object UnknownProvenance : Provenance { override fun matches(pkg: Package): Boolean = false + override fun matches(other: KnownProvenance): Boolean = false } sealed interface KnownProvenance : Provenance @@ -53,6 +55,8 @@ data class ArtifactProvenance( val sourceArtifact: RemoteArtifact ) : KnownProvenance { override fun matches(pkg: Package): Boolean = sourceArtifact == pkg.sourceArtifact + override fun matches(other: KnownProvenance): Boolean = + other is ArtifactProvenance && sourceArtifact == other.sourceArtifact } /** @@ -79,6 +83,12 @@ data class RepositoryProvenance( * Return true if this provenance matches the processed VCS information of the [package][pkg]. */ override fun matches(pkg: Package): Boolean = vcsInfo == pkg.vcsProcessed + + /** + * Return true if this provenance matches the [knownProvenance][other]. + */ + override fun matches(other: KnownProvenance): Boolean = + other is RepositoryProvenance && other.vcsInfo.normalize().matches(vcsInfo.normalize()) } /**