Skip to content

Commit b608307

Browse files
committed
refactor(Repository): Add RepositoryProvenance attribute
The `Repository` data structure seems the easiest place to allow `Provenance`s as `Analyzer` and `Scanner` input. This avoids refactoring the attributes of higher level data structures, such as `OrtResult`. At the momemnt the implementation limits it to `RepositoryProvence` though, in order to keep its previous behavior. To that end, it also continues to expose the raw `VcsInfo` of the `provenance` as its `vcs` attribute. Signed-off-by: Jens Keim <[email protected]>
1 parent 896046f commit b608307

File tree

13 files changed

+59
-20
lines changed

13 files changed

+59
-20
lines changed

analyzer/src/main/kotlin/Analyzer.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import org.ossreviewtoolkit.model.AnalyzerResult
4141
import org.ossreviewtoolkit.model.AnalyzerRun
4242
import org.ossreviewtoolkit.model.OrtResult
4343
import org.ossreviewtoolkit.model.Repository
44+
import org.ossreviewtoolkit.model.RepositoryProvenance
4445
import org.ossreviewtoolkit.model.config.AnalyzerConfiguration
4546
import org.ossreviewtoolkit.model.config.Excludes
4647
import org.ossreviewtoolkit.model.config.RepositoryConfiguration
@@ -146,7 +147,12 @@ class Analyzer(private val config: AnalyzerConfiguration, private val labels: Ma
146147
// Only include nested VCS if they are part of the analyzed directory.
147148
workingTree.getRootPath().resolve(path).startsWith(info.absoluteProjectPath)
148149
}.orEmpty()
149-
val repository = Repository(vcs = vcs, nestedRepositories = nestedVcs, config = info.repositoryConfiguration)
150+
val provenance = RepositoryProvenance(vcs, vcs.revision)
151+
val repository = Repository(
152+
provenance = provenance,
153+
nestedRepositories = nestedVcs,
154+
config = info.repositoryConfiguration
155+
)
150156

151157
val endTime = Instant.now()
152158

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

Lines changed: 2 additions & 1 deletion
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
@@ -120,7 +121,7 @@ internal class CreateAnalyzerResultFromPackageListCommand : OrtHelperCommand(
120121
environment = Environment()
121122
),
122123
repository = Repository(
123-
vcs = projectVcs.normalize(),
124+
provenance = RepositoryProvenance(projectVcs.normalize(), projectVcs.revision),
124125
config = RepositoryConfiguration(
125126
excludes = Excludes(
126127
scopes = listOf(

evaluator/src/test/kotlin/ProjectSourceRuleTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,14 +207,15 @@ private fun createOrtResult(
207207
url = "https://github.com/oss-review-toolkit/example.git",
208208
revision = "0000000000000000000000000000000000000000"
209209
)
210+
val provenance = RepositoryProvenance(vcsInfo, vcsInfo.revision)
210211
val licenseFindings = detectedLicensesForFilePath.flatMapTo(mutableSetOf()) { (filePath, licenses) ->
211212
licenses.map { license ->
212213
LicenseFinding(license, TextLocation(filePath, startLine = 1, endLine = 2))
213214
}
214215
}
215216

216217
return OrtResult.EMPTY.copy(
217-
repository = Repository(vcsInfo),
218+
repository = Repository(provenance),
218219
analyzer = AnalyzerRun.EMPTY.copy(
219220
result = AnalyzerResult.EMPTY.copy(
220221
projects = setOf(

evaluator/src/testFixtures/kotlin/TestData.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import org.ossreviewtoolkit.model.Package
3636
import org.ossreviewtoolkit.model.PackageLinkage
3737
import org.ossreviewtoolkit.model.Project
3838
import org.ossreviewtoolkit.model.Repository
39+
import org.ossreviewtoolkit.model.RepositoryProvenance
3940
import org.ossreviewtoolkit.model.ScanResult
4041
import org.ossreviewtoolkit.model.ScanSummary
4142
import org.ossreviewtoolkit.model.ScannerDetails
@@ -179,7 +180,10 @@ val allProjects = setOf(
179180

180181
val ortResult = OrtResult(
181182
repository = Repository(
182-
vcs = VcsInfo.EMPTY,
183+
provenance = RepositoryProvenance(
184+
vcsInfo = VcsInfo.EMPTY,
185+
resolvedRevision = ""
186+
),
183187
config = RepositoryConfiguration(
184188
excludes = Excludes(
185189
paths = listOf(

model/src/main/kotlin/Repository.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,15 @@ import org.ossreviewtoolkit.utils.ort.ORT_REPO_CONFIG_FILENAME
2828
* A description of the source code repository that was used as input for ORT.
2929
*/
3030
data class Repository(
31+
/**
32+
* Provenance wrapper for original VCS information, if present.
33+
*/
34+
val provenance: RepositoryProvenance,
35+
3136
/**
3237
* Original VCS-related information from the working tree containing the analyzer root.
3338
*/
34-
val vcs: VcsInfo,
39+
val vcs: VcsInfo = provenance.vcsInfo,
3540

3641
/**
3742
* Processed VCS-related information from the working tree containing the analyzer root that has e.g. common
@@ -57,6 +62,7 @@ data class Repository(
5762
*/
5863
@JvmField
5964
val EMPTY = Repository(
65+
provenance = RepositoryProvenance(VcsInfo.EMPTY, VcsInfo.EMPTY.revision),
6066
vcs = VcsInfo.EMPTY,
6167
vcsProcessed = VcsInfo.EMPTY,
6268
nestedRepositories = emptyMap(),

model/src/test/kotlin/OrtResultTest.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class OrtResultTest : WordSpec({
8282
"getDefinitionFilePathRelativeToAnalyzerRoot()" should {
8383
"use the correct vcs" {
8484
val vcs = VcsInfo(type = VcsType.GIT, url = "https://example.com/git", revision = "")
85+
val provenance = RepositoryProvenance(vcs, vcs.revision)
8586
val nestedVcs1 = VcsInfo(type = VcsType.GIT, url = "https://example.com/git1", revision = "")
8687
val nestedVcs2 = VcsInfo(type = VcsType.GIT, url = "https://example.com/git2", revision = "")
8788
val project1 = Project.EMPTY.copy(
@@ -104,7 +105,7 @@ class OrtResultTest : WordSpec({
104105
)
105106
val ortResult = OrtResult(
106107
Repository(
107-
vcs = vcs,
108+
provenance = provenance,
108109
nestedRepositories = mapOf(
109110
"path/1" to nestedVcs1,
110111
"path/2" to nestedVcs2
@@ -122,6 +123,7 @@ class OrtResultTest : WordSpec({
122123

123124
"fail if no vcs matches" {
124125
val vcs = VcsInfo(type = VcsType.GIT, url = "https://example.com/git", revision = "")
126+
val provenance = RepositoryProvenance(vcs, vcs.revision)
125127
val nestedVcs1 = VcsInfo(type = VcsType.GIT, url = "https://example.com/git1", revision = "")
126128
val nestedVcs2 = VcsInfo(type = VcsType.GIT, url = "https://example.com/git2", revision = "")
127129
val project = Project.EMPTY.copy(
@@ -132,7 +134,7 @@ class OrtResultTest : WordSpec({
132134
)
133135
val ortResult = OrtResult(
134136
Repository(
135-
vcs = vcs,
137+
provenance = provenance,
136138
nestedRepositories = mapOf(
137139
"path/1" to nestedVcs1
138140
)

model/src/testFixtures/kotlin/TestData.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,10 @@ val scanResults = listOf(
136136

137137
val ortResult = OrtResult(
138138
repository = Repository(
139-
vcs = VcsInfo.EMPTY,
139+
provenance = RepositoryProvenance(
140+
vcsInfo = VcsInfo.EMPTY,
141+
resolvedRevision = ""
142+
),
140143
config = RepositoryConfiguration(
141144
excludes = Excludes(
142145
paths = listOf(

plugins/reporters/ctrlx/src/funTest/kotlin/CtrlXAutomationReporterFunTest.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import org.ossreviewtoolkit.model.OrtResult
4242
import org.ossreviewtoolkit.model.Package
4343
import org.ossreviewtoolkit.model.Project
4444
import org.ossreviewtoolkit.model.Repository
45+
import org.ossreviewtoolkit.model.RepositoryProvenance
4546
import org.ossreviewtoolkit.model.RootDependencyIndex
4647
import org.ossreviewtoolkit.model.Scope
4748
import org.ossreviewtoolkit.model.VcsInfo
@@ -142,6 +143,8 @@ private fun createReporterInput(): ReporterInput {
142143
path = "sub/path"
143144
)
144145

146+
val analyzedProvenance = RepositoryProvenance(analyzedVcs, analyzedVcs.revision)
147+
145148
val package1 = Package.EMPTY.copy(
146149
id = Identifier("Maven:ns:package1:1.0"),
147150
declaredLicenses = setOf("LicenseRef-scancode-broadcom-commercial"),
@@ -164,8 +167,7 @@ private fun createReporterInput(): ReporterInput {
164167
return ReporterInput(
165168
OrtResult(
166169
repository = Repository(
167-
vcs = analyzedVcs,
168-
vcsProcessed = analyzedVcs
170+
provenance = analyzedProvenance
169171
),
170172
analyzer = AnalyzerRun.EMPTY.copy(
171173
result = AnalyzerResult(

plugins/reporters/fossid/src/test/kotlin/FossIdReporterTest.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import org.ossreviewtoolkit.clients.fossid.model.report.SelectionType
4242
import org.ossreviewtoolkit.model.Identifier
4343
import org.ossreviewtoolkit.model.OrtResult
4444
import org.ossreviewtoolkit.model.Repository
45+
import org.ossreviewtoolkit.model.RepositoryProvenance
4546
import org.ossreviewtoolkit.model.ScanResult
4647
import org.ossreviewtoolkit.model.ScanSummary
4748
import org.ossreviewtoolkit.model.ScannerDetails
@@ -238,6 +239,7 @@ private fun createReporterInput(vararg scanCodes: String): ReporterInput {
238239
url = "https://github.com/path/first-project.git",
239240
path = "sub/path"
240241
)
242+
val analyzedProvenance = RepositoryProvenance(analyzedVcs, analyzedVcs.revision)
241243

242244
val results = scanCodes.associateByTo(
243245
destination = sortedMapOf(),
@@ -266,8 +268,7 @@ private fun createReporterInput(vararg scanCodes: String): ReporterInput {
266268
)
267269
)
268270
),
269-
vcs = analyzedVcs,
270-
vcsProcessed = analyzedVcs
271+
provenance = analyzedProvenance
271272
),
272273
scanner = scannerRunOf(*results.toList().toTypedArray())
273274
)

plugins/reporters/freemarker/src/test/kotlin/FreeMarkerTemplateProcessorTest.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ private val PROJECT_VCS_INFO = VcsInfo(
9494
url = "ssh://git@host/manifests/repo?manifest=path/to/manifest.xml",
9595
revision = "deadbeaf44444444333333332222222211111111"
9696
)
97+
private val PROJECT_PROVENANCE = RepositoryProvenance(
98+
PROJECT_VCS_INFO,
99+
PROJECT_VCS_INFO.revision
100+
)
97101
private val NESTED_VCS_INFO = VcsInfo(
98102
type = VcsType.GIT,
99103
url = "ssh://git@host/project/repo",
@@ -107,7 +111,7 @@ private val idNestedProject = Identifier("SpdxDocumentFile:@ort:project-in-neste
107111

108112
private val ORT_RESULT = OrtResult(
109113
repository = Repository(
110-
vcs = PROJECT_VCS_INFO,
114+
provenance = PROJECT_PROVENANCE,
111115
config = RepositoryConfiguration(),
112116
nestedRepositories = mapOf("nested-vcs-dir" to NESTED_VCS_INFO)
113117
),

0 commit comments

Comments
 (0)