From 5991983e33c49cf38adb558c5b9ff027216d72b9 Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Wed, 31 Jan 2024 22:50:21 +0100 Subject: [PATCH] feat(ort-config): Support namespace-level package curations This is required to support curations like the one added in [1]. [1]: https://github.com/oss-review-toolkit/ort-config/pull/165 Signed-off-by: Sebastian Schuberth --- .../kotlin/OrtConfigPackageCurationProviderFunTest.kt | 9 +++++++++ .../main/kotlin/OrtConfigPackageCurationProvider.kt | 11 +++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/plugins/package-curation-providers/ort-config/src/funTest/kotlin/OrtConfigPackageCurationProviderFunTest.kt b/plugins/package-curation-providers/ort-config/src/funTest/kotlin/OrtConfigPackageCurationProviderFunTest.kt index 08bb72266a6d0..c500cabed2901 100644 --- a/plugins/package-curation-providers/ort-config/src/funTest/kotlin/OrtConfigPackageCurationProviderFunTest.kt +++ b/plugins/package-curation-providers/ort-config/src/funTest/kotlin/OrtConfigPackageCurationProviderFunTest.kt @@ -39,6 +39,15 @@ class OrtConfigPackageCurationProviderFunTest : StringSpec({ curations.filter { it.isApplicable(azureCoreAmqp) } shouldNot beEmpty() } + "The provider returns curations that match the namespace of a package" { + val xrd4j = Identifier("Maven:org.niis.xrd4j:foo:1.2.3") + 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")) diff --git a/plugins/package-curation-providers/ort-config/src/main/kotlin/OrtConfigPackageCurationProvider.kt b/plugins/package-curation-providers/ort-config/src/main/kotlin/OrtConfigPackageCurationProvider.kt index fb4b8a319d4d6..5fd950b0464b5 100644 --- a/plugins/package-curation-providers/ort-config/src/main/kotlin/OrtConfigPackageCurationProvider.kt +++ b/plugins/package-curation-providers/ort-config/src/main/kotlin/OrtConfigPackageCurationProvider.kt @@ -64,15 +64,18 @@ open class OrtConfigPackageCurationProvider : PackageCurationProvider { packages.flatMapTo(mutableSetOf()) { pkg -> getCurationsFor(pkg.id) } private fun getCurationsFor(pkgId: Identifier): List { - 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 listOf(packageCurationsFile, namespaceCurationsFile).filter { it.isFile }.flatMap { file -> runCatching { file.readValue>().filter { it.isApplicable(pkgId) } }.getOrElse { throw IOException("Failed parsing package curation from '${file.absolutePath}'.", it) } - } else { - emptyList() } } }