Skip to content

Commit c05897c

Browse files
committed
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 <[email protected]>
1 parent f04b444 commit c05897c

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

helper-cli/src/funTest/kotlin/commands/CreateAnalyzerResultFromPackageListCommandFunTest.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ import io.kotest.matchers.shouldBe
2626

2727
import org.ossreviewtoolkit.helper.HelperMain
2828
import org.ossreviewtoolkit.model.OrtResult
29+
import org.ossreviewtoolkit.model.ResolvedConfiguration
2930
import org.ossreviewtoolkit.model.readValue
30-
import org.ossreviewtoolkit.model.toYaml
3131
import org.ossreviewtoolkit.utils.ort.Environment
3232
import org.ossreviewtoolkit.utils.ort.createOrtTempDir
3333
import org.ossreviewtoolkit.utils.test.getAssetFile
@@ -47,7 +47,8 @@ class CreateAnalyzerResultFromPackageListCommandFunTest : WordSpec({
4747
outputFile.absolutePath
4848
)
4949

50-
outputFile.readText() shouldBe expectedOutputFile.readValue<OrtResult>().patchEnvironment().toYaml()
50+
outputFile.readValue<OrtResult>().patchAnalyzerResult() shouldBe
51+
expectedOutputFile.readValue<OrtResult>().patchAnalyzerResult()
5152
}
5253
}
5354
})
@@ -61,4 +62,8 @@ private fun runMain(vararg args: String) {
6162
}
6263
}
6364

64-
private fun OrtResult.patchEnvironment(): OrtResult = copy(analyzer = analyzer?.copy(environment = Environment()))
65+
private fun OrtResult.patchAnalyzerResult(): OrtResult =
66+
copy(
67+
analyzer = analyzer?.copy(environment = Environment()),
68+
resolvedConfiguration = ResolvedConfiguration()
69+
)

helper-cli/src/main/kotlin/commands/CreateAnalyzerResultFromPackageListCommand.kt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import com.fasterxml.jackson.module.kotlin.readValue
2424

2525
import com.github.ajalt.clikt.core.CliktCommand
2626
import com.github.ajalt.clikt.parameters.options.convert
27+
import com.github.ajalt.clikt.parameters.options.default
2728
import com.github.ajalt.clikt.parameters.options.option
2829
import com.github.ajalt.clikt.parameters.options.required
2930
import com.github.ajalt.clikt.parameters.types.file
@@ -44,13 +45,18 @@ import org.ossreviewtoolkit.model.Scope
4445
import org.ossreviewtoolkit.model.VcsInfo
4546
import org.ossreviewtoolkit.model.VcsType
4647
import org.ossreviewtoolkit.model.config.Excludes
48+
import org.ossreviewtoolkit.model.config.OrtConfiguration
4749
import org.ossreviewtoolkit.model.config.RepositoryConfiguration
4850
import org.ossreviewtoolkit.model.config.ScopeExclude
4951
import org.ossreviewtoolkit.model.config.ScopeExcludeReason
5052
import org.ossreviewtoolkit.model.mapper
5153
import org.ossreviewtoolkit.model.orEmpty
54+
import org.ossreviewtoolkit.model.utils.addPackageCurations
55+
import org.ossreviewtoolkit.plugins.packagecurationproviders.api.PackageCurationProviderFactory
5256
import org.ossreviewtoolkit.utils.common.expandTilde
5357
import org.ossreviewtoolkit.utils.ort.Environment
58+
import org.ossreviewtoolkit.utils.ort.ORT_CONFIG_FILENAME
59+
import org.ossreviewtoolkit.utils.ort.ortConfigDirectory
5460

5561
internal class CreateAnalyzerResultFromPackageListCommand : CliktCommand(
5662
"A command which turns a package list file into an analyzer result."
@@ -71,6 +77,14 @@ internal class CreateAnalyzerResultFromPackageListCommand : CliktCommand(
7177
.convert { it.absoluteFile.normalize() }
7278
.required()
7379

80+
private val configFile by option(
81+
"--config",
82+
help = "The path to the ORT configuration file that configures the scan results storage."
83+
).convert { it.expandTilde() }
84+
.file(mustExist = true, canBeFile = true, canBeDir = false, mustBeWritable = false, mustBeReadable = true)
85+
.convert { it.absoluteFile.normalize() }
86+
.default(ortConfigDirectory.resolve(ORT_CONFIG_FILENAME))
87+
7488
override fun run() {
7589
val packageList = packageListFile.mapper().copy().apply {
7690
// 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(
92106
)
93107
)
94108

109+
val ortConfig = OrtConfiguration.load(emptyMap(), configFile)
110+
val packageCurationProviders = PackageCurationProviderFactory.create(ortConfig.packageCurationProviders)
111+
95112
val ortResult = OrtResult(
96113
analyzer = AnalyzerRun.EMPTY.copy(
97114
result = AnalyzerResult(
@@ -110,7 +127,7 @@ internal class CreateAnalyzerResultFromPackageListCommand : CliktCommand(
110127
)
111128
)
112129
)
113-
)
130+
).addPackageCurations(packageCurationProviders)
114131

115132
writeOrtResult(ortResult, ortFile)
116133
}

0 commit comments

Comments
 (0)