Skip to content

Commit

Permalink
ChangeManagedDependencyGroupIdAndArtifactId now resolves current vers…
Browse files Browse the repository at this point in the history
…ion (if a property) to fix edge case when changing to latest.patch version
  • Loading branch information
nmck257 committed Oct 15, 2024
1 parent 41bf5df commit 9da3321
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public Xml.Tag visitTag(Xml.Tag tag, ExecutionContext ctx) {
Map<String, String> properties = pom.getProperties();
resolvedArtifactId = ResolvedPom.placeholderHelper.replacePlaceholders(newArtifactId, properties::get);
}
String resolvedNewVersion = resolveSemverVersion(ctx, newGroupId, resolvedArtifactId, versionTag.get().getValue().orElse(null));
String resolvedNewVersion = resolveSemverVersion(ctx, newGroupId, resolvedArtifactId, getResolutionResult().getPom().getValue(versionTag.get().getValue().orElse(null)));
t = (Xml.Tag) new ChangeTagValueVisitor<>(versionTag.get(), resolvedNewVersion).visitNonNull(t, 0, getCursor().getParentOrThrow());
}
changed = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,61 @@ void changeManagedDependencyWithPropertyName() {
);
}

@Test
void changeManagedDependencyWithPropertyVersion() {
rewriteRun(
spec -> spec.recipe(new ChangeManagedDependencyGroupIdAndArtifactId(
"javax.activation",
"javax.activation-api",
"jakarta.activation",
"jakarta.activation-api",
"latest.patch"
)),
pomXml(
"""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<properties>
<version.property>1.2.0</version.property>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>javax.activation-api</artifactId>
<version>${version.property}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
""",
"""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<properties>
<version.property>1.2.0</version.property>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
<version>1.2.2</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
"""
)
);
}

@Test
void latestPatchMangedDependency() {
rewriteRun(
Expand Down

0 comments on commit 9da3321

Please sign in to comment.