Skip to content

Commit c377a4c

Browse files
committed
fix(reporter): Limit the reporting to results without VCS path
Currently, when there is two packages with the same provenance, the scan results are duplicated. This is because FossID does not support VCS path and repository is scanned once, and results are then duplicated for each package with the same provenance. This is a temporary fix until scan results are stored by provenance. Signed-off-by: Nicolas Nobelis <[email protected]>
1 parent d5cf793 commit c377a4c

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-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: 21 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
@@ -51,6 +55,7 @@ import org.ossreviewtoolkit.model.licenses.ResolvedLicenseInfo
5155
import org.ossreviewtoolkit.model.licenses.filterExcluded
5256
import org.ossreviewtoolkit.reporter.Reporter
5357
import org.ossreviewtoolkit.reporter.ReporterInput
58+
import org.ossreviewtoolkit.utils.common.PATH_STRING_COMPARATOR
5459
import org.ossreviewtoolkit.utils.common.expandTilde
5560
import org.ossreviewtoolkit.utils.spdx.SpdxConstants
5661
import org.ossreviewtoolkit.utils.spdx.model.SpdxLicenseChoice
@@ -325,6 +330,22 @@ class FreemarkerTemplateProcessor(
325330
fun collectLicenses(snippetFindings: Collection<SnippetFinding>) : Set<String> =
326331
snippetFindings.map { it.snippet.licenses.toString() }.toSet()
327332

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

0 commit comments

Comments
 (0)