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

EvaluatedModel: Fix-up path excludes serialization #8566

Merged
merged 2 commits into from
Apr 26, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ path_excludes:
pattern: "**/*.java"
reason: "EXAMPLE_OF"
comment: "These are example files."
- _id: 2
pattern: "analyzer/src/funTest/assets/projects/synthetic/gradle/lib/excluded-file.dat"
reason: "DATA_FILE_OF"
scope_excludes:
- _id: 0
pattern: "testCompile"
Expand Down Expand Up @@ -976,9 +979,7 @@ repository:
paths:
- 0
- 1
- _id: 2
pattern: "analyzer/src/funTest/assets/projects/synthetic/gradle/lib/excluded-file.dat"
reason: "DATA_FILE_OF"
- 2
scopes:
- 0
resolutions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
"pattern" : "**/*.java",
"reason" : "EXAMPLE_OF",
"comment" : "These are example files."
}, {
"_id" : 2,
"pattern" : "analyzer/src/funTest/assets/projects/synthetic/gradle/lib/excluded-file.dat",
"reason" : "DATA_FILE_OF"
} ],
"scope_excludes" : [ {
"_id" : 0,
Expand Down Expand Up @@ -1073,11 +1077,7 @@
},
"config" : {
"excludes" : {
"paths" : [ 0, 1, {
"_id" : 2,
"pattern" : "analyzer/src/funTest/assets/projects/synthetic/gradle/lib/excluded-file.dat",
"reason" : "DATA_FILE_OF"
} ],
"paths" : [ 0, 1, 2 ],
"scopes" : [ 0 ]
},
"resolutions" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ path_excludes:
pattern: "**/*.java"
reason: "EXAMPLE_OF"
comment: "These are example files."
- _id: 2
pattern: "analyzer/src/funTest/assets/projects/synthetic/gradle/lib/excluded-file.dat"
reason: "DATA_FILE_OF"
scope_excludes:
- _id: 0
pattern: "testCompile"
Expand Down Expand Up @@ -980,9 +983,7 @@ repository:
paths:
- 0
- 1
- _id: 2
pattern: "analyzer/src/funTest/assets/projects/synthetic/gradle/lib/excluded-file.dat"
reason: "DATA_FILE_OF"
- 2
scopes:
- 0
resolutions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ internal class EvaluatedModelMapper(private val input: ReporterInput) {
vulnerabilitiesResolutions = vulnerabilitiesResolutions,
vulnerabilities = vulnerabilities,
statistics = with(input) { getStatistics(ortResult, licenseInfoResolver, ortConfig) },
repository = input.ortResult.repository.deduplicateResolutions(),
repository = input.ortResult.repository.deduplicateResolutionsAndExcludes(),
severeIssueThreshold = input.ortConfig.severeIssueThreshold,
severeRuleViolationThreshold = input.ortConfig.severeRuleViolationThreshold,
repositoryConfiguration = input.ortResult.repository.config.toYaml(),
Expand Down Expand Up @@ -724,23 +724,26 @@ internal class EvaluatedModelMapper(private val input: ReporterInput) {
values.map { addIfRequired(it) }.distinct()

/**
* Return a copy of the [RepositoryConfiguration] with [Resolutions] that refer to the same instances as the
* [ResolvedConfiguration] for equal [Resolutions]. This is required for the [EvaluatedModel] to contained indexed
* references instead of duplicate [Resolutions].
* Return a copy of the [RepositoryConfiguration] with [Resolutions] and [Excludes] that refer to the same instances
* as the [ResolvedConfiguration] for equal entries. This is required for the [EvaluatedModel] to contain indexed
* entries instead of duplicate ones.
*/
private fun Repository.deduplicateResolutions(): Repository {
private fun Repository.deduplicateResolutionsAndExcludes(): Repository {
val resolutions = with(config.resolutions) {
copy(
issues = issues.map { resolution -> issueResolutions.find { resolution == it } ?: resolution },
ruleViolations = ruleViolations.map { resolution ->
ruleViolationResolutions.find { resolution == it } ?: resolution
},
vulnerabilities = vulnerabilities.map { resolution ->
vulnerabilitiesResolutions.find { resolution == it } ?: resolution
}
issues = issues.map { issueResolutions.addIfRequired(it) },
ruleViolations = ruleViolations.map { ruleViolationResolutions.addIfRequired(it) },
vulnerabilities = vulnerabilities.map { vulnerabilitiesResolutions.addIfRequired(it) }
)
}

val excludes = with(config.excludes) {
copy(
paths = paths.map { pathExcludes.addIfRequired(it) },
scopes = scopes.map { scopeExcludes.addIfRequired(it) }
)
}

return copy(config = config.copy(resolutions = resolutions))
return copy(config = config.copy(excludes = excludes, resolutions = resolutions))
}
}
Loading