From 67a4c3872e64fdb360abb62c50ebb9febd70d421 Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Wed, 31 Jan 2024 22:36:17 +0100 Subject: [PATCH 1/2] test(ort-config): Improve test names Signed-off-by: Sebastian Schuberth --- .../funTest/kotlin/OrtConfigPackageCurationProviderFunTest.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 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 145785a0b4802..08bb72266a6d0 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 @@ -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) @@ -39,7 +39,7 @@ class OrtConfigPackageCurationProviderFunTest : StringSpec({ curations.filter { it.isApplicable(azureCoreAmqp) } shouldNot beEmpty() } - "provider does not fail for packages which have no curations" { + "The provider does not fail for packages which have no curations" { val packages = createPackagesFromIds(Identifier("Some:Bogus:Package:Id")) val curations = OrtConfigPackageCurationProvider().getCurationsFor(packages) From 42cb229039fc2fea288a4ffef1df5c91ff4a9cc9 Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Wed, 31 Jan 2024 22:50:21 +0100 Subject: [PATCH 2/2] 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 --- .../OrtConfigPackageCurationProviderFunTest.kt | 9 +++++++++ .../main/kotlin/OrtConfigPackageCurationProvider.kt | 12 ++++++++---- 2 files changed, 17 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..475bd59e1c133 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: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")) 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..cf41964bc17a6 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,19 @@ 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 namespace-level curations before package-level curations to allow overriding the former. + return listOf(namespaceCurationsFile, packageCurationsFile).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() } } }