Skip to content

Commit

Permalink
refactor(bazel)!: Align create function and parameter naming
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
  • Loading branch information
sschuberth committed Aug 15, 2024
1 parent 48f4128 commit d03abd4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class LocalBazelModuleRegistryService(directory: File) : BazelModuleRegistryServ
* Create a [LocalBazelModuleRegistryService] if the given [url] points to a local file. In this case,
* also replace the placeholder for the workspace by the given [projectDir]. Return *null* for all other URLs.
*/
fun createForLocalUrl(url: String, projectDir: File): LocalBazelModuleRegistryService? =
fun create(url: String, projectDir: File): LocalBazelModuleRegistryService? =
url.takeIf { it.startsWith(FILE_URL_PREFIX) }?.let { fileUrl ->
val directory = fileUrl.removePrefix(FILE_URL_PREFIX)
.replace(WORKSPACE_PLACEHOLDER, projectDir.absolutePath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ internal class CompositeBazelModuleRegistryService(
}.groupByTo(mutableMapOf(), { it.first }) { it.second }.mapValues { it.value.toSet() }

val packageNamesForRegistry = packageNamesForServer.mapKeys { (url, _) ->
LocalBazelModuleRegistryService.createForLocalUrl(url, projectDir)
LocalBazelModuleRegistryService.create(url, projectDir)
?: RemoteBazelModuleRegistryService.create(url)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,14 @@ internal class MultiBazelModuleRegistryService(
) : BazelModuleRegistryService {
companion object {
/**
* Create an instance of [MultiBazelModuleRegistryService] for the given [registryUrls]. Based on the URLs,
* concrete [BazelModuleRegistryService] implementations are created. Local registry services use the given
* [projectDir] as workspace. These services are then queried in the order defined by the passed in collection.
* Note that as the last service a remote module registry for the Bazel Central Registry is added that serves
* as a fallback.
* Create an instance of [MultiBazelModuleRegistryService] for the given [urls]. Based on the URLs, concrete
* [BazelModuleRegistryService] implementations are created. Local registry services use the given [projectDir]
* as workspace. These services are then queried in the order defined by the passed in collection. Note that as
* the last service a remote module registry for the Bazel Central Registry is added that serves as a fallback.
*/
fun create(registryUrls: Collection<String>, projectDir: File): MultiBazelModuleRegistryService {
val registryServices = registryUrls.mapTo(mutableListOf()) { url ->
LocalBazelModuleRegistryService.createForLocalUrl(url, projectDir)
fun create(urls: Collection<String>, projectDir: File): MultiBazelModuleRegistryService {
val registryServices = urls.mapTo(mutableListOf()) { url ->
LocalBazelModuleRegistryService.create(url, projectDir)
?: RemoteBazelModuleRegistryService.create(url)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,13 @@ private class MockRegistryServices(
val centralRegistry = mockk<RemoteBazelModuleRegistryService>()

every {
LocalBazelModuleRegistryService.createForLocalUrl(any(), projectDir)
LocalBazelModuleRegistryService.create(any(), projectDir)
} returns null
every {
LocalBazelModuleRegistryService.createForLocalUrl(registryUrls[0], projectDir)
LocalBazelModuleRegistryService.create(registryUrls[0], projectDir)
} returns localRegistry1
every {
LocalBazelModuleRegistryService.createForLocalUrl(registryUrls[2], projectDir)
LocalBazelModuleRegistryService.create(registryUrls[2], projectDir)
} returns localRegistry2
every {
RemoteBazelModuleRegistryService.create(registryUrls[1])
Expand Down

0 comments on commit d03abd4

Please sign in to comment.