diff --git a/plugins/scanners/fossid/src/main/kotlin/FossId.kt b/plugins/scanners/fossid/src/main/kotlin/FossId.kt index 1ba487f1f61d3..27e9d97c38c9d 100644 --- a/plugins/scanners/fossid/src/main/kotlin/FossId.kt +++ b/plugins/scanners/fossid/src/main/kotlin/FossId.kt @@ -306,7 +306,7 @@ class FossId internal constructor( val (scanCode, scanId) = if (config.deltaScans) { checkAndCreateDeltaScan(scans, url, revision, projectCode, projectName, context, issues) } else { - checkAndCreateScan(scans, url, revision, projectCode, projectName) + checkAndCreateScan(scans, url, revision, projectCode, projectName, context, issues) } if (config.waitForResult && provenance is RepositoryProvenance) { @@ -460,7 +460,9 @@ class FossId internal constructor( url: String, revision: String, projectCode: String, - projectName: String + projectName: String, + context: ScanContext, + issues: MutableList ): Pair { val existingScan = scans.recentScansForRepository(url, revision = revision).findLatestPendingOrFinishedScan() @@ -475,6 +477,21 @@ class FossId internal constructor( service.downloadFromGit(config.user, config.apiKey, scanCode) .checkResponse("download data from Git", false) + val excludesRules = context.excludes?.let { + convertRules(it, issues).also { + logger.info { "${it.size} rule(s) from ORT excludes have been found." } + } + }.orEmpty() + + excludesRules.forEach { + service.createIgnoreRule(config.user, config.apiKey, scanCode, it.type, it.value, RuleScope.SCAN) + .checkResponse("create ignore rules", false) + + logger.info { + "Ignore rule of type '${it.type}' and value '${it.value}' has been created for the new scan." + } + } + scanCode to scanId } else { logger.info { "Scan '${existingScan.code}' found for $url and revision $revision." } diff --git a/plugins/scanners/fossid/src/test/kotlin/FossIdTest.kt b/plugins/scanners/fossid/src/test/kotlin/FossIdTest.kt index ac4625422b95b..0c845cc0f5d8b 100644 --- a/plugins/scanners/fossid/src/test/kotlin/FossIdTest.kt +++ b/plugins/scanners/fossid/src/test/kotlin/FossIdTest.kt @@ -935,6 +935,46 @@ class FossIdTest : WordSpec({ } } + "apply exclusion rules to a non-delta scan" { + val projectCode = projectCode(PROJECT) + val scanCode = scanCode(PROJECT, null) + val config = createConfig(deltaScans = false) + val vcsInfo = createVcsInfo() + val scan = createScan(vcsInfo.url, "${vcsInfo.revision}_other", scanCode) + + val service = FossIdRestService.create(config.serverUrl) + .expectProjectRequest(projectCode) + .expectListScans(projectCode, listOf(scan)) + .expectCheckScanStatus(scanCode, ScanStatus.NEW, ScanStatus.FINISHED) + .expectCreateScan(projectCode, scanCode, vcsInfo, "") + .expectDownload(scanCode) + .expectCreateIgnoreRule(scanCode, IGNORE_RULE.type, IGNORE_RULE.value, DEFAULT_IGNORE_RULE_SCOPE) + .mockFiles(scanCode, identifiedRange = 1..2, markedRange = 1..2) + coEvery { service.runScan(any()) } returns EntityResponseBody(status = 1) + + val fossId = createFossId(config) + + fossId.scan( + createPackage(createIdentifier(index = 1), vcsInfo), + mapOf(FossId.PROJECT_REVISION_LABEL to ""), + Excludes(listOf(PathExclude("*.docx", PathExcludeReason.OTHER))) + ) + + coVerify { + service.createScan(USER, API_KEY, projectCode, scanCode, vcsInfo.url, vcsInfo.revision) + service.downloadFromGit(USER, API_KEY, scanCode) + service.checkDownloadStatus(USER, API_KEY, scanCode) + service.createIgnoreRule( + USER, + API_KEY, + scanCode, + IGNORE_RULE.type, + IGNORE_RULE.value, + DEFAULT_IGNORE_RULE_SCOPE + ) + } + } + "delete newly triggered scans if a package cannot be scanned" { val id1 = createIdentifier(index = 1) val vcsInfo1 = createVcsInfo()