Skip to content

Commit 8f4060c

Browse files
committed
fix(scanoss): Exclude identified snippets from SnippetFindings
Modify `generateSummary()` to filter out snippets that are already identified. Signed-off-by: Agustin Isasmendi <[email protected]>
1 parent 3a175c2 commit 8f4060c

File tree

3 files changed

+155
-1
lines changed

3 files changed

+155
-1
lines changed

plugins/scanners/scanoss/src/main/kotlin/ScanOssResultParser.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ package org.ossreviewtoolkit.plugins.scanners.scanoss
2222
import com.scanoss.dto.ScanFileDetails
2323
import com.scanoss.dto.ScanFileResult
2424
import com.scanoss.dto.enums.MatchType
25+
import com.scanoss.dto.enums.StatusType
2526

2627
import java.lang.invoke.MethodHandles
2728
import java.time.Instant
@@ -63,7 +64,13 @@ internal fun generateSummary(startTime: Instant, endTime: Instant, results: List
6364

6465
MatchType.snippet -> {
6566
val localFile = requireNotNull(result.filePath)
66-
snippetFindings += createSnippetFindings(details, localFile)
67+
if (details.status == StatusType.pending) {
68+
snippetFindings += createSnippetFindings(details, localFile)
69+
} else {
70+
logger.warn { "File '$localFile' is identified, not including on snippet findings" }
71+
licenseFindings += getLicenseFindings(details, result.filePath)
72+
copyrightFindings += getCopyrightFindings(details, result.filePath)
73+
}
6774
}
6875

6976
MatchType.none -> {

plugins/scanners/scanoss/src/test/kotlin/ScanOssResultParserTest.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,5 +224,19 @@ class ScanOssResultParserTest : WordSpec({
224224
sourceLocation.endLine shouldBe 24
225225
}
226226
}
227+
228+
"should exclude identified snippets from snippet findings" {
229+
// The scanoss-identified-snippet.json contains two snippets, but one is identified.
230+
// Only unidentified snippets should be included in the SnippetFindings.
231+
val results = readResource("/scanoss-identified-snippet.json").let {
232+
JsonUtils.toScanFileResultsFromObject(JsonUtils.toJsonObject(it))
233+
}
234+
235+
val time = Instant.now()
236+
val summary = generateSummary(time, time, results)
237+
238+
// Should have only one finding because the identified snippet is excluded
239+
summary.snippetFindings should haveSize(1)
240+
}
227241
}
228242
})
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
{
2+
"main.c": [
3+
{
4+
"id": "snippet",
5+
"lines": "14-22",
6+
"oss_lines": "34-42",
7+
"matched": "19%",
8+
"file_hash": "4597ef1de00849bb96d42e78f2cfc3a7",
9+
"source_hash": "f5aef06745de4d711838ea21198f2fc1",
10+
"quality": [
11+
{
12+
"score": "4/5",
13+
"source": "best_practices"
14+
}
15+
],
16+
"cryptography": [],
17+
"purl": [
18+
"pkg:sourceforge/check"
19+
],
20+
"vendor": "check",
21+
"component": "check",
22+
"version": "0.8.1",
23+
"latest": "0.8.1",
24+
"url": "https://sourceforge.net/projects/check",
25+
"status": "identified",
26+
"release_date": "2002-03-02",
27+
"file": "src/check_error.c",
28+
"url_hash": "d81953e1dca4c498140c44f5d6fa92d6",
29+
"licenses": [
30+
{
31+
"name": "LGPL-2.1-or-later",
32+
"patent_hints": "yes",
33+
"copyleft": "yes",
34+
"checklist_url": "https://www.osadl.org/fileadmin/checklists/unreflicenses/LGPL-2.1-or-later.txt",
35+
"incompatible_with": "Apache-1.0, Apache-1.1, Apache-2.0, BSD-4-Clause, BSD-4-Clause-UC, BSD-4.3TAHOE, ECL-2.0, FTL, IJG, LicenseRef-scancode-bsla-no-advert, Minpack, OpenSSL, PHP-3.01, Python-2.0, zlib-acknowledgement, XFree86-1.1",
36+
"osadl_updated": "2025-02-10T14:26:00+0000",
37+
"source": "scancode",
38+
"url": "https://spdx.org/licenses/LGPL-2.1-or-later.html"
39+
},
40+
{
41+
"name": "LGPL-2.1-or-later",
42+
"patent_hints": "yes",
43+
"copyleft": "yes",
44+
"checklist_url": "https://www.osadl.org/fileadmin/checklists/unreflicenses/LGPL-2.1-or-later.txt",
45+
"incompatible_with": "Apache-1.0, Apache-1.1, Apache-2.0, BSD-4-Clause, BSD-4-Clause-UC, BSD-4.3TAHOE, ECL-2.0, FTL, IJG, LicenseRef-scancode-bsla-no-advert, Minpack, OpenSSL, PHP-3.01, Python-2.0, zlib-acknowledgement, XFree86-1.1",
46+
"osadl_updated": "2025-02-10T14:26:00+0000",
47+
"source": "file_header",
48+
"url": "https://spdx.org/licenses/LGPL-2.1-or-later.html"
49+
}
50+
],
51+
"url_stats": {},
52+
"dependencies": [],
53+
"copyrights": [
54+
{
55+
"name": "Copyright (C) 2001; 2002 Arien Malec",
56+
"source": "file_header"
57+
},
58+
{
59+
"name": "Copyright (c) 2001; 2002 Arien Malec",
60+
"source": "scancode"
61+
}
62+
],
63+
"vulnerabilities": [],
64+
"server": {
65+
"version": "5.4.10",
66+
"kb_version": {
67+
"monthly": "25.04",
68+
"daily": "25.05.07"
69+
},
70+
"hostname": "d2",
71+
"flags": "16384",
72+
"elapsed": "0.107563s"
73+
}
74+
}
75+
],
76+
"hung_task.c": [
77+
{
78+
"component": "proton_bluecross",
79+
"file": "kernel/hung_task.c",
80+
"file_hash": "581734935cfbe570d280a1265aaa2a6b",
81+
"file_url": "https://api.scanoss.com/file_contents/581734935cfbe570d280a1265aaa2a6b",
82+
"id": "snippet",
83+
"latest": "17",
84+
"licenses": [
85+
{
86+
"checklist_url": "https://www.osadl.org/fileadmin/checklists/unreflicenses/GPL-2.0-only.txt",
87+
"copyleft": "yes",
88+
"incompatible_with": "Apache-1.0, Apache-1.1, Apache-2.0, BSD-4-Clause, BSD-4-Clause-UC, BSD-4.3TAHOE, ECL-2.0, FTL, IJG, LicenseRef-scancode-bsla-no-advert, Minpack, OpenSSL, PHP-3.01, Python-2.0, zlib-acknowledgement, XFree86-1.1",
89+
"name": "GPL-2.0-only",
90+
"osadl_updated": "2025-02-10T14:26:00+0000",
91+
"patent_hints": "yes",
92+
"source": "scancode",
93+
"url": "https://spdx.org/licenses/GPL-2.0-only.html"
94+
},
95+
{
96+
"name": "GPL-2.0-only WITH Linux-syscall-note",
97+
"source": "scancode",
98+
"url": "https://spdx.org/licenses/GPL-2.0-only WITH Linux-syscall-note.html"
99+
},
100+
{
101+
"checklist_url": "https://www.osadl.org/fileadmin/checklists/unreflicenses/GPL-2.0-only.txt",
102+
"copyleft": "yes",
103+
"incompatible_with": "Apache-1.0, Apache-1.1, Apache-2.0, BSD-4-Clause, BSD-4-Clause-UC, BSD-4.3TAHOE, ECL-2.0, FTL, IJG, LicenseRef-scancode-bsla-no-advert, Minpack, OpenSSL, PHP-3.01, Python-2.0, zlib-acknowledgement, XFree86-1.1",
104+
"name": "GPL-2.0-only",
105+
"osadl_updated": "2025-02-10T14:26:00+0000",
106+
"patent_hints": "yes",
107+
"source": "scancode",
108+
"url": "https://spdx.org/licenses/GPL-2.0-only.html"
109+
}
110+
],
111+
"lines": "12-150",
112+
"matched": "35%",
113+
"oss_lines": "10-148",
114+
"purl": [
115+
"pkg:github/kdrag0n/proton_bluecross"
116+
],
117+
"release_date": "2019-02-21",
118+
"server": {
119+
"kb_version": {
120+
"daily": "25.03.27",
121+
"monthly": "25.03"
122+
},
123+
"version": "5.4.10"
124+
},
125+
"source_hash": "45dd1e50621a8a32f88fbe0251a470ab",
126+
"status": "pending",
127+
"url": "https://github.com/kdrag0n/proton_bluecross",
128+
"url_hash": "a9c1c67f0930dc42dbd40c29e565bcdd",
129+
"vendor": "kdrag0n",
130+
"version": "15"
131+
}
132+
]
133+
}

0 commit comments

Comments
 (0)