diff --git a/evaluator/src/test/kotlin/ProjectSourceRuleTest.kt b/evaluator/src/test/kotlin/ProjectSourceRuleTest.kt index becc2ed0e5640..5fbd8d32f6658 100644 --- a/evaluator/src/test/kotlin/ProjectSourceRuleTest.kt +++ b/evaluator/src/test/kotlin/ProjectSourceRuleTest.kt @@ -201,7 +201,7 @@ private fun createOrtResult( url = "https://github.com/oss-review-toolkit/example.git", revision = "0000000000000000000000000000000000000000" ) - val licenseFindings = detectedLicensesForFilePath.flatMapTo(sortedSetOf()) { (filePath, licenses) -> + val licenseFindings = detectedLicensesForFilePath.flatMapTo(mutableSetOf()) { (filePath, licenses) -> licenses.map { license -> LicenseFinding(license, TextLocation(filePath, startLine = 1, endLine = 2)) } diff --git a/evaluator/src/test/kotlin/TestData.kt b/evaluator/src/test/kotlin/TestData.kt index 79b533c28f6cb..6a7b892ba4eb0 100644 --- a/evaluator/src/test/kotlin/TestData.kt +++ b/evaluator/src/test/kotlin/TestData.kt @@ -259,7 +259,7 @@ val ortResult = OrtResult( provenance = UnknownProvenance, scanner = ScannerDetails.EMPTY, summary = ScanSummary.EMPTY.copy( - licenseFindings = sortedSetOf( + licenseFindings = setOf( LicenseFinding("LicenseRef-a", TextLocation("LICENSE", 1)), LicenseFinding("LicenseRef-b", TextLocation("LICENSE", 2)) ) diff --git a/helper-cli/src/main/kotlin/commands/SubtractScanResultsCommand.kt b/helper-cli/src/main/kotlin/commands/SubtractScanResultsCommand.kt index 649cfb4432052..57516d6904ee5 100644 --- a/helper-cli/src/main/kotlin/commands/SubtractScanResultsCommand.kt +++ b/helper-cli/src/main/kotlin/commands/SubtractScanResultsCommand.kt @@ -95,7 +95,7 @@ private operator fun ScanSummary.minus(other: ScanSummary?): ScanSummary { if (other == null) return this return copy( - licenseFindings = (licenseFindings - other.licenseFindings).toSortedSet(), + licenseFindings = licenseFindings - other.licenseFindings, copyrightFindings = copyrightFindings - other.copyrightFindings ) } diff --git a/model/src/main/kotlin/LicenseFinding.kt b/model/src/main/kotlin/LicenseFinding.kt index 34171b4ca6a8a..916a05aeea228 100644 --- a/model/src/main/kotlin/LicenseFinding.kt +++ b/model/src/main/kotlin/LicenseFinding.kt @@ -48,9 +48,9 @@ data class LicenseFinding( * 100.0 means that the scanner is 100% confident that the finding is correct. */ val score: Float? = null -) : Comparable { +) { companion object { - private val COMPARATOR = compareBy({ it.license.toString() }, { it.location }) + val COMPARATOR = compareBy({ it.license.toString() }, { it.location }) .thenByDescending { it.score } /** @@ -73,8 +73,6 @@ data class LicenseFinding( } constructor(license: String, location: TextLocation, score: Float? = null) : this(license.toSpdx(), location, score) - - override fun compareTo(other: LicenseFinding) = COMPARATOR.compare(this, other) } /** diff --git a/model/src/main/kotlin/ScanSummary.kt b/model/src/main/kotlin/ScanSummary.kt index 4bee0426e8b53..e345927a0fe1e 100644 --- a/model/src/main/kotlin/ScanSummary.kt +++ b/model/src/main/kotlin/ScanSummary.kt @@ -26,10 +26,10 @@ import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.databind.annotation.JsonSerialize import java.time.Instant -import java.util.SortedSet import org.ossreviewtoolkit.model.config.LicenseFilePatterns import org.ossreviewtoolkit.model.utils.CopyrightFindingSortedSetConverter +import org.ossreviewtoolkit.model.utils.LicenseFindingSortedSetConverter import org.ossreviewtoolkit.model.utils.RootLicenseMatcher import org.ossreviewtoolkit.model.utils.SnippetFinding import org.ossreviewtoolkit.model.utils.SnippetFindingSortedSetConverter @@ -63,7 +63,8 @@ data class ScanSummary( */ @JsonInclude(JsonInclude.Include.NON_EMPTY) @JsonProperty("licenses") - val licenseFindings: SortedSet = sortedSetOf(), + @JsonSerialize(converter = LicenseFindingSortedSetConverter::class) + val licenseFindings: Set = emptySet(), /** * The detected copyright findings. @@ -119,12 +120,9 @@ data class ScanSummary( fun TextLocation.matchesPath() = this.path.startsWith("$path/") || this.path in applicableLicenseFiles - val licenseFindings = licenseFindings.filter { it.location.matchesPath() }.toSortedSet() - val copyrightFindings = copyrightFindings.filterTo(mutableSetOf()) { it.location.matchesPath() } - return copy( - licenseFindings = licenseFindings, - copyrightFindings = copyrightFindings + licenseFindings = licenseFindings.filterTo(mutableSetOf()) { it.location.matchesPath() }, + copyrightFindings = copyrightFindings.filterTo(mutableSetOf()) { it.location.matchesPath() } ) } @@ -136,7 +134,7 @@ data class ScanSummary( val matcher = FileMatcher(ignorePatterns) return copy( - licenseFindings = licenseFindings.filterTo(sortedSetOf()) { !matcher.matches(it.location.path) }, + licenseFindings = licenseFindings.filterTo(mutableSetOf()) { !matcher.matches(it.location.path) }, copyrightFindings = copyrightFindings.filterTo(mutableSetOf()) { !matcher.matches(it.location.path) } ) } diff --git a/model/src/main/kotlin/utils/SortedSetConverters.kt b/model/src/main/kotlin/utils/SortedSetConverters.kt index f0cd41ae6841a..bd13c51a16335 100644 --- a/model/src/main/kotlin/utils/SortedSetConverters.kt +++ b/model/src/main/kotlin/utils/SortedSetConverters.kt @@ -26,6 +26,7 @@ import com.fasterxml.jackson.databind.util.StdConverter import java.util.SortedSet import org.ossreviewtoolkit.model.CopyrightFinding +import org.ossreviewtoolkit.model.LicenseFinding import org.ossreviewtoolkit.model.Package import org.ossreviewtoolkit.model.Project @@ -33,6 +34,10 @@ class CopyrightFindingSortedSetConverter : StdConverter, S override fun convert(value: Set) = value.toSortedSet(CopyrightFinding.COMPARATOR) } +class LicenseFindingSortedSetConverter : StdConverter, SortedSet>() { + override fun convert(value: Set) = value.toSortedSet(LicenseFinding.COMPARATOR) +} + class PackageSortedSetConverter : StdConverter, SortedSet>() { override fun convert(value: Set) = value.toSortedSet(compareBy { it.id }) } diff --git a/model/src/test/kotlin/licenses/TestData.kt b/model/src/test/kotlin/licenses/TestData.kt index 657ac696cd6fe..ed7276c60c57d 100644 --- a/model/src/test/kotlin/licenses/TestData.kt +++ b/model/src/test/kotlin/licenses/TestData.kt @@ -49,7 +49,7 @@ val concludedLicense = "LicenseRef-a AND LicenseRef-b".toSpdx() val declaredLicenses = setOf("LicenseRef-a", "LicenseRef-b") val declaredLicensesProcessed = DeclaredLicenseProcessor.process(declaredLicenses) -val licenseFindings = sortedSetOf( +val licenseFindings = setOf( LicenseFinding("LicenseRef-a", TextLocation("LICENSE", 1)), LicenseFinding("LicenseRef-b", TextLocation("LICENSE", 2)) ) diff --git a/plugins/reporters/evaluated-model/src/main/kotlin/EvaluatedModelMapper.kt b/plugins/reporters/evaluated-model/src/main/kotlin/EvaluatedModelMapper.kt index b5400df51c7ca..886526bc8e81a 100644 --- a/plugins/reporters/evaluated-model/src/main/kotlin/EvaluatedModelMapper.kt +++ b/plugins/reporters/evaluated-model/src/main/kotlin/EvaluatedModelMapper.kt @@ -24,6 +24,7 @@ import org.ossreviewtoolkit.model.CuratedPackage import org.ossreviewtoolkit.model.DependencyNode import org.ossreviewtoolkit.model.Identifier import org.ossreviewtoolkit.model.Issue +import org.ossreviewtoolkit.model.LicenseFinding import org.ossreviewtoolkit.model.PackageLinkage import org.ossreviewtoolkit.model.Project import org.ossreviewtoolkit.model.Provenance @@ -635,8 +636,9 @@ internal class EvaluatedModelMapper(private val input: ReporterInput) { ) { val pathExcludes = getPathExcludes(id, scanResult.provenance) val licenseFindingCurations = getLicenseFindingCurations(id, scanResult.provenance) + // Sort the curated findings here to avoid the need to sort in the web-app each time it is loaded. val curatedFindings = curationsMatcher.applyAll(scanResult.summary.licenseFindings, licenseFindingCurations) - .mapNotNullTo(mutableSetOf()) { it.curatedFinding } + .mapNotNull { it.curatedFinding }.toSortedSet(LicenseFinding.COMPARATOR) val matchResult = findingsMatcher.match(curatedFindings, scanResult.summary.copyrightFindings) val matchedFindings = matchResult.matchedFindings.entries.groupBy { it.key.license }.mapValues { entry -> val licenseFindings = entry.value.map { it.key } diff --git a/plugins/reporters/freemarker/src/main/kotlin/FreemarkerTemplateProcessor.kt b/plugins/reporters/freemarker/src/main/kotlin/FreemarkerTemplateProcessor.kt index 853d7b9376388..114feb9276dc5 100644 --- a/plugins/reporters/freemarker/src/main/kotlin/FreemarkerTemplateProcessor.kt +++ b/plugins/reporters/freemarker/src/main/kotlin/FreemarkerTemplateProcessor.kt @@ -469,7 +469,7 @@ internal fun OrtResult.deduplicateProjectScanResults(targetProjects: Set ): List { - val licenseFindings = findingsPaths.mapTo(sortedSetOf()) { LicenseFinding("MIT", TextLocation(it, 1)) } + val licenseFindings = findingsPaths.mapTo(mutableSetOf()) { LicenseFinding("MIT", TextLocation(it, 1)) } val copyrightFindings = findingsPaths.mapTo(mutableSetOf()) { CopyrightFinding("(c)", TextLocation(it, 1)) } return listOf( diff --git a/plugins/reporters/opossum/src/test/kotlin/OpossumReporterTest.kt b/plugins/reporters/opossum/src/test/kotlin/OpossumReporterTest.kt index 1f750131c7ec2..a3c7cf839dc9f 100644 --- a/plugins/reporters/opossum/src/test/kotlin/OpossumReporterTest.kt +++ b/plugins/reporters/opossum/src/test/kotlin/OpossumReporterTest.kt @@ -454,7 +454,7 @@ private fun createOrtResult(): OrtResult { ), summary = ScanSummary.EMPTY.copy( packageVerificationCode = "0000000000000000000000000000000000000000", - licenseFindings = sortedSetOf( + licenseFindings = setOf( LicenseFinding( license = "Apache-2.0", location = TextLocation("LICENSE", 1) @@ -491,7 +491,7 @@ private fun createOrtResult(): OrtResult { startTime = Instant.EPOCH, endTime = Instant.EPOCH, packageVerificationCode = "0000000000000000000000000000000000000000", - licenseFindings = sortedSetOf( + licenseFindings = setOf( LicenseFinding( license = "BSD-2-Clause", location = TextLocation("LICENSE", 1) diff --git a/plugins/reporters/spdx/src/funTest/kotlin/SpdxDocumentReporterFunTest.kt b/plugins/reporters/spdx/src/funTest/kotlin/SpdxDocumentReporterFunTest.kt index e360726042a38..7fb411e832230 100644 --- a/plugins/reporters/spdx/src/funTest/kotlin/SpdxDocumentReporterFunTest.kt +++ b/plugins/reporters/spdx/src/funTest/kotlin/SpdxDocumentReporterFunTest.kt @@ -277,7 +277,7 @@ private val ortResult = OrtResult( scanner = ScannerDetails.EMPTY, summary = ScanSummary.EMPTY.copy( packageVerificationCode = "0000000000000000000000000000000000000000", - licenseFindings = sortedSetOf( + licenseFindings = setOf( LicenseFinding( license = "Apache-2.0", location = TextLocation("LICENSE", 1) @@ -308,7 +308,7 @@ private val ortResult = OrtResult( scanner = ScannerDetails.EMPTY, summary = ScanSummary.EMPTY.copy( packageVerificationCode = "0000000000000000000000000000000000000000", - licenseFindings = sortedSetOf( + licenseFindings = setOf( LicenseFinding( license = "BSD-2-Clause", location = TextLocation("LICENSE", 1) diff --git a/reporter/src/testFixtures/kotlin/TestData.kt b/reporter/src/testFixtures/kotlin/TestData.kt index 4cb7437de8a4e..6c58f3d0523d1 100644 --- a/reporter/src/testFixtures/kotlin/TestData.kt +++ b/reporter/src/testFixtures/kotlin/TestData.kt @@ -227,7 +227,7 @@ val ORT_RESULT = OrtResult( provenance = UnknownProvenance, scanner = ScannerDetails(name = "scanner", version = "1.0", configuration = ""), summary = ScanSummary.EMPTY.copy( - licenseFindings = sortedSetOf( + licenseFindings = setOf( LicenseFinding( license = "MIT", location = TextLocation("project-with-findings/file", 1) @@ -254,7 +254,7 @@ val ORT_RESULT = OrtResult( provenance = UnknownProvenance, scanner = ScannerDetails(name = "scanner", version = "1.0", configuration = ""), summary = ScanSummary.EMPTY.copy( - licenseFindings = sortedSetOf( + licenseFindings = setOf( LicenseFinding( license = "MIT", location = TextLocation("file", 1) @@ -279,7 +279,7 @@ val ORT_RESULT = OrtResult( ), scanner = ScannerDetails(name = "scanner", version = "1.0", configuration = ""), summary = ScanSummary.EMPTY.copy( - licenseFindings = sortedSetOf( + licenseFindings = setOf( LicenseFinding( license = "MIT", location = TextLocation("LICENSE", 1) @@ -312,7 +312,7 @@ val ORT_RESULT = OrtResult( ), scanner = ScannerDetails(name = "scanner", version = "1.0", configuration = ""), summary = ScanSummary.EMPTY.copy( - licenseFindings = sortedSetOf( + licenseFindings = setOf( LicenseFinding( license = "MIT", location = TextLocation("LICENSE", 1) @@ -353,7 +353,7 @@ val ORT_RESULT = OrtResult( ), scanner = ScannerDetails(name = "scanner", version = "1.0", configuration = ""), summary = ScanSummary.EMPTY.copy( - licenseFindings = sortedSetOf( + licenseFindings = setOf( LicenseFinding( license = "MIT", location = TextLocation("file1", 1) @@ -386,7 +386,7 @@ val ORT_RESULT = OrtResult( ), scanner = ScannerDetails(name = "scanner", version = "1.0", configuration = ""), summary = ScanSummary.EMPTY.copy( - licenseFindings = sortedSetOf( + licenseFindings = setOf( LicenseFinding( license = "BSD-3-Clause", location = TextLocation("LICENSE", 1) diff --git a/scanner/src/funTest/kotlin/scanners/ScannerIntegrationFunTest.kt b/scanner/src/funTest/kotlin/scanners/ScannerIntegrationFunTest.kt index 2d41032668850..60df276a9db5d 100644 --- a/scanner/src/funTest/kotlin/scanners/ScannerIntegrationFunTest.kt +++ b/scanner/src/funTest/kotlin/scanners/ScannerIntegrationFunTest.kt @@ -87,7 +87,7 @@ private class DummyScanner : PathScannerWrapper { override val criteria = ScannerCriteria.forDetails(details) override fun scanPath(path: File, context: ScanContext): ScanSummary { - val licenseFindings = path.listFiles().orEmpty().mapTo(sortedSetOf()) { file -> + val licenseFindings = path.listFiles().orEmpty().mapTo(mutableSetOf()) { file -> LicenseFinding( license = SpdxConstants.NONE, location = TextLocation(file.relativeTo(path).invariantSeparatorsPath, TextLocation.UNKNOWN_LINE) diff --git a/scanner/src/funTest/kotlin/storages/AbstractProvenanceBasedStorageFunTest.kt b/scanner/src/funTest/kotlin/storages/AbstractProvenanceBasedStorageFunTest.kt index 0abae62c62871..d60e4e8e5b01f 100644 --- a/scanner/src/funTest/kotlin/storages/AbstractProvenanceBasedStorageFunTest.kt +++ b/scanner/src/funTest/kotlin/storages/AbstractProvenanceBasedStorageFunTest.kt @@ -225,7 +225,7 @@ private fun createScanResult( provenance, scannerDetails, ScanSummary.EMPTY.copy( - licenseFindings = sortedSetOf( + licenseFindings = setOf( LicenseFinding(license, TextLocation("file.txt", 1, 2)) ) ) diff --git a/scanner/src/funTest/kotlin/storages/AbstractStorageFunTest.kt b/scanner/src/funTest/kotlin/storages/AbstractStorageFunTest.kt index 0b2a72b75b76a..b6d758018eac4 100644 --- a/scanner/src/funTest/kotlin/storages/AbstractStorageFunTest.kt +++ b/scanner/src/funTest/kotlin/storages/AbstractStorageFunTest.kt @@ -103,11 +103,11 @@ abstract class AbstractStorageFunTest(vararg listeners: TestListener) : WordSpec startTime = Instant.EPOCH + Duration.ofMinutes(1), endTime = Instant.EPOCH + Duration.ofMinutes(2), packageVerificationCode = "packageVerificationCode", - licenseFindings = sortedSetOf( + licenseFindings = setOf( LicenseFinding("license-1.1", DUMMY_TEXT_LOCATION), LicenseFinding("license-1.2", DUMMY_TEXT_LOCATION) ), - issues = mutableListOf( + issues = listOf( Issue(source = "source-1", message = "error-1"), Issue(source = "source-2", message = "error-2") ) diff --git a/scanner/src/funTest/kotlin/storages/ClearlyDefinedStorageFunTest.kt b/scanner/src/funTest/kotlin/storages/ClearlyDefinedStorageFunTest.kt index 686272c5c507b..70285ea5eeb10 100644 --- a/scanner/src/funTest/kotlin/storages/ClearlyDefinedStorageFunTest.kt +++ b/scanner/src/funTest/kotlin/storages/ClearlyDefinedStorageFunTest.kt @@ -74,7 +74,7 @@ class ClearlyDefinedStorageFunTest : StringSpec({ startTime = Instant.parse("2020-02-14T00:36:14.000335513Z"), endTime = Instant.parse("2020-02-14T00:36:37.000492119Z"), packageVerificationCode = SpdxConstants.NONE, - licenseFindings = sortedSetOf( + licenseFindings = setOf( LicenseFinding( license = "MIT", location = TextLocation( diff --git a/scanner/src/main/kotlin/Scanner.kt b/scanner/src/main/kotlin/Scanner.kt index a7f22c386f869..df1d7a6775043 100644 --- a/scanner/src/main/kotlin/Scanner.kt +++ b/scanner/src/main/kotlin/Scanner.kt @@ -709,7 +709,7 @@ fun ScanResult.toNestedProvenanceScanResult(nestedProvenance: NestedProvenance): copy( provenance = provenance, summary = summary.copy( - licenseFindings = licenseFindingsByProvenance[provenance].orEmpty().toSortedSet(), + licenseFindings = licenseFindingsByProvenance[provenance].orEmpty().toSet(), copyrightFindings = copyrightFindingsByProvenance[provenance].orEmpty().toSet() ) ) diff --git a/scanner/src/main/kotlin/provenance/NestedProvenanceScanResult.kt b/scanner/src/main/kotlin/provenance/NestedProvenanceScanResult.kt index f7462751c00e3..b352a68848db8 100644 --- a/scanner/src/main/kotlin/provenance/NestedProvenanceScanResult.kt +++ b/scanner/src/main/kotlin/provenance/NestedProvenanceScanResult.kt @@ -20,7 +20,6 @@ package org.ossreviewtoolkit.scanner.provenance import java.time.Instant -import java.util.SortedSet import org.ossreviewtoolkit.model.CopyrightFinding import org.ossreviewtoolkit.model.KnownProvenance @@ -107,12 +106,12 @@ data class NestedProvenanceScanResult( } } - private fun Map>.mergeLicenseFindings(): SortedSet { + private fun Map>.mergeLicenseFindings(): Set { val findingsByPath = mapKeys { getPath(it.key) }.mapValues { (_, scanResults) -> scanResults.flatMap { it.summary.licenseFindings } } - val findings = findingsByPath.flatMapTo(sortedSetOf()) { (path, findings) -> + val findings = findingsByPath.flatMapTo(mutableSetOf()) { (path, findings) -> val prefix = if (path.isEmpty()) path else "$path/" findings.map { it.copy(location = it.location.copy(path = "$prefix${it.location.path}")) } } diff --git a/scanner/src/main/kotlin/scanners/Askalono.kt b/scanner/src/main/kotlin/scanners/Askalono.kt index e7545a6f7b265..e77c770b1e767 100644 --- a/scanner/src/main/kotlin/scanners/Askalono.kt +++ b/scanner/src/main/kotlin/scanners/Askalono.kt @@ -81,7 +81,7 @@ class Askalono internal constructor( } private fun generateSummary(startTime: Instant, endTime: Instant, scanPath: File, result: String): ScanSummary { - val licenseFindings = sortedSetOf() + val licenseFindings = mutableSetOf() result.lines().forEach { line -> val root = jsonMapper.readTree(line) diff --git a/scanner/src/main/kotlin/scanners/BoyterLc.kt b/scanner/src/main/kotlin/scanners/BoyterLc.kt index 36001a0ed5978..627a136fa7024 100644 --- a/scanner/src/main/kotlin/scanners/BoyterLc.kt +++ b/scanner/src/main/kotlin/scanners/BoyterLc.kt @@ -92,7 +92,7 @@ class BoyterLc internal constructor( } private fun generateSummary(startTime: Instant, endTime: Instant, scanPath: File, resultFile: File): ScanSummary { - val licenseFindings = sortedSetOf() + val licenseFindings = mutableSetOf() val result = resultFile.readTree() result.flatMapTo(licenseFindings) { file -> diff --git a/scanner/src/main/kotlin/scanners/Licensee.kt b/scanner/src/main/kotlin/scanners/Licensee.kt index 101fd1ab4aff9..e382f65a70c8e 100644 --- a/scanner/src/main/kotlin/scanners/Licensee.kt +++ b/scanner/src/main/kotlin/scanners/Licensee.kt @@ -81,7 +81,7 @@ class Licensee internal constructor( } private fun generateSummary(startTime: Instant, endTime: Instant, scanPath: File, result: String): ScanSummary { - val licenseFindings = sortedSetOf() + val licenseFindings = mutableSetOf() val json = jsonMapper.readTree(result) val matchedFiles = json["matched_files"] diff --git a/scanner/src/main/kotlin/scanners/fossid/FossId.kt b/scanner/src/main/kotlin/scanners/fossid/FossId.kt index c01969a388a9d..49e630d5a2dec 100644 --- a/scanner/src/main/kotlin/scanners/fossid/FossId.kt +++ b/scanner/src/main/kotlin/scanners/fossid/FossId.kt @@ -859,7 +859,7 @@ class FossId internal constructor( startTime = startTime, endTime = Instant.now(), packageVerificationCode = "", - licenseFindings = licenseFindings.toSortedSet(), + licenseFindings = licenseFindings, copyrightFindings = copyrightFindings, snippetFindings = snippetFindings, issues = issues diff --git a/scanner/src/main/kotlin/scanners/scancode/ScanCodeResultParser.kt b/scanner/src/main/kotlin/scanners/scancode/ScanCodeResultParser.kt index c5e755e1d21ec..131c8b0a0804d 100644 --- a/scanner/src/main/kotlin/scanners/scancode/ScanCodeResultParser.kt +++ b/scanner/src/main/kotlin/scanners/scancode/ScanCodeResultParser.kt @@ -130,7 +130,7 @@ internal fun generateSummary( startTime = startTime, endTime = endTime, packageVerificationCode = verificationCode, - licenseFindings = getLicenseFindings(result, detectedLicenseMapping, parseExpressions).toSortedSet(), + licenseFindings = getLicenseFindings(result, detectedLicenseMapping, parseExpressions), copyrightFindings = getCopyrightFindings(result), issues = issues + getIssues(result) ) diff --git a/scanner/src/main/kotlin/scanners/scanoss/ScanOssResultParser.kt b/scanner/src/main/kotlin/scanners/scanoss/ScanOssResultParser.kt index 2866cb8ff6909..0908235088b08 100644 --- a/scanner/src/main/kotlin/scanners/scanoss/ScanOssResultParser.kt +++ b/scanner/src/main/kotlin/scanners/scanoss/ScanOssResultParser.kt @@ -96,7 +96,7 @@ internal fun generateSummary( startTime = startTime, endTime = endTime, packageVerificationCode = verificationCode, - licenseFindings = licenseFindings.toSortedSet(), + licenseFindings = licenseFindings, copyrightFindings = copyrightFindings, snippetFindings = snippetFindings ) diff --git a/scanner/src/test/kotlin/ScannerTest.kt b/scanner/src/test/kotlin/ScannerTest.kt index 5a1f0e838e0aa..035cc4098264c 100644 --- a/scanner/src/test/kotlin/ScannerTest.kt +++ b/scanner/src/test/kotlin/ScannerTest.kt @@ -35,7 +35,6 @@ import io.mockk.verify import java.io.File import java.io.IOException -import java.util.SortedSet import org.ossreviewtoolkit.model.ArtifactProvenance import org.ossreviewtoolkit.model.Hash @@ -637,7 +636,7 @@ class ScannerTest : WordSpec({ val scanResult = createScanResult( provenanceWithoutVcsPath, scannerWrapper.details, - sortedSetOf( + setOf( // Add a license finding outside the subdirectory that is matched by a license file pattern. LicenseFinding("Apache-2.0", TextLocation("LICENSE", 1, 1)), // Add a license finding outside the subdirectory that is not matched by a license file pattern. @@ -661,7 +660,7 @@ class ScannerTest : WordSpec({ val filteredScanResult = createScanResult( provenanceWithVcsPath, scannerWrapper.details, - sortedSetOf( + setOf( // Add a license finding outside the subdirectory that is matched by a license file pattern. LicenseFinding("Apache-2.0", TextLocation("LICENSE", 1, 1)), // Add a license finding inside the subdirectory. @@ -826,9 +825,9 @@ private class FakePathScannerWrapper : PathScannerWrapper { override val criteria = ScannerCriteria.forDetails(details) override fun scanPath(path: File, context: ScanContext): ScanSummary { - val licenseFindings = path.walk().filter { it.isFile }.map { file -> + val licenseFindings = path.walk().filter { it.isFile }.mapTo(mutableSetOf()) { file -> LicenseFinding("Apache-2.0", TextLocation(file.relativeTo(path).path, 1, 2)) - }.toSortedSet() + } return ScanSummary.EMPTY.copy(licenseFindings = licenseFindings) } @@ -964,7 +963,7 @@ private fun VcsInfo.Companion.valid() = private fun createScanResult( provenance: Provenance, scannerDetails: ScannerDetails, - licenseFindings: SortedSet = sortedSetOf( + licenseFindings: Set = setOf( LicenseFinding("Apache-2.0", TextLocation("${scannerDetails.name}.txt", 1, 2)) ) ) = @@ -991,7 +990,7 @@ private fun createStoredScanResult(provenance: Provenance, scannerDetails: Scann provenance, scannerDetails, ScanSummary.EMPTY.copy( - licenseFindings = sortedSetOf( + licenseFindings = setOf( LicenseFinding("Apache-2.0", TextLocation("storage.txt", 1, 2)) ) ) diff --git a/scanner/src/test/kotlin/provenance/NestedProvenanceScanResultTest.kt b/scanner/src/test/kotlin/provenance/NestedProvenanceScanResultTest.kt index c6cd65135eb0b..66239af3990dc 100644 --- a/scanner/src/test/kotlin/provenance/NestedProvenanceScanResultTest.kt +++ b/scanner/src/test/kotlin/provenance/NestedProvenanceScanResultTest.kt @@ -117,7 +117,7 @@ private val scanResultRoot = ScanResult( provenance = provenanceRoot, scanner = scannerDetails, summary = ScanSummary.EMPTY.copy( - licenseFindings = sortedSetOf( + licenseFindings = setOf( LicenseFinding("Apache-2.0", TextLocation("file", 1)), LicenseFinding("Apache-2.0", TextLocation("submodules/file", 1)) ), @@ -132,7 +132,7 @@ private val scanResultSubmoduleA = ScanResult( provenance = provenanceSubmoduleA, scanner = scannerDetails, summary = ScanSummary.EMPTY.copy( - licenseFindings = sortedSetOf( + licenseFindings = setOf( LicenseFinding("Apache-2.0", TextLocation("fileA", 1)), LicenseFinding("Apache-2.0", TextLocation("dir/fileA", 1)) ), @@ -147,7 +147,7 @@ private val scanResultSubmoduleB = ScanResult( provenance = provenanceSubmoduleA, scanner = scannerDetails, summary = ScanSummary.EMPTY.copy( - licenseFindings = sortedSetOf( + licenseFindings = setOf( LicenseFinding("Apache-2.0", TextLocation("fileB", 1)), LicenseFinding("Apache-2.0", TextLocation("dir/fileB", 1)) ),