Skip to content

Commit ac3df58

Browse files
nnobelismnonnenmacher
authored andcommitted
feat(scanner): Expose includes in the scan context
As for the excludes, the includes are only passed to scanners without a scanner matcher i.e. scanners for which results are never taken from a scan storage. This is for preventing the need to do an invalidation of the scan results if the includes change. Signed-off-by: Nicolas Nobelis <[email protected]>
1 parent e111395 commit ac3df58

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

scanner/src/main/kotlin/ScanContext.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import org.ossreviewtoolkit.model.OrtResult
2424
import org.ossreviewtoolkit.model.Package
2525
import org.ossreviewtoolkit.model.PackageType
2626
import org.ossreviewtoolkit.model.config.Excludes
27+
import org.ossreviewtoolkit.model.config.Includes
2728
import org.ossreviewtoolkit.model.config.ScannerConfiguration
2829
import org.ossreviewtoolkit.model.config.SnippetChoices
2930
import org.ossreviewtoolkit.utils.spdx.SpdxExpression
@@ -47,6 +48,11 @@ data class ScanContext(
4748
*/
4849
val excludes: Excludes? = null,
4950

51+
/**
52+
* The [Includes] of the project to scan.
53+
*/
54+
val includes: Includes? = null,
55+
5056
/**
5157
* The detected license mappings configured in the
5258
* [scanner configuration][ScannerConfiguration.detectedLicenseMapping]. Can be used by [ScannerWrapper]

scanner/src/main/kotlin/Scanner.kt

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ class Scanner(
114114
ortResult.labels + labels,
115115
PackageType.PROJECT,
116116
ortResult.repository.config.excludes,
117+
ortResult.repository.config.includes,
117118
scannerConfig.detectedLicenseMapping,
118119
snippetChoices = ortResult.repository.config.snippetChoices
119120
)
@@ -127,6 +128,7 @@ class Scanner(
127128
ortResult.labels,
128129
PackageType.PACKAGE,
129130
ortResult.repository.config.excludes,
131+
ortResult.repository.config.includes,
130132
scannerConfig.detectedLicenseMapping,
131133
snippetChoices = ortResult.repository.config.snippetChoices
132134
)
@@ -332,8 +334,9 @@ class Scanner(
332334
val nestedProvenance = controller.getNestedProvenance(referencePackage.id) ?: return@scanner
333335

334336
val adjustedContext = context.copy(
335-
// Hide excludes from scanners with a scanner matcher.
337+
// Hide includes and excludes from scanners with a scanner matcher.
336338
excludes = context.excludes.takeUnless { scanner.matcher != null },
339+
includes = context.includes.takeUnless { scanner.matcher != null },
337340
// Tell scanners also about the non-reference packages.
338341
coveredPackages = packagesWithIncompleteScanResult
339342
)
@@ -399,8 +402,13 @@ class Scanner(
399402
"'${scanner.descriptor.displayName}'."
400403
}
401404

402-
// Filter the scan context to hide the excludes from scanner with scan matcher.
403-
val filteredContext = if (scanner.matcher == null) context else context.copy(excludes = null)
405+
// Filter the scan context to hide the includes and excludes from scanner with scan matcher.
406+
val filteredContext = if (scanner.matcher == null) {
407+
context
408+
} else {
409+
context.copy(excludes = null, includes = null)
410+
}
411+
404412
val scanResult = scanner.scanProvenance(provenance, filteredContext)
405413

406414
val completedPackages = controller.getPackagesCompletedByProvenance(scanner, provenance)
@@ -581,8 +589,12 @@ class Scanner(
581589
val results = scanners.mapNotNull { scanner ->
582590
logger.info { "Scan of $provenance with path scanner '${scanner.descriptor.displayName}' started." }
583591

584-
// Filter the scan context to hide the excludes from scanner with scan matcher.
585-
val filteredContext = if (scanner.matcher == null) context else context.copy(excludes = null)
592+
// Filter the scan context to hide the includes and excludes from scanner with scan matcher.
593+
val filteredContext = if (scanner.matcher == null) {
594+
context
595+
} else {
596+
context.copy(excludes = null, includes = null)
597+
}
586598

587599
val summary = runCatching {
588600
scanner.scanPath(downloadDir, filteredContext)

0 commit comments

Comments
 (0)