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 <[email protected]>
  • Loading branch information
pepper-jk committed Feb 5, 2025
1 parent c0a51c2 commit 6928b27
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 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 Down Expand Up @@ -85,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 6928b27

Please sign in to comment.