Skip to content

Commit

Permalink
fix(bazel): Distict registry URLs by their normalized form
Browse files Browse the repository at this point in the history
This avoids output like

    Creating remote Bazel module registry at 'https://bcr.bazel.build/'.
    Creating remote Bazel module registry at 'https://bcr.bazel.build'.

Signed-off-by: Sebastian Schuberth <[email protected]>
  • Loading branch information
sschuberth committed Aug 13, 2024
1 parent fdf23c0 commit 9cf85a7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import retrofit2.http.Path
/**
* The client uses the Bazel Central Registry by default.
*/
private const val DEFAULT_URL = "https://bcr.bazel.build"
const val DEFAULT_URL = "https://bcr.bazel.build"

/**
* Interface for a Bazel Module Registry, based on the directory structure of https://bcr.bazel.build/ and the Git
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ internal class CompositeBazelModuleRegistryService(
* created based on the passed in [urls]; local registries use the given [projectDir] as workspace.
*/
fun create(urls: Collection<String>, projectDir: File): CompositeBazelModuleRegistryService {
val packageNamesForServer = urls.filter { it.endsWith("source.json") }.mapNotNull { url ->
val registryUrls = urls.distinctBy { it.removeSuffix("/") }

val packageNamesForServer = registryUrls.filter { it.endsWith("source.json") }.mapNotNull { url ->
val groups = URL_REGEX.matchEntire(url)?.groups

val serverName = groups?.get("server")?.value ?: let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package org.ossreviewtoolkit.plugins.packagemanagers.bazel
import java.io.File

import org.ossreviewtoolkit.clients.bazelmoduleregistry.BazelModuleRegistryService
import org.ossreviewtoolkit.clients.bazelmoduleregistry.DEFAULT_URL
import org.ossreviewtoolkit.clients.bazelmoduleregistry.LocalBazelModuleRegistryService
import org.ossreviewtoolkit.clients.bazelmoduleregistry.ModuleMetadata
import org.ossreviewtoolkit.clients.bazelmoduleregistry.ModuleSourceInfo
Expand All @@ -46,14 +47,14 @@ internal class MultiBazelModuleRegistryService(
* the last service a remote module registry for the Bazel Central Registry is added that serves as a fallback.
*/
fun create(urls: Collection<String>, projectDir: File): MultiBazelModuleRegistryService {
val registryServices = urls.mapTo(mutableListOf()) { url ->
// Add the default Bazel registry as a fallback.
val registryUrls = (urls + DEFAULT_URL).distinctBy { it.removeSuffix("/") }

val registryServices = registryUrls.mapTo(mutableListOf()) { url ->
LocalBazelModuleRegistryService.create(url, projectDir)
?: RemoteBazelModuleRegistryService.create(url)
}

// Add the default Bazel registry as a fallback.
registryServices += RemoteBazelModuleRegistryService.create()

return MultiBazelModuleRegistryService(registryServices)
}

Expand Down

0 comments on commit 9cf85a7

Please sign in to comment.