Skip to content

Commit f1eabc5

Browse files
committed
feat(model): Extends the model to capture Snippets from snippet scanners
Snippet scanners such as ScanOSS [1] and FossID [2] can identify code snippets potentially coming from a third party source. To do so, they scan the Internet for source code and build a Knowledge Base (KB). Then, the source code to check for snippets is scanned and compared against this KB. Snippet Findings are not License nor Copyright findings as a human operator needs to review them and either accept or flag them as false positives. Therefore, this commit adds a new property ORT data model in the `ScanSummary` to carry these snippet findings. This model has been created by comparing the results from FossID and ScanOSS and trying to find a common abstraction. This is currently the minimal model required to handle snippets. Further properties will be added in the future. Blackduck [3] is another scanner considered for integration in ORT [4] which supports snippets. However since it does not deliver snippets through its API, it was not considered when designing the snippet Data model for ORT. Fixes: #3265. [1]: https://www.scanoss.com/ [2]: https://fossid.com/ [3]: https://www.synopsys.com/software-integrity/security-testing/software-composition-analysis.html [4]: #4632 Signed-off-by: Nicolas Nobelis <[email protected]>
1 parent e584873 commit f1eabc5

File tree

4 files changed

+89
-2
lines changed

4 files changed

+89
-2
lines changed

model/src/main/kotlin/ScanSummary.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import java.util.SortedSet
2929

3030
import org.ossreviewtoolkit.model.config.LicenseFilePatterns
3131
import org.ossreviewtoolkit.model.utils.RootLicenseMatcher
32+
import org.ossreviewtoolkit.model.utils.SnippetFinding
3233
import org.ossreviewtoolkit.utils.common.FileMatcher
3334
import org.ossreviewtoolkit.utils.spdx.SpdxExpression
3435

@@ -66,6 +67,12 @@ data class ScanSummary(
6667
@JsonProperty("copyrights")
6768
val copyrightFindings: SortedSet<CopyrightFinding>,
6869

70+
/**
71+
* The detected snippet findings, aggregated per file of the source code repository being scanned.
72+
*/
73+
@JsonProperty("snippets")
74+
val snippetFindings: Map<String, Set<SnippetFinding>> = emptyMap(),
75+
6976
/**
7077
* The list of issues that occurred during the scan. This property is not serialized if the list is empty to reduce
7178
* the size of the result file. If there are no issues at all, [ScannerRun.hasIssues] already contains that
@@ -84,7 +91,8 @@ data class ScanSummary(
8491
endTime = Instant.EPOCH,
8592
packageVerificationCode = "",
8693
licenseFindings = sortedSetOf(),
87-
copyrightFindings = sortedSetOf()
94+
copyrightFindings = sortedSetOf(),
95+
snippetFindings = emptyMap()
8896
)
8997
}
9098

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright (C) 2023 The ORT Project Authors (see <https://github.com/oss-review-toolkit/ort/blob/main/NOTICE>)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
* License-Filename: LICENSE
18+
*/
19+
20+
package org.ossreviewtoolkit.model.utils
21+
22+
import org.ossreviewtoolkit.model.TextLocation
23+
import org.ossreviewtoolkit.utils.spdx.SpdxExpression
24+
25+
/**
26+
* A class representing a snippet finding. A snippet finding is a code snippet of [artifact] and [version], with the
27+
* following [licenses], matching the code being scanned.
28+
* It is meant to be reviewed by an operator as it could be a false positive.
29+
*/
30+
data class SnippetFinding(
31+
/**
32+
* The author/vendor of the component the code snippet is commit from.
33+
*/
34+
val author: String,
35+
/**
36+
* The artifact name of the component the code snippet is commit from.
37+
*/
38+
val artifact: String,
39+
/**
40+
* The version of the component the code snippet is commit from.
41+
*/
42+
val version: String,
43+
/**
44+
* The license(s) of the component the code snippet is commit from.
45+
*/
46+
val licenses: Set<SpdxExpression>,
47+
/**
48+
* The matching score between the code being scanned and the code snippet. This is scanner specific (e.g. for
49+
* ScanOSS this is a percentage).
50+
*/
51+
val score: Float,
52+
53+
/**
54+
* The text location in the scanned source file where the snippet has matched.
55+
*/
56+
val sourceLocation: TextLocation,
57+
58+
/**
59+
* The text location in the snippet that has matched.
60+
*/
61+
val snippetLocation: TextLocation
62+
) : Comparable<SnippetFinding> {
63+
companion object {
64+
private val COMPARATOR =
65+
compareBy<SnippetFinding>(
66+
{ it.author },
67+
{ it.artifact },
68+
{ it.version },
69+
{ it.licenses.toString() }
70+
).thenByDescending { it.score }
71+
}
72+
73+
override fun compareTo(other: SnippetFinding) = COMPARATOR.compare(this, other)
74+
}

scanner/src/funTest/assets/dummy-expected-output-for-analyzer-result.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ scanner:
237237
package_verification_code: ""
238238
licenses: []
239239
copyrights: []
240+
snippets: {}
240241
issues:
241242
- timestamp: "1970-01-01T00:00:00Z"
242243
source: "scanner"
@@ -282,6 +283,7 @@ scanner:
282283
start_line: -1
283284
end_line: -1
284285
copyrights: []
286+
snippets: {}
285287
Maven:org.apache.commons:commons-lang3:3.5:
286288
- provenance:
287289
source_artifact:
@@ -309,6 +311,7 @@ scanner:
309311
start_line: -1
310312
end_line: -1
311313
copyrights: []
314+
snippets: {}
312315
Maven:org.apache.commons:commons-text:1.1:
313316
- provenance:
314317
source_artifact:
@@ -336,6 +339,7 @@ scanner:
336339
start_line: -1
337340
end_line: -1
338341
copyrights: []
342+
snippets: {}
339343
Maven:org.hamcrest:hamcrest-core:1.3:
340344
- provenance:
341345
source_artifact:
@@ -363,6 +367,7 @@ scanner:
363367
start_line: -1
364368
end_line: -1
365369
copyrights: []
370+
snippets: {}
366371
storage_stats:
367372
num_reads: 0
368373
num_hits: 0

scanner/src/main/kotlin/scanners/fossid/FossId.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ class FossId internal constructor(
214214
endTime: Instant = Instant.now(),
215215
issue: Issue
216216
) = ScanSummary(
217-
startTime, endTime, "", sortedSetOf(), sortedSetOf(), listOf(issue)
217+
startTime, endTime, "", sortedSetOf(), sortedSetOf(), issues = listOf(issue)
218218
)
219219

220220
override fun scanPackage(pkg: Package, context: ScanContext): ScanResult {

0 commit comments

Comments
 (0)