Skip to content

Commit e01ca18

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 78fb251 commit e01ca18

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
@@ -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
@@ -148,7 +149,12 @@ class Analyzer(private val config: AnalyzerConfiguration, private val labels: Ma
148149
// Only include nested VCS if they are part of the analyzed directory.
149150
workingTree.getRootPath().resolve(path).startsWith(info.absoluteProjectPath)
150151
}.orEmpty()
151-
val repository = Repository(vcs = vcs, nestedRepositories = nestedVcs, config = info.repositoryConfiguration)
152+
val provenance = RepositoryProvenance(vcs, vcs.revision)
153+
val repository = Repository(
154+
provenance = provenance,
155+
nestedRepositories = nestedVcs,
156+
config = info.repositoryConfiguration
157+
)
152158

153159
val endTime = Instant.now()
154160

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, ""),
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
@@ -127,6 +127,7 @@ class OrtResultTest : WordSpec({
127127
"getDefinitionFilePathRelativeToAnalyzerRoot()" should {
128128
"use the correct vcs" {
129129
val vcs = VcsInfo(type = VcsType.GIT, url = "https://example.com/git", revision = "")
130+
val provenance = RepositoryProvenance(vcs, vcs.revision)
130131
val nestedVcs1 = VcsInfo(type = VcsType.GIT, url = "https://example.com/git1", revision = "")
131132
val nestedVcs2 = VcsInfo(type = VcsType.GIT, url = "https://example.com/git2", revision = "")
132133
val project1 = Project.EMPTY.copy(
@@ -149,7 +150,7 @@ class OrtResultTest : WordSpec({
149150
)
150151
val ortResult = OrtResult(
151152
Repository(
152-
vcs = vcs,
153+
provenance = provenance,
153154
nestedRepositories = mapOf(
154155
"path/1" to nestedVcs1,
155156
"path/2" to nestedVcs2
@@ -167,6 +168,7 @@ class OrtResultTest : WordSpec({
167168

168169
"fail if no vcs matches" {
169170
val vcs = VcsInfo(type = VcsType.GIT, url = "https://example.com/git", revision = "")
171+
val provenance = RepositoryProvenance(vcs, vcs.revision)
170172
val nestedVcs1 = VcsInfo(type = VcsType.GIT, url = "https://example.com/git1", revision = "")
171173
val nestedVcs2 = VcsInfo(type = VcsType.GIT, url = "https://example.com/git2", revision = "")
172174
val project = Project.EMPTY.copy(
@@ -177,7 +179,7 @@ class OrtResultTest : WordSpec({
177179
)
178180
val ortResult = OrtResult(
179181
Repository(
180-
vcs = vcs,
182+
provenance = provenance,
181183
nestedRepositories = mapOf(
182184
"path/1" to nestedVcs1
183185
)

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
@@ -143,6 +144,8 @@ private fun createReporterInput(): ReporterInput {
143144
path = "sub/path"
144145
)
145146

147+
val analyzedProvenance = RepositoryProvenance(analyzedVcs, analyzedVcs.revision)
148+
146149
val package1 = Package.EMPTY.copy(
147150
id = Identifier("Maven:ns:package1:1.0"),
148151
declaredLicenses = setOf("LicenseRef-scancode-broadcom-commercial"),
@@ -165,8 +168,7 @@ private fun createReporterInput(): ReporterInput {
165168
return ReporterInput(
166169
OrtResult(
167170
repository = Repository(
168-
vcs = analyzedVcs,
169-
vcsProcessed = analyzedVcs
171+
provenance = analyzedProvenance
170172
),
171173
analyzer = AnalyzerRun.EMPTY.copy(
172174
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
@@ -97,6 +97,10 @@ private val PROJECT_ROOT_VCS_INFO = VcsInfo(
9797
private val PROJECT_SUB_VCS_INFO = PROJECT_ROOT_VCS_INFO.copy(
9898
path = "sub-dir"
9999
)
100+
private val PROJECT_PROVENANCE = RepositoryProvenance(
101+
PROJECT_ROOT_VCS_INFO,
102+
PROJECT_ROOT_VCS_INFO.revision
103+
)
100104
private val NESTED_VCS_INFO = VcsInfo(
101105
type = VcsType.GIT,
102106
url = "ssh://git@host/project/repo",
@@ -110,7 +114,7 @@ private val idNestedProject = Identifier("SpdxDocumentFile:@ort:project-in-neste
110114

111115
private val ORT_RESULT = OrtResult(
112116
repository = Repository(
113-
vcs = PROJECT_ROOT_VCS_INFO,
117+
provenance = PROJECT_PROVENANCE,
114118
config = RepositoryConfiguration(),
115119
nestedRepositories = mapOf("nested-vcs-dir" to NESTED_VCS_INFO)
116120
),

0 commit comments

Comments
 (0)