Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support namespace-level package curations from ort-config #8204

Merged
merged 2 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import org.ossreviewtoolkit.model.Identifier
import org.ossreviewtoolkit.model.Package

class OrtConfigPackageCurationProviderFunTest : StringSpec({
"provider can load curations from the ort-config repository" {
"The provider succeeds to return known curations for packages" {
val azureCore = Identifier("NuGet:Azure:Core:1.22.0")
val azureCoreAmqp = Identifier("NuGet:Azure.Core:Amqp:1.2.0")
val packages = createPackagesFromIds(azureCore, azureCoreAmqp)
Expand All @@ -39,7 +39,16 @@ class OrtConfigPackageCurationProviderFunTest : StringSpec({
curations.filter { it.isApplicable(azureCoreAmqp) } shouldNot beEmpty()
}

"provider does not fail for packages which have no curations" {
"The provider returns curations that match the namespace of a package" {
val xrd4j = Identifier("Maven:org.niis.xrd4j:foo:0.0.0")
val packages = createPackagesFromIds(xrd4j)

val curations = OrtConfigPackageCurationProvider().getCurationsFor(packages)

curations.filter { it.isApplicable(xrd4j) } shouldNot beEmpty()
}

"The provider does not fail for packages which have no curations" {
val packages = createPackagesFromIds(Identifier("Some:Bogus:Package:Id"))

val curations = OrtConfigPackageCurationProvider().getCurationsFor(packages)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,19 @@ open class OrtConfigPackageCurationProvider : PackageCurationProvider {
packages.flatMapTo(mutableSetOf()) { pkg -> getCurationsFor(pkg.id) }

private fun getCurationsFor(pkgId: Identifier): List<PackageCuration> {
val file = curationsDir.resolve("curations").resolve(pkgId.toCurationPath())
return if (file.isFile) {
// The ORT config repository follows path layout conventions, so curations can be looked up directly.
val packageCurationsFile = curationsDir.resolve("curations").resolve(pkgId.toCurationPath())

// Also consider curations for all packages in a namespace.
val namespaceCurationsFile = packageCurationsFile.resolveSibling("_.yml")

// Return namespace-level curations before package-level curations to allow overriding the former.
return listOf(namespaceCurationsFile, packageCurationsFile).filter { it.isFile }.flatMap { file ->
runCatching {
file.readValue<List<PackageCuration>>().filter { it.isApplicable(pkgId) }
}.getOrElse {
throw IOException("Failed parsing package curation from '${file.absolutePath}'.", it)
}
} else {
emptyList()
}
}
}
Expand Down
Loading