Skip to content

Commit c830d6f

Browse files
isasmendiagussschuberth
authored andcommitted
chore(scanoss): Determine the snippet license only once
The `licenses` variable is constant in the loop, so extract it to determine the resulting `license` only once. Signed-off-by: Agustin Isasmendi <[email protected]>
1 parent 1c0d990 commit c830d6f

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ private fun getSnippets(details: ScanFileDetails): Set<Snippet> {
144144
val url = requireNotNull(details.url)
145145
val purls = requireNotNull(details.purls)
146146

147-
val licenses = details.licenseDetails.orEmpty().mapTo(mutableSetOf()) { license ->
148-
SpdxExpression.parse(license.name)
149-
}
147+
val license = details.licenseDetails.orEmpty()
148+
.map { license -> SpdxExpression.parse(license.name) }
149+
.toExpression()?.sorted() ?: SpdxLicenseIdExpression(SpdxConstants.NOASSERTION)
150150

151151
val score = matched.substringBeforeLast("%").toFloat()
152152
val locations = convertLines(fileUrl, ossLines)
@@ -157,8 +157,6 @@ private fun getSnippets(details: ScanFileDetails): Set<Snippet> {
157157
return buildSet {
158158
purls.forEach { purl ->
159159
locations.forEach { snippetLocation ->
160-
val license = licenses.toExpression()?.sorted() ?: SpdxLicenseIdExpression(SpdxConstants.NOASSERTION)
161-
162160
add(Snippet(score, snippetLocation, provenance, purl, license))
163161
}
164162
}

0 commit comments

Comments
 (0)