Skip to content

Commit

Permalink
refactor(clients)!: Rename a class to BazelModuleRegistryService
Browse files Browse the repository at this point in the history
Retrofit uses a "Service" suffix for these kind of interfaces in its
introductory example [1] and in its own code base [2]. Also most of ORT's
existing code uses that suffix already, so align on it as a convention.

[1]: https://square.github.io/retrofit/
[2]: https://github.com/search?q=repo%3Asquare%2Fretrofit+%22interface+%22+language%3AKotlin&type=code

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
  • Loading branch information
sschuberth committed Jun 19, 2024
1 parent c021ca5 commit 794befc
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 = BazelModuleRegistryClient.create()
val client = BazelModuleRegistryService.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 BazelModuleRegistryClient {
interface BazelModuleRegistryService {
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): BazelModuleRegistryClient {
fun create(url: String? = null, client: OkHttpClient? = null): BazelModuleRegistryService {
val bmrClient = client ?: OkHttpClient()

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

return retrofit.create(BazelModuleRegistryClient::class.java)
return retrofit.create(BazelModuleRegistryService::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.BazelModuleRegistryClient
import org.ossreviewtoolkit.clients.bazelmoduleregistry.BazelModuleRegistryService
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 = BazelModuleRegistryClient.create(registryUrl)
val registry = BazelModuleRegistryService.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: BazelModuleRegistryClient): ModuleMetadata? =
private fun getModuleMetadata(id: Identifier, registry: BazelModuleRegistryService): 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: BazelModuleRegistryClient): ModuleSourceInfo? =
private fun getModuleSourceInfo(id: Identifier, registry: BazelModuleRegistryService): ModuleSourceInfo? =
runCatching {
runBlocking { registry.getModuleSourceInfo(id.name, id.version) }
}.onFailure {
Expand Down

0 comments on commit 794befc

Please sign in to comment.