Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(scanner): Add flag to scanner to detect unlicensed files #9487

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions model/src/main/kotlin/config/ScannerConfiguration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ data class ScannerConfiguration(
*/
val skipExcluded: Boolean = false,

/**
* A flag to indicate whether the scanner should add files without license to the scanner results.
*/
val includeFilesWithoutFindings: Boolean = false,

/**
* Configuration of a [FileArchiver] that archives certain scanned files in an external [FileStorage].
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ scanner:
config:
skip_concluded: false
skip_excluded: false
include_files_without_findings: false
detected_license_mapping:
LicenseRef-scancode-agpl-generic-additional-terms: "NOASSERTION"
LicenseRef-scancode-free-unknown: "NOASSERTION"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ scanner:
config:
skip_concluded: false
skip_excluded: false
include_files_without_findings: false
detected_license_mapping:
LicenseRef-scancode-agpl-generic-additional-terms: "NOASSERTION"
LicenseRef-scancode-free-unknown: "NOASSERTION"
Expand Down
29 changes: 28 additions & 1 deletion scanner/src/main/kotlin/Scanner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,16 @@ import org.ossreviewtoolkit.model.FileList
import org.ossreviewtoolkit.model.Identifier
import org.ossreviewtoolkit.model.Issue
import org.ossreviewtoolkit.model.KnownProvenance
import org.ossreviewtoolkit.model.LicenseFinding
import org.ossreviewtoolkit.model.OrtResult
import org.ossreviewtoolkit.model.Package
import org.ossreviewtoolkit.model.PackageType
import org.ossreviewtoolkit.model.ProvenanceResolutionResult
import org.ossreviewtoolkit.model.ScanResult
import org.ossreviewtoolkit.model.ScanSummary
import org.ossreviewtoolkit.model.ScannerRun
import org.ossreviewtoolkit.model.TextLocation
import org.ossreviewtoolkit.model.TextLocation.Companion.UNKNOWN_LINE
import org.ossreviewtoolkit.model.VcsInfo
import org.ossreviewtoolkit.model.config.DownloaderConfiguration
import org.ossreviewtoolkit.model.config.ScannerConfiguration
Expand All @@ -67,6 +70,7 @@ import org.ossreviewtoolkit.utils.common.collectMessages
import org.ossreviewtoolkit.utils.common.safeDeleteRecursively
import org.ossreviewtoolkit.utils.ort.Environment
import org.ossreviewtoolkit.utils.ort.showStackTrace
import org.ossreviewtoolkit.utils.spdx.SpdxConstants
import org.ossreviewtoolkit.utils.spdx.toSpdx

class Scanner(
Expand Down Expand Up @@ -205,13 +209,36 @@ class Scanner(
}
}

val scanResults = if (scannerConfig.includeFilesWithoutFindings) {
filteredScanResults.mapTo(mutableSetOf()) { scanResult ->
val allPaths = controller.getAllFileLists()[scanResult.provenance]?.files?.mapTo(mutableSetOf()) {
it.path
}.orEmpty()

val pathsWithFindings = scanResult.summary.licenseFindings.mapTo(mutableSetOf()) { it.location.path }
val pathsWithoutFindings = allPaths - pathsWithFindings

val findingsThatAreNone = pathsWithoutFindings.mapTo(mutableSetOf()) {
LicenseFinding(SpdxConstants.NONE, TextLocation(it, UNKNOWN_LINE))
}

scanResult.copy(
summary = scanResult.summary.copy(
licenseFindings = scanResult.summary.licenseFindings + findingsThatAreNone
)
)
}
} else {
filteredScanResults
}

val scannerNames = scannerWrappers.mapTo(mutableSetOf()) { it.name }
val scanners = packages.associateBy({ it.id }) { scannerNames }

return ScannerRun.EMPTY.copy(
config = scannerConfig,
provenances = provenances,
scanResults = filteredScanResults,
scanResults = scanResults,
files = files,
scanners = scanners
)
Expand Down
Loading