diff --git a/plugins/commands/requirements/src/main/kotlin/RequirementsCommand.kt b/plugins/commands/requirements/src/main/kotlin/RequirementsCommand.kt index 2bda71bbf6126..9fce26216e682 100644 --- a/plugins/commands/requirements/src/main/kotlin/RequirementsCommand.kt +++ b/plugins/commands/requirements/src/main/kotlin/RequirementsCommand.kt @@ -33,7 +33,7 @@ import org.ossreviewtoolkit.model.config.AnalyzerConfiguration import org.ossreviewtoolkit.model.config.RepositoryConfiguration import org.ossreviewtoolkit.plugins.commands.api.OrtCommand import org.ossreviewtoolkit.scanner.CommandLinePathScannerWrapper -import org.ossreviewtoolkit.scanner.ScannerMatcherConfig +import org.ossreviewtoolkit.scanner.ScannerWrapperConfig import org.ossreviewtoolkit.utils.common.CommandLineTool import org.ossreviewtoolkit.utils.spdx.scanCodeLicenseTextDir @@ -89,8 +89,8 @@ class RequirementsCommand : OrtCommand( logger.debug { "$it is a $category." } it.getDeclaredConstructor( String::class.java, - ScannerMatcherConfig::class.java - ).newInstance("", ScannerMatcherConfig.EMPTY) + ScannerWrapperConfig::class.java + ).newInstance("", ScannerWrapperConfig.EMPTY) } VersionControlSystem::class.java.isAssignableFrom(it) -> { diff --git a/plugins/scanners/askalono/src/main/kotlin/Askalono.kt b/plugins/scanners/askalono/src/main/kotlin/Askalono.kt index 143411f70fee4..8f56085f3b8de 100644 --- a/plugins/scanners/askalono/src/main/kotlin/Askalono.kt +++ b/plugins/scanners/askalono/src/main/kotlin/Askalono.kt @@ -57,6 +57,10 @@ class Askalono internal constructor(name: String, private val wrapperConfig: Sca override val matcher by lazy { ScannerMatcher.create(details, wrapperConfig.matcherConfig) } + override val readFromStorage by lazy { wrapperConfig.readFromStorageWithDefault(matcher) } + + override val writeToStorage by lazy { wrapperConfig.writeToStorageWithDefault(matcher) } + override fun command(workingDir: File?) = listOfNotNull(workingDir, if (Os.isWindows) "askalono.exe" else "askalono").joinToString(File.separator) diff --git a/plugins/scanners/boyterlc/src/main/kotlin/BoyterLc.kt b/plugins/scanners/boyterlc/src/main/kotlin/BoyterLc.kt index 070b2636725ab..8e2fe1cbc8036 100644 --- a/plugins/scanners/boyterlc/src/main/kotlin/BoyterLc.kt +++ b/plugins/scanners/boyterlc/src/main/kotlin/BoyterLc.kt @@ -63,6 +63,10 @@ class BoyterLc internal constructor(name: String, private val wrapperConfig: Sca override val matcher by lazy { ScannerMatcher.create(details, wrapperConfig.matcherConfig) } + override val readFromStorage by lazy { wrapperConfig.readFromStorageWithDefault(matcher) } + + override val writeToStorage by lazy { wrapperConfig.writeToStorageWithDefault(matcher) } + override fun command(workingDir: File?) = listOfNotNull(workingDir, if (Os.isWindows) "lc.exe" else "lc").joinToString(File.separator) diff --git a/plugins/scanners/fossid/src/main/kotlin/FossId.kt b/plugins/scanners/fossid/src/main/kotlin/FossId.kt index bf69687b04ada..bcb70a57aa25c 100644 --- a/plugins/scanners/fossid/src/main/kotlin/FossId.kt +++ b/plugins/scanners/fossid/src/main/kotlin/FossId.kt @@ -97,7 +97,8 @@ import org.ossreviewtoolkit.utils.ort.showStackTrace */ class FossId internal constructor( override val name: String, - private val config: FossIdConfig + private val config: FossIdConfig, + private val wrapperConfig: ScannerWrapperConfig ) : PackageScannerWrapper { companion object { @JvmStatic @@ -170,7 +171,8 @@ class FossId internal constructor( } class Factory : ScannerWrapperFactory("FossId") { - override fun create(config: FossIdConfig, wrapperConfig: ScannerWrapperConfig) = FossId(type, config) + override fun create(config: FossIdConfig, wrapperConfig: ScannerWrapperConfig) = + FossId(type, config, wrapperConfig) override fun parseConfig(options: Options, secrets: Options) = FossIdConfig.create(options, secrets) } @@ -206,6 +208,10 @@ class FossId internal constructor( override val matcher: ScannerMatcher? = null + override val readFromStorage by lazy { wrapperConfig.readFromStorageWithDefault(matcher) } + + override val writeToStorage by lazy { wrapperConfig.writeToStorageWithDefault(matcher) } + private suspend fun getProject(projectCode: String): Project? = service.getProject(config.user, config.apiKey, projectCode).run { when { diff --git a/plugins/scanners/fossid/src/test/kotlin/FossIdTest.kt b/plugins/scanners/fossid/src/test/kotlin/FossIdTest.kt index b90304b6c2f25..a5025d5b295c1 100644 --- a/plugins/scanners/fossid/src/test/kotlin/FossIdTest.kt +++ b/plugins/scanners/fossid/src/test/kotlin/FossIdTest.kt @@ -106,6 +106,7 @@ import org.ossreviewtoolkit.plugins.scanners.fossid.FossId.Companion.SCAN_ID_KEY import org.ossreviewtoolkit.plugins.scanners.fossid.FossId.Companion.SERVER_URL_KEY import org.ossreviewtoolkit.plugins.scanners.fossid.FossId.Companion.convertGitUrlToProjectName import org.ossreviewtoolkit.scanner.ScanContext +import org.ossreviewtoolkit.scanner.ScannerWrapperConfig import org.ossreviewtoolkit.utils.spdx.SpdxExpression @Suppress("LargeClass") @@ -1151,7 +1152,7 @@ private val DEFAULT_IGNORE_RULE_SCOPE = RuleScope.SCAN /** * Create a new [FossId] instance with the specified [config]. */ -private fun createFossId(config: FossIdConfig): FossId = FossId("FossId", config) +private fun createFossId(config: FossIdConfig): FossId = FossId("FossId", config, ScannerWrapperConfig.EMPTY) /** * Create a standard [FossIdConfig] whose properties can be partly specified. diff --git a/plugins/scanners/licensee/src/main/kotlin/Licensee.kt b/plugins/scanners/licensee/src/main/kotlin/Licensee.kt index 21de1dc234381..bbaf27b6d2bd0 100644 --- a/plugins/scanners/licensee/src/main/kotlin/Licensee.kt +++ b/plugins/scanners/licensee/src/main/kotlin/Licensee.kt @@ -62,6 +62,10 @@ class Licensee internal constructor(name: String, private val wrapperConfig: Sca override val matcher by lazy { ScannerMatcher.create(details, wrapperConfig.matcherConfig) } + override val readFromStorage by lazy { wrapperConfig.readFromStorageWithDefault(matcher) } + + override val writeToStorage by lazy { wrapperConfig.writeToStorageWithDefault(matcher) } + override fun command(workingDir: File?) = listOfNotNull(workingDir, if (Os.isWindows) "licensee.bat" else "licensee").joinToString(File.separator) diff --git a/plugins/scanners/scancode/src/main/kotlin/ScanCode.kt b/plugins/scanners/scancode/src/main/kotlin/ScanCode.kt index 9a3c97bbafc14..8e08edcae9505 100644 --- a/plugins/scanners/scancode/src/main/kotlin/ScanCode.kt +++ b/plugins/scanners/scancode/src/main/kotlin/ScanCode.kt @@ -109,6 +109,10 @@ class ScanCode internal constructor( override val matcher by lazy { ScannerMatcher.create(details, wrapperConfig.matcherConfig) } + override val readFromStorage by lazy { wrapperConfig.readFromStorageWithDefault(matcher) } + + override val writeToStorage by lazy { wrapperConfig.writeToStorageWithDefault(matcher) } + override val configuration by lazy { buildList { addAll(configurationOptions) diff --git a/plugins/scanners/scanoss/src/main/kotlin/ScanOss.kt b/plugins/scanners/scanoss/src/main/kotlin/ScanOss.kt index 923eba7b6cbd2..3ec8f7d5bc0b1 100644 --- a/plugins/scanners/scanoss/src/main/kotlin/ScanOss.kt +++ b/plugins/scanners/scanoss/src/main/kotlin/ScanOss.kt @@ -76,6 +76,10 @@ class ScanOss internal constructor( override val matcher by lazy { ScannerMatcher.create(details, wrapperConfig.matcherConfig) } + override val readFromStorage by lazy { wrapperConfig.readFromStorageWithDefault(matcher) } + + override val writeToStorage by lazy { wrapperConfig.writeToStorageWithDefault(matcher) } + /** * The name of the file corresponding to the fingerprints can be sent to SCANOSS for more precise matches. * However, for anonymity, a unique identifier should be generated and used instead. This property holds the diff --git a/scanner/src/funTest/kotlin/scanners/ScannerIntegrationFunTest.kt b/scanner/src/funTest/kotlin/scanners/ScannerIntegrationFunTest.kt index 33ac5c26acf90..3fc24d27fdf46 100644 --- a/scanner/src/funTest/kotlin/scanners/ScannerIntegrationFunTest.kt +++ b/scanner/src/funTest/kotlin/scanners/ScannerIntegrationFunTest.kt @@ -216,6 +216,8 @@ internal class DummyScanner(override val name: String = "Dummy") : PathScannerWr override val configuration = "" override val matcher = ScannerMatcher.create(details) + override val readFromStorage = true + override val writeToStorage = true override fun scanPath(path: File, context: ScanContext): ScanSummary { val relevantFiles = path.walk() diff --git a/scanner/src/main/kotlin/ScannerWrapper.kt b/scanner/src/main/kotlin/ScannerWrapper.kt index f77ae696fb128..85f09bbfbe9be 100644 --- a/scanner/src/main/kotlin/ScannerWrapper.kt +++ b/scanner/src/main/kotlin/ScannerWrapper.kt @@ -71,9 +71,20 @@ sealed interface ScannerWrapper { * name of a property of the [ScannerMatcher] class. For instance, to specify that a specific minimum version of * ScanCode is allowed, set this property: `config.ScanCode.options.minVersion=3.0.2`. * - * If this property is null, it means that the results of this [ScannerWrapper] cannot be stored in a scan storage. + * If this property is null, it means that the results of this [ScannerWrapper] cannot be read from a scan storage. */ val matcher: ScannerMatcher? + + /** + * If `true`, scan results for this scanner shall be read from the configured scan storages. Enabling this option + * requires that the [matcher] is not `null`. + */ + val readFromStorage: Boolean + + /** + * If `true`, scan results for this scanner shall be written to the configured scan storages. + */ + val writeToStorage: Boolean } /** diff --git a/scanner/src/main/kotlin/ScannerWrapperConfig.kt b/scanner/src/main/kotlin/ScannerWrapperConfig.kt index 95d319d0f781f..59d7b2af68b69 100644 --- a/scanner/src/main/kotlin/ScannerWrapperConfig.kt +++ b/scanner/src/main/kotlin/ScannerWrapperConfig.kt @@ -78,4 +78,14 @@ data class ScannerWrapperConfig( ) to filteredOptions } } + + /** + * Return [readFromStorage] if it is not `null`, otherwise return `true` if the provided [matcher] is not `null`. + */ + fun readFromStorageWithDefault(matcher: ScannerMatcher?) = readFromStorage ?: (matcher != null) + + /** + * Return [writeToStorage] if it is not `null`, otherwise return `true` if the provided [matcher] is not `null`. + */ + fun writeToStorageWithDefault(matcher: ScannerMatcher?) = writeToStorage ?: (matcher != null) } diff --git a/scanner/src/test/kotlin/ScannerTest.kt b/scanner/src/test/kotlin/ScannerTest.kt index 37492f6cc4a19..a391d0260b7eb 100644 --- a/scanner/src/test/kotlin/ScannerTest.kt +++ b/scanner/src/test/kotlin/ScannerTest.kt @@ -809,6 +809,8 @@ private class FakePackageScannerWrapper( // Explicit nullability is required here for a mock response. override val matcher: ScannerMatcher? = ScannerMatcher.create(details) + override val readFromStorage = true + override val writeToStorage = true override fun scanPackage(pkg: Package, context: ScanContext): ScanResult = createScanResult(packageProvenanceResolver.resolveProvenance(pkg, sourceCodeOriginPriority), details) @@ -823,6 +825,8 @@ private class FakeProvenanceScannerWrapper : ProvenanceScannerWrapper { override val configuration = "config" override val matcher = ScannerMatcher.create(details) + override val readFromStorage = true + override val writeToStorage = true override fun scanProvenance(provenance: KnownProvenance, context: ScanContext): ScanResult = createScanResult(provenance, details) @@ -837,6 +841,8 @@ private class FakePathScannerWrapper : PathScannerWrapper { override val configuration = "config" override val matcher = ScannerMatcher.create(details) + override val readFromStorage = true + override val writeToStorage = true override fun scanPath(path: File, context: ScanContext): ScanSummary { val licenseFindings = path.walk().filter { it.isFile }.mapTo(mutableSetOf()) { file ->