Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavaEE to Quarkus 2 Declarative Migration Recipe #73

Merged
merged 23 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d645b00
JavaEE to Quarkus 2 Declarative Migration Recipe
ammachado Feb 4, 2024
d1451f4
Add JavaEEtoQuarkus2MigrationTest and verify pom changes
timtebeek Feb 4, 2024
475857e
Merge branch 'main' into main
timtebeek Feb 4, 2024
f61e285
Merge branch 'main' into main
timtebeek Feb 5, 2024
2065265
Apply suggestions from code review
timtebeek Feb 5, 2024
6743def
Merge branch 'main' into main
timtebeek Feb 5, 2024
88efbda
Split Recipe to Maven Dependencies Upgrade YML and Code Tranformation…
ammachado Feb 5, 2024
c31622f
Updated Tests
ammachado Feb 5, 2024
60cc5e1
Remove recipe from quarkus.yml
ammachado Feb 5, 2024
8d5c734
Merge all three JavaEEtoQuarkus2 recipes into one file
timtebeek Feb 6, 2024
af2b54f
Update src/test/java/org/openrewrite/quarkus/quarkus2/JavaEEtoQuarkus…
timtebeek Feb 6, 2024
9509f27
Updated Dependency Migration Description to reflect that this migrate…
ShatanikB Feb 7, 2024
1867feb
Merge branch 'main' into main
timtebeek Feb 12, 2024
421ff81
Merge branch 'main' into main
timtebeek Mar 15, 2024
0ade672
Merge "main" into "main"
ShatanikB Apr 24, 2024
12e8a53
Updated dependency versions and tests
ShatanikB Apr 24, 2024
a509c5a
Merge branch 'main' into main
timtebeek May 2, 2024
57b3683
Merge branch 'main' into main
ShatanikB May 21, 2024
8f9d4a5
Merge branch 'main' into main
timtebeek Jun 14, 2024
23ef2d3
Move recipes and reformat tests
timtebeek Jul 12, 2024
ca1d498
Merge branch 'main' into main
timtebeek Jul 12, 2024
f1cb466
Break up dependency & maven recipes; expect to remove war plugin
timtebeek Jul 12, 2024
b25b2de
Bump failsafe and surefire plugin versions
timtebeek Jul 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ build/
.idea/
.boot-releases
out/
.vscode/
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ dependencies {
implementation("org.openrewrite:rewrite-properties:${rewriteVersion}")

implementation("org.openrewrite.recipe:rewrite-java-dependencies:${rewriteVersion}")
implementation("org.openrewrite.recipe:rewrite-migrate-java:${rewriteVersion}")

runtimeOnly("org.openrewrite:rewrite-java-17:${rewriteVersion}")

Expand All @@ -38,6 +39,8 @@ dependencies {
testImplementation("javax.xml.bind:jaxb-api:2.4.0-b180830.0359")
testImplementation("jakarta.xml.bind:jakarta.xml.bind-api:3.0.0")

testImplementation("javax:javaee-api:7.0")

testRuntimeOnly("org.openrewrite:rewrite-java-17:${rewriteVersion}")

testRuntimeOnly("io.quarkus:quarkus-grpc:1.13.+")
Expand Down
196 changes: 196 additions & 0 deletions src/main/resources/META-INF/rewrite/javaee7-to-quarkus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
#
# Copyright 2024 the original author or authors.
# <p>
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# <p>
# https://www.apache.org/licenses/LICENSE-2.0
# <p>
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.quarkus.migrate.javaee.JavaEEtoQuarkus2Migration
displayName: Migrate JavaEE to Quarkus 2
description: These recipes help with the migration of a JavaEE application using EJBs and Hibernate to Quarkus 2. Additional transformations like JSF, JMS, Quarkus Tests may be necessary.
recipeList:
- org.openrewrite.quarkus.migrate.javaee.AddQuarkus2MavenPlugins
- org.openrewrite.quarkus.migrate.javaee.AddQuarkus2Dependencies
- org.openrewrite.quarkus.migrate.javaee.RemoveJavaEEDependencies

- org.openrewrite.quarkus.migrate.javaee.JavaEEtoQuarkus2CodeMigration
- org.openrewrite.java.migrate.Java8toJava11

---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.quarkus.migrate.javaee.AddQuarkus2Dependencies
displayName: Add Quarkus 2 dependencies
description: Add Quarkus 2 dependencies to the project.
recipeList:
# Add Basic Quarkus Extensions
- org.openrewrite.java.dependencies.AddDependency:
groupId: io.quarkus
artifactId: quarkus-arc
- org.openrewrite.java.dependencies.AddDependency:
groupId: io.quarkus
artifactId: quarkus-resteasy
- org.openrewrite.java.dependencies.AddDependency:
groupId: io.quarkus
artifactId: quarkus-resteasy-jackson
- org.openrewrite.java.dependencies.AddDependency:
groupId: io.quarkus
artifactId: quarkus-undertow
- org.openrewrite.java.dependencies.AddDependency:
groupId: io.quarkus
artifactId: quarkus-hibernate-orm
- org.openrewrite.java.dependencies.AddDependency:
groupId: io.quarkus
artifactId: quarkus-jdbc-h2
- org.openrewrite.java.dependencies.AddDependency:
groupId: io.quarkus
artifactId: quarkus-junit5
scope: test
- org.openrewrite.java.dependencies.AddDependency:
groupId: io.rest-assured
artifactId: rest-assured
scope: test

---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.quarkus.migrate.javaee.RemoveJavaEEDependencies
displayName: Remove JavaEE dependencies
description: Remove JavaEE dependencies from the project.
recipeList:
# Remove JavaEE dependencies
- org.openrewrite.java.dependencies.RemoveDependency:
groupId: javax*
artifactId: javaee-api
- org.openrewrite.java.dependencies.RemoveDependency:
groupId: javax*
artifactId: cdi-api
- org.openrewrite.java.dependencies.RemoveDependency:
groupId: javax*
artifactId: javax*

---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.quarkus.migrate.javaee.AddQuarkus2MavenPlugins
displayName: Migrate JavaEE Maven Dependencies to Quarkus 2
description: Upgrade Standard JavaEE dependencies to Quarkus 2 dependencies.
recipeList:
# Add Quarkus BOM
- org.openrewrite.maven.AddManagedDependency:
groupId: io.quarkus.platform
artifactId: quarkus-bom
version: '2.x'
type: pom
scope: import

# Add Maven Plugins
- org.openrewrite.maven.AddPlugin:
groupId: io.quarkus.platform
artifactId: quarkus-maven-plugin
version: '2.16.12.Final'
executions: <executions><execution><goals><goal>build</goal><goal>generate-code</goal><goal>generate-code-tests</goal></goals></execution></executions>
- org.openrewrite.maven.AddPlugin:
groupId: org.apache.maven.plugins
artifactId: maven-compiler-plugin
version: '3.13.0'
configuration: <configuration><compilerArgs><arg>-parameters</arg></compilerArgs></configuration>
- org.openrewrite.maven.AddPlugin:
groupId: org.apache.maven.plugins
artifactId: maven-surefire-plugin
version: '3.3.1'
configuration: <configuration><systemPropertyVariables><java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager><maven.home>${maven.home}</maven.home></systemPropertyVariables></configuration>
- org.openrewrite.maven.AddPlugin:
groupId: org.apache.maven.plugins
artifactId: maven-failsafe-plugin
version: '3.3.1'
executions: <executions><execution><goals><goal>integration-test</goal><goal>verify</goal></goals></execution></executions>
configuration: <configuration><systemPropertyVariables><native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path><java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager><maven.home>${maven.home}</maven.home></systemPropertyVariables></configuration>
- org.openrewrite.maven.AddProfile:
id: native
activation: <activation><property><name>native</name></property></activation>
properties: <properties><skipITs>false</skipITs><quarkus.package.type>native</quarkus.package.type></properties>
- org.openrewrite.quarkus.ConfigureQuarkusMavenPluginWithReasonableDefaults
- org.openrewrite.maven.BestPractices

# Prep for Java 11 upgrade
- org.openrewrite.maven.AddProperty:
key: maven.compiler.source
value: 11
- org.openrewrite.maven.AddProperty:
key: maven.compiler.target
value: 11
- org.openrewrite.maven.ChangePackaging:
groupId: '*'
artifactId: '*'
packaging: jar

- org.openrewrite.maven.RemovePlugin:
groupId: org.apache.maven.plugins
artifactId: maven-war-plugin

---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.quarkus.migrate.javaee.JavaEEtoQuarkus2CodeMigration
displayName: Migrate JavaEE Code to Quarkus 2
description: Migrate Standard JavaEE Code to Quarkus 2
recipeList:
# Convert some EJB annotations to CDI
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: javax.ejb.Stateless
newFullyQualifiedTypeName: javax.enterprise.context.Dependent
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: javax.ejb.Stateful
newFullyQualifiedTypeName: javax.enterprise.context.SessionScoped
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: javax.ejb.Singleton
newFullyQualifiedTypeName: javax.enterprise.context.ApplicationScoped
- org.openrewrite.java.RemoveAnnotationAttribute:
annotationType: javax.ejb.EJB
attributeName: name
- org.openrewrite.java.RemoveAnnotationAttribute:
annotationType: javax.ejb.EJB
attributeName: description
- org.openrewrite.java.RemoveAnnotationAttribute:
annotationType: javax.ejb.EJB
attributeName: beanName
- org.openrewrite.java.RemoveAnnotationAttribute:
annotationType: javax.ejb.EJB
attributeName: beanInterface
- org.openrewrite.java.RemoveAnnotationAttribute:
annotationType: javax.ejb.EJB
attributeName: mappedName
- org.openrewrite.java.RemoveAnnotationAttribute:
annotationType: javax.ejb.EJB
attributeName: lookup
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: javax.ejb.EJB
newFullyQualifiedTypeName: javax.inject.Inject
- org.openrewrite.java.RemoveAnnotation:
annotationPattern: '@javax.ejb.Local'

# Convert JPA annotations
- org.openrewrite.java.RemoveAnnotationAttribute:
annotationType: javax.persistence.PersistenceContext
attributeName: name
- org.openrewrite.java.RemoveAnnotationAttribute:
annotationType: javax.persistence.PersistenceContext
attributeName: unitName
- org.openrewrite.java.RemoveAnnotationAttribute:
annotationType: javax.persistence.PersistenceContext
attributeName: type
- org.openrewrite.java.RemoveAnnotationAttribute:
annotationType: javax.persistence.PersistenceContext
attributeName: synchronization
- org.openrewrite.java.RemoveAnnotationAttribute:
annotationType: javax.persistence.PersistenceContext
attributeName: properties
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: javax.persistence.PersistenceContext
newFullyQualifiedTypeName: javax.inject.Inject
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/rewrite/quarkus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,4 @@ recipeList:
- org.openrewrite.java.ChangePackage:
oldPackageName: io.vertx.core.http.HttpMethod
newPackageName: io.quarkus.vertx.web.Route.HttpMethod
recursive: false
recursive: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
/*
* Copyright 2024 the original author or authors.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* https://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openrewrite.quarkus.migrate.javaee;

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

import static org.openrewrite.java.Assertions.java;

class JavaEEtoQuarkus2CodeTranformationsTest implements RewriteTest {

@Override
public void defaults(RecipeSpec spec) {
spec.parser(JavaParser.fromJavaVersion()
.logCompilationWarningsAndErrors(true)
.classpath("javaee-api"))
.recipeFromResources("org.openrewrite.quarkus.migrate.javaee.JavaEEtoQuarkus2CodeMigration");
}

@Test
@DocumentExample
void javaEEtoQuarkus2CodeTransformationsTest() {
rewriteRun(
java(
// language=java
"""
package org.acme;

import javax.ejb.EJB;
import javax.ejb.Local;
import javax.ejb.SessionContext;
import javax.ejb.Singleton;
import javax.ejb.Stateful;
import javax.ejb.Stateless;

import javax.annotation.Resource;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

@Stateless
public class PingEJBSLS {

@PersistenceContext
private EntityManager entityManager;

@Resource
private SessionContext context;

@EJB
private PingEJBLocal pingEJBLocal;

@EJB(lookup = "java:global/PingEJBSingleton")
private PingEJBSingleton pingEJBSingleton;

public String getMsg() {
return "PingEJBSLS: " + pingEJBLocal.getMsg() + " " + pingEJBSingleton.getMsg();
}

}

@Stateful
@Local
public class PingEJBLocal {

private static int hitCount;

public String getMsg() {
return "PingEJBLocal: " + hitCount++;
}

}

@Singleton
public class PingEJBSingleton {

private static int hitCount;

@PersistenceContext
private EntityManager entityManager;

public String getMsg() {
return "PingEJBSingleton: " + hitCount++;
}
}
""",
// language=java
"""
package org.acme;

import javax.ejb.SessionContext;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.Dependent;
import javax.enterprise.context.SessionScoped;
import javax.inject.Inject;
import javax.annotation.Resource;
import javax.persistence.EntityManager;

@Dependent
public class PingEJBSLS {

@Inject
private EntityManager entityManager;

@Resource
private SessionContext context;

@Inject
private PingEJBLocal pingEJBLocal;

@Inject
private PingEJBSingleton pingEJBSingleton;

public String getMsg() {
return "PingEJBSLS: " + pingEJBLocal.getMsg() + " " + pingEJBSingleton.getMsg();
}

}

@SessionScoped
public class PingEJBLocal {

private static int hitCount;

public String getMsg() {
return "PingEJBLocal: " + hitCount++;
}

}

@ApplicationScoped
public class PingEJBSingleton {

private static int hitCount;

@Inject
private EntityManager entityManager;

public String getMsg() {
return "PingEJBSingleton: " + hitCount++;
}
}
"""
)
);
}
}
Loading