Skip to content

Commit

Permalink
feat(Provenance): Add DirectoryProvenance as a LocalProvenance
Browse files Browse the repository at this point in the history
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]: oss-review-toolkit#8803 (comment)

Signed-off-by: Jens Keim <jens.keim@forvia.com>
  • Loading branch information
pepper-jk committed Jan 30, 2025
1 parent fd8adfb commit a984e1f
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions model/src/main/kotlin/Provenance.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -45,6 +47,8 @@ sealed interface KnownProvenance : Provenance

sealed interface RemoteProvenance : KnownProvenance

sealed interface LocalProvenance : KnownProvenance

/**
* Provenance information for a source artifact.
*/
Expand Down Expand Up @@ -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.
*/
Expand Down

0 comments on commit a984e1f

Please sign in to comment.