From 0822eae45c5eef1ca0119d372bdc67e6b8e5a94f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Wawrzyk?= Date: Mon, 29 Apr 2024 15:56:50 +0200 Subject: [PATCH] Attempt to avoid bumping unrelated versions when updating rules (#377) --- .../Result_WORKSPACE.bzlignore | 23 +++++++++++++++++++ .../WORKSPACE.bzlignore | 23 +++++++++++++++++++ .../bazel/rules/BazelRuleHeuristic.kt | 5 ++-- 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/e2e/src/test/resources/rules/heuristic/heuristic_rules_variables/Result_WORKSPACE.bzlignore b/e2e/src/test/resources/rules/heuristic/heuristic_rules_variables/Result_WORKSPACE.bzlignore index 7ff46495..d50b4874 100644 --- a/e2e/src/test/resources/rules/heuristic/heuristic_rules_variables/Result_WORKSPACE.bzlignore +++ b/e2e/src/test/resources/rules/heuristic/heuristic_rules_variables/Result_WORKSPACE.bzlignore @@ -37,3 +37,26 @@ load( ) apple_support_dependencies() + +RULES_JVM_EXTERNAL_TAG = "5.2" + +RULES_JVM_EXTERNAL_SHA = "f86fd42a809e1871ca0aabe89db0d440451219c3ce46c58da240c7dcdc00125f" + +http_archive( + name = "rules_jvm_external", + sha256 = RULES_JVM_EXTERNAL_SHA, + strip_prefix = "rules_jvm_external-{}".format(RULES_JVM_EXTERNAL_TAG), + url = "https://github.com/bazelbuild/rules_jvm_external/releases/download/5.2/rules_jvm_external-5.2.tar.gz", +) + +load("@rules_jvm_external//:defs.bzl", "maven_install") + +maven_install( + artifacts = [ + "com.fasterxml.jackson.core:jackson-core:2.0.0", + ], + fail_if_repin_required = False, + repositories = [ + "https://repo.maven.apache.org/maven2", + ], +) diff --git a/e2e/src/test/resources/rules/heuristic/heuristic_rules_variables/WORKSPACE.bzlignore b/e2e/src/test/resources/rules/heuristic/heuristic_rules_variables/WORKSPACE.bzlignore index b209b758..f8caf528 100644 --- a/e2e/src/test/resources/rules/heuristic/heuristic_rules_variables/WORKSPACE.bzlignore +++ b/e2e/src/test/resources/rules/heuristic/heuristic_rules_variables/WORKSPACE.bzlignore @@ -37,3 +37,26 @@ load( ) apple_support_dependencies() + +RULES_JVM_EXTERNAL_TAG = "5.2" + +RULES_JVM_EXTERNAL_SHA = "f86fd42a809e1871ca0aabe89db0d440451219c3ce46c58da240c7dcdc00125f" + +http_archive( + name = "rules_jvm_external", + sha256 = RULES_JVM_EXTERNAL_SHA, + strip_prefix = "rules_jvm_external-{}".format(RULES_JVM_EXTERNAL_TAG), + url = "https://github.com/bazelbuild/rules_jvm_external/releases/download/5.2/rules_jvm_external-5.2.tar.gz", +) + +load("@rules_jvm_external//:defs.bzl", "maven_install") + +maven_install( + artifacts = [ + "com.fasterxml.jackson.core:jackson-core:2.0.0", + ], + fail_if_repin_required = False, + repositories = [ + "https://repo.maven.apache.org/maven2", + ], +) diff --git a/kinds/bazel/rules/src/main/kotlin/org/virtuslab/bazelsteward/bazel/rules/BazelRuleHeuristic.kt b/kinds/bazel/rules/src/main/kotlin/org/virtuslab/bazelsteward/bazel/rules/BazelRuleHeuristic.kt index 65f4215d..73882eeb 100644 --- a/kinds/bazel/rules/src/main/kotlin/org/virtuslab/bazelsteward/bazel/rules/BazelRuleHeuristic.kt +++ b/kinds/bazel/rules/src/main/kotlin/org/virtuslab/bazelsteward/bazel/rules/BazelRuleHeuristic.kt @@ -24,7 +24,8 @@ object BazelRuleHeuristic : VersionReplacementHeuristic { suggested, ) - fun allMatches(content: String): List = regexes.flatMap { it.findAll(content).toList() } + fun allMatches(content: String): List = + regexes.map { it.findAll(content).toList() }.firstOrNull { it.isNotEmpty() } ?: emptyList() } override fun apply(files: List, updateSuggestion: UpdateSuggestion): LibraryUpdate? { @@ -43,7 +44,7 @@ object BazelRuleHeuristic : VersionReplacementHeuristic { ReplaceRequest( listOf( """(?<=")(${Regex.escape(current)})(?=")""".toRegex(), - """(?