Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve plugin config vs classpath exceptions #7723

Merged
merged 3 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -41,20 +43,27 @@ interface PackageConfigurationProviderFactory<CONFIG> :
fun create(
configurations: List<ProviderPluginConfiguration>
): List<Pair<String, PackageConfigurationProvider>> =
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
}.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."
}

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."
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -41,8 +43,15 @@ interface PackageCurationProviderFactory<CONFIG> : TypedConfigurablePluginFactor
fun create(configurations: List<ProviderPluginConfiguration>): List<Pair<String, PackageCurationProvider>> =
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."
Expand Down
4 changes: 2 additions & 2 deletions scanner/src/main/kotlin/storages/ClearlyDefinedStorage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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'." }
}
}

Expand Down