Skip to content

Commit

Permalink
refactor(scanner): Rename sourceCodeOriginsPriority
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
fviernau committed Mar 15, 2024
1 parent 16ee7fd commit 3c83d5f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
24 changes: 11 additions & 13 deletions scanner/src/main/kotlin/provenance/PackageProvenanceResolver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<SourceCodeOrigin>): KnownProvenance
fun resolveProvenance(pkg: Package, defaultSourceCodeOrigins: List<SourceCodeOrigin>): KnownProvenance
}

/**
Expand All @@ -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<SourceCodeOrigin>
): KnownProvenance {
override fun resolveProvenance(pkg: Package, defaultSourceCodeOrigins: List<SourceCodeOrigin>): KnownProvenance {
val errors = mutableMapOf<SourceCodeOrigin, Throwable>()
val sourceCodeOrigins = pkg.sourceCodeOrigins ?: defaultSourceCodeOriginsPriority
val sourceCodeOrigins = pkg.sourceCodeOrigins ?: defaultSourceCodeOrigins

sourceCodeOrigins.forEach { sourceCodeOrigin ->
runCatching {
Expand Down Expand Up @@ -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) ->
Expand Down
7 changes: 2 additions & 5 deletions scanner/src/test/kotlin/ScannerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<SourceCodeOrigin>
): KnownProvenance {
defaultSourceCodeOriginsPriority.forEach { sourceCodeOrigin ->
override fun resolveProvenance(pkg: Package, defaultSourceCodeOrigins: List<SourceCodeOrigin>): KnownProvenance {
defaultSourceCodeOrigins.forEach { sourceCodeOrigin ->
when (sourceCodeOrigin) {
SourceCodeOrigin.ARTIFACT -> {
if (pkg.sourceArtifact != RemoteArtifact.EMPTY) {
Expand Down

0 comments on commit 3c83d5f

Please sign in to comment.