Skip to content

Commit 1d4115c

Browse files
committed
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]: oss-review-toolkit#8803 (comment) Signed-off-by: Jens Keim <[email protected]>
1 parent fd8adfb commit 1d4115c

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

model/src/main/kotlin/Provenance.kt

+21
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
package org.ossreviewtoolkit.model
2121

22+
import java.nio.file.Files
23+
import java.nio.file.Path
2224
import com.fasterxml.jackson.core.JsonParser
2325
import com.fasterxml.jackson.databind.DeserializationContext
2426
import com.fasterxml.jackson.databind.JsonNode
@@ -45,6 +47,8 @@ sealed interface KnownProvenance : Provenance
4547

4648
sealed interface RemoteProvenance : KnownProvenance
4749

50+
sealed interface LocalProvenance : KnownProvenance
51+
4852
/**
4953
* Provenance information for a source artifact.
5054
*/
@@ -83,6 +87,23 @@ data class RepositoryProvenance(
8387
override fun matches(pkg: Package): Boolean = vcsInfo == pkg.vcsProcessed
8488
}
8589

90+
/**
91+
* Provenance information for a local directory path.
92+
*/
93+
data class DirectoryProvenance(
94+
val directoryPath: Path
95+
) : LocalProvenance {
96+
init {
97+
require(Files.exists(directoryPath)) { "The directory path must exist." }
98+
}
99+
100+
/**
101+
* Return true if this provenance matches the package URL of the [package][pkg],
102+
* as it contains the local file path for non-remote Provenances.
103+
*/
104+
override fun matches(pkg: Package): Boolean = directoryPath.toString() == pkg.purl
105+
}
106+
86107
/**
87108
* A custom deserializer for polymorphic deserialization of [Provenance] without requiring type information.
88109
*/

0 commit comments

Comments
 (0)