Skip to content

Commit f847423

Browse files
committed
refactor(Repository): Add RepositoryProvenance attribute
In order to support non-VCS input for ORT, `KnownProvenance`s need to be supported as input for `anaylzer` and `scanner`. The `Repository` data structure appears to be the best place to facilitate this change. This change focusses on adding a `RepositoryProvenance` attribute to `Repository`, which allows to keep previous behavior. For now it also exposes the raw `VcsInfo` of the `provenance` as its `vcs` attribute. Signed-off-by: Jens Keim <[email protected]>
1 parent d47c9ac commit f847423

File tree

13 files changed

+77
-20
lines changed

13 files changed

+77
-20
lines changed

analyzer/src/main/kotlin/Analyzer.kt

Lines changed: 9 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,14 @@ 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 repository = Repository(
153+
provenance = RepositoryProvenance(
154+
vcsInfo = vcs,
155+
resolvedRevision = vcs.revision
156+
),
157+
nestedRepositories = nestedVcs,
158+
config = info.repositoryConfiguration
159+
)
152160

153161
val endTime = Instant.now()
154162

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

Lines changed: 5 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,10 @@ internal class CreateAnalyzerResultFromPackageListCommand : OrtHelperCommand(
120121
environment = Environment()
121122
),
122123
repository = Repository(
123-
vcs = projectVcs.normalize(),
124+
provenance = RepositoryProvenance(
125+
vcsInfo = projectVcs.normalize(),
126+
resolvedRevision = projectVcs.revision
127+
),
124128
config = RepositoryConfiguration(
125129
excludes = Excludes(
126130
scopes = listOf(

evaluator/src/test/kotlin/ProjectSourceRuleTest.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,12 @@ private fun createOrtResult(
214214
}
215215

216216
return OrtResult.EMPTY.copy(
217-
repository = Repository(vcsInfo),
217+
repository = Repository(
218+
provenance = RepositoryProvenance(
219+
vcsInfo = vcsInfo,
220+
resolvedRevision = vcsInfo.revision
221+
)
222+
),
218223
analyzer = AnalyzerRun.EMPTY.copy(
219224
result = AnalyzerResult.EMPTY.copy(
220225
projects = setOf(

evaluator/src/testFixtures/kotlin/TestData.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ import org.ossreviewtoolkit.model.AdvisorRun
2929
import org.ossreviewtoolkit.model.AdvisorSummary
3030
import org.ossreviewtoolkit.model.AnalyzerResult
3131
import org.ossreviewtoolkit.model.AnalyzerRun
32+
import org.ossreviewtoolkit.model.HashAlgorithm
3233
import org.ossreviewtoolkit.model.Identifier
3334
import org.ossreviewtoolkit.model.LicenseFinding
3435
import org.ossreviewtoolkit.model.OrtResult
3536
import org.ossreviewtoolkit.model.Package
3637
import org.ossreviewtoolkit.model.PackageLinkage
3738
import org.ossreviewtoolkit.model.Project
3839
import org.ossreviewtoolkit.model.Repository
40+
import org.ossreviewtoolkit.model.RepositoryProvenance
3941
import org.ossreviewtoolkit.model.ScanResult
4042
import org.ossreviewtoolkit.model.ScanSummary
4143
import org.ossreviewtoolkit.model.ScannerDetails
@@ -179,7 +181,10 @@ val allProjects = setOf(
179181

180182
val ortResult = OrtResult(
181183
repository = Repository(
182-
vcs = VcsInfo.EMPTY,
184+
provenance = RepositoryProvenance(
185+
vcsInfo = VcsInfo.EMPTY,
186+
resolvedRevision = HashAlgorithm.SHA1.emptyValue
187+
),
183188
config = RepositoryConfiguration(
184189
excludes = Excludes(
185190
paths = listOf(

model/src/main/kotlin/Repository.kt

Lines changed: 10 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,10 @@ data class Repository(
5762
*/
5863
@JvmField
5964
val EMPTY = Repository(
65+
provenance = RepositoryProvenance(
66+
vcsInfo = VcsInfo.EMPTY,
67+
resolvedRevision = HashAlgorithm.SHA1.emptyValue
68+
),
6069
vcs = VcsInfo.EMPTY,
6170
vcsProcessed = VcsInfo.EMPTY,
6271
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(vcsInfo = vcs, resolvedRevision = 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(vcsInfo = vcs, resolvedRevision = 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 = HashAlgorithm.SHA1.emptyValue
142+
),
140143
config = RepositoryConfiguration(
141144
excludes = Excludes(
142145
paths = listOf(

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

Lines changed: 5 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
@@ -165,8 +166,10 @@ private fun createReporterInput(): ReporterInput {
165166
return ReporterInput(
166167
OrtResult(
167168
repository = Repository(
168-
vcs = analyzedVcs,
169-
vcsProcessed = analyzedVcs
169+
provenance = RepositoryProvenance(
170+
vcsInfo = analyzedVcs,
171+
resolvedRevision = analyzedVcs.revision
172+
)
170173
),
171174
analyzer = AnalyzerRun.EMPTY.copy(
172175
result = AnalyzerResult(

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

Lines changed: 5 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
@@ -266,8 +267,10 @@ private fun createReporterInput(vararg scanCodes: String): ReporterInput {
266267
)
267268
)
268269
),
269-
vcs = analyzedVcs,
270-
vcsProcessed = analyzedVcs
270+
provenance = RepositoryProvenance(
271+
vcsInfo = analyzedVcs,
272+
resolvedRevision = analyzedVcs.revision
273+
)
271274
),
272275
scanner = scannerRunOf(*results.toList().toTypedArray())
273276
)

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+
vcsInfo = PROJECT_ROOT_VCS_INFO,
102+
resolvedRevision = 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)