Skip to content

Commit

Permalink
fix(evaluated-model): Fix inconsistency with path exclude serialization
Browse files Browse the repository at this point in the history
Consistently refer path excludes (via indexes into the `pathExcludes`
list) from the serialized repository configuration to simplify its
parsing. Therefore add all path excludes to `pathExcludes`. While at it,
do the same for resolutions for consistency.

Signed-off-by: Frank Viernau <frank_viernau@epam.com>
  • Loading branch information
fviernau committed Apr 26, 2024
1 parent e098d42 commit c3c6325
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 24 deletions.
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 @@ -1103,9 +1106,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 @@ -1198,11 +1202,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 @@ -1107,9 +1110,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 contain indexed
* references instead of duplicate [Resolutions].
* Return a copy of the [RepositoryConfiguration] with [Resolutions] and [Excludes] that refer to the same instances

Check warning on line 727 in plugins/reporters/evaluated-model/src/main/kotlin/EvaluatedModelMapper.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unresolved reference in KDoc

Cannot resolve symbol 'Excludes'
* 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))
}
}

0 comments on commit c3c6325

Please sign in to comment.