Skip to content

Commit

Permalink
feat(ort-config): Support namespace-level package curations
Browse files Browse the repository at this point in the history
This is required to support curations like the one added in [1].

[1]: oss-review-toolkit/ort-config#165

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
  • Loading branch information
sschuberth committed Feb 1, 2024
1 parent 384e657 commit b55f91f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"))

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

0 comments on commit b55f91f

Please sign in to comment.