Skip to content

Commit

Permalink
model: Inline ScanRecord
Browse files Browse the repository at this point in the history
`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 <frank_viernau@epam.com>
  • Loading branch information
fviernau committed Oct 18, 2022
1 parent 0aed1b4 commit 9d9a449
Show file tree
Hide file tree
Showing 22 changed files with 784 additions and 869 deletions.
247 changes: 123 additions & 124 deletions cli/src/funTest/assets/semver4j-ort-result.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,130 +191,129 @@ scanner:
- "postgresStorage"
storage_writers:
- "postgresStorage"
results:
scan_results:
Maven:com.vdurmont:semver4j:3.1.0:
- provenance:
vcs_info:
type: "Git"
url: "https://github.com/vdurmont/semver4j.git"
revision: "7653e418d610ffcd2811bcb55fd72d00d420950b"
path: ""
resolved_revision: "7653e418d610ffcd2811bcb55fd72d00d420950b"
scanner:
name: "ScanCode"
version: "3.2.1-rc2"
configuration: "--copyright --license --ignore *.ort.yml --info --strip-root\
\ --timeout 300 --ignore META-INF/DEPENDENCIES --json-pp"
summary:
start_time: "2020-09-30T09:27:12.023451Z"
end_time: "2020-09-30T09:28:20.525647Z"
package_verification_code: "48ba11487d53ce933b5d4db1d069b70a803ff19b"
licenses:
- license: "BSD-3-Clause"
location:
path: "pom.xml"
start_line: 28
end_line: 34
- license: "MIT"
location:
path: "LICENSE.md"
start_line: 1
end_line: 1
- license: "MIT"
location:
path: "LICENSE.md"
start_line: 5
end_line: 21
- license: "MIT"
location:
path: "pom.xml"
start_line: 30
end_line: 31
copyrights:
- statement: "Copyright (c) 2015-present Vincent DURMONT <vdurmont@gmail.com>"
location:
path: "LICENSE.md"
start_line: 3
end_line: 3
Maven:junit:junit:4.12:
- provenance:
vcs_info:
type: "Git"
url: "https://github.com/junit-team/junit.git"
revision: "r4.12"
path: ""
resolved_revision: "64155f8a9babcfcf4263cf4d08253a1556e75481"
scanner:
name: "ScanCode"
version: "3.2.1-rc2"
configuration: "--copyright --license --ignore *.ort.yml --info --strip-root --timeout 300\
\ --ignore META-INF/DEPENDENCIES --json-pp"
summary:
start_time: "2020-09-30T09:28:32.817956Z"
end_time: "2020-09-30T09:29:02.889213Z"
package_verification_code: "2acb4f0b06b706fa94e9159c2f9abc1397c46ba0"
licenses:
- license: "Apache-2.0"
location:
path: "pom.xml"
start_line: 19
end_line: 23
- license: "Apache-2.0"
location:
path: "src/site/resources/css/hopscotch-0.1.2.min.css"
start_line: 5
end_line: 15
- license: "Apache-2.0"
location:
path: "src/site/resources/scripts/hopscotch-0.1.2.min.js"
start_line: 5
end_line: 15
- license: "EPL-1.0"
location:
path: "LICENSE-junit.txt"
start_line: 3
end_line: 213
- license: "EPL-1.0"
location:
path: "epl-v10.html"
start_line: 7
end_line: 257
- license: "EPL-1.0"
location:
path: "pom.xml"
start_line: 18
end_line: 20
- license: "EPL-1.0"
location:
path: "src/site/fml/faq.fml"
start_line: 157
end_line: 157
- license: "EPL-2.0"
location:
path: "pom.xml"
start_line: 19
end_line: 23
- license: "NOASSERTION"
location:
path: "src/site/fml/faq.fml"
start_line: 156
end_line: 156
copyrights:
- statement: "Copyright 2013 LinkedIn Corp."
location:
path: "src/site/resources/css/hopscotch-0.1.2.min.css"
start_line: 3
end_line: 3
- statement: "Copyright 2013 LinkedIn Corp."
location:
path: "src/site/resources/scripts/hopscotch-0.1.2.min.js"
start_line: 3
end_line: 3
storage_stats:
num_reads: 4
num_hits: 4
has_issues: false
scan_results:
Maven:com.vdurmont:semver4j:3.1.0:
- provenance:
vcs_info:
type: "Git"
url: "https://github.com/vdurmont/semver4j.git"
revision: "7653e418d610ffcd2811bcb55fd72d00d420950b"
path: ""
resolved_revision: "7653e418d610ffcd2811bcb55fd72d00d420950b"
scanner:
name: "ScanCode"
version: "3.2.1-rc2"
configuration: "--copyright --license --ignore *.ort.yml --info --strip-root\
\ --timeout 300 --ignore META-INF/DEPENDENCIES --json-pp"
summary:
start_time: "2020-09-30T09:27:12.023451Z"
end_time: "2020-09-30T09:28:20.525647Z"
package_verification_code: "48ba11487d53ce933b5d4db1d069b70a803ff19b"
licenses:
- license: "BSD-3-Clause"
location:
path: "pom.xml"
start_line: 28
end_line: 34
- license: "MIT"
location:
path: "LICENSE.md"
start_line: 1
end_line: 1
- license: "MIT"
location:
path: "LICENSE.md"
start_line: 5
end_line: 21
- license: "MIT"
location:
path: "pom.xml"
start_line: 30
end_line: 31
copyrights:
- statement: "Copyright (c) 2015-present Vincent DURMONT <vdurmont@gmail.com>"
location:
path: "LICENSE.md"
start_line: 3
end_line: 3
Maven:junit:junit:4.12:
- provenance:
vcs_info:
type: "Git"
url: "https://github.com/junit-team/junit.git"
revision: "r4.12"
path: ""
resolved_revision: "64155f8a9babcfcf4263cf4d08253a1556e75481"
scanner:
name: "ScanCode"
version: "3.2.1-rc2"
configuration: "--copyright --license --ignore *.ort.yml --info --strip-root --timeout 300\
\ --ignore META-INF/DEPENDENCIES --json-pp"
summary:
start_time: "2020-09-30T09:28:32.817956Z"
end_time: "2020-09-30T09:29:02.889213Z"
package_verification_code: "2acb4f0b06b706fa94e9159c2f9abc1397c46ba0"
licenses:
- license: "Apache-2.0"
location:
path: "pom.xml"
start_line: 19
end_line: 23
- license: "Apache-2.0"
location:
path: "src/site/resources/css/hopscotch-0.1.2.min.css"
start_line: 5
end_line: 15
- license: "Apache-2.0"
location:
path: "src/site/resources/scripts/hopscotch-0.1.2.min.js"
start_line: 5
end_line: 15
- license: "EPL-1.0"
location:
path: "LICENSE-junit.txt"
start_line: 3
end_line: 213
- license: "EPL-1.0"
location:
path: "epl-v10.html"
start_line: 7
end_line: 257
- license: "EPL-1.0"
location:
path: "pom.xml"
start_line: 18
end_line: 20
- license: "EPL-1.0"
location:
path: "src/site/fml/faq.fml"
start_line: 157
end_line: 157
- license: "EPL-2.0"
location:
path: "pom.xml"
start_line: 19
end_line: 23
- license: "NOASSERTION"
location:
path: "src/site/fml/faq.fml"
start_line: 156
end_line: 156
copyrights:
- statement: "Copyright 2013 LinkedIn Corp."
location:
path: "src/site/resources/css/hopscotch-0.1.2.min.css"
start_line: 3
end_line: 3
- statement: "Copyright 2013 LinkedIn Corp."
location:
path: "src/site/resources/scripts/hopscotch-0.1.2.min.js"
start_line: 3
end_line: 3
storage_stats:
num_reads: 4
num_hits: 4
has_issues: false
advisor:
start_time: "2021-04-29T14:54:16.562951Z"
end_time: "2021-04-29T14:54:18.969210Z"
Expand Down
23 changes: 9 additions & 14 deletions evaluator/src/test/kotlin/ProjectSourceRuleTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import io.kotest.matchers.shouldBe

import java.io.File

import org.ossreviewtoolkit.model.AccessStatistics
import org.ossreviewtoolkit.model.AnalyzerResult
import org.ossreviewtoolkit.model.AnalyzerRun
import org.ossreviewtoolkit.model.Identifier
Expand All @@ -33,7 +32,6 @@ import org.ossreviewtoolkit.model.OrtResult
import org.ossreviewtoolkit.model.Project
import org.ossreviewtoolkit.model.Repository
import org.ossreviewtoolkit.model.RepositoryProvenance
import org.ossreviewtoolkit.model.ScanRecord
import org.ossreviewtoolkit.model.ScanResult
import org.ossreviewtoolkit.model.ScanSummary
import org.ossreviewtoolkit.model.ScannerDetails
Expand Down Expand Up @@ -220,20 +218,17 @@ private fun createOrtResult(
)
),
scanner = ScannerRun.EMPTY.copy(
results = ScanRecord(
scanResults = sortedMapOf(
id to listOf(
ScanResult(
provenance = RepositoryProvenance(vcsInfo, vcsInfo.revision),
scanner = ScannerDetails.EMPTY,
summary = ScanSummary.EMPTY.copy(
licenseFindings = licenseFindings,
packageVerificationCode = "0000000000000000000000000000000000000000"
)
scanResults = sortedMapOf(
id to listOf(
ScanResult(
provenance = RepositoryProvenance(vcsInfo, vcsInfo.revision),
scanner = ScannerDetails.EMPTY,
summary = ScanSummary.EMPTY.copy(
licenseFindings = licenseFindings,
packageVerificationCode = "0000000000000000000000000000000000000000"
)
)
),
storageStats = AccessStatistics()
)
)
)
)
Expand Down
25 changes: 10 additions & 15 deletions evaluator/src/test/kotlin/TestData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package org.ossreviewtoolkit.evaluator
import java.net.URI
import java.time.Instant

import org.ossreviewtoolkit.model.AccessStatistics
import org.ossreviewtoolkit.model.AdvisorDetails
import org.ossreviewtoolkit.model.AdvisorRecord
import org.ossreviewtoolkit.model.AdvisorResult
Expand All @@ -38,7 +37,6 @@ import org.ossreviewtoolkit.model.Package
import org.ossreviewtoolkit.model.PackageLinkage
import org.ossreviewtoolkit.model.Project
import org.ossreviewtoolkit.model.Repository
import org.ossreviewtoolkit.model.ScanRecord
import org.ossreviewtoolkit.model.ScanResult
import org.ossreviewtoolkit.model.ScanSummary
import org.ossreviewtoolkit.model.ScannerDetails
Expand Down Expand Up @@ -259,22 +257,19 @@ val ortResult = OrtResult(
)
),
scanner = ScannerRun.EMPTY.copy(
results = ScanRecord(
scanResults = sortedMapOf(
Identifier("Maven:org.ossreviewtoolkit:package-with-only-detected-license:1.0") to listOf(
ScanResult(
provenance = UnknownProvenance,
scanner = ScannerDetails.EMPTY,
summary = ScanSummary.EMPTY.copy(
licenseFindings = sortedSetOf(
LicenseFinding("LicenseRef-a", TextLocation("LICENSE", 1)),
LicenseFinding("LicenseRef-b", TextLocation("LICENSE", 2))
)
scanResults = sortedMapOf(
Identifier("Maven:org.ossreviewtoolkit:package-with-only-detected-license:1.0") to listOf(
ScanResult(
provenance = UnknownProvenance,
scanner = ScannerDetails.EMPTY,
summary = ScanSummary.EMPTY.copy(
licenseFindings = sortedSetOf(
LicenseFinding("LicenseRef-a", TextLocation("LICENSE", 1)),
LicenseFinding("LicenseRef-b", TextLocation("LICENSE", 2))
)
)
)
),
storageStats = AccessStatistics()
)
)
),
labels = mapOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ internal class SubtractScanResultsCommand : CliktCommand(
val lhsOrtResult = readOrtResult(lhsOrtFile)
val rhsOrtResult = readOrtResult(rhsOrtFile)

val rhsScanSummaries = rhsOrtResult.scanner!!.results.scanResults.flatMap { it.value }.associateBy(
val rhsScanSummaries = rhsOrtResult.scanner!!.scanResults.flatMap { it.value }.associateBy(
keySelector = { it.provenance.key() },
valueTransform = { it.summary }
)

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

val result = lhsOrtResult.copy(
scanner = lhsOrtResult.scanner!!.copy(
results = lhsOrtResult.scanner!!.results.copy(
scanResults = scanResults
)
scanResults = scanResults
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private fun OrtResult.getLicenseFindingsForAllProjects(): Set<LicenseFinding> {
val result = mutableSetOf<LicenseFinding>()

val projectIds = getProjects().mapTo(mutableSetOf()) { it.id }
scanner?.results?.scanResults?.forEach { (id, results) ->
scanner?.scanResults?.forEach { (id, results) ->
if (id in projectIds) {
results.forEach { scanResult ->
result += scanResult.summary.licenseFindings
Expand Down
Loading

0 comments on commit 9d9a449

Please sign in to comment.