Skip to content

Commit

Permalink
feat(Provenance): Add matches(KnownProvenance) method
Browse files Browse the repository at this point in the history
In preparation of replacing `VcsInfo` in `Repository` with
`KnownProvenances`, we add a method to match `KnownProvenances`
against each other.

Signed-off-by: Jens Keim <[email protected]>
  • Loading branch information
keimje1 committed Jun 20, 2024
1 parent dc15a42 commit d4557a5
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions model/src/main/kotlin/Provenance.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

/**
Expand All @@ -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())
}

/**
Expand Down

0 comments on commit d4557a5

Please sign in to comment.