Skip to content

Commit 6e340da

Browse files
committed
feat(helper-cli): Support package curations with flat definition files
Signed-off-by: Frank Viernau <[email protected]>
1 parent 88fe337 commit 6e340da

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-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: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import com.fasterxml.jackson.module.kotlin.readValue
2323

2424
import com.github.ajalt.clikt.core.CliktCommand
2525
import com.github.ajalt.clikt.parameters.options.convert
26+
import com.github.ajalt.clikt.parameters.options.default
2627
import com.github.ajalt.clikt.parameters.options.option
2728
import com.github.ajalt.clikt.parameters.options.required
2829
import com.github.ajalt.clikt.parameters.types.file
@@ -43,13 +44,18 @@ import org.ossreviewtoolkit.model.Scope
4344
import org.ossreviewtoolkit.model.VcsInfo
4445
import org.ossreviewtoolkit.model.VcsType
4546
import org.ossreviewtoolkit.model.config.Excludes
47+
import org.ossreviewtoolkit.model.config.OrtConfiguration
4648
import org.ossreviewtoolkit.model.config.RepositoryConfiguration
4749
import org.ossreviewtoolkit.model.config.ScopeExclude
4850
import org.ossreviewtoolkit.model.config.ScopeExcludeReason
4951
import org.ossreviewtoolkit.model.mapper
5052
import org.ossreviewtoolkit.model.orEmpty
53+
import org.ossreviewtoolkit.model.utils.addPackageCurations
54+
import org.ossreviewtoolkit.plugins.packagecurationproviders.api.PackageCurationProviderFactory
5155
import org.ossreviewtoolkit.utils.common.expandTilde
5256
import org.ossreviewtoolkit.utils.ort.Environment
57+
import org.ossreviewtoolkit.utils.ort.ORT_CONFIG_FILENAME
58+
import org.ossreviewtoolkit.utils.ort.ortConfigDirectory
5359

5460
internal class CreateAnalyzerResultFromPackageListCommand : CliktCommand(
5561
"A command which turns a simple definition file into an analyzer result."
@@ -70,6 +76,14 @@ internal class CreateAnalyzerResultFromPackageListCommand : CliktCommand(
7076
.convert { it.absoluteFile.normalize() }
7177
.required()
7278

79+
private val configFile by option(
80+
"--config",
81+
help = "The path to the ORT configuration file that configures the scan results storage."
82+
).convert { it.expandTilde() }
83+
.file(mustExist = true, canBeFile = true, canBeDir = false, mustBeWritable = false, mustBeReadable = true)
84+
.convert { it.absoluteFile.normalize() }
85+
.default(ortConfigDirectory.resolve(ORT_CONFIG_FILENAME))
86+
7387
override fun run() {
7488
val packageList = packageListFile.mapper().readValue<PackageList>(packageListFile)
7589

@@ -92,6 +106,12 @@ internal class CreateAnalyzerResultFromPackageListCommand : CliktCommand(
92106
)
93107
)
94108

109+
val ortConfig = OrtConfiguration.load(emptyMap(), configFile)
110+
111+
val packageCurationProviders = buildList {
112+
addAll(PackageCurationProviderFactory.create(ortConfig.packageCurationProviders))
113+
}
114+
95115
val ortResult = OrtResult(
96116
analyzer = AnalyzerRun.EMPTY.copy(
97117
result = AnalyzerResult(
@@ -110,7 +130,7 @@ internal class CreateAnalyzerResultFromPackageListCommand : CliktCommand(
110130
)
111131
)
112132
)
113-
)
133+
).addPackageCurations(packageCurationProviders)
114134

115135
writeOrtResult(ortResult, ortFile)
116136
}

0 commit comments

Comments
 (0)