From a984e1f7c141660e3bad87d222f9e0cf52bcf2ed Mon Sep 17 00:00:00 2001 From: Jens Keim Date: Thu, 30 Jan 2025 16:28:03 +0100 Subject: [PATCH] feat(Provenance): Add `DirectoryProvenance` as a `LocalProvenance` In contrast to the previously added `RemoteProvenance` stands the `LocalProvenance`, which has no remote source, but instead references a local input of some kind. The `DirectoryProvenance` references a local project directory, which is lacking supported (remote) version control. It is defined by its local directory path only. See [1] for more context on the new Provenance Hierarchy. [1]: https://github.com/oss-review-toolkit/ort/issues/8803#issuecomment-2236958430 Signed-off-by: Jens Keim --- model/src/main/kotlin/Provenance.kt | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/model/src/main/kotlin/Provenance.kt b/model/src/main/kotlin/Provenance.kt index 5290e442ac5f6..b5bf23b042bea 100644 --- a/model/src/main/kotlin/Provenance.kt +++ b/model/src/main/kotlin/Provenance.kt @@ -19,6 +19,8 @@ package org.ossreviewtoolkit.model +import java.nio.file.Files +import java.nio.file.Path import com.fasterxml.jackson.core.JsonParser import com.fasterxml.jackson.databind.DeserializationContext import com.fasterxml.jackson.databind.JsonNode @@ -45,6 +47,8 @@ sealed interface KnownProvenance : Provenance sealed interface RemoteProvenance : KnownProvenance +sealed interface LocalProvenance : KnownProvenance + /** * Provenance information for a source artifact. */ @@ -83,6 +87,23 @@ data class RepositoryProvenance( override fun matches(pkg: Package): Boolean = vcsInfo == pkg.vcsProcessed } +/** + * Provenance information for a local directory path. + */ +data class DirectoryProvenance( + val directoryPath: Path +) : LocalProvenance { + init { + require(Files.exists(directoryPath)) { "The directory path must exist." } + } + + /** + * Return true if this provenance's directoryPath matches the package URL of the [package][pkg], + * as it contains the local file path for non-remote Provenances. + */ + override fun matches(pkg: Package): Boolean = directoryPath.toString() == pkg.purl +} + /** * A custom deserializer for polymorphic deserialization of [Provenance] without requiring type information. */