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 Sep 6, 2023
1 parent 68e730d commit b253e95
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -48,7 +48,8 @@ class CreateAnalyzerResultFromPackageListCommandFunTest : WordSpec({
outputFile.absolutePath
)

outputFile.readText() shouldBe expectedOutputFile.readValue<OrtResult>().patchEnvironment().toYaml()
outputFile.readValue<OrtResult>().patchAnalyzerResult() shouldBe
expectedOutputFile.readValue<OrtResult>().patchAnalyzerResult()
}
}
})
Expand All @@ -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()
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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."
Expand All @@ -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<PackageList>(packageListFile)

Expand All @@ -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(
Expand All @@ -112,7 +132,7 @@ internal class CreateAnalyzerResultFromPackageListCommand : CliktCommand(
)
)
)
)
).addPackageCurations(packageCurationProviders)

writeOrtResult(ortResult, ortFile)
}
Expand Down

0 comments on commit b253e95

Please sign in to comment.