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 <sebastian@doubleopen.org>
  • Loading branch information
sschuberth committed Aug 15, 2024
1 parent d03abd4 commit b1dd96a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 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,7 @@ 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 packageNamesForServer = urls.distinct().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
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import io.mockk.unmockkAll
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 Down Expand Up @@ -163,7 +164,7 @@ private class MockRegistryServices(
RemoteBazelModuleRegistryService.create(registryUrls[1])
} returns remoteRegistry
every {
RemoteBazelModuleRegistryService.create()
RemoteBazelModuleRegistryService.create(DEFAULT_URL)
} returns centralRegistry

return MockRegistryServices(listOf(localRegistry1, localRegistry2, remoteRegistry, centralRegistry))
Expand Down

0 comments on commit b1dd96a

Please sign in to comment.