Skip to content

Commit

Permalink
AnalyzerCommand: Create package curation providers from config file
Browse files Browse the repository at this point in the history
Use the `PackageCurationProviderFactory` to create the package curation
providers that are configured in the config file and remove the now
unused command line options to enable package curation providers.

The only exception is currently the provider that reads package
curations from the repository configuration, this will be handled in a
later commit.

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.io>
  • Loading branch information
mnonnenmacher committed Jan 6, 2023
1 parent 08e563a commit 5155072
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 51 deletions.
4 changes: 4 additions & 0 deletions analyzer/src/main/kotlin/PackageCurationProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package org.ossreviewtoolkit.analyzer

import org.ossreviewtoolkit.model.Identifier
import org.ossreviewtoolkit.model.PackageCuration
import org.ossreviewtoolkit.model.config.PackageCurationProviderConfiguration
import org.ossreviewtoolkit.utils.common.ConfigurablePluginFactory
import org.ossreviewtoolkit.utils.common.NamedPlugin

Expand All @@ -30,6 +31,9 @@ import org.ossreviewtoolkit.utils.common.NamedPlugin
interface PackageCurationProviderFactory<CONFIG> : ConfigurablePluginFactory<PackageCurationProvider> {
companion object {
val ALL = NamedPlugin.getAll<PackageCurationProviderFactory<*>>()

fun create(configurations: List<PackageCurationProviderConfiguration>) =
configurations.map { ALL.getValue(it.name).create(it.config) }.reversed()
}

override fun create(config: Map<String, String>): PackageCurationProvider = create(parseConfig(config))
Expand Down
53 changes: 2 additions & 51 deletions cli/src/main/kotlin/commands/AnalyzerCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import com.github.ajalt.clikt.parameters.options.convert
import com.github.ajalt.clikt.parameters.options.default
import com.github.ajalt.clikt.parameters.options.defaultLazy
import com.github.ajalt.clikt.parameters.options.deprecated
import com.github.ajalt.clikt.parameters.options.flag
import com.github.ajalt.clikt.parameters.options.option
import com.github.ajalt.clikt.parameters.options.required
import com.github.ajalt.clikt.parameters.options.split
Expand All @@ -40,14 +39,11 @@ import java.time.Duration
import kotlin.time.toKotlinDuration

import org.ossreviewtoolkit.analyzer.Analyzer
import org.ossreviewtoolkit.analyzer.PackageCurationProviderFactory
import org.ossreviewtoolkit.analyzer.PackageManager
import org.ossreviewtoolkit.analyzer.PackageManagerFactory
import org.ossreviewtoolkit.analyzer.curation.ClearlyDefinedPackageCurationProvider
import org.ossreviewtoolkit.analyzer.curation.CompositePackageCurationProvider
import org.ossreviewtoolkit.analyzer.curation.FilePackageCurationProvider
import org.ossreviewtoolkit.analyzer.curation.OrtConfigPackageCurationProvider
import org.ossreviewtoolkit.analyzer.curation.SimplePackageCurationProvider
import org.ossreviewtoolkit.analyzer.curation.Sw360PackageCurationProvider
import org.ossreviewtoolkit.cli.OrtCommand
import org.ossreviewtoolkit.cli.utils.SeverityStats
import org.ossreviewtoolkit.cli.utils.configurationGroup
Expand All @@ -64,8 +60,6 @@ import org.ossreviewtoolkit.model.utils.DefaultResolutionProvider
import org.ossreviewtoolkit.model.utils.mergeLabels
import org.ossreviewtoolkit.utils.common.expandTilde
import org.ossreviewtoolkit.utils.common.safeMkdirs
import org.ossreviewtoolkit.utils.ort.ORT_PACKAGE_CURATIONS_DIRNAME
import org.ossreviewtoolkit.utils.ort.ORT_PACKAGE_CURATIONS_FILENAME
import org.ossreviewtoolkit.utils.ort.ORT_REPO_CONFIG_FILENAME
import org.ossreviewtoolkit.utils.ort.ORT_RESOLUTIONS_FILENAME
import org.ossreviewtoolkit.utils.ort.ortConfigDirectory
Expand Down Expand Up @@ -98,24 +92,6 @@ class AnalyzerCommand : OrtCommand(
help = "The list of output formats to be used for the ORT result file(s)."
).enum<FileFormat>().split(",").default(listOf(FileFormat.YAML)).outputGroup()

private val packageCurationsFile by option(
"--package-curations-file",
help = "A file containing package curation data."
).convert { it.expandTilde() }
.file(mustExist = true, canBeFile = true, canBeDir = false, mustBeWritable = false, mustBeReadable = true)
.convert { it.absoluteFile.normalize() }
.default(ortConfigDirectory.resolve(ORT_PACKAGE_CURATIONS_FILENAME))
.configurationGroup()

private val packageCurationsDir by option(
"--package-curations-dir",
help = "A directory containing package curation data."
).convert { it.expandTilde() }
.file(mustExist = true, canBeFile = false, canBeDir = true, mustBeWritable = false, mustBeReadable = true)
.convert { it.absoluteFile.normalize() }
.default(ortConfigDirectory.resolve(ORT_PACKAGE_CURATIONS_DIRNAME))
.configurationGroup()

private val repositoryConfigurationFile by option(
"--repository-configuration-file",
help = "A file containing the repository configuration. If set, overrides any repository configuration " +
Expand All @@ -135,21 +111,6 @@ class AnalyzerCommand : OrtCommand(
.default(ortConfigDirectory.resolve(ORT_RESOLUTIONS_FILENAME))
.configurationGroup()

private val useClearlyDefinedCurations by option(
"--clearly-defined-curations",
help = "Whether to fall back to package curation data from the ClearlyDefine service or not."
).flag()

private val useOrtCurations by option(
"--ort-curations",
help = "Whether to fall back to package curation data from the ort-config repository or not."
).flag()

private val useSw360Curations by option(
"--sw360-curations",
help = "Whether to fall back to package curation data from the SW360 service or not."
).flag()

private val labels by option(
"--label", "-l",
help = "Set a label in the ORT result, overwriting any existing label of the same name. Can be used multiple " +
Expand Down Expand Up @@ -199,8 +160,6 @@ class AnalyzerCommand : OrtCommand(
}

val configurationFiles = listOf(
packageCurationsFile,
packageCurationsDir,
repositoryConfigurationFile,
resolutionsFile
)
Expand Down Expand Up @@ -232,15 +191,7 @@ class AnalyzerCommand : OrtCommand(
val analyzer = Analyzer(analyzerConfiguration, labels)

val curationProviders = buildList {
if (useClearlyDefinedCurations) add(ClearlyDefinedPackageCurationProvider())

if (useSw360Curations) {
ortConfig.analyzer.sw360Configuration?.let { add(Sw360PackageCurationProvider(it)) }
}

if (useOrtCurations) add(OrtConfigPackageCurationProvider())

add(FilePackageCurationProvider.from(packageCurationsFile, packageCurationsDir))
addAll(PackageCurationProviderFactory.create(ortConfig.packageCurationProviders))

val repositoryPackageCurations = repositoryConfiguration.curations.packages

Expand Down

0 comments on commit 5155072

Please sign in to comment.