From e04636d128aab2a95e299da9535966bba9569222 Mon Sep 17 00:00:00 2001 From: Dan <114250114+hb-man@users.noreply.github.com> Date: Tue, 16 Jul 2024 16:27:30 +0400 Subject: [PATCH] Fix lock file parsing for Bazel 7.2.0 (#397) Fixes #396 --- .../bazelsteward/bzlmod/BzlModDataExtractor.kt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/kinds/bzlmod/src/main/kotlin/org/virtuslab/bazelsteward/bzlmod/BzlModDataExtractor.kt b/kinds/bzlmod/src/main/kotlin/org/virtuslab/bazelsteward/bzlmod/BzlModDataExtractor.kt index 18050dc8..18cd4610 100644 --- a/kinds/bzlmod/src/main/kotlin/org/virtuslab/bazelsteward/bzlmod/BzlModDataExtractor.kt +++ b/kinds/bzlmod/src/main/kotlin/org/virtuslab/bazelsteward/bzlmod/BzlModDataExtractor.kt @@ -37,10 +37,17 @@ class BzlModDataExtractor( private fun findRepositories(): List { val lockFile = workspaceRoot.resolve("MODULE.bazel.lock") + val defaultRepo = "https://bcr.bazel.build" val repositories = if (lockFile.exists()) { - jsonReader.readTree(lockFile.toFile()).path("flags").path("cmdRegistries").map { it.asText() } + val jsonNode = jsonReader.readTree(lockFile.toFile()) + val cmdRegistries = jsonNode.path("flags").path("cmdRegistries") + if (cmdRegistries.isArray && !cmdRegistries.isEmpty) { + cmdRegistries.map { it.asText() } + } else { + listOf(defaultRepo) + } } else { - listOf("https://bcr.bazel.build") + listOf(defaultRepo) } return repositories.map { it.removeSuffix("/") } }