From b253e954e058ba2181cfe35ecedd99a120b7c721 Mon Sep 17 00:00:00 2001 From: Frank Viernau Date: Thu, 20 Jul 2023 13:21:00 +0200 Subject: [PATCH] feat(helper-cli): Support package curations with flat definition files Signed-off-by: Frank Viernau --- ...yzerResultFromPackageListCommandFunTest.kt | 11 +++++++--- ...ateAnalyzerResultFromPackageListCommand.kt | 22 ++++++++++++++++++- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/helper-cli/src/funTest/kotlin/commands/CreateAnalyzerResultFromPackageListCommandFunTest.kt b/helper-cli/src/funTest/kotlin/commands/CreateAnalyzerResultFromPackageListCommandFunTest.kt index 54940db1641c5..913d11c285bf7 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.common.redirectStdout import org.ossreviewtoolkit.utils.ort.Environment import org.ossreviewtoolkit.utils.ort.createOrtTempDir @@ -48,7 +48,8 @@ class CreateAnalyzerResultFromPackageListCommandFunTest : WordSpec({ outputFile.absolutePath ) - outputFile.readText() shouldBe expectedOutputFile.readValue().patchEnvironment().toYaml() + outputFile.readValue().patchAnalyzerResult() shouldBe + expectedOutputFile.readValue().patchAnalyzerResult() } } }) @@ -63,4 +64,8 @@ private fun runMain(vararg args: String) = } }.lineSequence() -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 483e139f599c9..0a30a422a4b73 100644 --- a/helper-cli/src/main/kotlin/commands/CreateAnalyzerResultFromPackageListCommand.kt +++ b/helper-cli/src/main/kotlin/commands/CreateAnalyzerResultFromPackageListCommand.kt @@ -25,6 +25,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 @@ -45,13 +46,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 simple definition file into an analyzer result." @@ -72,6 +78,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().readValue(packageListFile) @@ -94,6 +108,12 @@ internal class CreateAnalyzerResultFromPackageListCommand : CliktCommand( ) ) + val ortConfig = OrtConfiguration.load(emptyMap(), configFile) + + val packageCurationProviders = buildList { + addAll(PackageCurationProviderFactory.create(ortConfig.packageCurationProviders)) + } + val ortResult = OrtResult( analyzer = AnalyzerRun.EMPTY.copy( result = AnalyzerResult( @@ -112,7 +132,7 @@ internal class CreateAnalyzerResultFromPackageListCommand : CliktCommand( ) ) ) - ) + ).addPackageCurations(packageCurationProviders) writeOrtResult(ortResult, ortFile) }