Skip to content

Commit e334e27

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 bf5b8a0 commit e334e27

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

model/src/main/kotlin/Provenance.kt

+20
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize
2626
import com.fasterxml.jackson.databind.deser.std.StdDeserializer
2727
import com.fasterxml.jackson.module.kotlin.treeToValue
2828

29+
import java.nio.file.Files
30+
import java.nio.file.Path
31+
2932
/**
3033
* Provenance information about the origin of source code.
3134
*/
@@ -85,6 +88,23 @@ data class RepositoryProvenance(
8588
override fun matches(pkg: Package): Boolean = vcsInfo == pkg.vcsProcessed
8689
}
8790

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

0 commit comments

Comments
 (0)