From 3c83d5fa0b035485e73e86fe0c5eebeef736deeb Mon Sep 17 00:00:00 2001 From: Frank Viernau Date: Fri, 15 Mar 2024 11:33:00 +0100 Subject: [PATCH] refactor(scanner): Rename `sourceCodeOriginsPriority` Drop the `Priority`-suffix to align with the `sourceCodeOriginsProperty` in other places, e.g. in `Package`. Adjust the KDoc to make clear that the given list of source code origins is in order of priority. While at it, re-word the comment a bit further, and re-align the analog part of the comment in the `PackageProvenanceResolver` interface with the one in the `DefaultPackageProvenanceResolver` class. Signed-off-by: Frank Viernau --- .../provenance/PackageProvenanceResolver.kt | 24 +++++++++---------- scanner/src/test/kotlin/ScannerTest.kt | 7 ++---- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/scanner/src/main/kotlin/provenance/PackageProvenanceResolver.kt b/scanner/src/main/kotlin/provenance/PackageProvenanceResolver.kt index 4c1b3891c7281..1dc8302324e78 100644 --- a/scanner/src/main/kotlin/provenance/PackageProvenanceResolver.kt +++ b/scanner/src/main/kotlin/provenance/PackageProvenanceResolver.kt @@ -47,11 +47,12 @@ import org.ossreviewtoolkit.utils.ort.showStackTrace */ interface PackageProvenanceResolver { /** - * Resolve the [KnownProvenance] of [pkg] based on the provided [defaultSourceCodeOriginsPriority]. + * Resolve the [Provenance] of [pkg] based on [Package.sourceCodeOrigins] if specified, or else on + * [defaultSourceCodeOrigins]. Each source code origins are listed in order of priority. * * Throws an [IOException] if the provenance cannot be resolved. */ - fun resolveProvenance(pkg: Package, defaultSourceCodeOriginsPriority: List): KnownProvenance + fun resolveProvenance(pkg: Package, defaultSourceCodeOrigins: List): KnownProvenance } /** @@ -62,18 +63,15 @@ class DefaultPackageProvenanceResolver( private val workingTreeCache: WorkingTreeCache ) : PackageProvenanceResolver { /** - * Resolve the [Provenance] of [pkg] based on the provided [defaultSourceCodeOriginsPriority] which is used in case - * the [Package][pkg] does not specify the source code origins to be used. For source artifacts it is verified that - * the [RemoteArtifact] does exist. For a VCS it is verified that the revision exists. If the revision provided by - * the [package][pkg] metadata does not exist or is missing, the function tries to guess the tag based on the name - * and version of the [package][pkg]. + * Resolve the [Provenance] of [pkg] based on [Package.sourceCodeOrigins] if specified, or else on + * [defaultSourceCodeOrigins]. Each source code origins are listed in order of priority. For source artifacts it is + * verified that the [RemoteArtifact] does exist. For a VCS it is verified that the revision exists. If the revision + * provided by the [package][pkg] metadata does not exist or is missing, the function tries to guess the tag based + * on the name and version of the [package][pkg]. */ - override fun resolveProvenance( - pkg: Package, - defaultSourceCodeOriginsPriority: List - ): KnownProvenance { + override fun resolveProvenance(pkg: Package, defaultSourceCodeOrigins: List): KnownProvenance { val errors = mutableMapOf() - val sourceCodeOrigins = pkg.sourceCodeOrigins ?: defaultSourceCodeOriginsPriority + val sourceCodeOrigins = pkg.sourceCodeOrigins ?: defaultSourceCodeOrigins sourceCodeOrigins.forEach { sourceCodeOrigin -> runCatching { @@ -103,7 +101,7 @@ class DefaultPackageProvenanceResolver( val message = buildString { append( "Could not resolve provenance for package '${pkg.id.toCoordinates()}' for source code origins " + - "$defaultSourceCodeOriginsPriority." + "$defaultSourceCodeOrigins." ) errors.forEach { (origin, throwable) -> diff --git a/scanner/src/test/kotlin/ScannerTest.kt b/scanner/src/test/kotlin/ScannerTest.kt index b2297e750cf9c..10a477846ca0d 100644 --- a/scanner/src/test/kotlin/ScannerTest.kt +++ b/scanner/src/test/kotlin/ScannerTest.kt @@ -952,11 +952,8 @@ private class FakeProvenanceDownloader(val filename: String = "fake.txt") : Prov * validation. */ private class FakePackageProvenanceResolver : PackageProvenanceResolver { - override fun resolveProvenance( - pkg: Package, - defaultSourceCodeOriginsPriority: List - ): KnownProvenance { - defaultSourceCodeOriginsPriority.forEach { sourceCodeOrigin -> + override fun resolveProvenance(pkg: Package, defaultSourceCodeOrigins: List): KnownProvenance { + defaultSourceCodeOrigins.forEach { sourceCodeOrigin -> when (sourceCodeOrigin) { SourceCodeOrigin.ARTIFACT -> { if (pkg.sourceArtifact != RemoteArtifact.EMPTY) {