Skip to content

Commit 4092054

Browse files
authored
Johnzon upgrade for Jakarta 9 (#577)
* Johnzon upgrade for Jakarta 9 Polish * Fix tests
1 parent 88fbdcc commit 4092054

File tree

3 files changed

+81
-48
lines changed

3 files changed

+81
-48
lines changed

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ dependencies {
5454
testRuntimeOnly("com.fasterxml.jackson.datatype:jackson-datatype-jsr353")
5555
testRuntimeOnly("com.fasterxml.jackson.core:jackson-core")
5656
testRuntimeOnly("com.fasterxml.jackson.core:jackson-databind")
57+
testRuntimeOnly("org.apache.johnzon:johnzon-core:1.2.18")
5758
testRuntimeOnly("org.codehaus.groovy:groovy:latest.release")
5859
testRuntimeOnly("jakarta.annotation:jakarta.annotation-api:2.1.1")
5960
testRuntimeOnly("org.springframework:spring-core:6.1.13")

src/main/resources/META-INF/rewrite/jakarta-ee-9.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -952,10 +952,12 @@ recipeList:
952952
groupId: org.apache.johnzon
953953
artifactId: "*"
954954
newVersion: latest.release
955-
- org.openrewrite.maven.ChangeDependencyClassifier:
956-
groupId: org.apache.johnzon
957-
artifactId: "*"
958-
newClassifier: jakarta
955+
- org.openrewrite.java.dependencies.AddDependency:
956+
groupId: jakarta.json
957+
artifactId: jakarta.json-api
958+
scope: provided
959+
version: 2.1.X
960+
onlyIfUsing: org.apache.johnzon..*
959961
---
960962
# Currently this recipe is only updating the artifacts to a version that is compatible with J2EE 9. There still may be
961963
# breaking changes to the Rest Assured API that need to be addressed.

src/test/java/org/openrewrite/java/migrate/jakarta/JohnzonJavaxtoJakartaTest.java

Lines changed: 74 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717

1818
import org.junit.jupiter.api.Test;
1919
import org.openrewrite.config.Environment;
20+
import org.openrewrite.java.JavaParser;
2021
import org.openrewrite.test.RecipeSpec;
2122
import org.openrewrite.test.RewriteTest;
2223

2324
import java.util.regex.Matcher;
2425
import java.util.regex.Pattern;
2526

2627
import static org.assertj.core.api.Assertions.assertThat;
28+
import static org.openrewrite.java.Assertions.*;
2729
import static org.openrewrite.maven.Assertions.pomXml;
2830

2931
class JohnzonJavaxtoJakartaTest implements RewriteTest {
@@ -34,55 +36,83 @@ public void defaults(RecipeSpec spec) {
3436
Environment.builder()
3537
.scanRuntimeClasspath("org.openrewrite.java.migrate")
3638
.build()
37-
.activateRecipes("org.openrewrite.java.migrate.jakarta.JohnzonJavaxToJakarta"));
39+
.activateRecipes("org.openrewrite.java.migrate.jakarta.JohnzonJavaxToJakarta")
40+
).parser(JavaParser.fromJavaVersion().classpath("johnzon-core"));
3841
}
3942

4043
@Test
4144
void migrateJohnzonDependencies() {
42-
//language=xml
4345
rewriteRun(
44-
pomXml(
45-
"""
46-
<project>
47-
<groupId>com.example.ehcache</groupId>
48-
<artifactId>johnzon-legacy</artifactId>
49-
<version>1.0.0</version>
50-
<properties>
51-
<johnzon.version>1.2.5</johnzon.version>
52-
</properties>
53-
<dependencies>
54-
<dependency>
55-
<groupId>org.apache.johnzon</groupId>
56-
<artifactId>johnzon-core</artifactId>
57-
<version>${johnzon.version}</version>
58-
</dependency>
59-
</dependencies>
60-
</project>
61-
""",
62-
spec -> spec.after(actual -> {
63-
assertThat(actual).isNotNull();
64-
Matcher version = Pattern.compile("<johnzon.version>([0-9]+\\.[0-9]+\\.[0-9]+)</johnzon.version>")
65-
.matcher(actual);
66-
assertThat(version.find()).isTrue();
67-
return """
68-
<project>
69-
<groupId>com.example.ehcache</groupId>
70-
<artifactId>johnzon-legacy</artifactId>
71-
<version>1.0.0</version>
72-
<properties>
73-
<johnzon.version>%s</johnzon.version>
74-
</properties>
75-
<dependencies>
76-
<dependency>
77-
<groupId>org.apache.johnzon</groupId>
78-
<artifactId>johnzon-core</artifactId>
79-
<version>${johnzon.version}</version>
80-
<classifier>jakarta</classifier>
81-
</dependency>
82-
</dependencies>
83-
</project>
84-
""".formatted(version.group(1));
85-
})
46+
mavenProject("demo",
47+
pomXml(
48+
//language=xml
49+
"""
50+
<project>
51+
<groupId>com.example.ehcache</groupId>
52+
<artifactId>johnzon-legacy</artifactId>
53+
<version>1.0.0</version>
54+
<properties>
55+
<johnzon.version>1.2.5</johnzon.version>
56+
</properties>
57+
<dependencies>
58+
<dependency>
59+
<groupId>org.apache.johnzon</groupId>
60+
<artifactId>johnzon-core</artifactId>
61+
<version>${johnzon.version}</version>
62+
</dependency>
63+
</dependencies>
64+
</project>
65+
""",
66+
spec -> spec.after(actual -> {
67+
assertThat(actual).isNotNull();
68+
Matcher version = Pattern.compile("<johnzon.version>([0-9]+\\.[0-9]+\\.[0-9]+)</johnzon.version>")
69+
.matcher(actual);
70+
71+
Matcher jsonApiVersion = Pattern.compile("2.1.\\d+").matcher(actual);
72+
assertThat(jsonApiVersion.find()).describedAs("Expected jakarta.json-api 2.1.x version in %s", actual).isTrue();
73+
74+
assertThat(version.find()).isTrue();
75+
return """
76+
<project>
77+
<groupId>com.example.ehcache</groupId>
78+
<artifactId>johnzon-legacy</artifactId>
79+
<version>1.0.0</version>
80+
<properties>
81+
<johnzon.version>%s</johnzon.version>
82+
</properties>
83+
<dependencies>
84+
<dependency>
85+
<groupId>org.apache.johnzon</groupId>
86+
<artifactId>johnzon-core</artifactId>
87+
<version>${johnzon.version}</version>
88+
</dependency>
89+
<dependency>
90+
<groupId>jakarta.json</groupId>
91+
<artifactId>jakarta.json-api</artifactId>
92+
<version>%s</version>
93+
<scope>provided</scope>
94+
</dependency>
95+
</dependencies>
96+
</project>
97+
""".formatted(version.group(1), jsonApiVersion.group(0));
98+
})
99+
),
100+
srcMainJava(
101+
java(
102+
//language=java
103+
"""
104+
package com.example.demo;
105+
106+
import org.apache.johnzon.core.Snippet;
107+
108+
public class A {
109+
110+
void foo(Snippet snippet, String str) {
111+
}
112+
}
113+
"""
114+
)
115+
)
86116
)
87117
);
88118
}

0 commit comments

Comments
 (0)