From e6a57c061d2bf939edd2174180c682201e03e05a Mon Sep 17 00:00:00 2001 From: Frank Viernau Date: Thu, 20 Jul 2023 13:21:00 +0200 Subject: [PATCH] feat(helper-cli): Inlcude package curations into generated ORT file As the analyzer is responsible for adding all package curations from all configurated providers to the resolved configuration in the ORT file, do so as well when generating the analyzer result from a package list file. This allows to use the standard package curation workflow with `CreateAnalyzerResultFromPackageListCommand`. Signed-off-by: Frank Viernau --- ...yzerResultFromPackageListCommandFunTest.kt | 11 ++++++++--- ...ateAnalyzerResultFromPackageListCommand.kt | 19 ++++++++++++++++++- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/helper-cli/src/funTest/kotlin/commands/CreateAnalyzerResultFromPackageListCommandFunTest.kt b/helper-cli/src/funTest/kotlin/commands/CreateAnalyzerResultFromPackageListCommandFunTest.kt index 6613e1dddd298..ce3c7dc6cf5f8 100644 --- a/helper-cli/src/funTest/kotlin/commands/CreateAnalyzerResultFromPackageListCommandFunTest.kt +++ b/helper-cli/src/funTest/kotlin/commands/CreateAnalyzerResultFromPackageListCommandFunTest.kt @@ -26,8 +26,8 @@ import io.kotest.matchers.shouldBe import org.ossreviewtoolkit.helper.HelperMain import org.ossreviewtoolkit.model.OrtResult +import org.ossreviewtoolkit.model.ResolvedConfiguration import org.ossreviewtoolkit.model.readValue -import org.ossreviewtoolkit.model.toYaml import org.ossreviewtoolkit.utils.ort.Environment import org.ossreviewtoolkit.utils.ort.createOrtTempDir import org.ossreviewtoolkit.utils.test.getAssetFile @@ -47,7 +47,8 @@ class CreateAnalyzerResultFromPackageListCommandFunTest : WordSpec({ outputFile.absolutePath ) - outputFile.readText() shouldBe expectedOutputFile.readValue().patchEnvironment().toYaml() + outputFile.readValue().patchAnalyzerResult() shouldBe + expectedOutputFile.readValue().patchAnalyzerResult() } } }) @@ -61,4 +62,8 @@ private fun runMain(vararg args: String) { } } -private fun OrtResult.patchEnvironment(): OrtResult = copy(analyzer = analyzer?.copy(environment = Environment())) +private fun OrtResult.patchAnalyzerResult(): OrtResult = + copy( + analyzer = analyzer?.copy(environment = Environment()), + resolvedConfiguration = ResolvedConfiguration() + ) diff --git a/helper-cli/src/main/kotlin/commands/CreateAnalyzerResultFromPackageListCommand.kt b/helper-cli/src/main/kotlin/commands/CreateAnalyzerResultFromPackageListCommand.kt index 7ffa6f7bef7ae..06a5c9e40299a 100644 --- a/helper-cli/src/main/kotlin/commands/CreateAnalyzerResultFromPackageListCommand.kt +++ b/helper-cli/src/main/kotlin/commands/CreateAnalyzerResultFromPackageListCommand.kt @@ -24,6 +24,7 @@ import com.fasterxml.jackson.module.kotlin.readValue import com.github.ajalt.clikt.core.CliktCommand import com.github.ajalt.clikt.parameters.options.convert +import com.github.ajalt.clikt.parameters.options.default import com.github.ajalt.clikt.parameters.options.option import com.github.ajalt.clikt.parameters.options.required import com.github.ajalt.clikt.parameters.types.file @@ -44,13 +45,18 @@ import org.ossreviewtoolkit.model.Scope import org.ossreviewtoolkit.model.VcsInfo import org.ossreviewtoolkit.model.VcsType import org.ossreviewtoolkit.model.config.Excludes +import org.ossreviewtoolkit.model.config.OrtConfiguration import org.ossreviewtoolkit.model.config.RepositoryConfiguration import org.ossreviewtoolkit.model.config.ScopeExclude import org.ossreviewtoolkit.model.config.ScopeExcludeReason import org.ossreviewtoolkit.model.mapper import org.ossreviewtoolkit.model.orEmpty +import org.ossreviewtoolkit.model.utils.addPackageCurations +import org.ossreviewtoolkit.plugins.packagecurationproviders.api.PackageCurationProviderFactory import org.ossreviewtoolkit.utils.common.expandTilde import org.ossreviewtoolkit.utils.ort.Environment +import org.ossreviewtoolkit.utils.ort.ORT_CONFIG_FILENAME +import org.ossreviewtoolkit.utils.ort.ortConfigDirectory internal class CreateAnalyzerResultFromPackageListCommand : CliktCommand( "A command which turns a package list file into an analyzer result." @@ -71,6 +77,14 @@ internal class CreateAnalyzerResultFromPackageListCommand : CliktCommand( .convert { it.absoluteFile.normalize() } .required() + private val configFile by option( + "--config", + help = "The path to the ORT configuration file that configures the scan results storage." + ).convert { it.expandTilde() } + .file(mustExist = true, canBeFile = true, canBeDir = false, mustBeWritable = false, mustBeReadable = true) + .convert { it.absoluteFile.normalize() } + .default(ortConfigDirectory.resolve(ORT_CONFIG_FILENAME)) + override fun run() { val packageList = packageListFile.mapper().copy().apply { // Use camel case already now (even if in all places snake case is used), because there is a plan @@ -92,6 +106,9 @@ internal class CreateAnalyzerResultFromPackageListCommand : CliktCommand( ) ) + val ortConfig = OrtConfiguration.load(emptyMap(), configFile) + val packageCurationProviders = PackageCurationProviderFactory.create(ortConfig.packageCurationProviders) + val ortResult = OrtResult( analyzer = AnalyzerRun.EMPTY.copy( result = AnalyzerResult( @@ -110,7 +127,7 @@ internal class CreateAnalyzerResultFromPackageListCommand : CliktCommand( ) ) ) - ) + ).addPackageCurations(packageCurationProviders) writeOrtResult(ortResult, ortFile) }