Skip to content

Commit 8fb435c

Browse files
committed
fix(reporter): Limit the reporting to results without VCS path
Currently, when there are two packages with the same provenance, the scan results are duplicated, which leads to duplication in the report too. FossID doesn't support the VCS path. Therefore, results with a VCS provenance containing a non-empty VCS path are most likely duplicates that can be safely removed. This is a temporary fix until scan results are stored by provenance. Signed-off-by: Nicolas Nobelis <[email protected]>
1 parent a38d748 commit 8fb435c

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

plugins/reporters/fossid-snippets/src/main/resources/templates/asciidoc/fossid_snippets.ftl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727

2828
= FossID Snippets
2929
List of all the packages with their files and snippets.
30-
[#list ortResult.scanResults as package, scanResults]
30+
[#assign filteredResults = helper.filterResultsByVCS(ortResult.scanResults)]
31+
[#list filteredResults as package, scanResults]
3132

3233
== Package '${package.toCoordinates()}'
33-
3434
[#list scanResults as scanResult]
3535
[#assign summary = scanResult.summary]
3636

plugins/reporters/freemarker/src/main/kotlin/FreemarkerTemplateProcessor.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,17 @@ import org.ossreviewtoolkit.model.AdvisorCapability
3333
import org.ossreviewtoolkit.model.AdvisorRecord
3434
import org.ossreviewtoolkit.model.AdvisorResult
3535
import org.ossreviewtoolkit.model.AdvisorResultFilter
36+
import org.ossreviewtoolkit.model.ArtifactProvenance
3637
import org.ossreviewtoolkit.model.Identifier
3738
import org.ossreviewtoolkit.model.Issue
3839
import org.ossreviewtoolkit.model.OrtResult
3940
import org.ossreviewtoolkit.model.Package
41+
import org.ossreviewtoolkit.model.RepositoryProvenance
4042
import org.ossreviewtoolkit.model.RuleViolation
43+
import org.ossreviewtoolkit.model.ScanResult
4144
import org.ossreviewtoolkit.model.Severity
4245
import org.ossreviewtoolkit.model.SnippetFinding
46+
import org.ossreviewtoolkit.model.UnknownProvenance
4347
import org.ossreviewtoolkit.model.Vulnerability
4448
import org.ossreviewtoolkit.model.VulnerabilityReference
4549
import org.ossreviewtoolkit.model.config.RuleViolationResolution
@@ -325,6 +329,22 @@ class FreemarkerTemplateProcessor(
325329
fun collectLicenses(snippetFindings: Collection<SnippetFinding>): Set<String> =
326330
snippetFindings.mapTo(mutableSetOf()) { it.snippet.licenses.toString() }
327331

332+
/**
333+
* Filter the scan results to remove the ones having a VCS provenance without an empty path: Since FossID does
334+
* not support support VCS path, they are most likely duplicates of other results.
335+
*/
336+
@Suppress("UNUSED") // This function is used in the templates.
337+
fun filterResultsByVCS(scanResults: Map<Identifier, List<ScanResult>>): Map<Identifier, List<ScanResult>> {
338+
return scanResults.mapValues {
339+
it.value.filter { result ->
340+
when (val provenance = result.provenance) {
341+
is ArtifactProvenance, UnknownProvenance -> true
342+
is RepositoryProvenance -> provenance.vcsInfo.path.isEmpty()
343+
}
344+
}
345+
}.filterValues { it.isNotEmpty() }
346+
}
347+
328348
/**
329349
* Return a flag indicating that issues have been encountered during the run of an advisor with the given
330350
* [capability] with at least the given [severity]. This typically means that the report is incomplete;

0 commit comments

Comments
 (0)