Skip to content

Commit 9867ef0

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 c6cbdbc commit 9867ef0

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

model/src/main/kotlin/Provenance.kt

+19
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
@@ -85,6 +87,23 @@ data class RepositoryProvenance(
8587
override fun matches(pkg: Package): Boolean = vcsInfo == pkg.vcsProcessed
8688
}
8789

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's directoryPath 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+
88107
/**
89108
* A custom deserializer for polymorphic deserialization of [Provenance] without requiring type information.
90109
*/

0 commit comments

Comments
 (0)