Skip to content

Commit 22c1541

Browse files
committed
feat(fossid-webapp): Fill the snippet additional data
This information will be accessed in a future commit to fill a FossID snippet report which will be added to ORT. Additionally, the `id` will be used to fetch the matched lines of a snippet using the function `FossIdRestService.listMatchedLines`. Signed-off-by: Nicolas Nobelis <[email protected]>
1 parent 4e05ac4 commit 22c1541

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,18 @@ class FossId internal constructor(
132132
@JvmStatic
133133
internal val PROJECT_REVISION_LABEL = "projectVcsRevision"
134134

135+
@JvmStatic
136+
internal val SNIPPET_DATA_ID = "id"
137+
138+
@JvmStatic
139+
internal val SNIPPET_DATA_MATCH_TYPE = "matchType"
140+
141+
@JvmStatic
142+
internal val SNIPPET_DATA_FILE = "file"
143+
144+
@JvmStatic
145+
internal val SNIPPET_DATA_RELEASE_DATE = "releaseDate"
146+
135147
/**
136148
* The scan states for which a scan can be triggered.
137149
*/
@@ -825,6 +837,13 @@ class FossId internal constructor(
825837
val snippetProvenance = ArtifactProvenance(RemoteArtifact(it.url, Hash.NONE))
826838
val purl = it.purl ?: "pkg:${urlToPackageType(it.url)}/${it.author}/${it.artifact}@${it.version}"
827839

840+
val additionalSnippetData = mapOf(
841+
SNIPPET_DATA_ID to it.id.toString(),
842+
SNIPPET_DATA_FILE to it.file,
843+
SNIPPET_DATA_MATCH_TYPE to it.matchType.toString(),
844+
SNIPPET_DATA_RELEASE_DATE to it.releaseDate.orEmpty()
845+
)
846+
828847
// TODO: FossID doesn't return the line numbers of the match, only the character range. One must use
829848
// another call "getMatchedLine" to retrieve the matched line numbers. Unfortunately, this is a
830849
// call per snippet which is too expensive. When it is available for a batch of snippets, it can
@@ -834,7 +853,8 @@ class FossId internal constructor(
834853
TextLocation(it.file, TextLocation.UNKNOWN_LINE),
835854
snippetProvenance,
836855
purl,
837-
license
856+
license,
857+
additionalSnippetData
838858
)
839859
}
840860

scanner/src/test/kotlin/scanners/fossid/FossIdTest.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1319,7 +1319,13 @@ private fun createSnippetFindings(index: Int): Set<SnippetFinding> = (1..5).map
13191319
TextLocation("file$snippetIndex", TextLocation.UNKNOWN_LINE),
13201320
ArtifactProvenance(RemoteArtifact("url$snippetIndex", Hash.NONE)),
13211321
"pkg:generic/author$snippetIndex/artifact$snippetIndex@version$snippetIndex",
1322-
SpdxExpression.parse("MIT")
1322+
SpdxExpression.Companion.parse("MIT"),
1323+
mapOf(
1324+
FossId.SNIPPET_DATA_ID to "$snippetIndex",
1325+
FossId.SNIPPET_DATA_FILE to "file$snippetIndex",
1326+
FossId.SNIPPET_DATA_RELEASE_DATE to "releaseDate$snippetIndex",
1327+
FossId.SNIPPET_DATA_MATCH_TYPE to MatchType.PARTIAL.toString()
1328+
)
13231329
)
13241330
)
13251331
}.toSet()

0 commit comments

Comments
 (0)