Skip to content

Commit aa42ab6

Browse files
committed
feat(scanoss-plugin): implement ort.yml configuration parsing & add SCANOSS snippet report generation
- Implement snippet choice functionality for SCANOSS integration - Add support for processing exclude paths from ort.yml configuration - Add dedicated SCANOSS snippet report similar to FossID reporting Signed-off-by: Agustin Isasmendi <[email protected]>
1 parent 22bc094 commit aa42ab6

File tree

13 files changed

+530
-109
lines changed

13 files changed

+530
-109
lines changed
12.7 MB
Binary file not shown.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
plugins {
21+
// Apply precompiled plugins.
22+
id("ort-plugin-conventions")
23+
}
24+
25+
dependencies {
26+
api(projects.reporter)
27+
28+
ksp(projects.reporter)
29+
30+
implementation(projects.model)
31+
implementation(projects.plugins.reporters.asciidocReporter)
32+
implementation(projects.plugins.reporters.freemarkerReporter)
33+
implementation(projects.utils.commonUtils)
34+
implementation(projects.utils.ortUtils)
35+
36+
implementation(libs.kotlinx.coroutines)
37+
38+
testImplementation(libs.mockk)
39+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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.plugins.reporters.scanoss
21+
22+
import java.io.File
23+
24+
import org.ossreviewtoolkit.plugins.api.OrtPlugin
25+
import org.ossreviewtoolkit.plugins.api.PluginDescriptor
26+
import org.ossreviewtoolkit.plugins.reporters.asciidoc.AsciiDocTemplateReporterConfig
27+
import org.ossreviewtoolkit.plugins.reporters.asciidoc.HtmlTemplateReporter
28+
import org.ossreviewtoolkit.reporter.Reporter
29+
import org.ossreviewtoolkit.reporter.ReporterFactory
30+
import org.ossreviewtoolkit.reporter.ReporterInput
31+
32+
33+
@OrtPlugin(
34+
displayName = "SCANOSS Snippet Reporter",
35+
description = "Generates a detailed report of the SCANOSS snippet findings.",
36+
factory = ReporterFactory::class
37+
)
38+
class ScanossSnippetReporter(override val descriptor: PluginDescriptor = ScanossSnippetReporterFactory.descriptor) :
39+
Reporter by delegateReporter {
40+
companion object {
41+
private val delegateReporter = HtmlTemplateReporter(
42+
ScanossSnippetReporterFactory.descriptor,
43+
AsciiDocTemplateReporterConfig(templateIds = listOf("scanoss_snippet"), templatePaths = null)
44+
)
45+
}
46+
47+
override fun generateReport(input: ReporterInput, outputDir: File): List<Result<File>> {
48+
val hasScanossResults = input.ortResult.scanner?.scanResults?.any { it.scanner.name == "SCANOSS" } == true
49+
require(hasScanossResults) { "No SCANOSS scan results have been found." }
50+
51+
return delegateReporter.generateReport(input, outputDir)
52+
}
53+
}
54+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Use Unix line endings for Freemarker templates for consistency across platforms.
2+
**/*.ftl text eol=lf
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
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+
:publisher: OSS Review Toolkit
21+
[#assign now = .now]
22+
:revdate: ${now?date?iso_local}
23+
24+
:title-page:
25+
:sectnums:
26+
:toc:
27+
28+
= SCANOSS Snippets
29+
List of all the provenances with their files and snippets.
30+
[#list ortResult.scanner.scanResults as scanResult]
31+
32+
[#--[#if scanResult.scanner.name != "FossId"] [#continue] [/#if]--]
33+
34+
[#assign snippetsLimitIssue = helper.getSnippetsLimitIssue()]
35+
36+
[#if snippetsLimitIssue?has_content]
37+
[WARNING]
38+
====
39+
${snippetsLimitIssue}
40+
====
41+
[/#if]
42+
43+
[#if scanResult.provenance.vcsInfo??]
44+
[#assign url = scanResult.provenance.vcsInfo.url]
45+
[#else]
46+
[#assign url = scanResult.provenance.sourceArtifact.url]
47+
[/#if]
48+
== Provenance '${url}'
49+
50+
[#assign summary = scanResult.summary]
51+
52+
Scan start time : ${summary.startTime} +
53+
End time : ${summary.startTime} +
54+
[#if scanResult.provenance.vcsInfo??]
55+
[#assign gitRepoUrl = url]
56+
[#assign gitRevision = scanResult.provenance.vcsInfo.revision]
57+
Git repo URL: ${gitRepoUrl} +
58+
Git revision: ${gitRevision}
59+
60+
[#if gitRepoUrl?contains("github.com")]
61+
[#assign githubBaseURL = '${gitRepoUrl?remove_ending(".git")}/blob/${gitRevision}']
62+
[/#if]
63+
[/#if]
64+
65+
[#list helper.groupSnippetsByFile(summary.snippetFindings) as filePath, snippetFindings ]
66+
67+
[#if gitRepoUrl?? && gitRepoUrl?contains("github.com")]
68+
[#assign localFileURL = '${githubBaseURL}/${filePath}[${filePath}]']
69+
[#else]
70+
[#assign localFileURL = "${filePath}"]
71+
[/#if]
72+
[#assign licenses = helper.collectLicenses(snippetFindings)]
73+
74+
*${localFileURL}* +
75+
License(s):
76+
[#list licenses as license]
77+
${license}[#sep],
78+
[/#list]
79+
80+
[#list helper.groupSnippetsBySourceLines(snippetFindings) as sourceLocation, snippetFinding]
81+
[#assign snippetCount = snippetFinding.snippets?size]
82+
83+
[width=100%]
84+
[cols="1,3,4,1,1"]
85+
|===
86+
| Source Location | pURL | License | Score | Release Date
87+
88+
.${snippetCount*2}+|
89+
Partial match +
90+
${sourceLocation.startLine?c}-${sourceLocation.endLine?c}
91+
92+
93+
[#list snippetFinding.snippets as snippet ]
94+
95+
| ${snippet.purl!""}
96+
| ${snippet.license!""}
97+
| ${snippet.score!""}
98+
| ${snippet.additionalData['release_date']}
99+
100+
4+a|
101+
.Create a snippet choice for this snippet or mark it as false positive
102+
[%collapsible]
103+
====
104+
Add the following lines to the *.ort.yml* file.
105+
106+
To **choose** this snippet:
107+
[source,yaml]
108+
--
109+
snippet_choices:
110+
- provenance:
111+
url: "${scanResult.provenance.vcsInfo.url}"
112+
choices:
113+
- given:
114+
source_location:
115+
path: "${filePath}"
116+
start_line: ${snippetFinding.sourceLocation.startLine?c}
117+
end_line: ${snippetFinding.sourceLocation.endLine?c}
118+
choice:
119+
purl: "${snippet.purl!""}"
120+
reason: "ORIGINAL_FINDING"
121+
comment: "Explain why this snippet choice was made"
122+
--
123+
Or to mark this location has having ONLY **false positives snippets**:
124+
[source,yaml]
125+
--
126+
snippet_choices:
127+
- provenance:
128+
url: "${scanResult.provenance.vcsInfo.url}"
129+
choices:
130+
- given:
131+
source_location:
132+
path: "${filePath}"
133+
start_line: ${snippetFinding.sourceLocation.startLine?c}
134+
end_line: ${snippetFinding.sourceLocation.endLine?c}
135+
choice:
136+
reason: "NO_RELEVANT_FINDING"
137+
comment: "Explain why this location has only false positives snippets"
138+
--
139+
====
140+
[/#list]
141+
|===
142+
[/#list]
143+
[/#list]
144+
[/#list]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[#ftl]
2+
[#-- @implicitly included --]
3+
4+
[#-- @ftlvariable name="projects" type="kotlin.collections.Set<org.ossreviewtoolkit.reporter.utils.FreemarkerTemplateProcessor.PackageModel>" --]
5+
[#-- @ftlvariable name="pack ages" type="kotlin.collections.Set<org.ossreviewtoolkit.reporter.utils.FreemarkerTemplateProcessor.PackageModel>" --]
6+
[#-- @ftlvariable name="ortResult" type="org.ossreviewtoolkit.model.OrtResult" --]
7+
[#-- @ftlvariable name="licenseTextProvider" type="org.ossreviewtoolkit.reporter.LicenseTextProvider" --]
8+
[#-- @ftlvariable name="LicenseView" type="org.ossreviewtoolkit.model.licenses.LicenseView" --]
9+
[#-- @ftlvariable name="helper" type="org.ossreviewtoolkit.plugins.reporters.freemarker.FreemarkerTemplateProcessor.TemplateHelper" --]
10+
[#-- @ftlvariable name="projectsAsPackages" type="kotlin.collections.Set<org.ossreviewtoolkit.model.Identifier>" --]

0 commit comments

Comments
 (0)