From ea256717e7e7458d32207a3e27640d10b4a5ed67 Mon Sep 17 00:00:00 2001 From: Steve Hill Date: Wed, 7 Aug 2024 23:37:18 -0700 Subject: [PATCH] Resolve artifactId before downloading versions --- ...ManagedDependencyGroupIdAndArtifactId.java | 9 ++- ...gedDependencyGroupIdAndArtifactIdTest.java | 55 +++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/ChangeManagedDependencyGroupIdAndArtifactId.java b/rewrite-maven/src/main/java/org/openrewrite/maven/ChangeManagedDependencyGroupIdAndArtifactId.java index 19c6744d118..787c289ad43 100644 --- a/rewrite-maven/src/main/java/org/openrewrite/maven/ChangeManagedDependencyGroupIdAndArtifactId.java +++ b/rewrite-maven/src/main/java/org/openrewrite/maven/ChangeManagedDependencyGroupIdAndArtifactId.java @@ -22,6 +22,7 @@ import org.openrewrite.internal.lang.Nullable; import org.openrewrite.maven.table.MavenMetadataFailures; import org.openrewrite.maven.tree.MavenMetadata; +import org.openrewrite.maven.tree.ResolvedPom; import org.openrewrite.semver.Semver; import org.openrewrite.semver.VersionComparator; import org.openrewrite.xml.ChangeTagValueVisitor; @@ -156,7 +157,13 @@ public Xml.Tag visitTag(Xml.Tag tag, ExecutionContext ctx) { Optional versionTag = t.getChild("version"); if (versionTag.isPresent()) { - String resolvedNewVersion = resolveSemverVersion(ctx, newGroupId, newArtifactId, versionTag.get().getValue().orElse(null)); + String resolvedArtifactId = newArtifactId; + if (resolvedArtifactId.contains("${")) { + ResolvedPom pom = getResolutionResult().getPom(); + Map properties = pom.getProperties(); + resolvedArtifactId = ResolvedPom.placeholderHelper.replacePlaceholders(newArtifactId, properties::get); + } + String resolvedNewVersion = resolveSemverVersion(ctx, newGroupId, resolvedArtifactId, versionTag.get().getValue().orElse(null)); t = (Xml.Tag) new ChangeTagValueVisitor<>(versionTag.get(), resolvedNewVersion).visitNonNull(t, 0, getCursor().getParentOrThrow()); } changed = true; diff --git a/rewrite-maven/src/test/java/org/openrewrite/maven/ChangeManagedDependencyGroupIdAndArtifactIdTest.java b/rewrite-maven/src/test/java/org/openrewrite/maven/ChangeManagedDependencyGroupIdAndArtifactIdTest.java index b1458dda26d..5d0a36bfdfc 100644 --- a/rewrite-maven/src/test/java/org/openrewrite/maven/ChangeManagedDependencyGroupIdAndArtifactIdTest.java +++ b/rewrite-maven/src/test/java/org/openrewrite/maven/ChangeManagedDependencyGroupIdAndArtifactIdTest.java @@ -127,6 +127,61 @@ void changeManagedDependencyWithDynamicVersion() { ); } + @Test + void changeManagedDependencyWithPropertyName() { + rewriteRun( + spec -> spec.recipe(new ChangeManagedDependencyGroupIdAndArtifactId( + "javax.activation", + "javax.activation-api", + "jakarta.activation", + "jakarta.acti${partial.arti}-api", + "2.1.0" + )), + pomXml( + """ + + 4.0.0 + com.mycompany.app + my-app + 1 + + vation + + + + + javax.activation + javax.activation-api + 1.2.0 + + + + + """, + """ + + 4.0.0 + com.mycompany.app + my-app + 1 + + vation + + + + + jakarta.activation + jakarta.acti${partial.arti}-api + 2.1.0 + + + + + """ + ) + ); + } + @Test void latestPatchMangedDependency() { rewriteRun(