@@ -62,13 +62,16 @@ import org.ossreviewtoolkit.clients.fossid.listIgnoredFiles
62
62
import org.ossreviewtoolkit.clients.fossid.listMarkedAsIdentifiedFiles
63
63
import org.ossreviewtoolkit.clients.fossid.listPendingFiles
64
64
import org.ossreviewtoolkit.clients.fossid.listScansForProject
65
+ import org.ossreviewtoolkit.clients.fossid.listSnippets
65
66
import org.ossreviewtoolkit.clients.fossid.model.Scan
66
67
import org.ossreviewtoolkit.clients.fossid.model.identification.common.LicenseMatchType
67
68
import org.ossreviewtoolkit.clients.fossid.model.identification.identifiedFiles.IdentifiedFile
68
69
import org.ossreviewtoolkit.clients.fossid.model.identification.ignored.IgnoredFile
69
70
import org.ossreviewtoolkit.clients.fossid.model.identification.markedAsIdentified.License
70
71
import org.ossreviewtoolkit.clients.fossid.model.identification.markedAsIdentified.LicenseFile
71
72
import org.ossreviewtoolkit.clients.fossid.model.identification.markedAsIdentified.MarkedAsIdentifiedFile
73
+ import org.ossreviewtoolkit.clients.fossid.model.result.MatchType
74
+ import org.ossreviewtoolkit.clients.fossid.model.result.Snippet
72
75
import org.ossreviewtoolkit.clients.fossid.model.rules.IgnoreRule
73
76
import org.ossreviewtoolkit.clients.fossid.model.rules.RuleScope
74
77
import org.ossreviewtoolkit.clients.fossid.model.rules.RuleType
@@ -90,11 +93,13 @@ import org.ossreviewtoolkit.model.TextLocation
90
93
import org.ossreviewtoolkit.model.VcsInfo
91
94
import org.ossreviewtoolkit.model.VcsType
92
95
import org.ossreviewtoolkit.model.config.ScannerConfiguration
96
+ import org.ossreviewtoolkit.model.utils.SnippetFinding
93
97
import org.ossreviewtoolkit.scanner.ScanContext
94
98
import org.ossreviewtoolkit.scanner.scanners.fossid.FossId.Companion.SCAN_CODE_KEY
95
99
import org.ossreviewtoolkit.scanner.scanners.fossid.FossId.Companion.SCAN_ID_KEY
96
100
import org.ossreviewtoolkit.scanner.scanners.fossid.FossId.Companion.SERVER_URL_KEY
97
101
import org.ossreviewtoolkit.scanner.scanners.fossid.FossId.Companion.convertGitUrlToProjectName
102
+ import org.ossreviewtoolkit.utils.spdx.SpdxExpression
98
103
99
104
@Suppress(" LargeClass" )
100
105
class FossIdTest : WordSpec ({
@@ -314,6 +319,7 @@ class FossIdTest : WordSpec({
314
319
summary.licenseFindings shouldContainExactlyInAnyOrder expectedLicenseFindings
315
320
}
316
321
322
+ // TODO: Deprecation: Remove the pending files in issues. This is a breaking change.
317
323
" report pending files as issues" {
318
324
val projectCode = projectCode(PROJECT )
319
325
val scanCode = scanCode(PROJECT , null)
@@ -328,7 +334,7 @@ class FossIdTest : WordSpec({
328
334
.expectCheckScanStatus(scanCode, ScanStatus .FINISHED )
329
335
.expectCreateScan(projectCode, scanCode, vcsInfo, "")
330
336
.expectDownload(scanCode)
331
- .mockFiles(scanCode, pendingRange = 4..5)
337
+ .mockFiles(scanCode, pendingRange = 4..5, snippetRange = 1..5 )
332
338
333
339
val fossId = createFossId(config)
334
340
@@ -341,6 +347,35 @@ class FossIdTest : WordSpec({
341
347
summary.issues.map { it.copy(timestamp = Instant .EPOCH ) } shouldBe expectedIssues
342
348
}
343
349
350
+ " report pending files as snippets" {
351
+ val projectCode = projectCode(PROJECT )
352
+ val scanCode = scanCode(PROJECT , null)
353
+ val config = createConfig(deltaScans = false)
354
+ val vcsInfo = createVcsInfo()
355
+ val scan = createScan(vcsInfo.url, "${vcsInfo.revision}_other ", scanCode)
356
+ val pkgId = createIdentifier(index = 42)
357
+
358
+ FossIdRestService .create(config.serverUrl)
359
+ .expectProjectRequest(projectCode)
360
+ .expectListScans(projectCode, listOf(scan))
361
+ .expectCheckScanStatus(scanCode, ScanStatus .FINISHED )
362
+ .expectCreateScan(projectCode, scanCode, vcsInfo, "")
363
+ .expectDownload(scanCode)
364
+ .mockFiles(scanCode, pendingRange = 1..5, snippetRange = 1..5)
365
+
366
+ val fossId = createFossId(config)
367
+
368
+ val summary = fossId.scan(createPackage(pkgId, vcsInfo)).summary
369
+
370
+ val expectedPendingFile = (1..5).map(::createPendingFile).toSet()
371
+ val expectedSnippetFindings = (1..5).map(::createSnippetFinding).toSet()
372
+
373
+ summary.snippetFindings.keys shouldBe expectedPendingFile
374
+ summary.snippetFindings.values.forEach {
375
+ it shouldBe expectedSnippetFindings
376
+ }
377
+ }
378
+
344
379
" create a new project if none exists yet" {
345
380
val projectCode = projectCode(PROJECT )
346
381
val scanCode = scanCode(PROJECT , null)
@@ -1238,6 +1273,49 @@ private fun createIgnoredFile(index: Int): IgnoredFile =
1238
1273
*/
1239
1274
private fun createPendingFile (index : Int ): String = " /pending/file/$index "
1240
1275
1276
+ /* *
1277
+ * Generate a FossID snippet based on the given [index].
1278
+ */
1279
+ private fun createSnippet (index : Int ): Snippet = Snippet (
1280
+ index,
1281
+ " created$index " ,
1282
+ index,
1283
+ index,
1284
+ index,
1285
+ MatchType .PARTIAL ,
1286
+ " reason$index " ,
1287
+ " author$index " ,
1288
+ " artifact$index " ,
1289
+ " version$index " ,
1290
+ " MIT" ,
1291
+ " releaseDate$index " ,
1292
+ " mirror$index " ,
1293
+ " file$index " ,
1294
+ " fileLicense$index " ,
1295
+ " url$index " ,
1296
+ " hits$index " ,
1297
+ index,
1298
+ " updated$index " ,
1299
+ " cpe$index " ,
1300
+ " $index " ,
1301
+ " matchField$index " ,
1302
+ " classification$index " ,
1303
+ " highlighting$index "
1304
+ )
1305
+
1306
+ /* *
1307
+ * Generate a ORT snippet finding based on the given [index].
1308
+ */
1309
+ private fun createSnippetFinding (index : Int ): SnippetFinding = SnippetFinding (
1310
+ " author$index " ,
1311
+ " artifact$index " ,
1312
+ " version$index " ,
1313
+ setOf (SpdxExpression .Companion .parse(" MIT" )),
1314
+ index.toFloat(),
1315
+ TextLocation (" file$index " , - 1 ),
1316
+ TextLocation (" url$index " , - 1 )
1317
+ )
1318
+
1241
1319
/* *
1242
1320
* Prepare this service mock to answer a request for a project with the given [projectCode]. Return a response with
1243
1321
* the given [status] and [error].
@@ -1348,12 +1426,14 @@ private fun FossIdServiceWithVersion.mockFiles(
1348
1426
identifiedRange : IntRange = IntRange .EMPTY ,
1349
1427
markedRange : IntRange = IntRange .EMPTY ,
1350
1428
ignoredRange : IntRange = IntRange .EMPTY ,
1351
- pendingRange : IntRange = IntRange .EMPTY
1429
+ pendingRange : IntRange = IntRange .EMPTY ,
1430
+ snippetRange : IntRange = IntRange .EMPTY
1352
1431
): FossIdServiceWithVersion {
1353
1432
val identifiedFiles = identifiedRange.map(::createIdentifiedFile)
1354
1433
val markedFiles = markedRange.map(::createMarkedIdentifiedFile)
1355
1434
val ignoredFiles = ignoredRange.map(::createIgnoredFile)
1356
1435
val pendingFiles = pendingRange.map(::createPendingFile)
1436
+ val snippets = snippetRange.map(::createSnippet)
1357
1437
1358
1438
coEvery { listIdentifiedFiles(USER , API_KEY , scanCode) } returns
1359
1439
PolymorphicResponseBody (
@@ -1367,6 +1447,8 @@ private fun FossIdServiceWithVersion.mockFiles(
1367
1447
PolymorphicResponseBody (status = 1 , data = PolymorphicList (ignoredFiles))
1368
1448
coEvery { listPendingFiles(USER , API_KEY , scanCode) } returns
1369
1449
PolymorphicResponseBody (status = 1 , data = PolymorphicList (pendingFiles))
1450
+ coEvery { listSnippets(USER , API_KEY , scanCode, any()) } returns
1451
+ PolymorphicResponseBody (status = 1 , data = PolymorphicList (snippets))
1370
1452
1371
1453
return this
1372
1454
}
0 commit comments