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

Minor StaticHTML reporter code improvements #7916

Merged
merged 3 commits into from
Nov 22, 2023
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
2 changes: 1 addition & 1 deletion reporter/src/main/kotlin/ReportTableModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ data class ReportTableModel(
scopes = scopes.zipWithDefault(other.scopes, sortedMapOf()) { left, right ->
left.zipWithCollections(right).toSortedMap()
}.toSortedMap(),
concludedLicenses = (concludedLicenses + other.concludedLicenses),
concludedLicenses = concludedLicenses + other.concludedLicenses,
declaredLicenses = declaredLicenses + other.declaredLicenses,
detectedLicenses = (detectedLicenses + other.detectedLicenses).toSortedSet(),
analyzerIssues = analyzerIssues.zipWithCollections(other.analyzerIssues).toSortedMap(),
Expand Down
79 changes: 40 additions & 39 deletions reporter/src/main/kotlin/ReportTableModelMapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ object ReportTableModelMapper {

val packageForId = ortResult.getPackage(id)?.metadata ?: ortResult.getProject(id)?.toPackage()

DependencyRow(
val row = DependencyRow(
id = id,
sourceArtifact = packageForId?.sourceArtifact.orEmpty(),
vcsInfo = packageForId?.vcsProcessed.orEmpty(),
Expand All @@ -101,56 +101,57 @@ object ReportTableModelMapper {
it.toResolvableIssue(resolutionProvider, howToFixTextProvider)
},
scanIssues = scanIssues.map { it.toResolvableIssue(resolutionProvider, howToFixTextProvider) }
).also { row ->
val isRowExcluded = pathExcludes.isNotEmpty()
|| (row.scopes.isNotEmpty() && row.scopes.all { it.value.isNotEmpty() })
)

val isRowExcluded = ortResult.isExcluded(row.id)

val nonExcludedAnalyzerIssues = if (isRowExcluded) emptyList() else row.analyzerIssues
val nonExcludedScanIssues = if (isRowExcluded) emptyList() else row.scanIssues

val summaryRow = SummaryRow(
id = row.id,
scopes = sortedMapOf(project.id to row.scopes),
concludedLicenses = row.concludedLicense?.let { setOf(it) }.orEmpty(),
declaredLicenses = row.declaredLicenses.mapTo(mutableSetOf()) { it.license.toString() },
detectedLicenses = row.detectedLicenses.mapTo(sortedSetOf()) { it.license.toString() },
analyzerIssues = if (nonExcludedAnalyzerIssues.isNotEmpty()) {
sortedMapOf(project.id to nonExcludedAnalyzerIssues)
} else {
sortedMapOf()
},
scanIssues = if (nonExcludedScanIssues.isNotEmpty()) {
sortedMapOf(project.id to nonExcludedScanIssues)
} else {
sortedMapOf()
}
)

summaryRows[row.id] = summaryRows[row.id]?.merge(summaryRow) ?: summaryRow

val nonExcludedAnalyzerIssues = if (isRowExcluded) emptyList() else row.analyzerIssues
val nonExcludedScanIssues = if (isRowExcluded) emptyList() else row.scanIssues
val unresolvedAnalyzerIssues = row.analyzerIssues.filterUnresolved()
val unresolvedScanIssues = row.scanIssues.filterUnresolved()

val summaryRow = SummaryRow(
if ((unresolvedAnalyzerIssues.isNotEmpty() || unresolvedScanIssues.isNotEmpty())
&& !isRowExcluded
) {
val issueRow = IssueRow(
id = row.id,
scopes = sortedMapOf(project.id to row.scopes),
concludedLicenses = row.concludedLicense?.let { setOf(it) }.orEmpty(),
declaredLicenses = row.declaredLicenses.mapTo(mutableSetOf()) { it.license.toString() },
detectedLicenses = row.detectedLicenses.mapTo(sortedSetOf()) { it.license.toString() },
analyzerIssues = if (nonExcludedAnalyzerIssues.isNotEmpty()) {
sortedMapOf(project.id to nonExcludedAnalyzerIssues)
analyzerIssues = if (unresolvedAnalyzerIssues.isNotEmpty()) {
sortedMapOf(project.id to unresolvedAnalyzerIssues)
} else {
sortedMapOf()
},
scanIssues = if (nonExcludedScanIssues.isNotEmpty()) {
sortedMapOf(project.id to nonExcludedScanIssues)
scanIssues = if (unresolvedScanIssues.isNotEmpty()) {
sortedMapOf(project.id to unresolvedScanIssues)
} else {
sortedMapOf()
}
)

summaryRows[row.id] = summaryRows[row.id]?.merge(summaryRow) ?: summaryRow

val unresolvedAnalyzerIssues = row.analyzerIssues.filterUnresolved()
val unresolvedScanIssues = row.scanIssues.filterUnresolved()

if ((unresolvedAnalyzerIssues.isNotEmpty() || unresolvedScanIssues.isNotEmpty())
&& !isRowExcluded
) {
val issueRow = IssueRow(
id = row.id,
analyzerIssues = if (unresolvedAnalyzerIssues.isNotEmpty()) {
sortedMapOf(project.id to unresolvedAnalyzerIssues)
} else {
sortedMapOf()
},
scanIssues = if (unresolvedScanIssues.isNotEmpty()) {
sortedMapOf(project.id to unresolvedScanIssues)
} else {
sortedMapOf()
}
)

issueSummaryRows[row.id] = issueSummaryRows[issueRow.id]?.merge(issueRow) ?: issueRow
}
issueSummaryRows[row.id] = issueSummaryRows[issueRow.id]?.merge(issueRow) ?: issueRow
}

row
}

ProjectTable(
Expand Down