Skip to content

Commit

Permalink
Switch to UpgradeDependencyVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek committed Jan 5, 2024
1 parent 4e4e71a commit 793000d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 27 deletions.
6 changes: 3 additions & 3 deletions src/main/resources/META-INF/rewrite/micrometer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ name: org.openrewrite.micrometer.UpgradeMicrometer
displayName: Upgrade Micrometer
description: This recipe will apply changes commonly needed when migrating Micrometer.
recipeList:
- org.openrewrite.java.dependencies.ChangeDependency:
oldGroupId: io.micrometer
oldArtifactId: micrometer-core
- org.openrewrite.java.dependencies.UpgradeDependencyVersion:
groupId: io.micrometer
artifactId: micrometer-core
newVersion: 1.x
42 changes: 18 additions & 24 deletions src/test/java/org/openrewrite/micrometer/UpgradeMicrometer.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.openrewrite.maven.Assertions.pomXml;

class UpgradeMicrometer implements RewriteTest {
Expand All @@ -45,7 +43,7 @@ void maven() {
rewriteRun(
//language=xml
pomXml(
"""
"""
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
Expand All @@ -62,27 +60,23 @@ void maven() {
</dependencies>
</project>
""",
spec -> spec.after(actual -> {
Matcher matcher = Pattern.compile("<version>(1\\.1[1-9]\\.\\d+)</version>").matcher(actual);
assertTrue(matcher.find(), actual);
return """
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
<version>%s</version>
</dependency>
</dependencies>
</project>
""".formatted(matcher.group(1));
})));
spec -> spec.after(actual -> """
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
<version>%s</version>
</dependency>
</dependencies>
</project>
""".formatted(Pattern.compile("<version>(1\\.1[1-9]\\.\\d+)</version>").matcher(actual).results().findFirst().orElseThrow().group(1)))));
}
}
}

0 comments on commit 793000d

Please sign in to comment.