@@ -86,20 +86,26 @@ fun ScanCodeResult.toScanSummary(preferFileLicense: Boolean = false): ScanSummar
8686 ? : files.flatMap { it.scanCodeKeyToSpdxIdMappings }.toMap()
8787
8888 filesOfTypeFile.forEach { file ->
89- val licensesWithoutReferences = file.licenses.filter {
90- val fromFile = it.fromFile
91- fromFile == null
92- // Note that "fromFile" contains the name of the input directory, see
93- // https://github.com/aboutcode-org/scancode-toolkit/issues/3712.
94- || inputPath.resolveSibling(fromFile) == inputPath / file.path
95- || (inputPath.path == " ." && fromFile.substringAfter(' /' ) == file.path)
96- // Check if input is a single file.
97- || fromFile == inputPath.name
89+ // Only keep those licenses that originate from the current file, i.e. that are not references to other files.
90+ val licensesFromCurrentFile = file.licenses.filter {
91+ when (val fromFile = it.fromFile) {
92+ null , inputPath.name -> true
93+
94+ else -> when {
95+ // Note that "fromFile" contains the name of the input directory, see
96+ // https://github.com/aboutcode-org/scancode-toolkit/issues/3712.
97+ inputPath.resolveSibling(fromFile) == inputPath / file.path -> true
98+
99+ inputPath.path == " ." && fromFile.substringAfter(' /' ) == file.path -> true
100+
101+ else -> false
102+ }
103+ }
98104 }
99105
100106 // ScanCode creates separate license entries for each license in an expression. Deduplicate these by grouping by
101107 // the same expression.
102- val licenses = licensesWithoutReferences .groupBy {
108+ val licenses = licensesFromCurrentFile .groupBy {
103109 LicenseMatch (it.licenseExpression, it.startLine, it.endLine, it.score)
104110 }.map {
105111 // Arbitrarily take the first of the duplicate license entries.
0 commit comments