Skip to content

Commit

Permalink
Johnzon upgrade for Jakarta 9 (#577)
Browse files Browse the repository at this point in the history
* Johnzon upgrade for Jakarta 9

Polish

* Fix tests
  • Loading branch information
BoykoAlex authored Oct 13, 2024
1 parent 88fbdcc commit 4092054
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 48 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ dependencies {
testRuntimeOnly("com.fasterxml.jackson.datatype:jackson-datatype-jsr353")
testRuntimeOnly("com.fasterxml.jackson.core:jackson-core")
testRuntimeOnly("com.fasterxml.jackson.core:jackson-databind")
testRuntimeOnly("org.apache.johnzon:johnzon-core:1.2.18")
testRuntimeOnly("org.codehaus.groovy:groovy:latest.release")
testRuntimeOnly("jakarta.annotation:jakarta.annotation-api:2.1.1")
testRuntimeOnly("org.springframework:spring-core:6.1.13")
Expand Down
10 changes: 6 additions & 4 deletions src/main/resources/META-INF/rewrite/jakarta-ee-9.yml
Original file line number Diff line number Diff line change
Expand Up @@ -952,10 +952,12 @@ recipeList:
groupId: org.apache.johnzon
artifactId: "*"
newVersion: latest.release
- org.openrewrite.maven.ChangeDependencyClassifier:
groupId: org.apache.johnzon
artifactId: "*"
newClassifier: jakarta
- org.openrewrite.java.dependencies.AddDependency:
groupId: jakarta.json
artifactId: jakarta.json-api
scope: provided
version: 2.1.X
onlyIfUsing: org.apache.johnzon..*
---
# Currently this recipe is only updating the artifacts to a version that is compatible with J2EE 9. There still may be
# breaking changes to the Rest Assured API that need to be addressed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@

import org.junit.jupiter.api.Test;
import org.openrewrite.config.Environment;
import org.openrewrite.java.JavaParser;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;

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

import static org.assertj.core.api.Assertions.assertThat;
import static org.openrewrite.java.Assertions.*;
import static org.openrewrite.maven.Assertions.pomXml;

class JohnzonJavaxtoJakartaTest implements RewriteTest {
Expand All @@ -34,55 +36,83 @@ public void defaults(RecipeSpec spec) {
Environment.builder()
.scanRuntimeClasspath("org.openrewrite.java.migrate")
.build()
.activateRecipes("org.openrewrite.java.migrate.jakarta.JohnzonJavaxToJakarta"));
.activateRecipes("org.openrewrite.java.migrate.jakarta.JohnzonJavaxToJakarta")
).parser(JavaParser.fromJavaVersion().classpath("johnzon-core"));
}

@Test
void migrateJohnzonDependencies() {
//language=xml
rewriteRun(
pomXml(
"""
<project>
<groupId>com.example.ehcache</groupId>
<artifactId>johnzon-legacy</artifactId>
<version>1.0.0</version>
<properties>
<johnzon.version>1.2.5</johnzon.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.johnzon</groupId>
<artifactId>johnzon-core</artifactId>
<version>${johnzon.version}</version>
</dependency>
</dependencies>
</project>
""",
spec -> spec.after(actual -> {
assertThat(actual).isNotNull();
Matcher version = Pattern.compile("<johnzon.version>([0-9]+\\.[0-9]+\\.[0-9]+)</johnzon.version>")
.matcher(actual);
assertThat(version.find()).isTrue();
return """
<project>
<groupId>com.example.ehcache</groupId>
<artifactId>johnzon-legacy</artifactId>
<version>1.0.0</version>
<properties>
<johnzon.version>%s</johnzon.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.johnzon</groupId>
<artifactId>johnzon-core</artifactId>
<version>${johnzon.version}</version>
<classifier>jakarta</classifier>
</dependency>
</dependencies>
</project>
""".formatted(version.group(1));
})
mavenProject("demo",
pomXml(
//language=xml
"""
<project>
<groupId>com.example.ehcache</groupId>
<artifactId>johnzon-legacy</artifactId>
<version>1.0.0</version>
<properties>
<johnzon.version>1.2.5</johnzon.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.johnzon</groupId>
<artifactId>johnzon-core</artifactId>
<version>${johnzon.version}</version>
</dependency>
</dependencies>
</project>
""",
spec -> spec.after(actual -> {
assertThat(actual).isNotNull();
Matcher version = Pattern.compile("<johnzon.version>([0-9]+\\.[0-9]+\\.[0-9]+)</johnzon.version>")
.matcher(actual);

Matcher jsonApiVersion = Pattern.compile("2.1.\\d+").matcher(actual);
assertThat(jsonApiVersion.find()).describedAs("Expected jakarta.json-api 2.1.x version in %s", actual).isTrue();

assertThat(version.find()).isTrue();
return """
<project>
<groupId>com.example.ehcache</groupId>
<artifactId>johnzon-legacy</artifactId>
<version>1.0.0</version>
<properties>
<johnzon.version>%s</johnzon.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.johnzon</groupId>
<artifactId>johnzon-core</artifactId>
<version>${johnzon.version}</version>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
<version>%s</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
""".formatted(version.group(1), jsonApiVersion.group(0));
})
),
srcMainJava(
java(
//language=java
"""
package com.example.demo;
import org.apache.johnzon.core.Snippet;
public class A {
void foo(Snippet snippet, String str) {
}
}
"""
)
)
)
);
}
Expand Down

0 comments on commit 4092054

Please sign in to comment.