Skip to content

Commit

Permalink
fix(scancode): Make path comparisons separator-agnostic
Browse files Browse the repository at this point in the history
This fixes scan results eventually being swallowed on Windows with
ScanCode 32.

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
  • Loading branch information
sschuberth committed Aug 22, 2024
1 parent e951d63 commit 456e3fc
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.ossreviewtoolkit.plugins.scanners.scancode

import java.io.File
import java.time.Instant
import java.time.ZoneId
import java.time.format.DateTimeFormatter
Expand Down Expand Up @@ -64,7 +65,7 @@ fun ScanCodeResult.toScanSummary(preferFileLicense: Boolean = false): ScanSummar
val issues = mutableListOf<Issue>()

val header = headers.single()
val inputName = header.options.input.first().substringAfterLast('/')
val inputPath = File(header.options.input.first())

val outputFormatVersion = header.outputFormatVersion?.let { Semver(it) }
if (outputFormatVersion != null && outputFormatVersion.major > MAX_SUPPORTED_OUTPUT_FORMAT_MAJOR_VERSION) {
Expand All @@ -84,10 +85,12 @@ fun ScanCodeResult.toScanSummary(preferFileLicense: Boolean = false): ScanSummar

filesOfTypeFile.forEach { file ->
val licensesWithoutReferences = file.licenses.filter {
// Note that "fromFile" contains the name of the input directory, see
// https://github.com/nexB/scancode-toolkit/issues/3712.
it !is LicenseEntry.Version3 || it.fromFile == null || it.fromFile == "$inputName/${file.path}"
|| it.fromFile == inputName // Input is a single file.
it !is LicenseEntry.Version3 || it.fromFile == null
// Note that "fromFile" contains the name of the input directory, see
// https://github.com/nexB/scancode-toolkit/issues/3712.
|| inputPath.resolveSibling(it.fromFile) == inputPath.resolve(file.path)
// Check if input is a single file.
|| it.fromFile == inputPath.name
}

// ScanCode creates separate license entries for each license in an expression. Deduplicate these by grouping by
Expand Down

0 comments on commit 456e3fc

Please sign in to comment.