Skip to content

Commit

Permalink
feat(helper-cli): Support package curations with flat definition files
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Viernau <frank_viernau@epam.com>
  • Loading branch information
fviernau committed Aug 14, 2023
1 parent 6d2d76c commit 28dae09
Showing 1 changed file with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -41,15 +42,22 @@ import org.ossreviewtoolkit.model.PackageReference
import org.ossreviewtoolkit.model.Project
import org.ossreviewtoolkit.model.RemoteArtifact
import org.ossreviewtoolkit.model.Repository
import org.ossreviewtoolkit.model.ResolvedPackageCurations
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.orEmpty
import org.ossreviewtoolkit.model.utils.addPackageCurations
import org.ossreviewtoolkit.plugins.packagecurationproviders.api.PackageCurationProviderFactory
import org.ossreviewtoolkit.plugins.packagecurationproviders.api.SimplePackageCurationProvider
import org.ossreviewtoolkit.utils.common.expandTilde
import org.ossreviewtoolkit.utils.ort.ORT_CONFIG_FILENAME
import org.ossreviewtoolkit.utils.ort.ortConfigDirectory

internal class CreateFlatAnalyzerResultCommand : CliktCommand(
"A command which turns a simple definition file into an analyzer result."
Expand All @@ -70,6 +78,14 @@ internal class CreateFlatAnalyzerResultCommand : 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 definitionFile = FileFormat.forFile(simpleDefinitionFile).mapper.readValue<SimpleDefinitionFile>(
simpleDefinitionFile
Expand All @@ -94,6 +110,12 @@ internal class CreateFlatAnalyzerResultCommand : CliktCommand(
)
)

val ortConfig = OrtConfiguration.load(emptyMap(), configFile)

val packageCurationProviders = buildList {
addAll(PackageCurationProviderFactory.create(ortConfig.packageCurationProviders))
}

val ortResult = OrtResult(
analyzer = AnalyzerRun.EMPTY.copy(
result = AnalyzerResult(
Expand All @@ -111,7 +133,7 @@ internal class CreateFlatAnalyzerResultCommand : CliktCommand(
)
)
)
)
).addPackageCurations(packageCurationProviders)

writeOrtResult(ortResult, ortFile)
}
Expand Down

0 comments on commit 28dae09

Please sign in to comment.