From 5792c9f3d03037c892de64452107c65ce0626a06 Mon Sep 17 00:00:00 2001 From: Nicolas Nobelis Date: Fri, 3 May 2024 15:41:50 +0200 Subject: [PATCH] feat(fossid-webapp): Add an issue when the snippet limit has been reached Also display this issue in the FossID snippet report. Signed-off-by: Nicolas Nobelis --- .../templates/asciidoc/fossid_snippet.ftl | 9 +++++++++ .../kotlin/FreemarkerTemplateProcessor.kt | 13 +++++++++++++ .../src/main/kotlin/FossIdScanResults.kt | 10 ++++++++++ .../test/kotlin/FossIdSnippetChoiceTest.kt | 19 ++++++++++++++++++- 4 files changed, 50 insertions(+), 1 deletion(-) diff --git a/plugins/reporters/fossid/src/main/resources/templates/asciidoc/fossid_snippet.ftl b/plugins/reporters/fossid/src/main/resources/templates/asciidoc/fossid_snippet.ftl index 412b595f33abb..0dd0f2e5a0bce 100644 --- a/plugins/reporters/fossid/src/main/resources/templates/asciidoc/fossid_snippet.ftl +++ b/plugins/reporters/fossid/src/main/resources/templates/asciidoc/fossid_snippet.ftl @@ -31,6 +31,15 @@ List of all the provenances with their files and snippets. [#if scanResult.scanner.name != "FossId"] [#continue] [/#if] +[#assign snippetsLimitIssue = helper.getSnippetsLimitIssue()] + +[#if snippetsLimitIssue??] +[WARNING] +==== +${snippetsLimitIssue} +==== +[/#if] + [#if scanResult.provenance.vcsInfo??] [#assign url = scanResult.provenance.vcsInfo.url] [#else] diff --git a/plugins/reporters/freemarker/src/main/kotlin/FreemarkerTemplateProcessor.kt b/plugins/reporters/freemarker/src/main/kotlin/FreemarkerTemplateProcessor.kt index 6d63e174effd4..5efdcf682646a 100644 --- a/plugins/reporters/freemarker/src/main/kotlin/FreemarkerTemplateProcessor.kt +++ b/plugins/reporters/freemarker/src/main/kotlin/FreemarkerTemplateProcessor.kt @@ -198,6 +198,7 @@ class FreemarkerTemplateProcessor( /** * A collection of helper functions for the Freemarker templates. */ + @Suppress("TooManyFunctions") class TemplateHelper(private val input: ReporterInput) { /** * Return only those [packages] that are a dependency of at least one of the provided [projects][projectIds]. @@ -277,6 +278,18 @@ class FreemarkerTemplateProcessor( fun hasUnresolvedIssues(threshold: Severity = input.ortConfig.severeIssueThreshold) = input.ortResult.getOpenIssues(minSeverity = threshold).isNotEmpty() + /** + * If there are any issue caused by reaching the snippets limit, return the text of the issue. Otherwise reuturn + * 'null'. + */ + @Suppress("UNUSED") // This function is used in the templates. + fun getSnippetsLimitIssue() = + input.ortResult.scanner?.scanResults?.flatMap { result -> + result.summary.issues + }?.firstOrNull { + it.message.contains("snippets limit") + }?.message + /** * Return `true` if there are any unresolved and non-excluded [RuleViolation]s whose severity is equal to or * greater than the [threshold], or `false` otherwise. diff --git a/plugins/scanners/fossid/src/main/kotlin/FossIdScanResults.kt b/plugins/scanners/fossid/src/main/kotlin/FossIdScanResults.kt index 5e32ea79570a6..546b0075d9149 100644 --- a/plugins/scanners/fossid/src/main/kotlin/FossIdScanResults.kt +++ b/plugins/scanners/fossid/src/main/kotlin/FossIdScanResults.kt @@ -191,6 +191,16 @@ internal fun mapSnippetFindings( results += mappedSnippets } + if (runningSnippetCount > snippetsLimit) { + issues += Issue( + source = "FossId", + message = "The snippets limit of $snippetsLimit has been reached. To see the possible remaining " + + "snippets, please perform a snippet choice for the snippets presents in the snippet report an " + + "rerun the scan.", + severity = Severity.HINT + ) + } + return results.also { remainingSnippetChoices.forEach { snippetChoice -> // The issue is created only if the chosen snippet does not correspond to a file marked by a previous run. diff --git a/plugins/scanners/fossid/src/test/kotlin/FossIdSnippetChoiceTest.kt b/plugins/scanners/fossid/src/test/kotlin/FossIdSnippetChoiceTest.kt index e0f83a92e87b6..82aa8545e2342 100644 --- a/plugins/scanners/fossid/src/test/kotlin/FossIdSnippetChoiceTest.kt +++ b/plugins/scanners/fossid/src/test/kotlin/FossIdSnippetChoiceTest.kt @@ -758,7 +758,12 @@ class FossIdSnippetChoiceTest : WordSpec({ } summary.snippetFindings.flatMap { it.snippets } shouldHaveSize 2 - // todo + test issue + + summary.issues.forAtLeastOne { + it.message shouldBe "The snippets limit of 2 has been reached. To see the possible remaining " + + "snippets, please perform a snippet choice for the snippets presents in the snippet report an " + + "rerun the scan." + } } "list all the snippets of a file even if if goes over the snippets limit" { @@ -796,6 +801,12 @@ class FossIdSnippetChoiceTest : WordSpec({ summary.snippetFindings shouldHaveSize 2 summary.snippetFindings.flatMap { it.snippets } shouldHaveSize 3 + + summary.issues.forAtLeastOne { + it.message shouldBe "The snippets limit of 2 has been reached. To see the possible remaining " + + "snippets, please perform a snippet choice for the snippets presents in the snippet report an " + + "rerun the scan." + } } "not count the chosen snippet when enforcing the snippet limits" { @@ -840,6 +851,12 @@ class FossIdSnippetChoiceTest : WordSpec({ summary.snippetFindings.drop(1).forEach { it.sourceLocation.path shouldBe FILE_2 } + + summary.issues.forAtLeastOne { + it.message shouldBe "The snippets limit of 2 has been reached. To see the possible remaining " + + "snippets, please perform a snippet choice for the snippets presents in the snippet report an " + + "rerun the scan." + } } } })