Skip to content

Commit 729a29d

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, we require a more generallized Repository, which allows any type of `KnownProvenance`. While we still set the signature of `Repository` to allow `KnownProvenance`s, this commit focuses on accomidateing `RepositoryProvenance` as then main input for now. Therefore we wrap `VcsInfo` with `RepositoryProvenance`, whenever it is used as input, and unwrap it, when it is produced as output. This gives us a quick update of the now depreacted code, without the necessity to support all `KnownProvenance` types from the get go. We also update any realted tests, mostly the expected `OrtResults`, but also some `Repository` definitions and calls. To avoid having `vcs` and `vcsProcessed` appear in the `OrtResult` output, we change them to be a method (fun) instead of a variable (val). This is still a soft refactor, to keep the widely used `vcsProcessed` available for now. We might still remove it later. Signed-off-by: Jens Keim <[email protected]>
1 parent f441abb commit 729a29d

File tree

50 files changed

+387
-409
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+387
-409
lines changed

analyzer/src/main/kotlin/Analyzer.kt

+9-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,18 @@ 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.map {
147+
it.key to RepositoryProvenance(it.value, it.value.revision)
148+
}.toMap(),
149+
config = info.repositoryConfiguration
150+
)
143151

144152
val endTime = Instant.now()
145153

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

+43-34
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,55 @@
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:
15-
type: "Git"
16-
url: "https://github.com/spdx/tools"
17-
revision: "e179fae47590eccedc46186ea0ce20cbade5fda7"
18-
path: ""
12+
vcs_info:
13+
type: "Git"
14+
url: "https://github.com/spdx/tools"
15+
revision: "e179fae47590eccedc46186ea0ce20cbade5fda7"
16+
path: ""
17+
resolved_revision: "e179fae47590eccedc46186ea0ce20cbade5fda7"
1918
submodules:
20-
type: "Git"
21-
url: "https://github.com/oss-review-toolkit/ort-test-data-git-submodules"
22-
revision: "fcea94bab5835172e826afddb9f6427274c983b9"
23-
path: ""
19+
vcs_info:
20+
type: "Git"
21+
url: "https://github.com/oss-review-toolkit/ort-test-data-git-submodules"
22+
revision: "fcea94bab5835172e826afddb9f6427274c983b9"
23+
path: ""
24+
resolved_revision: "fcea94bab5835172e826afddb9f6427274c983b9"
2425
submodules/commons-text:
25-
type: "Git"
26-
url: "https://github.com/apache/commons-text.git"
27-
revision: "7643b12421100d29fd2b78053e77bcb04a251b2e"
28-
path: ""
26+
vcs_info:
27+
type: "Git"
28+
url: "https://github.com/apache/commons-text.git"
29+
revision: "7643b12421100d29fd2b78053e77bcb04a251b2e"
30+
path: ""
31+
resolved_revision: "7643b12421100d29fd2b78053e77bcb04a251b2e"
2932
submodules/test-data-npm:
30-
type: "Git"
31-
url: "https://github.com/oss-review-toolkit/ort-test-data-npm.git"
32-
revision: "ad0367b7b9920144a47b8d30cc0c84cea102b821"
33-
path: ""
33+
vcs_info:
34+
type: "Git"
35+
url: "https://github.com/oss-review-toolkit/ort-test-data-npm.git"
36+
revision: "ad0367b7b9920144a47b8d30cc0c84cea102b821"
37+
path: ""
38+
resolved_revision: "ad0367b7b9920144a47b8d30cc0c84cea102b821"
3439
submodules/test-data-npm/isarray:
35-
type: "Git"
36-
url: "https://github.com/juliangruber/isarray.git"
37-
revision: "63ea4ca0a0d6b0574d6a470ebd26880c3026db4a"
38-
path: ""
40+
vcs_info:
41+
type: "Git"
42+
url: "https://github.com/juliangruber/isarray.git"
43+
revision: "63ea4ca0a0d6b0574d6a470ebd26880c3026db4a"
44+
path: ""
45+
resolved_revision: "63ea4ca0a0d6b0574d6a470ebd26880c3026db4a"
3946
submodules/test-data-npm/long.js:
40-
type: "Git"
41-
url: "https://github.com/dcodeIO/long.js.git"
42-
revision: "941c5c62471168b5d18153755c2a7b38d2560e58"
43-
path: ""
47+
vcs_info:
48+
type: "Git"
49+
url: "https://github.com/dcodeIO/long.js.git"
50+
revision: "941c5c62471168b5d18153755c2a7b38d2560e58"
51+
path: ""
52+
resolved_revision: "941c5c62471168b5d18153755c2a7b38d2560e58"
4453
config: {}
4554
analyzer:
4655
start_time: "1970-01-01T00:00:00Z"

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: "<REPLACE_REVISION>"
1310
config:
1411
excludes:
1512
scopes:

evaluator/src/main/kotlin/ProjectSourceRule.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ open class ProjectSourceRule(
9191
/**
9292
* Return the [VcsType] of the project's code repository.
9393
*/
94-
fun projectSourceGetVcsType(): VcsType = ortResult.repository.vcsProcessed.type
94+
fun projectSourceGetVcsType(): VcsType = ortResult.repository.vcsProcessed().type
9595

9696
/**
9797
* Return the file paths matching any of the given [glob expressions][patterns] with its file content matching

evaluator/src/main/kotlin/RuleSet.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ fun ruleSet(
159159
licenseInfoResolver: LicenseInfoResolver = ortResult.createLicenseInfoResolver(),
160160
resolutionProvider: ResolutionProvider = DefaultResolutionProvider.create(),
161161
projectSourceResolver: SourceTreeResolver = SourceTreeResolver.forRemoteRepository(
162-
ortResult.repository.vcsProcessed
162+
ortResult.repository.vcsProcessed()
163163
),
164164
configure: RuleSet.() -> Unit = { }
165165
) = RuleSet(ortResult, licenseInfoResolver, resolutionProvider, projectSourceResolver).apply(configure)

evaluator/src/test/kotlin/ProjectSourceRuleTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ private fun createOrtResult(
208208
}
209209

210210
return OrtResult.EMPTY.copy(
211-
repository = Repository(vcsInfo),
211+
repository = Repository(RepositoryProvenance(vcsInfo, vcsInfo.revision)),
212212
analyzer = AnalyzerRun.EMPTY.copy(
213213
result = AnalyzerResult.EMPTY.copy(
214214
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(

helper-cli/src/main/kotlin/utils/Extensions.kt

+5-3
Original file line numberDiff line numberDiff line change
@@ -691,10 +691,12 @@ internal fun OrtResult.getScanResultFor(packageConfiguration: PackageConfigurati
691691
* tree.
692692
*/
693693
internal fun OrtResult.getRepositoryPaths(): Map<String, Set<String>> {
694-
val result = mutableMapOf(repository.vcsProcessed.url to mutableSetOf(""))
694+
val result = mutableMapOf(repository.vcsProcessed().url to mutableSetOf(""))
695695

696-
repository.nestedRepositories.mapValues { (path, vcsInfo) ->
697-
result.getOrPut(vcsInfo.url) { mutableSetOf() } += path
696+
repository.nestedRepositories.mapValues { (path, provenance) ->
697+
if (provenance is RepositoryProvenance) {
698+
result.getOrPut(provenance.vcsInfo.url) { mutableSetOf() } += path
699+
}
698700
}
699701

700702
// For some Git-repo projects `OrtResult.repository.nestedRepositories´ misses some nested repositories for Git

helper-cli/src/main/kotlin/utils/Utils.kt

+27-16
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ import java.io.File
2525

2626
import org.ossreviewtoolkit.downloader.VersionControlSystem
2727
import org.ossreviewtoolkit.model.Identifier
28+
import org.ossreviewtoolkit.model.KnownProvenance
2829
import org.ossreviewtoolkit.model.OrtResult
2930
import org.ossreviewtoolkit.model.PackageCuration
31+
import org.ossreviewtoolkit.model.RepositoryProvenance
3032
import org.ossreviewtoolkit.model.VcsInfo
3133
import org.ossreviewtoolkit.model.config.LicenseFindingCuration
3234
import org.ossreviewtoolkit.model.config.PathExclude
@@ -68,8 +70,10 @@ internal fun findRepositoryPaths(directory: File): Map<String, Set<String>> {
6870

6971
val result = mutableMapOf<String, MutableSet<String>>()
7072

71-
findRepositories(directory).forEach { (path, vcs) ->
72-
result.getOrPut(vcs.url.replaceCredentialsInUri()) { mutableSetOf() } += path
73+
findRepositories(directory).forEach { (path, provenance) ->
74+
if (provenance is RepositoryProvenance) {
75+
result.getOrPut(provenance.vcsInfo.url.replaceCredentialsInUri()) { mutableSetOf() } += path
76+
}
7377
}
7478

7579
return result
@@ -79,14 +83,17 @@ internal fun findRepositoryPaths(directory: File): Map<String, Set<String>> {
7983
* Search the given [directory] for repositories and return a mapping from paths where each respective repository was
8084
* found to the corresponding [VcsInfo].
8185
*/
82-
internal fun findRepositories(directory: File): Map<String, VcsInfo> {
86+
internal fun findRepositories(directory: File): Map<String, KnownProvenance> {
8387
require(directory.isDirectory)
8488

8589
val workingTree = VersionControlSystem.forDirectory(directory)
86-
return workingTree?.getNested()?.filter { (path, _) ->
90+
val nestedVcs = workingTree?.getNested()?.filter { (path, _) ->
8791
// Only include nested VCS if they are part of the analyzed directory.
8892
workingTree.getRootPath().resolve(path).startsWith(directory)
8993
}.orEmpty()
94+
return nestedVcs.map {
95+
it.key to RepositoryProvenance(it.value, it.value.revision)
96+
}.toMap()
9097
}
9198

9299
/**
@@ -166,15 +173,17 @@ internal data class ProcessedCopyrightStatement(
166173
*/
167174
internal fun getLicenseFindingCurationsByRepository(
168175
curations: Collection<LicenseFindingCuration>,
169-
nestedRepositories: Map<String, VcsInfo>
176+
nestedRepositories: Map<String, KnownProvenance>
170177
): RepositoryLicenseFindingCurations {
171178
val result = mutableMapOf<String, MutableList<LicenseFindingCuration>>()
172179

173-
nestedRepositories.forEach { (path, vcs) ->
174-
val pathExcludesForRepository = result.getOrPut(vcs.url) { mutableListOf() }
175-
curations.forEach { curation ->
176-
curation.path.withoutPrefix("$path/")?.let {
177-
pathExcludesForRepository += curation.copy(path = it)
180+
nestedRepositories.forEach { (path, provenance) ->
181+
if (provenance is RepositoryProvenance) {
182+
val pathExcludesForRepository = result.getOrPut(provenance.vcsInfo.url) { mutableListOf() }
183+
curations.forEach { curation ->
184+
curation.path.withoutPrefix("$path/")?.let {
185+
pathExcludesForRepository += curation.copy(path = it)
186+
}
178187
}
179188
}
180189
}
@@ -187,15 +196,17 @@ internal fun getLicenseFindingCurationsByRepository(
187196
*/
188197
internal fun getPathExcludesByRepository(
189198
pathExcludes: Collection<PathExclude>,
190-
nestedRepositories: Map<String, VcsInfo>
199+
nestedRepositories: Map<String, KnownProvenance>
191200
): RepositoryPathExcludes {
192201
val result = mutableMapOf<String, MutableList<PathExclude>>()
193202

194-
nestedRepositories.forEach { (path, vcs) ->
195-
val pathExcludesForRepository = result.getOrPut(vcs.url) { mutableListOf() }
196-
pathExcludes.forEach { pathExclude ->
197-
pathExclude.pattern.withoutPrefix("$path/")?.let {
198-
pathExcludesForRepository += pathExclude.copy(pattern = it)
203+
nestedRepositories.forEach { (path, provenance) ->
204+
if (provenance is RepositoryProvenance) {
205+
val pathExcludesForRepository = result.getOrPut(provenance.vcsInfo.url) { mutableListOf() }
206+
pathExcludes.forEach { pathExclude ->
207+
pathExclude.pattern.withoutPrefix("$path/")?.let {
208+
pathExcludesForRepository += pathExclude.copy(pattern = it)
209+
}
199210
}
200211
}
201212
}

model/src/main/kotlin/OrtResult.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,9 @@ data class OrtResult(
194194
}
195195

196196
private val relativeProjectVcsPath: Map<Identifier, String?> by lazy {
197-
getProjects().associateBy({ it.id }, { repository.getRelativePath(it.vcsProcessed) })
197+
getProjects().associateBy({ it.id }, {
198+
repository.getRelativePath(RepositoryProvenance(it.vcsProcessed, it.vcsProcessed.revision))
199+
})
198200
}
199201

200202
/**

0 commit comments

Comments
 (0)