Skip to content

Commit 66b03c5

Browse files
mnonnenmachersschuberth
authored andcommitted
refactor(model)!: Replace PluginConfiguration with PluginConfig
Remove the old `PluginConfiguration` class and replace all usages with the new `PluginConfig` class [1]. Also add an `orEmpty()` convenience function to simplify some code that is changed as part of this commit. [1]: #9403 (comment) Signed-off-by: Martin Nonnenmacher <[email protected]>
1 parent e4fc496 commit 66b03c5

File tree

10 files changed

+25
-72
lines changed

10 files changed

+25
-72
lines changed

advisor/src/main/kotlin/Advisor.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import org.ossreviewtoolkit.model.Package
3737
import org.ossreviewtoolkit.model.config.AdvisorConfiguration
3838
import org.ossreviewtoolkit.model.vulnerabilities.Vulnerability
3939
import org.ossreviewtoolkit.model.vulnerabilities.VulnerabilityReference
40-
import org.ossreviewtoolkit.plugins.api.PluginConfig
40+
import org.ossreviewtoolkit.plugins.api.orEmpty
4141
import org.ossreviewtoolkit.utils.ort.Environment
4242

4343
/**
@@ -81,7 +81,7 @@ class Advisor(
8181
} else {
8282
val providers = providerFactories.map {
8383
val providerConfig = config.config?.get(it.descriptor.id)
84-
it.create(PluginConfig(providerConfig?.options.orEmpty(), providerConfig?.secrets.orEmpty()))
84+
it.create(providerConfig.orEmpty())
8585
}
8686

8787
providers.map { provider ->

model/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ plugins {
2727

2828
dependencies {
2929
api(projects.clients.clearlyDefinedClient)
30+
api(projects.plugins.api)
3031
api(projects.utils.ortUtils)
3132
api(projects.utils.spdxUtils)
3233

model/src/main/kotlin/config/AdvisorConfiguration.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ package org.ossreviewtoolkit.model.config
2121

2222
import com.fasterxml.jackson.annotation.JsonInclude
2323

24+
import org.ossreviewtoolkit.plugins.api.PluginConfig
2425
import org.ossreviewtoolkit.utils.common.Plugin
2526

2627
/**
@@ -34,8 +35,7 @@ data class AdvisorConfiguration(
3435
val skipExcluded: Boolean = false,
3536

3637
/**
37-
* A map with [configuration][PluginConfiguration] for advice providers using the [provider type][Plugin.type] as
38-
* key.
38+
* A map with [configuration][PluginConfig] for advice providers using the [provider type][Plugin.type] as key.
3939
*/
40-
val config: Map<String, PluginConfiguration>? = null
40+
val config: Map<String, PluginConfig>? = null
4141
)

model/src/main/kotlin/config/PluginConfiguration.kt

Lines changed: 0 additions & 56 deletions
This file was deleted.

model/src/main/kotlin/config/ReporterConfiguration.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ package org.ossreviewtoolkit.model.config
2121

2222
import com.fasterxml.jackson.annotation.JsonInclude
2323

24+
import org.ossreviewtoolkit.plugins.api.PluginConfig
25+
2426
/**
2527
* The base configuration model of the reporter.
2628
*/
@@ -30,5 +32,5 @@ data class ReporterConfiguration(
3032
* Reporter specific configuration options. The key needs to match the name of the reporter class, e.g. "FossId"
3133
* for the FossId reporter. See the documentation of the reporter for available options.
3234
*/
33-
val config: Map<String, PluginConfiguration>? = null
35+
val config: Map<String, PluginConfig>? = null
3436
)

model/src/main/kotlin/config/ScannerConfiguration.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import com.fasterxml.jackson.annotation.JsonInclude
2424
import com.fasterxml.jackson.annotation.JsonPropertyOrder
2525

2626
import org.ossreviewtoolkit.model.utils.FileArchiver
27+
import org.ossreviewtoolkit.plugins.api.PluginConfig
2728
import org.ossreviewtoolkit.utils.ort.ORT_REPO_CONFIG_FILENAME
2829
import org.ossreviewtoolkit.utils.ort.storage.FileStorage
2930
import org.ossreviewtoolkit.utils.spdx.SpdxConstants
@@ -92,7 +93,7 @@ data class ScannerConfiguration(
9293
* for the ScanCode wrapper. See the documentation of the scanner for available options.
9394
*/
9495
@JsonAlias("options")
95-
val config: Map<String, PluginConfiguration>? = null,
96+
val config: Map<String, PluginConfig>? = null,
9697

9798
/**
9899
* A map with the configurations of the scan result storages available. Based on this information the actual

plugins/api/src/main/kotlin/PluginConfig.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,8 @@ data class PluginConfig(
5252
*/
5353
override fun toString() = "${this::class.simpleName}(options=$options, secrets=[***])"
5454
}
55+
56+
/**
57+
* Returns this [PluginConfig] if it is not `null`, or the [empty][PluginConfig.EMPTY] [PluginConfig] otherwise.
58+
*/
59+
fun PluginConfig?.orEmpty() = this ?: PluginConfig.EMPTY

plugins/commands/reporter/src/main/kotlin/ReporterCommand.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ import org.apache.logging.log4j.kotlin.logger
4343

4444
import org.ossreviewtoolkit.model.config.CopyrightGarbage
4545
import org.ossreviewtoolkit.model.config.LicenseFilePatterns
46-
import org.ossreviewtoolkit.model.config.PluginConfiguration
4746
import org.ossreviewtoolkit.model.config.RepositoryConfiguration
4847
import org.ossreviewtoolkit.model.config.createFileArchiver
4948
import org.ossreviewtoolkit.model.config.orEmpty
@@ -57,6 +56,7 @@ import org.ossreviewtoolkit.model.utils.DefaultResolutionProvider
5756
import org.ossreviewtoolkit.plugins.api.OrtPlugin
5857
import org.ossreviewtoolkit.plugins.api.PluginConfig
5958
import org.ossreviewtoolkit.plugins.api.PluginDescriptor
59+
import org.ossreviewtoolkit.plugins.api.orEmpty
6060
import org.ossreviewtoolkit.plugins.commands.api.OrtCommand
6161
import org.ossreviewtoolkit.plugins.commands.api.OrtCommandFactory
6262
import org.ossreviewtoolkit.plugins.commands.api.utils.configurationGroup
@@ -277,7 +277,7 @@ class ReporterCommand(descriptor: PluginDescriptor = ReporterCommandFactory.desc
277277
howToFixTextProvider
278278
)
279279

280-
val reportConfigMap = sortedMapOf<String, PluginConfiguration>(String.CASE_INSENSITIVE_ORDER)
280+
val reportConfigMap = sortedMapOf<String, PluginConfig>(String.CASE_INSENSITIVE_ORDER)
281281

282282
// Obtain reporter-specific options defined in ORT's configuration.
283283
ortConfig.reporter.config?.forEach { (reporterName, config) ->
@@ -286,7 +286,7 @@ class ReporterCommand(descriptor: PluginDescriptor = ReporterCommandFactory.desc
286286

287287
// Allow overwriting reporter-specific options via the command line.
288288
reportOptions.forEach { (reporterName, option) ->
289-
val reportSpecificConfig = reportConfigMap.getOrPut(reporterName) { PluginConfiguration.EMPTY }
289+
val reportSpecificConfig = reportConfigMap.getOrPut(reporterName) { PluginConfig.EMPTY }
290290
val updatedConfig = reportSpecificConfig.copy(options = reportSpecificConfig.options + option)
291291
reportConfigMap[reporterName] = updatedConfig
292292
}
@@ -300,9 +300,8 @@ class ReporterCommand(descriptor: PluginDescriptor = ReporterCommandFactory.desc
300300
echo("Generating '${reporter.descriptor.id}' report(s) in thread '$threadName'...")
301301

302302
reporter to measureTimedValue {
303-
val options = reportConfigMap[reporter.descriptor.id] ?: PluginConfiguration.EMPTY
304-
reporter.create(PluginConfig(options.options, options.secrets))
305-
.generateReport(input, outputDir)
303+
val pluginConfig = reportConfigMap[reporter.descriptor.id].orEmpty()
304+
reporter.create(pluginConfig).generateReport(input, outputDir)
306305
}
307306
}
308307
}.awaitAll()

plugins/commands/scanner/src/main/kotlin/ScannerCommand.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import org.ossreviewtoolkit.model.utils.mergeLabels
5353
import org.ossreviewtoolkit.plugins.api.OrtPlugin
5454
import org.ossreviewtoolkit.plugins.api.PluginConfig
5555
import org.ossreviewtoolkit.plugins.api.PluginDescriptor
56+
import org.ossreviewtoolkit.plugins.api.orEmpty
5657
import org.ossreviewtoolkit.plugins.commands.api.OrtCommand
5758
import org.ossreviewtoolkit.plugins.commands.api.OrtCommandFactory
5859
import org.ossreviewtoolkit.plugins.commands.api.utils.SeverityStatsPrinter
@@ -176,7 +177,7 @@ class ScannerCommand(descriptor: PluginDescriptor = ScannerCommandFactory.descri
176177
.takeIf { PackageType.PACKAGE in packageTypes }.orEmpty()
177178
.map {
178179
val config = ortConfig.scanner.config?.get(it.descriptor.id)
179-
it.create(PluginConfig(config?.options.orEmpty(), config?.secrets.orEmpty()))
180+
it.create(config.orEmpty())
180181
}
181182

182183
val projectScannerWrappers = projectScannerWrapperFactories

scanner/src/main/kotlin/ScannerWrapper.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ import org.ossreviewtoolkit.model.Provenance
2727
import org.ossreviewtoolkit.model.ScanResult
2828
import org.ossreviewtoolkit.model.ScanSummary
2929
import org.ossreviewtoolkit.model.ScannerDetails
30-
import org.ossreviewtoolkit.model.config.PluginConfiguration
3130
import org.ossreviewtoolkit.model.config.ScannerConfiguration
3231
import org.ossreviewtoolkit.plugins.api.Plugin
32+
import org.ossreviewtoolkit.plugins.api.PluginConfig
3333
import org.ossreviewtoolkit.scanner.provenance.NestedProvenance
3434

3535
/**
@@ -55,7 +55,7 @@ sealed interface ScannerWrapper : Plugin {
5555
/**
5656
* The [ScannerMatcher] object to be used when looking up existing scan results from a scan storage. By default,
5757
* the properties of this object are initialized by the scanner implementation. These defaults can be overridden
58-
* with the scanner-specific [options][PluginConfiguration.options] in [ScannerConfiguration.config]: Use properties
58+
* with the scanner-specific [options][PluginConfig.options] in [ScannerConfiguration.config]: Use properties
5959
* of the form `scannerName.options.property`, where `scannerName` is the name of the scanner and `property` is the
6060
* name of a property of the [ScannerMatcher] class. For instance, to specify that a specific minimum version of
6161
* ScanCode is allowed, set this property: `config.ScanCode.options.minVersion=3.0.2`.

0 commit comments

Comments
 (0)