-
Notifications
You must be signed in to change notification settings - Fork 356
Various fixes related to path includes #10762
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
Draft
nnobelis
wants to merge
4
commits into
oss-review-toolkit:main
Choose a base branch
from
boschglobal:nnobelis/add_includes_to_webapp_report
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f1a5b18
feat(model): Add includes to package configurations
nnobelis 4f63d1c
feat(evaluated-model): Add path includes properties to the evaluated …
nnobelis 3c1463c
feat(web-app-template): Handle scan results excluded due to path incl…
nnobelis bfb62c7
feat(LicenseInfoResolver): Apply the path includes
nnobelis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,6 +44,7 @@ import org.ossreviewtoolkit.model.config.Resolutions | |
| import org.ossreviewtoolkit.model.config.RuleViolationResolution | ||
| import org.ossreviewtoolkit.model.config.ScopeExclude | ||
| import org.ossreviewtoolkit.model.config.VulnerabilityResolution | ||
| import org.ossreviewtoolkit.model.config.PathInclude | ||
| import org.ossreviewtoolkit.model.licenses.LicenseView | ||
| import org.ossreviewtoolkit.model.toYaml | ||
| import org.ossreviewtoolkit.model.utils.FindingCurationMatcher | ||
|
|
@@ -59,7 +60,7 @@ import org.ossreviewtoolkit.utils.spdx.calculatePackageVerificationCode | |
| /** | ||
| * Maps the [reporter input][input] to an [EvaluatedModel]. | ||
| */ | ||
| @Suppress("TooManyFunctions") | ||
| @Suppress("LargeClass", "TooManyFunctions") | ||
| internal class EvaluatedModelMapper(private val input: ReporterInput) { | ||
| private val packages = mutableMapOf<Identifier, EvaluatedPackage>() | ||
| private val paths = mutableListOf<EvaluatedPackagePath>() | ||
|
|
@@ -71,6 +72,7 @@ internal class EvaluatedModelMapper(private val input: ReporterInput) { | |
| private val issues = mutableListOf<EvaluatedIssue>() | ||
| private val issueResolutions = mutableListOf<IssueResolution>() | ||
| private val pathExcludes = mutableListOf<PathExclude>() | ||
| private val pathIncludes = mutableListOf<PathInclude>() | ||
| private val scopeExcludes = mutableListOf<ScopeExclude>() | ||
| private val ruleViolations = mutableListOf<EvaluatedRuleViolation>() | ||
| private val ruleViolationResolutions = mutableListOf<RuleViolationResolution>() | ||
|
|
@@ -84,6 +86,7 @@ internal class EvaluatedModelMapper(private val input: ReporterInput) { | |
| var id: Identifier, | ||
| var isExcluded: Boolean, | ||
| val pathExcludes: MutableList<PathExclude> = mutableListOf(), | ||
| val pathIncludes: MutableList<PathInclude> = mutableListOf(), | ||
| val scopeExcludes: MutableList<ScopeExclude> = mutableListOf() | ||
| ) | ||
|
|
||
|
|
@@ -134,6 +137,7 @@ internal class EvaluatedModelMapper(private val input: ReporterInput) { | |
|
|
||
| return EvaluatedModel( | ||
| pathExcludes = pathExcludes, | ||
| pathIncludes = pathIncludes, | ||
| scopeExcludes = scopeExcludes, | ||
| issueResolutions = issueResolutions, | ||
| issues = issues, | ||
|
|
@@ -169,21 +173,26 @@ internal class EvaluatedModelMapper(private val input: ReporterInput) { | |
|
|
||
| input.ortResult.getProjects().forEach { project -> | ||
| val pathExcludes = input.ortResult.getExcludes().findPathExcludes(project, input.ortResult) | ||
| val pathIncludes = input.ortResult.getIncludes().findPathIncludes(project, input.ortResult) | ||
| val dependencies = input.ortResult.dependencyNavigator.projectDependencies(project) | ||
| if (pathExcludes.isEmpty()) { | ||
| if (pathExcludes.isEmpty() && pathIncludes.isEmpty()) { | ||
| val info = packageExcludeInfo.getValue(project.id) | ||
| if (info.isExcluded) { | ||
| info.isExcluded = false | ||
| info.pathExcludes.clear() | ||
| info.scopeExcludes.clear() | ||
| } | ||
|
|
||
| info.pathIncludes.clear() | ||
| } else { | ||
| dependencies.forEach { id -> | ||
| val info = packageExcludeInfo.getOrPut(id) { PackageExcludeInfo(id, true) } | ||
|
|
||
| if (info.isExcluded) { | ||
| info.pathExcludes += pathExcludes | ||
| } | ||
|
|
||
| info.pathIncludes += pathIncludes | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -238,6 +247,14 @@ internal class EvaluatedModelMapper(private val input: ReporterInput) { | |
| .flatMap { it.pathExcludes } | ||
| } | ||
|
|
||
| private fun getPathIncludes(id: Identifier, provenance: Provenance): List<PathInclude> = | ||
| if (input.ortResult.isProject(id)) { | ||
| input.ortResult.getIncludes().paths | ||
| } else { | ||
| input.ortResult.getPackageConfigurations(id, provenance) | ||
| .flatMap { it.pathIncludes } | ||
| } | ||
|
|
||
| private fun addProject(project: Project) { | ||
| val scanResults = mutableListOf<EvaluatedScanResult>() | ||
| val detectedLicenses = mutableSetOf<LicenseId>() | ||
|
|
@@ -246,7 +263,9 @@ internal class EvaluatedModelMapper(private val input: ReporterInput) { | |
| val issues = mutableListOf<EvaluatedIssue>() | ||
|
|
||
| val applicablePathExcludes = input.ortResult.getExcludes().findPathExcludes(project, input.ortResult) | ||
| val applicablePathIncludes = input.ortResult.getIncludes().findPathIncludes(project, input.ortResult) | ||
| val evaluatedPathExcludes = pathExcludes.addIfRequired(applicablePathExcludes) | ||
| pathIncludes.addIfRequired(applicablePathIncludes) | ||
|
|
||
| val evaluatedPackage = EvaluatedPackage( | ||
| id = project.id, | ||
|
|
@@ -287,7 +306,8 @@ internal class EvaluatedModelMapper(private val input: ReporterInput) { | |
| findings.filter { it.type == EvaluatedFindingType.LICENSE }.mapNotNullTo(detectedLicenses) { it.license } | ||
|
|
||
| val includedDetectedLicenses = findings.filter { | ||
| it.type == EvaluatedFindingType.LICENSE && it.pathExcludes.isEmpty() | ||
| val isIncluded = pathIncludes.isEmpty() || pathIncludes.any { include -> include.matches(it.path) } | ||
| it.type == EvaluatedFindingType.LICENSE && it.pathExcludes.isEmpty() && isIncluded | ||
| }.mapNotNullTo(mutableSetOf()) { it.license } | ||
|
|
||
| detectedExcludedLicenses += detectedLicenses - includedDetectedLicenses | ||
|
|
@@ -660,6 +680,7 @@ internal class EvaluatedModelMapper(private val input: ReporterInput) { | |
| findings: MutableList<EvaluatedFinding> | ||
| ) { | ||
| val pathExcludes = getPathExcludes(id, scanResult.provenance) | ||
| val pathIncludes = getPathIncludes(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) | ||
|
|
@@ -679,6 +700,16 @@ internal class EvaluatedModelMapper(private val input: ReporterInput) { | |
| val evaluatedPathExcludes = pathExcludes | ||
| .filter { it.matches(copyrightFinding.location.getRelativePathToRoot(id)) } | ||
| .let { [email protected](it) } | ||
| pathIncludes.let { [email protected](it) } | ||
|
|
||
| val evaluatedPathIncludes = if (pathIncludes.isEmpty() || pathIncludes.any { include -> | ||
| include.matches(copyrightFinding.location.getRelativePathToRoot(id)) | ||
| } | ||
| ) { | ||
| emptyList() | ||
| } else { | ||
| pathIncludes | ||
| } | ||
|
|
||
| findings += EvaluatedFinding( | ||
| type = EvaluatedFindingType.COPYRIGHT, | ||
|
|
@@ -688,7 +719,8 @@ internal class EvaluatedModelMapper(private val input: ReporterInput) { | |
| startLine = copyrightFinding.location.startLine, | ||
| endLine = copyrightFinding.location.endLine, | ||
| scanResult = evaluatedScanResult, | ||
| pathExcludes = evaluatedPathExcludes | ||
| pathExcludes = evaluatedPathExcludes, | ||
| isExcludedByPathIncludes = evaluatedPathExcludes.isEmpty() && evaluatedPathIncludes.isNotEmpty() | ||
| ) | ||
| } | ||
|
|
||
|
|
@@ -699,6 +731,18 @@ internal class EvaluatedModelMapper(private val input: ReporterInput) { | |
| .filter { it.matches(licenseFinding.location.getRelativePathToRoot(id)) } | ||
| .let { [email protected](it) } | ||
|
|
||
| pathIncludes.let { [email protected](it) } | ||
|
|
||
| val evaluatedPathIncludes = if (pathIncludes.isEmpty() || pathIncludes.any { | ||
| include -> | ||
| include.matches(licenseFinding.location.getRelativePathToRoot(id)) | ||
| } | ||
| ) { | ||
| emptyList() | ||
| } else { | ||
| pathIncludes | ||
| } | ||
|
|
||
| findings += EvaluatedFinding( | ||
| type = EvaluatedFindingType.LICENSE, | ||
| license = actualLicense, | ||
|
|
@@ -707,7 +751,8 @@ internal class EvaluatedModelMapper(private val input: ReporterInput) { | |
| startLine = licenseFinding.location.startLine, | ||
| endLine = licenseFinding.location.endLine, | ||
| scanResult = evaluatedScanResult, | ||
| pathExcludes = evaluatedPathExcludes | ||
| pathExcludes = evaluatedPathExcludes, | ||
| isExcludedByPathIncludes = evaluatedPathExcludes.isEmpty() && evaluatedPathIncludes.isNotEmpty() | ||
| ) | ||
| } | ||
| } | ||
|
|
@@ -772,6 +817,12 @@ internal class EvaluatedModelMapper(private val input: ReporterInput) { | |
| ) | ||
| } | ||
|
|
||
| return copy(config = config.copy(excludes = excludes, resolutions = resolutions)) | ||
| val includes = with(config.includes) { | ||
| copy( | ||
| paths = paths.map { pathIncludes.addIfRequired(it) } | ||
| ) | ||
| } | ||
|
|
||
| return copy(config = config.copy(excludes = excludes, includes = includes, resolutions = resolutions)) | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think there is a problem here:
pathIncludes.isEmpty()can mean two things:I wonder if for the case that no path includes are defined at all,
Includesshould return a default path include which matches**to make the usage unambiguous.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.
I am not too sure about this.
I also experimented with
nullto reflect the tri-state, and is the end I went with a separated booleanisExcludedByPathIncludesinEvaluatedFinding.Maybe we can discuss this in the Community meeting.
Uh oh!
There was an error while loading. Please reload this page.
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.
Am I right that semantics is as follows: A file is included, if it is not matched by any exclude
ORif it is matched by at least one include and an arbitrary amount of excludes?Uh oh!
There was an error while loading. Please reload this page.
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.
No, excludes always win. A file is included when: (there are no includes defined (which means include all)
ORit is matched by an include)ANDit is not matched by an exclude.