From 18daa9dc4fd419509845e81604d98b87345ae397 Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Fri, 20 Oct 2023 08:33:16 +0200 Subject: [PATCH 1/3] style: Align formatting between configuration and curation providers Signed-off-by: Sebastian Schuberth --- .../PackageConfigurationProviderFactory.kt | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/plugins/package-configuration-providers/api/src/main/kotlin/PackageConfigurationProviderFactory.kt b/plugins/package-configuration-providers/api/src/main/kotlin/PackageConfigurationProviderFactory.kt index 1e69cd1fdbd2b..19ff586cdac6f 100644 --- a/plugins/package-configuration-providers/api/src/main/kotlin/PackageConfigurationProviderFactory.kt +++ b/plugins/package-configuration-providers/api/src/main/kotlin/PackageConfigurationProviderFactory.kt @@ -41,20 +41,20 @@ interface PackageConfigurationProviderFactory : fun create( configurations: List ): List> = - configurations.filter { it.enabled } - .map { it.id to ALL.getValue(it.type).create(it.options, it.secrets) } - .apply { - require(none { (id, _) -> id.isBlank() }) { - "The configuration contains a package configuration provider with a blank ID which is not " + - "allowed." - } + configurations.filter { + it.enabled + }.map { + it.id to ALL.getValue(it.type).create(it.options, it.secrets) + }.apply { + require(none { (id, _) -> id.isBlank() }) { + "The configuration contains a package configuration provider with a blank ID which is not allowed." + } - val duplicateIds = getDuplicates { (id, _) -> id }.keys - require(duplicateIds.isEmpty()) { - "Found multiple package configuration providers for the IDs ${duplicateIds.joinToString()}, " + - "which is not allowed. Please configure a unique ID for each package configuration " + - "provider." - } + val duplicateIds = getDuplicates { (id, _) -> id }.keys + require(duplicateIds.isEmpty()) { + "Found multiple package configuration providers for the IDs ${duplicateIds.joinToString()}, " + + "which is not allowed. Please configure a unique ID for each package configuration provider." } + } } } From 283fc15486a2d49a0ed41b0b212864b6f9b05a92 Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Fri, 20 Oct 2023 08:58:53 +0200 Subject: [PATCH 2/3] fix(plugins): Do not crash for enabled plugins that are unavailable Previously, if a provider plugin was enabled in ORT's configuration but was unavailable in the classpath, the `ALL` map lookup threw a `NoSuchElementException` resulting in ORT to crash. Avoid that by logging this case as an error instead, but continuing to run. The ORT result file will properly reflect only the used provider plugins. Signed-off-by: Sebastian Schuberth --- .../kotlin/PackageConfigurationProviderFactory.kt | 13 +++++++++++-- .../main/kotlin/PackageCurationProviderFactory.kt | 13 +++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/plugins/package-configuration-providers/api/src/main/kotlin/PackageConfigurationProviderFactory.kt b/plugins/package-configuration-providers/api/src/main/kotlin/PackageConfigurationProviderFactory.kt index 19ff586cdac6f..3f68646c62356 100644 --- a/plugins/package-configuration-providers/api/src/main/kotlin/PackageConfigurationProviderFactory.kt +++ b/plugins/package-configuration-providers/api/src/main/kotlin/PackageConfigurationProviderFactory.kt @@ -19,6 +19,8 @@ package org.ossreviewtoolkit.plugins.packageconfigurationproviders.api +import org.apache.logging.log4j.kotlin.logger + import org.ossreviewtoolkit.model.config.ProviderPluginConfiguration import org.ossreviewtoolkit.model.utils.PackageConfigurationProvider import org.ossreviewtoolkit.utils.common.Plugin @@ -43,8 +45,15 @@ interface PackageConfigurationProviderFactory : ): List> = configurations.filter { it.enabled - }.map { - it.id to ALL.getValue(it.type).create(it.options, it.secrets) + }.mapNotNull { + ALL[it.type]?.let { factory -> + it.id to factory.create(it.options, it.secrets) + }.also { factory -> + factory ?: logger.error { + "Configuration provider of type '${it.type}' is enabled in configuration but not available " + + "in the classpath." + } + } }.apply { require(none { (id, _) -> id.isBlank() }) { "The configuration contains a package configuration provider with a blank ID which is not allowed." diff --git a/plugins/package-curation-providers/api/src/main/kotlin/PackageCurationProviderFactory.kt b/plugins/package-curation-providers/api/src/main/kotlin/PackageCurationProviderFactory.kt index dede098a94d45..44c0afb119dc9 100644 --- a/plugins/package-curation-providers/api/src/main/kotlin/PackageCurationProviderFactory.kt +++ b/plugins/package-curation-providers/api/src/main/kotlin/PackageCurationProviderFactory.kt @@ -19,6 +19,8 @@ package org.ossreviewtoolkit.plugins.packagecurationproviders.api +import org.apache.logging.log4j.kotlin.logger + import org.ossreviewtoolkit.model.ResolvedPackageCurations.Companion.REPOSITORY_CONFIGURATION_PROVIDER_ID import org.ossreviewtoolkit.model.config.ProviderPluginConfiguration import org.ossreviewtoolkit.model.utils.PackageCurationProvider @@ -41,8 +43,15 @@ interface PackageCurationProviderFactory : TypedConfigurablePluginFactor fun create(configurations: List): List> = configurations.filter { it.enabled - }.map { - it.id to ALL.getValue(it.type).create(it.options, it.secrets) + }.mapNotNull { + ALL[it.type]?.let { factory -> + it.id to factory.create(it.options, it.secrets) + }.also { factory -> + factory ?: logger.error { + "Curation provider of type '${it.type}' is enabled in configuration but not available in the " + + "classpath." + } + } }.apply { require(none { (id, _) -> id.isBlank() }) { "The configuration contains a package curations provider with a blank ID which is not allowed." From c09a355cf6388d676e0e1b53575d10a38eea6312 Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Fri, 20 Oct 2023 09:02:43 +0200 Subject: [PATCH 3/3] style(scanner): Shorten a `null` check In exchange, use the longer but more readable `factory` lambda parameter name. Signed-off-by: Sebastian Schuberth --- scanner/src/main/kotlin/storages/ClearlyDefinedStorage.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scanner/src/main/kotlin/storages/ClearlyDefinedStorage.kt b/scanner/src/main/kotlin/storages/ClearlyDefinedStorage.kt index f3347a5ec56e3..4dff3ef196f28 100644 --- a/scanner/src/main/kotlin/storages/ClearlyDefinedStorage.kt +++ b/scanner/src/main/kotlin/storages/ClearlyDefinedStorage.kt @@ -113,8 +113,8 @@ class ClearlyDefinedStorage( ScannerWrapper.ALL[name]?.let { factory -> val scanner = factory.create(emptyMap(), emptyMap()) (scanner as? CommandLinePathScannerWrapper)?.let { cliScanner -> cliScanner to versions.last() } - }.also { - if (it == null) logger.debug { "Unsupported tool '$name' for coordinates '$coordinates'." } + }.also { factory -> + factory ?: logger.debug { "Unsupported tool '$name' for coordinates '$coordinates'." } } }