From d7b0833f3ed7cc2c7a111a07f85095866c085c83 Mon Sep 17 00:00:00 2001
From: Peter Streef
Date: Tue, 10 Sep 2024 16:17:00 +0200
Subject: [PATCH] `FindMinimumDependencyVersion` - use the artifact ID when
matching dependencies (#123)
---
.../dependencies/search/FindMinimumDependencyVersion.java | 3 ++-
.../search/FindMinimumDependencyVersionTest.java | 7 ++-----
2 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/src/main/java/org/openrewrite/java/dependencies/search/FindMinimumDependencyVersion.java b/src/main/java/org/openrewrite/java/dependencies/search/FindMinimumDependencyVersion.java
index d77fc74..394bd12 100644
--- a/src/main/java/org/openrewrite/java/dependencies/search/FindMinimumDependencyVersion.java
+++ b/src/main/java/org/openrewrite/java/dependencies/search/FindMinimumDependencyVersion.java
@@ -184,7 +184,8 @@ private void collectMinimumVersions(VersionParser versionParser, List acc) {
StaticVersionComparator versionComparator = new StaticVersionComparator();
for (ResolvedDependency dep : resolved) {
- if (StringUtils.matchesGlob(dep.getGroupId(), groupIdPattern)) {
+ if (StringUtils.matchesGlob(dep.getGroupId(), groupIdPattern) &&
+ StringUtils.matchesGlob(dep.getArtifactId(), artifactIdPattern)) {
acc.merge(new GroupArtifact(dep.getGroupId(), dep.getArtifactId()),
dep.getGav(), (d1, d2) -> versionComparator.compare(
versionParser.transform(d1.getVersion()),
diff --git a/src/test/java/org/openrewrite/java/dependencies/search/FindMinimumDependencyVersionTest.java b/src/test/java/org/openrewrite/java/dependencies/search/FindMinimumDependencyVersionTest.java
index 956a3e2..9b9cf61 100644
--- a/src/test/java/org/openrewrite/java/dependencies/search/FindMinimumDependencyVersionTest.java
+++ b/src/test/java/org/openrewrite/java/dependencies/search/FindMinimumDependencyVersionTest.java
@@ -28,7 +28,7 @@ class FindMinimumDependencyVersionTest implements RewriteTest {
@Override
public void defaults(RecipeSpec spec) {
- spec.recipe(new FindMinimumDependencyVersion("com.fasterxml.jackson*", "*", "2.14-2.16"));
+ spec.recipe(new FindMinimumDependencyVersion("com.fasterxml.jackson*", "jackson-core", "2.14-2.16"));
}
@Test
@@ -117,10 +117,7 @@ void minimumGradle() {
}
""",
"""
- /*~~(com.fasterxml.jackson.core:jackson-annotations:2.14.0
- com.fasterxml.jackson.core:jackson-core:2.14.0
- com.fasterxml.jackson.core:jackson-databind:2.14.0
- com.fasterxml.jackson:jackson-bom:2.14.0)~~>*/plugins { id 'java' }
+ /*~~(com.fasterxml.jackson.core:jackson-core:2.14.0)~~>*/plugins { id 'java' }
repositories { mavenCentral() }
dependencies {
implementation 'com.fasterxml.jackson.core:jackson-databind:2.14.0'