Skip to content

Commit 79b0793

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 af222ab commit 79b0793

File tree

13 files changed

+77
-21
lines changed

13 files changed

+77
-21
lines changed

analyzer/src/main/kotlin/Analyzer.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ 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
46+
import org.ossreviewtoolkit.model.VcsInfo
4547
import org.ossreviewtoolkit.model.config.AnalyzerConfiguration
4648
import org.ossreviewtoolkit.model.config.Excludes
4749
import org.ossreviewtoolkit.model.config.RepositoryConfiguration
@@ -147,7 +149,19 @@ class Analyzer(private val config: AnalyzerConfiguration, private val labels: Ma
147149
// Only include nested VCS if they are part of the analyzed directory.
148150
workingTree.getRootPath().resolve(path).startsWith(info.absoluteProjectPath)
149151
}.orEmpty()
150-
val repository = Repository(vcs = vcs, nestedRepositories = nestedVcs, config = info.repositoryConfiguration)
152+
153+
val repository = if (vcs == VcsInfo.EMPTY) {
154+
Repository.EMPTY
155+
} else {
156+
Repository(
157+
provenance = RepositoryProvenance(
158+
vcsInfo = vcs,
159+
resolvedRevision = vcs.revision
160+
),
161+
nestedRepositories = nestedVcs,
162+
config = info.repositoryConfiguration
163+
)
164+
}
151165

152166
val endTime = Instant.now()
153167

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

Lines changed: 7 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,12 @@ internal class CreateAnalyzerResultFromPackageListCommand : OrtHelperCommand(
120121
environment = Environment()
121122
),
122123
repository = Repository(
123-
vcs = projectVcs.normalize(),
124+
provenance = projectVcs.normalize().let {
125+
RepositoryProvenance(
126+
vcsInfo = it,
127+
resolvedRevision = it.revision
128+
)
129+
},
124130
config = RepositoryConfiguration(
125131
excludes = Excludes(
126132
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: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import org.ossreviewtoolkit.model.ScannerDetails
4242
import org.ossreviewtoolkit.model.Scope
4343
import org.ossreviewtoolkit.model.TextLocation
4444
import org.ossreviewtoolkit.model.UnknownProvenance
45-
import org.ossreviewtoolkit.model.VcsInfo
4645
import org.ossreviewtoolkit.model.config.AdvisorConfiguration
4746
import org.ossreviewtoolkit.model.config.AnalyzerConfiguration
4847
import org.ossreviewtoolkit.model.config.Excludes
@@ -179,7 +178,7 @@ val allProjects = setOf(
179178

180179
val ortResult = OrtResult(
181180
repository = Repository(
182-
vcs = VcsInfo.EMPTY,
181+
provenance = Repository.EMPTY.provenance,
183182
config = RepositoryConfiguration(
184183
excludes = Excludes(
185184
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
@@ -163,6 +163,7 @@ class OrtResultTest : WordSpec({
163163
"getDefinitionFilePathRelativeToAnalyzerRoot()" should {
164164
"use the correct vcs" {
165165
val vcs = VcsInfo(type = VcsType.GIT, url = "https://example.com/git", revision = "")
166+
val provenance = RepositoryProvenance(vcsInfo = vcs, resolvedRevision = vcs.revision)
166167
val nestedVcs1 = VcsInfo(type = VcsType.GIT, url = "https://example.com/git1", revision = "")
167168
val nestedVcs2 = VcsInfo(type = VcsType.GIT, url = "https://example.com/git2", revision = "")
168169
val project1 = Project.EMPTY.copy(
@@ -185,7 +186,7 @@ class OrtResultTest : WordSpec({
185186
)
186187
val ortResult = OrtResult(
187188
Repository(
188-
vcs = vcs,
189+
provenance = provenance,
189190
nestedRepositories = mapOf(
190191
"path/1" to nestedVcs1,
191192
"path/2" to nestedVcs2
@@ -203,6 +204,7 @@ class OrtResultTest : WordSpec({
203204

204205
"fail if no vcs matches" {
205206
val vcs = VcsInfo(type = VcsType.GIT, url = "https://example.com/git", revision = "")
207+
val provenance = RepositoryProvenance(vcsInfo = vcs, resolvedRevision = vcs.revision)
206208
val nestedVcs1 = VcsInfo(type = VcsType.GIT, url = "https://example.com/git1", revision = "")
207209
val nestedVcs2 = VcsInfo(type = VcsType.GIT, url = "https://example.com/git2", revision = "")
208210
val project = Project.EMPTY.copy(
@@ -213,7 +215,7 @@ class OrtResultTest : WordSpec({
213215
)
214216
val ortResult = OrtResult(
215217
Repository(
216-
vcs = vcs,
218+
provenance = provenance,
217219
nestedRepositories = mapOf(
218220
"path/1" to nestedVcs1
219221
)

model/src/testFixtures/kotlin/TestData.kt

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

137137
val ortResult = OrtResult(
138138
repository = Repository(
139-
vcs = VcsInfo.EMPTY,
139+
provenance = Repository.EMPTY.provenance,
140140
config = RepositoryConfiguration(
141141
excludes = Excludes(
142142
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)