Skip to content

Commit bee55e3

Browse files
nnobelisoheger-bosch
authored andcommitted
feat(fossid-webapp): Add an issue when the snippet limit has been reached
Also display this issue in the FossID snippet report. In case the limit has been exactly reached when listing the snippets of a pending file, adding an issue is the only possibility for the user to know that there may be other snippets beyond the limit, requiring some snippet choices and a second scanner run. A strict comparison could be used instead but deciding to create the issue would then require peeking the next snippet results, which would defeat the optimization brought by the introduction of the limit. Signed-off-by: Nicolas Nobelis <[email protected]>
1 parent 9223e90 commit bee55e3

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

plugins/reporters/fossid/src/main/resources/templates/asciidoc/fossid_snippet.ftl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ List of all the provenances with their files and snippets.
3131

3232
[#if scanResult.scanner.name != "FossId"] [#continue] [/#if]
3333

34+
[#assign snippetsLimitIssue = helper.getSnippetsLimitIssue()]
35+
36+
[#if snippetsLimitIssue??]
37+
[WARNING]
38+
====
39+
${snippetsLimitIssue}
40+
====
41+
[/#if]
42+
3443
[#if scanResult.provenance.vcsInfo??]
3544
[#assign url = scanResult.provenance.vcsInfo.url]
3645
[#else]

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ class FreemarkerTemplateProcessor(
198198
/**
199199
* A collection of helper functions for the Freemarker templates.
200200
*/
201+
@Suppress("TooManyFunctions")
201202
class TemplateHelper(private val input: ReporterInput) {
202203
/**
203204
* Return only those [packages] that are a dependency of at least one of the provided [projects][projectIds].
@@ -277,6 +278,18 @@ class FreemarkerTemplateProcessor(
277278
fun hasUnresolvedIssues(threshold: Severity = input.ortConfig.severeIssueThreshold) =
278279
input.ortResult.getOpenIssues(minSeverity = threshold).isNotEmpty()
279280

281+
/**
282+
* If there are any issue caused by reaching the snippets limit, return the text of the issue. Otherwise reuturn
283+
* 'null'.
284+
*/
285+
@Suppress("UNUSED") // This function is used in the templates.
286+
fun getSnippetsLimitIssue() =
287+
input.ortResult.scanner?.scanResults?.flatMap { result ->
288+
result.summary.issues
289+
}?.firstOrNull {
290+
it.message.contains("snippets limit")
291+
}?.message
292+
280293
/**
281294
* Return `true` if there are any unresolved and non-excluded [RuleViolation]s whose severity is equal to or
282295
* greater than the [threshold], or `false` otherwise.

plugins/scanners/fossid/src/main/kotlin/FossIdScanResults.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,16 @@ internal suspend fun mapSnippetFindings(
195195
results += mappedSnippets
196196
}
197197

198+
if (runningSnippetCount >= snippetsLimit) {
199+
issues += Issue(
200+
source = "FossId",
201+
message = "The snippets limit of $snippetsLimit has been reached. To see the possible remaining " +
202+
"snippets, please perform a snippet choice for the snippets presents in the snippet report an " +
203+
"rerun the scan.",
204+
severity = Severity.HINT
205+
)
206+
}
207+
198208
return results.also {
199209
remainingSnippetChoices.forEach { snippetChoice ->
200210
// The issue is created only if the chosen snippet does not correspond to a file marked by a previous run.

plugins/scanners/fossid/src/test/kotlin/FossIdSnippetChoiceTest.kt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,12 @@ class FossIdSnippetChoiceTest : WordSpec({
758758
}
759759

760760
summary.snippetFindings.flatMap { it.snippets } shouldHaveSize 2
761-
// todo + test issue
761+
762+
summary.issues.forAtLeastOne {
763+
it.message shouldBe "The snippets limit of 2 has been reached. To see the possible remaining " +
764+
"snippets, please perform a snippet choice for the snippets presents in the snippet report an " +
765+
"rerun the scan."
766+
}
762767
}
763768

764769
"list all the snippets of a file even if if goes over the snippets limit" {
@@ -796,6 +801,12 @@ class FossIdSnippetChoiceTest : WordSpec({
796801

797802
summary.snippetFindings shouldHaveSize 2
798803
summary.snippetFindings.flatMap { it.snippets } shouldHaveSize 3
804+
805+
summary.issues.forAtLeastOne {
806+
it.message shouldBe "The snippets limit of 2 has been reached. To see the possible remaining " +
807+
"snippets, please perform a snippet choice for the snippets presents in the snippet report an " +
808+
"rerun the scan."
809+
}
799810
}
800811

801812
"not count the chosen snippet when enforcing the snippet limits" {
@@ -840,6 +851,12 @@ class FossIdSnippetChoiceTest : WordSpec({
840851
summary.snippetFindings.drop(1).forEach {
841852
it.sourceLocation.path shouldBe FILE_2
842853
}
854+
855+
summary.issues.forAtLeastOne {
856+
it.message shouldBe "The snippets limit of 2 has been reached. To see the possible remaining " +
857+
"snippets, please perform a snippet choice for the snippets presents in the snippet report an " +
858+
"rerun the scan."
859+
}
843860
}
844861
}
845862
})

0 commit comments

Comments
 (0)