Skip to content

Commit 9d9a449

Browse files
committed
model: Inline ScanRecord
`ScanRecord` originally existed to separate the output from the input and for minimizing test setup. As tests have meanwhile been changed to consistently use `ScanRecord.EMPTY`, the test setup even becomes a bit more minimal when `ScanRecord` is inlined, as the construction of empty `AccessStatistics` has been removed, because it became redundant. One shortcoming of the nesting is that the code ends up with a multitude of class names which can be easily mixed up, e.g. the classes `ScannerRun`, `ScanRecord`, `ScanResult`, `ProvenanceScanResult` and so forth. From the above, it seems reasonable to eliminate one level of nesting to simplify the data model a bit. Signed-off-by: Frank Viernau <[email protected]>
1 parent 0aed1b4 commit 9d9a449

File tree

22 files changed

+784
-869
lines changed

22 files changed

+784
-869
lines changed

cli/src/funTest/assets/semver4j-ort-result.yml

+123-124
Original file line numberDiff line numberDiff line change
@@ -191,130 +191,129 @@ scanner:
191191
- "postgresStorage"
192192
storage_writers:
193193
- "postgresStorage"
194-
results:
195-
scan_results:
196-
Maven:com.vdurmont:semver4j:3.1.0:
197-
- provenance:
198-
vcs_info:
199-
type: "Git"
200-
url: "https://github.com/vdurmont/semver4j.git"
201-
revision: "7653e418d610ffcd2811bcb55fd72d00d420950b"
202-
path: ""
203-
resolved_revision: "7653e418d610ffcd2811bcb55fd72d00d420950b"
204-
scanner:
205-
name: "ScanCode"
206-
version: "3.2.1-rc2"
207-
configuration: "--copyright --license --ignore *.ort.yml --info --strip-root\
208-
\ --timeout 300 --ignore META-INF/DEPENDENCIES --json-pp"
209-
summary:
210-
start_time: "2020-09-30T09:27:12.023451Z"
211-
end_time: "2020-09-30T09:28:20.525647Z"
212-
package_verification_code: "48ba11487d53ce933b5d4db1d069b70a803ff19b"
213-
licenses:
214-
- license: "BSD-3-Clause"
215-
location:
216-
path: "pom.xml"
217-
start_line: 28
218-
end_line: 34
219-
- license: "MIT"
220-
location:
221-
path: "LICENSE.md"
222-
start_line: 1
223-
end_line: 1
224-
- license: "MIT"
225-
location:
226-
path: "LICENSE.md"
227-
start_line: 5
228-
end_line: 21
229-
- license: "MIT"
230-
location:
231-
path: "pom.xml"
232-
start_line: 30
233-
end_line: 31
234-
copyrights:
235-
- statement: "Copyright (c) 2015-present Vincent DURMONT <[email protected]>"
236-
location:
237-
path: "LICENSE.md"
238-
start_line: 3
239-
end_line: 3
240-
Maven:junit:junit:4.12:
241-
- provenance:
242-
vcs_info:
243-
type: "Git"
244-
url: "https://github.com/junit-team/junit.git"
245-
revision: "r4.12"
246-
path: ""
247-
resolved_revision: "64155f8a9babcfcf4263cf4d08253a1556e75481"
248-
scanner:
249-
name: "ScanCode"
250-
version: "3.2.1-rc2"
251-
configuration: "--copyright --license --ignore *.ort.yml --info --strip-root --timeout 300\
252-
\ --ignore META-INF/DEPENDENCIES --json-pp"
253-
summary:
254-
start_time: "2020-09-30T09:28:32.817956Z"
255-
end_time: "2020-09-30T09:29:02.889213Z"
256-
package_verification_code: "2acb4f0b06b706fa94e9159c2f9abc1397c46ba0"
257-
licenses:
258-
- license: "Apache-2.0"
259-
location:
260-
path: "pom.xml"
261-
start_line: 19
262-
end_line: 23
263-
- license: "Apache-2.0"
264-
location:
265-
path: "src/site/resources/css/hopscotch-0.1.2.min.css"
266-
start_line: 5
267-
end_line: 15
268-
- license: "Apache-2.0"
269-
location:
270-
path: "src/site/resources/scripts/hopscotch-0.1.2.min.js"
271-
start_line: 5
272-
end_line: 15
273-
- license: "EPL-1.0"
274-
location:
275-
path: "LICENSE-junit.txt"
276-
start_line: 3
277-
end_line: 213
278-
- license: "EPL-1.0"
279-
location:
280-
path: "epl-v10.html"
281-
start_line: 7
282-
end_line: 257
283-
- license: "EPL-1.0"
284-
location:
285-
path: "pom.xml"
286-
start_line: 18
287-
end_line: 20
288-
- license: "EPL-1.0"
289-
location:
290-
path: "src/site/fml/faq.fml"
291-
start_line: 157
292-
end_line: 157
293-
- license: "EPL-2.0"
294-
location:
295-
path: "pom.xml"
296-
start_line: 19
297-
end_line: 23
298-
- license: "NOASSERTION"
299-
location:
300-
path: "src/site/fml/faq.fml"
301-
start_line: 156
302-
end_line: 156
303-
copyrights:
304-
- statement: "Copyright 2013 LinkedIn Corp."
305-
location:
306-
path: "src/site/resources/css/hopscotch-0.1.2.min.css"
307-
start_line: 3
308-
end_line: 3
309-
- statement: "Copyright 2013 LinkedIn Corp."
310-
location:
311-
path: "src/site/resources/scripts/hopscotch-0.1.2.min.js"
312-
start_line: 3
313-
end_line: 3
314-
storage_stats:
315-
num_reads: 4
316-
num_hits: 4
317-
has_issues: false
194+
scan_results:
195+
Maven:com.vdurmont:semver4j:3.1.0:
196+
- provenance:
197+
vcs_info:
198+
type: "Git"
199+
url: "https://github.com/vdurmont/semver4j.git"
200+
revision: "7653e418d610ffcd2811bcb55fd72d00d420950b"
201+
path: ""
202+
resolved_revision: "7653e418d610ffcd2811bcb55fd72d00d420950b"
203+
scanner:
204+
name: "ScanCode"
205+
version: "3.2.1-rc2"
206+
configuration: "--copyright --license --ignore *.ort.yml --info --strip-root\
207+
\ --timeout 300 --ignore META-INF/DEPENDENCIES --json-pp"
208+
summary:
209+
start_time: "2020-09-30T09:27:12.023451Z"
210+
end_time: "2020-09-30T09:28:20.525647Z"
211+
package_verification_code: "48ba11487d53ce933b5d4db1d069b70a803ff19b"
212+
licenses:
213+
- license: "BSD-3-Clause"
214+
location:
215+
path: "pom.xml"
216+
start_line: 28
217+
end_line: 34
218+
- license: "MIT"
219+
location:
220+
path: "LICENSE.md"
221+
start_line: 1
222+
end_line: 1
223+
- license: "MIT"
224+
location:
225+
path: "LICENSE.md"
226+
start_line: 5
227+
end_line: 21
228+
- license: "MIT"
229+
location:
230+
path: "pom.xml"
231+
start_line: 30
232+
end_line: 31
233+
copyrights:
234+
- statement: "Copyright (c) 2015-present Vincent DURMONT <[email protected]>"
235+
location:
236+
path: "LICENSE.md"
237+
start_line: 3
238+
end_line: 3
239+
Maven:junit:junit:4.12:
240+
- provenance:
241+
vcs_info:
242+
type: "Git"
243+
url: "https://github.com/junit-team/junit.git"
244+
revision: "r4.12"
245+
path: ""
246+
resolved_revision: "64155f8a9babcfcf4263cf4d08253a1556e75481"
247+
scanner:
248+
name: "ScanCode"
249+
version: "3.2.1-rc2"
250+
configuration: "--copyright --license --ignore *.ort.yml --info --strip-root --timeout 300\
251+
\ --ignore META-INF/DEPENDENCIES --json-pp"
252+
summary:
253+
start_time: "2020-09-30T09:28:32.817956Z"
254+
end_time: "2020-09-30T09:29:02.889213Z"
255+
package_verification_code: "2acb4f0b06b706fa94e9159c2f9abc1397c46ba0"
256+
licenses:
257+
- license: "Apache-2.0"
258+
location:
259+
path: "pom.xml"
260+
start_line: 19
261+
end_line: 23
262+
- license: "Apache-2.0"
263+
location:
264+
path: "src/site/resources/css/hopscotch-0.1.2.min.css"
265+
start_line: 5
266+
end_line: 15
267+
- license: "Apache-2.0"
268+
location:
269+
path: "src/site/resources/scripts/hopscotch-0.1.2.min.js"
270+
start_line: 5
271+
end_line: 15
272+
- license: "EPL-1.0"
273+
location:
274+
path: "LICENSE-junit.txt"
275+
start_line: 3
276+
end_line: 213
277+
- license: "EPL-1.0"
278+
location:
279+
path: "epl-v10.html"
280+
start_line: 7
281+
end_line: 257
282+
- license: "EPL-1.0"
283+
location:
284+
path: "pom.xml"
285+
start_line: 18
286+
end_line: 20
287+
- license: "EPL-1.0"
288+
location:
289+
path: "src/site/fml/faq.fml"
290+
start_line: 157
291+
end_line: 157
292+
- license: "EPL-2.0"
293+
location:
294+
path: "pom.xml"
295+
start_line: 19
296+
end_line: 23
297+
- license: "NOASSERTION"
298+
location:
299+
path: "src/site/fml/faq.fml"
300+
start_line: 156
301+
end_line: 156
302+
copyrights:
303+
- statement: "Copyright 2013 LinkedIn Corp."
304+
location:
305+
path: "src/site/resources/css/hopscotch-0.1.2.min.css"
306+
start_line: 3
307+
end_line: 3
308+
- statement: "Copyright 2013 LinkedIn Corp."
309+
location:
310+
path: "src/site/resources/scripts/hopscotch-0.1.2.min.js"
311+
start_line: 3
312+
end_line: 3
313+
storage_stats:
314+
num_reads: 4
315+
num_hits: 4
316+
has_issues: false
318317
advisor:
319318
start_time: "2021-04-29T14:54:16.562951Z"
320319
end_time: "2021-04-29T14:54:18.969210Z"

evaluator/src/test/kotlin/ProjectSourceRuleTest.kt

+9-14
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import io.kotest.matchers.shouldBe
2424

2525
import java.io.File
2626

27-
import org.ossreviewtoolkit.model.AccessStatistics
2827
import org.ossreviewtoolkit.model.AnalyzerResult
2928
import org.ossreviewtoolkit.model.AnalyzerRun
3029
import org.ossreviewtoolkit.model.Identifier
@@ -33,7 +32,6 @@ import org.ossreviewtoolkit.model.OrtResult
3332
import org.ossreviewtoolkit.model.Project
3433
import org.ossreviewtoolkit.model.Repository
3534
import org.ossreviewtoolkit.model.RepositoryProvenance
36-
import org.ossreviewtoolkit.model.ScanRecord
3735
import org.ossreviewtoolkit.model.ScanResult
3836
import org.ossreviewtoolkit.model.ScanSummary
3937
import org.ossreviewtoolkit.model.ScannerDetails
@@ -220,20 +218,17 @@ private fun createOrtResult(
220218
)
221219
),
222220
scanner = ScannerRun.EMPTY.copy(
223-
results = ScanRecord(
224-
scanResults = sortedMapOf(
225-
id to listOf(
226-
ScanResult(
227-
provenance = RepositoryProvenance(vcsInfo, vcsInfo.revision),
228-
scanner = ScannerDetails.EMPTY,
229-
summary = ScanSummary.EMPTY.copy(
230-
licenseFindings = licenseFindings,
231-
packageVerificationCode = "0000000000000000000000000000000000000000"
232-
)
221+
scanResults = sortedMapOf(
222+
id to listOf(
223+
ScanResult(
224+
provenance = RepositoryProvenance(vcsInfo, vcsInfo.revision),
225+
scanner = ScannerDetails.EMPTY,
226+
summary = ScanSummary.EMPTY.copy(
227+
licenseFindings = licenseFindings,
228+
packageVerificationCode = "0000000000000000000000000000000000000000"
233229
)
234230
)
235-
),
236-
storageStats = AccessStatistics()
231+
)
237232
)
238233
)
239234
)

evaluator/src/test/kotlin/TestData.kt

+10-15
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ package org.ossreviewtoolkit.evaluator
2222
import java.net.URI
2323
import java.time.Instant
2424

25-
import org.ossreviewtoolkit.model.AccessStatistics
2625
import org.ossreviewtoolkit.model.AdvisorDetails
2726
import org.ossreviewtoolkit.model.AdvisorRecord
2827
import org.ossreviewtoolkit.model.AdvisorResult
@@ -38,7 +37,6 @@ import org.ossreviewtoolkit.model.Package
3837
import org.ossreviewtoolkit.model.PackageLinkage
3938
import org.ossreviewtoolkit.model.Project
4039
import org.ossreviewtoolkit.model.Repository
41-
import org.ossreviewtoolkit.model.ScanRecord
4240
import org.ossreviewtoolkit.model.ScanResult
4341
import org.ossreviewtoolkit.model.ScanSummary
4442
import org.ossreviewtoolkit.model.ScannerDetails
@@ -259,22 +257,19 @@ val ortResult = OrtResult(
259257
)
260258
),
261259
scanner = ScannerRun.EMPTY.copy(
262-
results = ScanRecord(
263-
scanResults = sortedMapOf(
264-
Identifier("Maven:org.ossreviewtoolkit:package-with-only-detected-license:1.0") to listOf(
265-
ScanResult(
266-
provenance = UnknownProvenance,
267-
scanner = ScannerDetails.EMPTY,
268-
summary = ScanSummary.EMPTY.copy(
269-
licenseFindings = sortedSetOf(
270-
LicenseFinding("LicenseRef-a", TextLocation("LICENSE", 1)),
271-
LicenseFinding("LicenseRef-b", TextLocation("LICENSE", 2))
272-
)
260+
scanResults = sortedMapOf(
261+
Identifier("Maven:org.ossreviewtoolkit:package-with-only-detected-license:1.0") to listOf(
262+
ScanResult(
263+
provenance = UnknownProvenance,
264+
scanner = ScannerDetails.EMPTY,
265+
summary = ScanSummary.EMPTY.copy(
266+
licenseFindings = sortedSetOf(
267+
LicenseFinding("LicenseRef-a", TextLocation("LICENSE", 1)),
268+
LicenseFinding("LicenseRef-b", TextLocation("LICENSE", 2))
273269
)
274270
)
275271
)
276-
),
277-
storageStats = AccessStatistics()
272+
)
278273
)
279274
),
280275
labels = mapOf(

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

+3-5
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ internal class SubtractScanResultsCommand : CliktCommand(
6666
val lhsOrtResult = readOrtResult(lhsOrtFile)
6767
val rhsOrtResult = readOrtResult(rhsOrtFile)
6868

69-
val rhsScanSummaries = rhsOrtResult.scanner!!.results.scanResults.flatMap { it.value }.associateBy(
69+
val rhsScanSummaries = rhsOrtResult.scanner!!.scanResults.flatMap { it.value }.associateBy(
7070
keySelector = { it.provenance.key() },
7171
valueTransform = { it.summary }
7272
)
7373

74-
val scanResults = lhsOrtResult.scanner!!.results.scanResults.mapValuesTo(sortedMapOf()) { (_, results) ->
74+
val scanResults = lhsOrtResult.scanner!!.scanResults.mapValuesTo(sortedMapOf()) { (_, results) ->
7575
results.map { lhsScanResult ->
7676
val lhsSummary = lhsScanResult.summary
7777
val rhsSummary = rhsScanSummaries[lhsScanResult.provenance.key()]
@@ -82,9 +82,7 @@ internal class SubtractScanResultsCommand : CliktCommand(
8282

8383
val result = lhsOrtResult.copy(
8484
scanner = lhsOrtResult.scanner!!.copy(
85-
results = lhsOrtResult.scanner!!.results.copy(
86-
scanResults = scanResults
87-
)
85+
scanResults = scanResults
8886
)
8987
)
9088

helper-cli/src/main/kotlin/commands/repoconfig/ImportLicenseFindingCurationsCommand.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ private fun OrtResult.getLicenseFindingsForAllProjects(): Set<LicenseFinding> {
119119
val result = mutableSetOf<LicenseFinding>()
120120

121121
val projectIds = getProjects().mapTo(mutableSetOf()) { it.id }
122-
scanner?.results?.scanResults?.forEach { (id, results) ->
122+
scanner?.scanResults?.forEach { (id, results) ->
123123
if (id in projectIds) {
124124
results.forEach { scanResult ->
125125
result += scanResult.summary.licenseFindings

0 commit comments

Comments
 (0)