Skip to content

Commit

Permalink
IncrementProjectVersion should only update matching old version
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek committed Dec 6, 2024
1 parent e571da7 commit 4c0f0ca
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,14 @@ public Xml.Tag visitTag(Xml.Tag tag, ExecutionContext ctx) {
return t;
}
String newVersion = acc.get(new GroupArtifact(
t.getChildValue("groupId").orElse(null), t.getChildValue("artifactId").orElse(null)));
if (newVersion == null || newVersion.equals(t.getChildValue("version").orElse(null))) {
t.getChildValue("groupId").orElse(null),
t.getChildValue("artifactId").orElse(null)));
String oldVersion = t.getChildValue("version").orElse(null);
if (newVersion == null || newVersion.equals(oldVersion)) {
return t;
}
t = t.withMarkers(t.getMarkers().add(new AlreadyIncremented(randomId())));
return (Xml.Tag) new ChangeTagValue("version", null, newVersion).getVisitor()
return (Xml.Tag) new ChangeTagValue("version", oldVersion, newVersion).getVisitor()
.visitNonNull(t, ctx);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,54 @@ public void defaults(RecipeSpec spec) {
void changeProjectVersion() {
rewriteRun(
pomXml(
"""
"""
<project>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-maven</artifactId>
<version>8.40.1-SNAPSHOT</version>
</project>
""",
"""
<project>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-maven</artifactId>
<version>8.40.1-SNAPSHOT</version>
<version>8.41.0-SNAPSHOT</version>
</project>
""",
"""
)
);
}

@Test
void changeProjectVersionShouldNotUpdateDependencyVersion() {
rewriteRun(
pomXml(
"""
<project>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-maven</artifactId>
<version>8.40.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>29.0-jre</version>
</dependency>
</dependencies>
</project>
""",
"""
<project>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-maven</artifactId>
<version>8.41.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>29.0-jre</version>
</dependency>
</dependencies>
</project>
"""
)
Expand Down

0 comments on commit 4c0f0ca

Please sign in to comment.