Skip to content

Commit

Permalink
refactor(Bazel)!: Rename the Bazel registry service
Browse files Browse the repository at this point in the history
In an upcoming change, a local registry service will be introduced,
requiring this renaming.

Signed-off-by: Nicolas Nobelis <nicolas.nobelis@bosch.com>
  • Loading branch information
nnobelis authored and sschuberth committed Jun 24, 2024
1 parent 72c1a14 commit 50c0512
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import io.kotest.matchers.comparables.shouldBeGreaterThan
import io.kotest.matchers.shouldBe

class BazelModuleRegistryClientFunTest : WordSpec({
val client = BazelModuleRegistryService.create()
val client = RemoteBazelModuleRegistryService.create()
val repoUrl = "https://github.com/google/glog"

"getModuleMetadata" should {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ private 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
* repository it is based on (https://github.com/bazelbuild/bazel-central-registry/).
*/
interface BazelModuleRegistryService {
interface RemoteBazelModuleRegistryService {
companion object {
/**
* Create a Bazel Module Registry client instance for communicating with a server running at the given [url],
* defaulting to the Bazel Central Registry, optionally with a pre-built OkHttp [client].
*/
fun create(url: String? = null, client: OkHttpClient? = null): BazelModuleRegistryService {
fun create(url: String? = null, client: OkHttpClient? = null): RemoteBazelModuleRegistryService {
val bmrClient = client ?: OkHttpClient()

val contentType = "application/json".toMediaType()
Expand All @@ -63,7 +63,7 @@ interface BazelModuleRegistryService {
.addConverterFactory(JSON.asConverterFactory(contentType))
.build()

return retrofit.create(BazelModuleRegistryService::class.java)
return retrofit.create(RemoteBazelModuleRegistryService::class.java)
}
}

Expand Down
8 changes: 4 additions & 4 deletions plugins/package-managers/bazel/src/main/kotlin/Bazel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import org.apache.logging.log4j.kotlin.logger

import org.ossreviewtoolkit.analyzer.AbstractPackageManagerFactory
import org.ossreviewtoolkit.analyzer.PackageManager
import org.ossreviewtoolkit.clients.bazelmoduleregistry.BazelModuleRegistryService
import org.ossreviewtoolkit.clients.bazelmoduleregistry.RemoteBazelModuleRegistryService
import org.ossreviewtoolkit.clients.bazelmoduleregistry.ModuleMetadata
import org.ossreviewtoolkit.clients.bazelmoduleregistry.ModuleSourceInfo
import org.ossreviewtoolkit.downloader.VersionControlSystem
Expand Down Expand Up @@ -125,7 +125,7 @@ class Bazel(
}

private fun getPackages(scopes: Set<Scope>, registryUrl: String?): Set<Package> {
val registry = BazelModuleRegistryService.create(registryUrl)
val registry = RemoteBazelModuleRegistryService.create(registryUrl)
val ids = scopes.flatMapTo(mutableSetOf()) { it.collectDependencies() }
val moduleMetadataForId = ids.associateWith { getModuleMetadata(it, registry) }
val moduleSourceInfoForId = ids.associateWith { getModuleSourceInfo(it, registry) }
Expand All @@ -143,14 +143,14 @@ class Bazel(
vcs = metadata?.vcsInfo().orEmpty()
)

private fun getModuleMetadata(id: Identifier, registry: BazelModuleRegistryService): ModuleMetadata? =
private fun getModuleMetadata(id: Identifier, registry: RemoteBazelModuleRegistryService): ModuleMetadata? =
runCatching {
runBlocking { registry.getModuleMetadata(id.name) }
}.onFailure {
logger.warn { "Failed to fetch metadata for Bazel module '${id.name}': ${it.collectMessages()}" }
}.getOrNull()

private fun getModuleSourceInfo(id: Identifier, registry: BazelModuleRegistryService): ModuleSourceInfo? =
private fun getModuleSourceInfo(id: Identifier, registry: RemoteBazelModuleRegistryService): ModuleSourceInfo? =
runCatching {
runBlocking { registry.getModuleSourceInfo(id.name, id.version) }
}.onFailure {
Expand Down

0 comments on commit 50c0512

Please sign in to comment.