-
Notifications
You must be signed in to change notification settings - Fork 316
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,13 +36,15 @@ 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.VcsInfo | ||
import org.ossreviewtoolkit.model.config.DownloaderConfiguration | ||
import org.ossreviewtoolkit.model.config.ScannerConfiguration | ||
|
@@ -192,8 +194,6 @@ class Scanner( | |
|
||
val vcsPathsForProvenances = getVcsPathsForProvenances(provenances) | ||
|
||
val filteredScanResults = filterScanResultsByVcsPaths(controller.getAllScanResults(), vcsPathsForProvenances) | ||
|
||
val files = controller.getAllFileLists().mapTo(mutableSetOf()) { (provenance, fileList) -> | ||
FileList( | ||
provenance = provenance.alignRevisions() as KnownProvenance, | ||
|
@@ -207,6 +207,40 @@ class Scanner( | |
} | ||
} | ||
|
||
val filteredScanResults = filterScanResultsByVcsPaths(controller.getAllScanResults(), vcsPathsForProvenances) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, a few random starting thoughts / comments:
|
||
.mapTo(mutableSetOf()) { scanResult -> | ||
val licenseFiles = scanResult.summary.licenseFindings.mapTo(mutableSetOf()) { licenseFinding -> | ||
licenseFinding.location.path | ||
} | ||
|
||
if (!scannerConfig.includeUnlicensed) { | ||
scanResult.copy(provenance = scanResult.provenance.alignRevisions()) | ||
} else { | ||
// Adds files without license to the scanned results | ||
val scanSummary = | ||
controller.getAllFileLists()[scanResult.provenance]?.files | ||
.orEmpty().asSequence().mapNotNull { fileEntry -> | ||
if (fileEntry.path in licenseFiles) { | ||
null | ||
} else { | ||
fileEntry.path | ||
} | ||
}.toSet().let { fileEntryLicenses -> | ||
(fileEntryLicenses subtract licenseFiles).mapTo(mutableSetOf()) { newFinding -> | ||
LicenseFinding(license = "NONE", location = TextLocation(newFinding, 1)) | ||
}.let { | ||
val allFindings = scanResult.summary.licenseFindings union it | ||
|
||
scanResult.summary.copy(licenseFindings = allFindings) | ||
} | ||
|
||
} | ||
|
||
scanResult.copy( | ||
provenance = scanResult.provenance.alignRevisions(), | ||
summary = scanSummary | ||
) | ||
Comment on lines
+219
to
+240
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To reduce nesting and make the code more readable, I propose something like this (completely untested; this goes to
Due to the introduced variables, this maybe is even clear enough to not require any code comments. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that I'm using the |
||
} | ||
} | ||
|
||
val scannerNames = scannerWrappers.mapTo(mutableSetOf()) { it.name } | ||
val scanners = packages.associateBy({ it.id }) { scannerNames } | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For my taste, this sounds too much like https://spdx.org/licenses/Unlicense.html. To avoid any confusion, I propose to rename this to
includeFilesWithoutFindings
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, property-ordering-wise I don't like this to go between the two "skip..." properties. Between
skipExcluded
andarchive
makes more sense to me.