Skip to content

Commit ba2a2a2

Browse files
committed
feat(Repository): Use KnownProvenance instead of VcsInfo
In order to allow source artifacts as well as local source code to be scanned, a more generalized `Repository` class is required, which allows any type of `KnownProvenance`. While the signature of the `Repository` class is set to allow any `KnownProvenance` object, this commit focuses on accommodating `RepositoryProvenance` as the main input for now. Therefore `VcsInfo` is wrapped within `RepositoryProvenance`, whenever it is used as input, and unwraped, when it is produced as output. This results in a faster update of the now deprecated code, without the necessity to support all `KnownProvenance` types from the get go. Any related tests are also updated, mostly the expected `OrtResults`, but also some `Repository` definitions and calls. To avoid having `vcs` and `vcsProcessed` appear in the `OrtResult` output, getter properties were created and marked as `@JsonIgnore`. Signed-off-by: Jens Keim <[email protected]>
1 parent 7969f0b commit ba2a2a2

File tree

40 files changed

+261
-319
lines changed

40 files changed

+261
-319
lines changed

analyzer/src/main/kotlin/Analyzer.kt

+7-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import org.ossreviewtoolkit.model.AnalyzerResult
4242
import org.ossreviewtoolkit.model.AnalyzerRun
4343
import org.ossreviewtoolkit.model.OrtResult
4444
import org.ossreviewtoolkit.model.Repository
45+
import org.ossreviewtoolkit.model.RepositoryProvenance
4546
import org.ossreviewtoolkit.model.config.AnalyzerConfiguration
4647
import org.ossreviewtoolkit.model.config.Excludes
4748
import org.ossreviewtoolkit.model.config.RepositoryConfiguration
@@ -135,11 +136,16 @@ class Analyzer(private val config: AnalyzerConfiguration, private val labels: Ma
135136

136137
val workingTree = VersionControlSystem.forDirectory(info.absoluteProjectPath)
137138
val vcs = workingTree?.getInfo().orEmpty()
139+
val revision = workingTree?.getRevision().orEmpty()
138140
val nestedVcs = workingTree?.getNested()?.filter { (path, _) ->
139141
// Only include nested VCS if they are part of the analyzed directory.
140142
workingTree.getRootPath().resolve(path).startsWith(info.absoluteProjectPath)
141143
}.orEmpty()
142-
val repository = Repository(vcs = vcs, nestedRepositories = nestedVcs, config = info.repositoryConfiguration)
144+
val repository = Repository(
145+
provenance = RepositoryProvenance(vcs, revision),
146+
nestedRepositories = nestedVcs,
147+
config = info.repositoryConfiguration
148+
)
143149

144150
val endTime = Instant.now()
145151

cli/src/funTest/assets/git-repo-expected-output.yml

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
---
22
repository:
3-
vcs:
4-
type: "GitRepo"
5-
url: "https://github.com/oss-review-toolkit/ort-test-data-git-repo?manifest=manifest.xml"
6-
revision: "31588aa8f8555474e1c3c66a359ec99e4cd4b1fa"
7-
path: ""
8-
vcs_processed:
9-
type: "GitRepo"
10-
url: "https://github.com/oss-review-toolkit/ort-test-data-git-repo.git?manifest=manifest.xml"
11-
revision: "31588aa8f8555474e1c3c66a359ec99e4cd4b1fa"
12-
path: ""
3+
provenance:
4+
vcs_info:
5+
type: "GitRepo"
6+
url: "https://github.com/oss-review-toolkit/ort-test-data-git-repo?manifest=manifest.xml"
7+
revision: "31588aa8f8555474e1c3c66a359ec99e4cd4b1fa"
8+
path: ""
9+
resolved_revision: "31588aa8f8555474e1c3c66a359ec99e4cd4b1fa"
1310
nested_repositories:
1411
spdx-tools:
1512
type: "Git"

cli/src/funTest/assets/gradle-all-dependencies-expected-result-with-curations.yml

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
---
22
repository:
3-
vcs:
4-
type: "Git"
5-
url: "<REPLACE_URL>"
6-
revision: "<REPLACE_REVISION>"
7-
path: "plugins/package-managers/gradle/src/funTest/assets/projects/synthetic/gradle"
8-
vcs_processed:
9-
type: "Git"
10-
url: "<REPLACE_URL_PROCESSED>"
11-
revision: "<REPLACE_REVISION>"
12-
path: "plugins/package-managers/gradle/src/funTest/assets/projects/synthetic/gradle"
3+
provenance:
4+
vcs_info:
5+
type: "Git"
6+
url: "<REPLACE_URL>"
7+
revision: "<REPLACE_REVISION>"
8+
path: "plugins/package-managers/gradle/src/funTest/assets/projects/synthetic/gradle"
9+
resolved_revision: "<REPLACE_REVISION>"
1310
config:
1411
excludes:
1512
paths:

cli/src/funTest/assets/semver4j-ort-result.yml

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
---
22
repository:
3-
vcs:
4-
type: "Git"
5-
url: "https://github.com/vdurmont/semver4j.git"
6-
revision: "7653e418d610ffcd2811bcb55fd72d00d420950b"
7-
path: ""
8-
vcs_processed:
9-
type: "Git"
10-
url: "https://github.com/vdurmont/semver4j.git"
11-
revision: "7653e418d610ffcd2811bcb55fd72d00d420950b"
12-
path: ""
3+
provenance:
4+
vcs_info:
5+
type: "Git"
6+
url: "https://github.com/vdurmont/semver4j.git"
7+
revision: "7653e418d610ffcd2811bcb55fd72d00d420950b"
8+
path: ""
9+
resolved_revision: "7653e418d610ffcd2811bcb55fd72d00d420950b"
1310
config:
1411
excludes:
1512
scopes:

evaluator/src/test/kotlin/ProjectSourceRuleTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ private fun createOrtResult(
214214
}
215215

216216
return OrtResult.EMPTY.copy(
217-
repository = Repository(vcsInfo),
217+
repository = Repository(RepositoryProvenance(vcsInfo, vcsInfo.revision)),
218218
analyzer = AnalyzerRun.EMPTY.copy(
219219
result = AnalyzerResult.EMPTY.copy(
220220
projects = setOf(

evaluator/src/test/kotlin/TestData.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import org.ossreviewtoolkit.model.Package
3737
import org.ossreviewtoolkit.model.PackageLinkage
3838
import org.ossreviewtoolkit.model.Project
3939
import org.ossreviewtoolkit.model.Repository
40+
import org.ossreviewtoolkit.model.RepositoryProvenance
4041
import org.ossreviewtoolkit.model.ScanResult
4142
import org.ossreviewtoolkit.model.ScanSummary
4243
import org.ossreviewtoolkit.model.ScannerDetails
@@ -180,7 +181,7 @@ val allProjects = setOf(
180181

181182
val ortResult = OrtResult(
182183
repository = Repository(
183-
vcs = VcsInfo.EMPTY,
184+
provenance = RepositoryProvenance(VcsInfo.EMPTY, ""),
184185
config = RepositoryConfiguration(
185186
excludes = Excludes(
186187
paths = listOf(

helper-cli/src/funTest/assets/create-analyzer-result-from-pkg-list-expected-output.yml

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
---
22
repository:
3-
vcs:
4-
type: "Git"
5-
url: "https://github.com/example/project.git"
6-
revision: "2222222222222222222222222222222222222222"
7-
path: "vcs-path/project"
8-
vcs_processed:
9-
type: "Git"
10-
url: "https://github.com/example/project.git"
11-
revision: "2222222222222222222222222222222222222222"
12-
path: "vcs-path/project"
3+
provenance:
4+
vcs_info:
5+
type: "Git"
6+
url: "https://github.com/example/project.git"
7+
revision: "2222222222222222222222222222222222222222"
8+
path: "vcs-path/project"
9+
resolved_revision: "2222222222222222222222222222222222222222"
1310
config:
1411
excludes:
1512
scopes:

helper-cli/src/main/kotlin/commands/CreateAnalyzerResultFromPackageListCommand.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import org.ossreviewtoolkit.model.PackageReference
4141
import org.ossreviewtoolkit.model.Project
4242
import org.ossreviewtoolkit.model.RemoteArtifact
4343
import org.ossreviewtoolkit.model.Repository
44+
import org.ossreviewtoolkit.model.RepositoryProvenance
4445
import org.ossreviewtoolkit.model.Scope
4546
import org.ossreviewtoolkit.model.VcsInfo
4647
import org.ossreviewtoolkit.model.VcsType
@@ -118,7 +119,7 @@ internal class CreateAnalyzerResultFromPackageListCommand : CliktCommand(
118119
environment = Environment()
119120
),
120121
repository = Repository(
121-
vcs = projectVcs.normalize(),
122+
provenance = RepositoryProvenance(projectVcs.normalize(), projectVcs.revision),
122123
config = RepositoryConfiguration(
123124
excludes = Excludes(
124125
scopes = listOf(

model/src/main/kotlin/Repository.kt

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

2020
package org.ossreviewtoolkit.model
2121

22+
import com.fasterxml.jackson.annotation.JsonIgnore
2223
import com.fasterxml.jackson.annotation.JsonInclude
2324

2425
import org.ossreviewtoolkit.model.config.RepositoryConfiguration
@@ -31,13 +32,7 @@ data class Repository(
3132
/**
3233
* Original VCS-related information from the working tree containing the analyzer root.
3334
*/
34-
val vcs: VcsInfo,
35-
36-
/**
37-
* Processed VCS-related information from the working tree containing the analyzer root that has e.g. common
38-
* mistakes corrected.
39-
*/
40-
val vcsProcessed: VcsInfo = vcs.normalize(),
35+
val provenance: KnownProvenance,
4136

4237
/**
4338
* A map of nested repositories, for example Git submodules or Git-Repo modules. The key is the path to the
@@ -57,18 +52,33 @@ data class Repository(
5752
*/
5853
@JvmField
5954
val EMPTY = Repository(
60-
vcs = VcsInfo.EMPTY,
61-
vcsProcessed = VcsInfo.EMPTY,
55+
provenance = RepositoryProvenance(VcsInfo.EMPTY, ""),
6256
nestedRepositories = emptyMap(),
6357
config = RepositoryConfiguration()
6458
)
6559
}
6660

61+
@JsonIgnore
62+
val vcs = if (provenance is RepositoryProvenance) {
63+
provenance.vcsInfo
64+
} else {
65+
VcsInfo.EMPTY
66+
}
67+
68+
@JsonIgnore
69+
val vcsProcessed = if (provenance is RepositoryProvenance) {
70+
provenance.vcsInfo.normalize()
71+
} else {
72+
VcsInfo.EMPTY
73+
}
74+
6775
/**
68-
* Return the path of [vcs] relative to [Repository.vcs], or null if [vcs] is neither [Repository.vcs] nor contained
69-
* in [nestedRepositories].
76+
* Return the path of [vcs] relative to [Repository.provenance], or null if [vcs] is neither
77+
* [Repository.provenance] nor contained in [nestedRepositories].
7078
*/
7179
fun getRelativePath(vcs: VcsInfo): String? {
80+
if (this.provenance !is RepositoryProvenance) return null
81+
7282
val normalizedVcs = vcs.normalize()
7383

7484
if (vcsProcessed.equalsDisregardingPath(normalizedVcs)) return ""

model/src/test/assets/analyzer-result-with-dependency-graph.yml

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
---
22
repository:
3-
vcs:
4-
type: "Git"
5-
url: "https://github.com/vdurmont/semver4j.git"
6-
revision: "7653e418d610ffcd2811bcb55fd72d00d420950b"
7-
path: ""
8-
vcs_processed:
9-
type: "Git"
10-
url: "https://github.com/vdurmont/semver4j.git"
11-
revision: "7653e418d610ffcd2811bcb55fd72d00d420950b"
12-
path: ""
3+
provenance:
4+
vcs_info:
5+
type: "Git"
6+
url: "https://github.com/vdurmont/semver4j.git"
7+
revision: "7653e418d610ffcd2811bcb55fd72d00d420950b"
8+
path: ""
9+
resolved_revision: "7653e418d610ffcd2811bcb55fd72d00d420950b"
1310
config: {}
1411
analyzer:
1512
start_time: "2021-04-26T05:48:05.390356Z"

model/src/test/assets/gradle-all-dependencies-expected-result.yml

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
---
22
repository:
3-
vcs:
4-
type: "Git"
5-
url: "https://github.com/oss-review-toolkit/ort.git"
6-
revision: "d27a886818b8ebba8e97e914133ec3cc650a534b"
7-
path: "analyzer/src/funTest/assets/projects/synthetic/gradle"
8-
vcs_processed:
9-
type: "Git"
10-
url: "https://github.com/oss-review-toolkit/ort.git"
11-
revision: "d27a886818b8ebba8e97e914133ec3cc650a534b"
12-
path: "analyzer/src/funTest/assets/projects/synthetic/gradle"
3+
provenance:
4+
vcs_info:
5+
type: "Git"
6+
url: "https://github.com/oss-review-toolkit/ort.git"
7+
revision: "d27a886818b8ebba8e97e914133ec3cc650a534b"
8+
path: "analyzer/src/funTest/assets/projects/synthetic/gradle"
9+
resolved_revision: "d27a886818b8ebba8e97e914133ec3cc650a534b"
1310
config:
1411
excludes:
1512
paths:

model/src/test/assets/result-with-issues-graph-old.yml

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
---
22
repository:
3-
vcs:
4-
type: "Git"
5-
url: "https://github.com/pbassiner/sbt-multi-project-example.git"
6-
revision: "31687c099ea6d645e819ef9d6ac9fc4c757a96bc"
7-
path: ""
8-
vcs_processed:
9-
type: "Git"
10-
url: "https://github.com/pbassiner/sbt-multi-project-example.git"
11-
revision: "31687c099ea6d645e819ef9d6ac9fc4c757a96bc"
12-
path: ""
3+
provenance:
4+
vcs_info:
5+
type: "Git"
6+
url: "https://github.com/pbassiner/sbt-multi-project-example.git"
7+
revision: "31687c099ea6d645e819ef9d6ac9fc4c757a96bc"
8+
path: ""
9+
resolved_revision: "31687c099ea6d645e819ef9d6ac9fc4c757a96bc"
1310
config: {}
1411
analyzer:
1512
start_time: "1970-01-01T00:00:00Z"

model/src/test/assets/result-with-issues-graph.yml

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
---
22
repository:
3-
vcs:
4-
type: "Git"
5-
url: "https://github.com/pbassiner/sbt-multi-project-example.git"
6-
revision: "31687c099ea6d645e819ef9d6ac9fc4c757a96bc"
7-
path: ""
8-
vcs_processed:
9-
type: "Git"
10-
url: "https://github.com/pbassiner/sbt-multi-project-example.git"
11-
revision: "31687c099ea6d645e819ef9d6ac9fc4c757a96bc"
12-
path: ""
3+
provenance:
4+
vcs_info:
5+
type: "Git"
6+
url: "https://github.com/pbassiner/sbt-multi-project-example.git"
7+
revision: "31687c099ea6d645e819ef9d6ac9fc4c757a96bc"
8+
path: ""
9+
resolved_revision: "31687c099ea6d645e819ef9d6ac9fc4c757a96bc"
1310
config: {}
1411
analyzer:
1512
start_time: "1970-01-01T00:00:00Z"

model/src/test/assets/result-with-issues-scopes.yml

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
---
22
repository:
3-
vcs:
4-
type: "Git"
5-
url: "https://github.com/pbassiner/sbt-multi-project-example.git"
6-
revision: "31687c099ea6d645e819ef9d6ac9fc4c757a96bc"
7-
path: ""
8-
vcs_processed:
9-
type: "Git"
10-
url: "https://github.com/pbassiner/sbt-multi-project-example.git"
11-
revision: "31687c099ea6d645e819ef9d6ac9fc4c757a96bc"
12-
path: ""
3+
provenance:
4+
vcs_info:
5+
type: "Git"
6+
url: "https://github.com/pbassiner/sbt-multi-project-example.git"
7+
revision: "31687c099ea6d645e819ef9d6ac9fc4c757a96bc"
8+
path: ""
9+
resolved_revision: "31687c099ea6d645e819ef9d6ac9fc4c757a96bc"
1310
config: {}
1411
analyzer:
1512
start_time: "1970-01-01T00:00:00Z"

model/src/test/assets/sbt-multi-project-example-expected-output.yml

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
---
22
repository:
3-
vcs:
4-
type: "Git"
5-
url: "https://github.com/oss-review-toolkit/sbt-multi-project-example.git"
6-
revision: "3c4e434b241b1f1addc97794932043b86afc2548"
7-
path: ""
8-
vcs_processed:
9-
type: "Git"
10-
url: "https://github.com/oss-review-toolkit/sbt-multi-project-example.git"
11-
revision: "3c4e434b241b1f1addc97794932043b86afc2548"
12-
path: ""
3+
provenance:
4+
vcs_info:
5+
type: "Git"
6+
url: "https://github.com/oss-review-toolkit/sbt-multi-project-example.git"
7+
revision: "3c4e434b241b1f1addc97794932043b86afc2548"
8+
path: ""
9+
resolved_revision: "3c4e434b241b1f1addc97794932043b86afc2548"
1310
config: {}
1411
analyzer:
1512
start_time: "1970-01-01T00:00:00Z"

model/src/test/assets/sbt-multi-project-example-graph-old.yml

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
---
22
repository:
3-
vcs:
4-
type: "Git"
5-
url: "https://github.com/oss-review-toolkit/sbt-multi-project-example.git"
6-
revision: "3c4e434b241b1f1addc97794932043b86afc2548"
7-
path: ""
8-
vcs_processed:
9-
type: "Git"
10-
url: "https://github.com/oss-review-toolkit/sbt-multi-project-example.git"
11-
revision: "3c4e434b241b1f1addc97794932043b86afc2548"
12-
path: ""
3+
provenance:
4+
vcs_info:
5+
type: "Git"
6+
url: "https://github.com/oss-review-toolkit/sbt-multi-project-example.git"
7+
revision: "3c4e434b241b1f1addc97794932043b86afc2548"
8+
path: ""
9+
resolved_revision: "3c4e434b241b1f1addc97794932043b86afc2548"
1310
config: {}
1411
analyzer:
1512
start_time: "1970-01-01T00:00:00Z"

0 commit comments

Comments
 (0)