@@ -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
@@ -79,22 +82,27 @@ import org.ossreviewtoolkit.clients.fossid.runScan
79
82
import org.ossreviewtoolkit.downloader.VersionControlSystem
80
83
import org.ossreviewtoolkit.downloader.vcs.Git
81
84
import org.ossreviewtoolkit.model.CopyrightFinding
85
+ import org.ossreviewtoolkit.model.Hash
82
86
import org.ossreviewtoolkit.model.Identifier
83
87
import org.ossreviewtoolkit.model.Issue
84
88
import org.ossreviewtoolkit.model.LicenseFinding
85
89
import org.ossreviewtoolkit.model.Package
86
90
import org.ossreviewtoolkit.model.PackageType
91
+ import org.ossreviewtoolkit.model.RemoteArtifact
87
92
import org.ossreviewtoolkit.model.ScanResult
88
93
import org.ossreviewtoolkit.model.Severity
89
94
import org.ossreviewtoolkit.model.TextLocation
90
95
import org.ossreviewtoolkit.model.VcsInfo
91
96
import org.ossreviewtoolkit.model.VcsType
92
97
import org.ossreviewtoolkit.model.config.ScannerConfiguration
98
+ import org.ossreviewtoolkit.model.utils.DetectedSnippet
99
+ import org.ossreviewtoolkit.model.utils.SnippetFinding
93
100
import org.ossreviewtoolkit.scanner.ScanContext
94
101
import org.ossreviewtoolkit.scanner.scanners.fossid.FossId.Companion.SCAN_CODE_KEY
95
102
import org.ossreviewtoolkit.scanner.scanners.fossid.FossId.Companion.SCAN_ID_KEY
96
103
import org.ossreviewtoolkit.scanner.scanners.fossid.FossId.Companion.SERVER_URL_KEY
97
104
import org.ossreviewtoolkit.scanner.scanners.fossid.FossId.Companion.convertGitUrlToProjectName
105
+ import org.ossreviewtoolkit.utils.spdx.SpdxExpression
98
106
99
107
@Suppress(" LargeClass" )
100
108
class FossIdTest : WordSpec ({
@@ -314,6 +322,7 @@ class FossIdTest : WordSpec({
314
322
summary.licenseFindings shouldContainExactlyInAnyOrder expectedLicenseFindings
315
323
}
316
324
325
+ // TODO: Deprecation: Remove the pending files in issues. This is a breaking change.
317
326
" report pending files as issues" {
318
327
val projectCode = projectCode(PROJECT )
319
328
val scanCode = scanCode(PROJECT , null)
@@ -328,7 +337,7 @@ class FossIdTest : WordSpec({
328
337
.expectCheckScanStatus(scanCode, ScanStatus .FINISHED )
329
338
.expectCreateScan(projectCode, scanCode, vcsInfo, "")
330
339
.expectDownload(scanCode)
331
- .mockFiles(scanCode, pendingRange = 4..5)
340
+ .mockFiles(scanCode, pendingRange = 4..5, snippetRange = 1..5 )
332
341
333
342
val fossId = createFossId(config)
334
343
@@ -341,6 +350,35 @@ class FossIdTest : WordSpec({
341
350
summary.issues.map { it.copy(timestamp = Instant .EPOCH ) } shouldBe expectedIssues
342
351
}
343
352
353
+ " report pending files as snippets" {
354
+ val projectCode = projectCode(PROJECT )
355
+ val scanCode = scanCode(PROJECT , null)
356
+ val config = createConfig(deltaScans = false)
357
+ val vcsInfo = createVcsInfo()
358
+ val scan = createScan(vcsInfo.url, "${vcsInfo.revision}_other ", scanCode)
359
+ val pkgId = createIdentifier(index = 42)
360
+
361
+ FossIdRestService .create(config.serverUrl)
362
+ .expectProjectRequest(projectCode)
363
+ .expectListScans(projectCode, listOf(scan))
364
+ .expectCheckScanStatus(scanCode, ScanStatus .FINISHED )
365
+ .expectCreateScan(projectCode, scanCode, vcsInfo, "")
366
+ .expectDownload(scanCode)
367
+ .mockFiles(scanCode, pendingRange = 1..5, snippetRange = 1..5)
368
+
369
+ val fossId = createFossId(config)
370
+
371
+ val summary = fossId.scan(createPackage(pkgId, vcsInfo)).summary
372
+
373
+ val expectedPendingFile = (1..5).map(::createPendingFile).toSet()
374
+ val expectedSnippetFindings = (1..5).map(::createSnippetFinding).toSet()
375
+
376
+ summary.snippetFindings.keys shouldBe expectedPendingFile
377
+ summary.snippetFindings.values.forEach {
378
+ it shouldBe expectedSnippetFindings
379
+ }
380
+ }
381
+
344
382
" create a new project if none exists yet" {
345
383
val projectCode = projectCode(PROJECT )
346
384
val scanCode = scanCode(PROJECT , null)
@@ -1238,6 +1276,51 @@ private fun createIgnoredFile(index: Int): IgnoredFile =
1238
1276
*/
1239
1277
private fun createPendingFile (index : Int ): String = " /pending/file/$index "
1240
1278
1279
+ /* *
1280
+ * Generate a FossID snippet based on the given [index].
1281
+ */
1282
+ private fun createSnippet (index : Int ): Snippet = Snippet (
1283
+ index,
1284
+ " created$index " ,
1285
+ index,
1286
+ index,
1287
+ index,
1288
+ MatchType .PARTIAL ,
1289
+ " reason$index " ,
1290
+ " author$index " ,
1291
+ " artifact$index " ,
1292
+ " version$index " ,
1293
+ " MIT" ,
1294
+ " releaseDate$index " ,
1295
+ " mirror$index " ,
1296
+ " file$index " ,
1297
+ " fileLicense$index " ,
1298
+ " url$index " ,
1299
+ " hits$index " ,
1300
+ index,
1301
+ " updated$index " ,
1302
+ " cpe$index " ,
1303
+ " $index " ,
1304
+ " matchField$index " ,
1305
+ " classification$index " ,
1306
+ " highlighting$index "
1307
+ )
1308
+
1309
+ /* *
1310
+ * Generate a ORT snippet finding based on the given [index].
1311
+ */
1312
+ private fun createSnippetFinding (index : Int ): SnippetFinding = SnippetFinding (
1313
+ index.toFloat(),
1314
+ TextLocation (" file$index " , TextLocation .UNKNOWN_LINE ),
1315
+ DetectedSnippet (
1316
+ TextLocation (" url$index " , TextLocation .UNKNOWN_LINE ),
1317
+ null ,
1318
+ RemoteArtifact (" url$index " , Hash .NONE ),
1319
+ setOf (" pkg:fossid/author$index /artifact$index @version$index " ),
1320
+ SpdxExpression .Companion .parse(" MIT" )
1321
+ )
1322
+ )
1323
+
1241
1324
/* *
1242
1325
* Prepare this service mock to answer a request for a project with the given [projectCode]. Return a response with
1243
1326
* the given [status] and [error].
@@ -1348,12 +1431,14 @@ private fun FossIdServiceWithVersion.mockFiles(
1348
1431
identifiedRange : IntRange = IntRange .EMPTY ,
1349
1432
markedRange : IntRange = IntRange .EMPTY ,
1350
1433
ignoredRange : IntRange = IntRange .EMPTY ,
1351
- pendingRange : IntRange = IntRange .EMPTY
1434
+ pendingRange : IntRange = IntRange .EMPTY ,
1435
+ snippetRange : IntRange = IntRange .EMPTY
1352
1436
): FossIdServiceWithVersion {
1353
1437
val identifiedFiles = identifiedRange.map(::createIdentifiedFile)
1354
1438
val markedFiles = markedRange.map(::createMarkedIdentifiedFile)
1355
1439
val ignoredFiles = ignoredRange.map(::createIgnoredFile)
1356
1440
val pendingFiles = pendingRange.map(::createPendingFile)
1441
+ val snippets = snippetRange.map(::createSnippet)
1357
1442
1358
1443
coEvery { listIdentifiedFiles(USER , API_KEY , scanCode) } returns
1359
1444
PolymorphicResponseBody (
@@ -1367,6 +1452,8 @@ private fun FossIdServiceWithVersion.mockFiles(
1367
1452
PolymorphicResponseBody (status = 1 , data = PolymorphicList (ignoredFiles))
1368
1453
coEvery { listPendingFiles(USER , API_KEY , scanCode) } returns
1369
1454
PolymorphicResponseBody (status = 1 , data = PolymorphicList (pendingFiles))
1455
+ coEvery { listSnippets(USER , API_KEY , scanCode, any()) } returns
1456
+ PolymorphicResponseBody (status = 1 , data = PolymorphicList (snippets))
1370
1457
1371
1458
return this
1372
1459
}
0 commit comments