From d645b0027c43fc93319e0010e1a08d5546dfa43a Mon Sep 17 00:00:00 2001 From: Adriano Machado <60320+ammachado@users.noreply.github.com> Date: Sun, 4 Feb 2024 04:43:51 +0000 Subject: [PATCH 01/13] JavaEE to Quarkus 2 Declarative Migration Recipe --- build.gradle.kts | 1 + .../resources/META-INF/rewrite/quarkus.yml | 145 ++++++++++++++++++ 2 files changed, 146 insertions(+) diff --git a/build.gradle.kts b/build.gradle.kts index 8134ed6..2066310 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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}") diff --git a/src/main/resources/META-INF/rewrite/quarkus.yml b/src/main/resources/META-INF/rewrite/quarkus.yml index c5dca9f..5132813 100644 --- a/src/main/resources/META-INF/rewrite/quarkus.yml +++ b/src/main/resources/META-INF/rewrite/quarkus.yml @@ -141,3 +141,148 @@ recipeList: oldPackageName: io.vertx.core.http.HttpMethod newPackageName: io.quarkus.vertx.web.Route.HttpMethod recursive: false +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.quarkus.quarkus2.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: + # Migrate to JEE8 +# - org.openrewrite.java.migrate.javaee8 + # Add Quarkus 2 dependencies + - org.openrewrite.maven.AddManagedDependency: + groupId: io.quarkus.platform + artifactId: quarkus-bom + version: 2.16.12.Final + type: pom + scope: import + - 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 + - org.openrewrite.maven.AddPlugin: + groupId: io.quarkus.platform + artifactId: quarkus-maven-plugin + version: 2.16.12.Final + executions: buildgenerate-codegenerate-code-tests + - org.openrewrite.maven.AddPlugin: + groupId: org.apache.maven.plugins + artifactId: maven-compiler-plugin + version: 3.10.1 + configuration: -parameters + - org.openrewrite.maven.AddPlugin: + groupId: org.apache.maven.plugins + artifactId: maven-surefire-plugin + version: 3.0.0-M7 + configuration: org.jboss.logmanager.LogManager${maven.home} + - org.openrewrite.maven.AddPlugin: + groupId: org.apache.maven.plugins + artifactId: maven-failsafe-plugin + version: 3.0.0-M7 + executions: integration-testverify + configuration: ${project.build.directory}/${project.build.finalName}-runnerorg.jboss.logmanager.LogManager${maven.home} + - org.openrewrite.maven.AddProfile: + id: native + activation: native + properties: falsenative + - org.openrewrite.quarkus.ConfigureQuarkusMavenPluginWithReasonableDefaults + # 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* + + # 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 + + # Migrate to Java 11 + - org.openrewrite.java.migrate.Java8toJava11 + - 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 +--- From d1451f4dd7197e0d230987421ee0283f6279ef7c Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Sun, 4 Feb 2024 10:50:36 +0100 Subject: [PATCH 02/13] Add JavaEEtoQuarkus2MigrationTest and verify pom changes --- .../JavaEEtoQuarkus2MigrationTest.java | 143 ++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 src/test/java/org/openrewrite/quarkus/quarkus2/JavaEEtoQuarkus2MigrationTest.java diff --git a/src/test/java/org/openrewrite/quarkus/quarkus2/JavaEEtoQuarkus2MigrationTest.java b/src/test/java/org/openrewrite/quarkus/quarkus2/JavaEEtoQuarkus2MigrationTest.java new file mode 100644 index 0000000..1475386 --- /dev/null +++ b/src/test/java/org/openrewrite/quarkus/quarkus2/JavaEEtoQuarkus2MigrationTest.java @@ -0,0 +1,143 @@ +/* + * Copyright 2024 the original author or authors. + *

+ * 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 + *

+ * https://www.apache.org/licenses/LICENSE-2.0 + *

+ * 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.quarkus2; + +import org.junit.jupiter.api.Test; +import org.openrewrite.test.RecipeSpec; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.maven.Assertions.pomXml; + +class JavaEEtoQuarkus2MigrationTest implements RewriteTest { + @Override + public void defaults(RecipeSpec spec) { + spec.recipeFromResources("org.openrewrite.quarkus.quarkus2.JavaEEtoQuarkus2Migration"); + } + + @Test + void convertJavaEEToQuarkus() { + rewriteRun( + spec -> spec.expectedCyclesThatMakeChanges(2), + //language=xml + pomXml( + """ + + 4.0.0 + org.openrewrite.example + my-app + 1 + + """, + """ + + 4.0.0 + org.openrewrite.example + my-app + 1 + + 11 + 11 + + + + + io.quarkus.platform + quarkus-bom + 2.16.12.Final + pom + import + + + + + + + io.quarkus.platform + quarkus-maven-plugin + 2.16.12.Final + + + + build + generate-code + generate-code-tests + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.10.1 + + + -parameters + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M7 + + + org.jboss.logmanager.LogManager + ${maven.home} + + + + + org.apache.maven.plugins + maven-failsafe-plugin + 3.0.0-M7 + + + + integration-test + verify + + + + + + ${project.build.directory}/${project.build.finalName}-runner + org.jboss.logmanager.LogManager + ${maven.home} + + + + + + + + native + + + native + + + + false + native + + + + + """ + ) + ); + } +} From 20652651faa6b41e6686325a85758c3d982792ce Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Mon, 5 Feb 2024 13:02:44 +0100 Subject: [PATCH 03/13] Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../quarkus/quarkus2/JavaEEtoQuarkus2MigrationTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/java/org/openrewrite/quarkus/quarkus2/JavaEEtoQuarkus2MigrationTest.java b/src/test/java/org/openrewrite/quarkus/quarkus2/JavaEEtoQuarkus2MigrationTest.java index 1475386..d19b645 100644 --- a/src/test/java/org/openrewrite/quarkus/quarkus2/JavaEEtoQuarkus2MigrationTest.java +++ b/src/test/java/org/openrewrite/quarkus/quarkus2/JavaEEtoQuarkus2MigrationTest.java @@ -16,6 +16,7 @@ package org.openrewrite.quarkus.quarkus2; import org.junit.jupiter.api.Test; +import org.openrewrite.DocumentExample; import org.openrewrite.test.RecipeSpec; import org.openrewrite.test.RewriteTest; @@ -27,6 +28,7 @@ public void defaults(RecipeSpec spec) { spec.recipeFromResources("org.openrewrite.quarkus.quarkus2.JavaEEtoQuarkus2Migration"); } + @DocumentExample @Test void convertJavaEEToQuarkus() { rewriteRun( From 88efbdaf4b2943f60a72324dd538e3b2e0aee833 Mon Sep 17 00:00:00 2001 From: Adriano Machado <60320+ammachado@users.noreply.github.com> Date: Mon, 5 Feb 2024 22:37:37 +0000 Subject: [PATCH 04/13] Split Recipe to Maven Dependencies Upgrade YML and Code Tranformations YML --- build.gradle.kts | 2 + ...javaee-to-quarkus-code-transformations.yml | 76 +++++++++++++ .../javaee-to-quarkus-maven-dependencies.yml | 107 ++++++++++++++++++ .../META-INF/rewrite/javaee-to-quarkus.yml | 24 ++++ 4 files changed, 209 insertions(+) create mode 100644 src/main/resources/META-INF/rewrite/javaee-to-quarkus-code-transformations.yml create mode 100644 src/main/resources/META-INF/rewrite/javaee-to-quarkus-maven-dependencies.yml create mode 100644 src/main/resources/META-INF/rewrite/javaee-to-quarkus.yml diff --git a/build.gradle.kts b/build.gradle.kts index 2066310..7d3e402 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -39,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.+") diff --git a/src/main/resources/META-INF/rewrite/javaee-to-quarkus-code-transformations.yml b/src/main/resources/META-INF/rewrite/javaee-to-quarkus-code-transformations.yml new file mode 100644 index 0000000..02fa4f2 --- /dev/null +++ b/src/main/resources/META-INF/rewrite/javaee-to-quarkus-code-transformations.yml @@ -0,0 +1,76 @@ +# +# Copyright 2024 the original author or authors. +#

+# 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 +#

+# https://www.apache.org/licenses/LICENSE-2.0 +#

+# 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.quarkus2.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 + + # Migrate to Java 11 + - org.openrewrite.java.migrate.Java8toJava11 \ No newline at end of file diff --git a/src/main/resources/META-INF/rewrite/javaee-to-quarkus-maven-dependencies.yml b/src/main/resources/META-INF/rewrite/javaee-to-quarkus-maven-dependencies.yml new file mode 100644 index 0000000..53ba632 --- /dev/null +++ b/src/main/resources/META-INF/rewrite/javaee-to-quarkus-maven-dependencies.yml @@ -0,0 +1,107 @@ +# +# Copyright 2024 the original author or authors. +#

+# 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 +#

+# https://www.apache.org/licenses/LICENSE-2.0 +#

+# 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.quarkus2.JavaEEtoQuarkus2MavenDependencyMigration +displayName: Migrate JavaEE Maven and Gradle 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 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 + + # Add Maven Plugins + - org.openrewrite.maven.AddPlugin: + groupId: io.quarkus.platform + artifactId: quarkus-maven-plugin + version: '2.16.12.Final' + executions: buildgenerate-codegenerate-code-tests + - org.openrewrite.maven.AddPlugin: + groupId: org.apache.maven.plugins + artifactId: maven-compiler-plugin + version: '3.10.1' + configuration: -parameters + - org.openrewrite.maven.AddPlugin: + groupId: org.apache.maven.plugins + artifactId: maven-surefire-plugin + version: '3.0.0-M7' + configuration: org.jboss.logmanager.LogManager${maven.home} + - org.openrewrite.maven.AddPlugin: + groupId: org.apache.maven.plugins + artifactId: maven-failsafe-plugin + version: '3.0.0-M7' + executions: integration-testverify + configuration: ${project.build.directory}/${project.build.finalName}-runnerorg.jboss.logmanager.LogManager${maven.home} + - org.openrewrite.maven.AddProfile: + id: native + activation: native + properties: falsenative + - org.openrewrite.quarkus.ConfigureQuarkusMavenPluginWithReasonableDefaults + - org.openrewrite.maven.BestPractices + + # 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* + + # 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 \ No newline at end of file diff --git a/src/main/resources/META-INF/rewrite/javaee-to-quarkus.yml b/src/main/resources/META-INF/rewrite/javaee-to-quarkus.yml new file mode 100644 index 0000000..68dcfe2 --- /dev/null +++ b/src/main/resources/META-INF/rewrite/javaee-to-quarkus.yml @@ -0,0 +1,24 @@ +# +# Copyright 2024 the original author or authors. +#

+# 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 +#

+# https://www.apache.org/licenses/LICENSE-2.0 +#

+# 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.quarkus2.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: + # Migrate Dependencies + - org.openrewrite.quarkus.quarkus2.JavaEEtoQuarkus2MavenDependencyMigration + # Migrate Code + - org.openrewrite.quarkus.quarkus2.JavaEEtoQuarkus2CodeMigration \ No newline at end of file From c31622fb09149575a12f1da26caaf5dc398f8d02 Mon Sep 17 00:00:00 2001 From: Adriano Machado <60320+ammachado@users.noreply.github.com> Date: Mon, 5 Feb 2024 22:49:33 +0000 Subject: [PATCH 05/13] Updated Tests --- ...avaEEtoQuarkus2CodeTranformationsTest.java | 153 +++++++ ...uarkus2MavenDependenciesMigrationTest.java | 404 ++++++++++++++++++ .../JavaEEtoQuarkus2MigrationTest.java | 145 ------- 3 files changed, 557 insertions(+), 145 deletions(-) create mode 100644 src/test/java/org/openrewrite/quarkus/quarkus2/JavaEEtoQuarkus2CodeTranformationsTest.java create mode 100644 src/test/java/org/openrewrite/quarkus/quarkus2/JavaEEtoQuarkus2MavenDependenciesMigrationTest.java delete mode 100644 src/test/java/org/openrewrite/quarkus/quarkus2/JavaEEtoQuarkus2MigrationTest.java diff --git a/src/test/java/org/openrewrite/quarkus/quarkus2/JavaEEtoQuarkus2CodeTranformationsTest.java b/src/test/java/org/openrewrite/quarkus/quarkus2/JavaEEtoQuarkus2CodeTranformationsTest.java new file mode 100644 index 0000000..8e5e903 --- /dev/null +++ b/src/test/java/org/openrewrite/quarkus/quarkus2/JavaEEtoQuarkus2CodeTranformationsTest.java @@ -0,0 +1,153 @@ +package org.openrewrite.quarkus.quarkus2; + +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.quarkus2.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++; + } + } + """ + ) + ); + } +} diff --git a/src/test/java/org/openrewrite/quarkus/quarkus2/JavaEEtoQuarkus2MavenDependenciesMigrationTest.java b/src/test/java/org/openrewrite/quarkus/quarkus2/JavaEEtoQuarkus2MavenDependenciesMigrationTest.java new file mode 100644 index 0000000..d85d929 --- /dev/null +++ b/src/test/java/org/openrewrite/quarkus/quarkus2/JavaEEtoQuarkus2MavenDependenciesMigrationTest.java @@ -0,0 +1,404 @@ +/* + * Copyright 2024 the original author or authors. + *

+ * 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 + *

+ * https://www.apache.org/licenses/LICENSE-2.0 + *

+ * 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.quarkus2; + +import org.junit.jupiter.api.Test; +import org.openrewrite.DocumentExample; +import org.openrewrite.test.RecipeSpec; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.maven.Assertions.pomXml; + +class JavaEEtoQuarkus2MavenDependenciesMigrationTest implements RewriteTest { + @Override + public void defaults(RecipeSpec spec) { + spec.recipeFromResources("org.openrewrite.quarkus.quarkus2.JavaEEtoQuarkus2MavenDependencyMigration"); + } + + @Test + @DocumentExample + void convertJavaEEToQuarkusDependencies1() { + rewriteRun( + spec -> spec.expectedCyclesThatMakeChanges(2), + //language=xml + pomXml( + """ + + + 4.0.0 + org.openrewrite.sample + Sample Java EE7 EJB Module + ee7-ejb + 1.0-SNAPSHOT + war + + + UTF-8 + UTF-8 + 1.8 + 1.8 + + + + + javax + javaee-api + 7.0 + provided + + + javax.annotation + javax.annotation-api + 1.3.2 + provided + + + + """, + """ + + + 4.0.0 + org.openrewrite.sample + ee7-ejb + 1.0-SNAPSHOT + Sample Java EE7 EJB Module + + + UTF-8 + UTF-8 + 11 + 11 + + + + + io.quarkus.platform + quarkus-bom + 2.16.12.Final + pom + import + + + + + + + io.quarkus.platform + quarkus-maven-plugin + 2.16.12.Final + + + + build + generate-code + generate-code-tests + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.10.1 + + + -parameters + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M7 + + + org.jboss.logmanager.LogManager + ${maven.home} + + + + + org.apache.maven.plugins + maven-failsafe-plugin + 3.0.0-M7 + + + + integration-test + verify + + + + + + ${project.build.directory}/${project.build.finalName}-runner + org.jboss.logmanager.LogManager + ${maven.home} + + + + + + + + native + + + native + + + + false + native + + + + + """ + ) + ); + } + + @Test + void convertJavaEEToQuarkusDependencies2() { + rewriteRun( + spec -> spec.expectedCyclesThatMakeChanges(2), + //language=xml + pomXml( + """ + + + 4.0.0 + com.dummyapp + oms-winter + 0.0.1-SNAPSHOT + oms-winter + war + Demo project for Java EE 7 JAX-RS, CDI, EJB, JPA, JTA + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 8 + 8 + + + + org.apache.maven.plugins + maven-war-plugin + 3.2.3 + + false + + + + + + + javax + javaee-api + 7.0 + provided + + + org.apache.commons + commons-lang3 + 3.12.0 + + + commons-beanutils + commons-beanutils + 1.9.4 + + + org.projectlombok + lombok + 1.18.30 + provided + + + com.fasterxml.jackson.jaxrs + jackson-jaxrs-json-provider + 2.12.3 + + + junit + junit + 4.13 + test + + + org.mockito + mockito-core + 3.2.4 + test + + + + """, + """ + + + 4.0.0 + com.dummyapp + oms-winter + 0.0.1-SNAPSHOT + oms-winter + Demo project for Java EE 7 JAX-RS, CDI, EJB, JPA, JTA + + 11 + 11 + + + + + io.quarkus.platform + quarkus-bom + 2.16.12.Final + pom + import + + + + + + + org.apache.commons + commons-lang3 + 3.12.0 + + + commons-beanutils + commons-beanutils + 1.9.4 + + + org.projectlombok + lombok + 1.18.30 + provided + + + com.fasterxml.jackson.jaxrs + jackson-jaxrs-json-provider + 2.12.3 + + + junit + junit + 4.13 + test + + + org.mockito + mockito-core + 3.2.4 + test + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.10.1 + + 8 + 8 + + + + org.apache.maven.plugins + maven-war-plugin + 3.2.3 + + false + + + + io.quarkus.platform + quarkus-maven-plugin + 2.16.12.Final + + + + build + generate-code + generate-code-tests + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M7 + + + org.jboss.logmanager.LogManager + ${maven.home} + + + + + org.apache.maven.plugins + maven-failsafe-plugin + 3.0.0-M7 + + + + integration-test + verify + + + + + + ${project.build.directory}/${project.build.finalName}-runner + org.jboss.logmanager.LogManager + ${maven.home} + + + + + + + + native + + + native + + + + false + native + + + + + """ + ) + ); + } + +} diff --git a/src/test/java/org/openrewrite/quarkus/quarkus2/JavaEEtoQuarkus2MigrationTest.java b/src/test/java/org/openrewrite/quarkus/quarkus2/JavaEEtoQuarkus2MigrationTest.java deleted file mode 100644 index d19b645..0000000 --- a/src/test/java/org/openrewrite/quarkus/quarkus2/JavaEEtoQuarkus2MigrationTest.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright 2024 the original author or authors. - *

- * 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 - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * 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.quarkus2; - -import org.junit.jupiter.api.Test; -import org.openrewrite.DocumentExample; -import org.openrewrite.test.RecipeSpec; -import org.openrewrite.test.RewriteTest; - -import static org.openrewrite.maven.Assertions.pomXml; - -class JavaEEtoQuarkus2MigrationTest implements RewriteTest { - @Override - public void defaults(RecipeSpec spec) { - spec.recipeFromResources("org.openrewrite.quarkus.quarkus2.JavaEEtoQuarkus2Migration"); - } - - @DocumentExample - @Test - void convertJavaEEToQuarkus() { - rewriteRun( - spec -> spec.expectedCyclesThatMakeChanges(2), - //language=xml - pomXml( - """ - - 4.0.0 - org.openrewrite.example - my-app - 1 - - """, - """ - - 4.0.0 - org.openrewrite.example - my-app - 1 - - 11 - 11 - - - - - io.quarkus.platform - quarkus-bom - 2.16.12.Final - pom - import - - - - - - - io.quarkus.platform - quarkus-maven-plugin - 2.16.12.Final - - - - build - generate-code - generate-code-tests - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.10.1 - - - -parameters - - - - - org.apache.maven.plugins - maven-surefire-plugin - 3.0.0-M7 - - - org.jboss.logmanager.LogManager - ${maven.home} - - - - - org.apache.maven.plugins - maven-failsafe-plugin - 3.0.0-M7 - - - - integration-test - verify - - - - - - ${project.build.directory}/${project.build.finalName}-runner - org.jboss.logmanager.LogManager - ${maven.home} - - - - - - - - native - - - native - - - - false - native - - - - - """ - ) - ); - } -} From 60cc5e1f44ea9a2d9ac14a6c0efe435f42e67bda Mon Sep 17 00:00:00 2001 From: Adriano Machado <60320+ammachado@users.noreply.github.com> Date: Mon, 5 Feb 2024 22:53:12 +0000 Subject: [PATCH 06/13] Remove recipe from quarkus.yml --- .../resources/META-INF/rewrite/quarkus.yml | 147 +----------------- 1 file changed, 1 insertion(+), 146 deletions(-) diff --git a/src/main/resources/META-INF/rewrite/quarkus.yml b/src/main/resources/META-INF/rewrite/quarkus.yml index 5132813..bd53688 100644 --- a/src/main/resources/META-INF/rewrite/quarkus.yml +++ b/src/main/resources/META-INF/rewrite/quarkus.yml @@ -140,149 +140,4 @@ recipeList: - org.openrewrite.java.ChangePackage: oldPackageName: io.vertx.core.http.HttpMethod newPackageName: io.quarkus.vertx.web.Route.HttpMethod - recursive: false ---- -type: specs.openrewrite.org/v1beta/recipe -name: org.openrewrite.quarkus.quarkus2.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: - # Migrate to JEE8 -# - org.openrewrite.java.migrate.javaee8 - # Add Quarkus 2 dependencies - - org.openrewrite.maven.AddManagedDependency: - groupId: io.quarkus.platform - artifactId: quarkus-bom - version: 2.16.12.Final - type: pom - scope: import - - 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 - - org.openrewrite.maven.AddPlugin: - groupId: io.quarkus.platform - artifactId: quarkus-maven-plugin - version: 2.16.12.Final - executions: buildgenerate-codegenerate-code-tests - - org.openrewrite.maven.AddPlugin: - groupId: org.apache.maven.plugins - artifactId: maven-compiler-plugin - version: 3.10.1 - configuration: -parameters - - org.openrewrite.maven.AddPlugin: - groupId: org.apache.maven.plugins - artifactId: maven-surefire-plugin - version: 3.0.0-M7 - configuration: org.jboss.logmanager.LogManager${maven.home} - - org.openrewrite.maven.AddPlugin: - groupId: org.apache.maven.plugins - artifactId: maven-failsafe-plugin - version: 3.0.0-M7 - executions: integration-testverify - configuration: ${project.build.directory}/${project.build.finalName}-runnerorg.jboss.logmanager.LogManager${maven.home} - - org.openrewrite.maven.AddProfile: - id: native - activation: native - properties: falsenative - - org.openrewrite.quarkus.ConfigureQuarkusMavenPluginWithReasonableDefaults - # 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* - - # 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 - - # Migrate to Java 11 - - org.openrewrite.java.migrate.Java8toJava11 - - 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 ---- + recursive: false \ No newline at end of file From 8d5c734141e69a85efeca39693ab978291b375ca Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Tue, 6 Feb 2024 11:32:46 +0100 Subject: [PATCH 07/13] Merge all three JavaEEtoQuarkus2 recipes into one file --- ...javaee-to-quarkus-code-transformations.yml | 76 --------- .../javaee-to-quarkus-maven-dependencies.yml | 107 ------------ .../META-INF/rewrite/javaee-to-quarkus.yml | 159 +++++++++++++++++- 3 files changed, 158 insertions(+), 184 deletions(-) delete mode 100644 src/main/resources/META-INF/rewrite/javaee-to-quarkus-code-transformations.yml delete mode 100644 src/main/resources/META-INF/rewrite/javaee-to-quarkus-maven-dependencies.yml diff --git a/src/main/resources/META-INF/rewrite/javaee-to-quarkus-code-transformations.yml b/src/main/resources/META-INF/rewrite/javaee-to-quarkus-code-transformations.yml deleted file mode 100644 index 02fa4f2..0000000 --- a/src/main/resources/META-INF/rewrite/javaee-to-quarkus-code-transformations.yml +++ /dev/null @@ -1,76 +0,0 @@ -# -# Copyright 2024 the original author or authors. -#

-# 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 -#

-# https://www.apache.org/licenses/LICENSE-2.0 -#

-# 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.quarkus2.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 - - # Migrate to Java 11 - - org.openrewrite.java.migrate.Java8toJava11 \ No newline at end of file diff --git a/src/main/resources/META-INF/rewrite/javaee-to-quarkus-maven-dependencies.yml b/src/main/resources/META-INF/rewrite/javaee-to-quarkus-maven-dependencies.yml deleted file mode 100644 index 53ba632..0000000 --- a/src/main/resources/META-INF/rewrite/javaee-to-quarkus-maven-dependencies.yml +++ /dev/null @@ -1,107 +0,0 @@ -# -# Copyright 2024 the original author or authors. -#

-# 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 -#

-# https://www.apache.org/licenses/LICENSE-2.0 -#

-# 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.quarkus2.JavaEEtoQuarkus2MavenDependencyMigration -displayName: Migrate JavaEE Maven and Gradle 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 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 - - # Add Maven Plugins - - org.openrewrite.maven.AddPlugin: - groupId: io.quarkus.platform - artifactId: quarkus-maven-plugin - version: '2.16.12.Final' - executions: buildgenerate-codegenerate-code-tests - - org.openrewrite.maven.AddPlugin: - groupId: org.apache.maven.plugins - artifactId: maven-compiler-plugin - version: '3.10.1' - configuration: -parameters - - org.openrewrite.maven.AddPlugin: - groupId: org.apache.maven.plugins - artifactId: maven-surefire-plugin - version: '3.0.0-M7' - configuration: org.jboss.logmanager.LogManager${maven.home} - - org.openrewrite.maven.AddPlugin: - groupId: org.apache.maven.plugins - artifactId: maven-failsafe-plugin - version: '3.0.0-M7' - executions: integration-testverify - configuration: ${project.build.directory}/${project.build.finalName}-runnerorg.jboss.logmanager.LogManager${maven.home} - - org.openrewrite.maven.AddProfile: - id: native - activation: native - properties: falsenative - - org.openrewrite.quarkus.ConfigureQuarkusMavenPluginWithReasonableDefaults - - org.openrewrite.maven.BestPractices - - # 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* - - # 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 \ No newline at end of file diff --git a/src/main/resources/META-INF/rewrite/javaee-to-quarkus.yml b/src/main/resources/META-INF/rewrite/javaee-to-quarkus.yml index 68dcfe2..3bbe6b5 100644 --- a/src/main/resources/META-INF/rewrite/javaee-to-quarkus.yml +++ b/src/main/resources/META-INF/rewrite/javaee-to-quarkus.yml @@ -21,4 +21,161 @@ recipeList: # Migrate Dependencies - org.openrewrite.quarkus.quarkus2.JavaEEtoQuarkus2MavenDependencyMigration # Migrate Code - - org.openrewrite.quarkus.quarkus2.JavaEEtoQuarkus2CodeMigration \ No newline at end of file + - org.openrewrite.quarkus.quarkus2.JavaEEtoQuarkus2CodeMigration + +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.quarkus.quarkus2.JavaEEtoQuarkus2MavenDependencyMigration +displayName: Migrate JavaEE Maven and Gradle 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 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 + + # Add Maven Plugins + - org.openrewrite.maven.AddPlugin: + groupId: io.quarkus.platform + artifactId: quarkus-maven-plugin + version: '2.16.12.Final' + executions: buildgenerate-codegenerate-code-tests + - org.openrewrite.maven.AddPlugin: + groupId: org.apache.maven.plugins + artifactId: maven-compiler-plugin + version: '3.10.1' + configuration: -parameters + - org.openrewrite.maven.AddPlugin: + groupId: org.apache.maven.plugins + artifactId: maven-surefire-plugin + version: '3.0.0-M7' + configuration: org.jboss.logmanager.LogManager${maven.home} + - org.openrewrite.maven.AddPlugin: + groupId: org.apache.maven.plugins + artifactId: maven-failsafe-plugin + version: '3.0.0-M7' + executions: integration-testverify + configuration: ${project.build.directory}/${project.build.finalName}-runnerorg.jboss.logmanager.LogManager${maven.home} + - org.openrewrite.maven.AddProfile: + id: native + activation: native + properties: falsenative + - org.openrewrite.quarkus.ConfigureQuarkusMavenPluginWithReasonableDefaults + - org.openrewrite.maven.BestPractices + + # 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* + + # 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 + +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.quarkus.quarkus2.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 + + # Migrate to Java 11 + - org.openrewrite.java.migrate.Java8toJava11 From af2b54f86d6009d6a7c698c32dbab49b715f1819 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Tue, 6 Feb 2024 11:38:30 +0100 Subject: [PATCH 08/13] Update src/test/java/org/openrewrite/quarkus/quarkus2/JavaEEtoQuarkus2CodeTranformationsTest.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../JavaEEtoQuarkus2CodeTranformationsTest.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/test/java/org/openrewrite/quarkus/quarkus2/JavaEEtoQuarkus2CodeTranformationsTest.java b/src/test/java/org/openrewrite/quarkus/quarkus2/JavaEEtoQuarkus2CodeTranformationsTest.java index 8e5e903..25b0508 100644 --- a/src/test/java/org/openrewrite/quarkus/quarkus2/JavaEEtoQuarkus2CodeTranformationsTest.java +++ b/src/test/java/org/openrewrite/quarkus/quarkus2/JavaEEtoQuarkus2CodeTranformationsTest.java @@ -1,3 +1,18 @@ +/* + * Copyright 2024 the original author or authors. + *

+ * 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 + *

+ * https://www.apache.org/licenses/LICENSE-2.0 + *

+ * 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.quarkus2; import org.junit.jupiter.api.Test; From 9509f2734d669deec7c775e4c6d14aa7da312c0c Mon Sep 17 00:00:00 2001 From: ShatanikB Date: Wed, 7 Feb 2024 01:09:21 +0000 Subject: [PATCH 09/13] Updated Dependency Migration Description to reflect that this migrates Maven only right now. Added a TODO for Gradle --- src/main/resources/META-INF/rewrite/javaee-to-quarkus.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/resources/META-INF/rewrite/javaee-to-quarkus.yml b/src/main/resources/META-INF/rewrite/javaee-to-quarkus.yml index 3bbe6b5..638b306 100644 --- a/src/main/resources/META-INF/rewrite/javaee-to-quarkus.yml +++ b/src/main/resources/META-INF/rewrite/javaee-to-quarkus.yml @@ -18,15 +18,16 @@ name: org.openrewrite.quarkus.quarkus2.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: - # Migrate Dependencies + # Migrate Maven Dependencies - org.openrewrite.quarkus.quarkus2.JavaEEtoQuarkus2MavenDependencyMigration + # TODO Migrate Gradle Dependencies # Migrate Code - org.openrewrite.quarkus.quarkus2.JavaEEtoQuarkus2CodeMigration --- type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.quarkus.quarkus2.JavaEEtoQuarkus2MavenDependencyMigration -displayName: Migrate JavaEE Maven and Gradle Dependencies to Quarkus 2 +displayName: Migrate JavaEE Maven Dependencies to Quarkus 2 description: Upgrade Standard JavaEE dependencies to Quarkus 2 dependencies. recipeList: # Add Quarkus BOM From 12e8a534ab87af4525ac490bc63c87d56f9ed93f Mon Sep 17 00:00:00 2001 From: ShatanikB Date: Wed, 24 Apr 2024 13:07:46 +0000 Subject: [PATCH 10/13] Updated dependency versions and tests --- .gitignore | 1 + ...-to-quarkus.yml => javaee7-to-quarkus.yml} | 6 +- ...avaEEtoQuarkus2CodeTranformationsTest.java | 258 +++--- ...uarkus2MavenDependenciesMigrationTest.java | 811 ++++++++++-------- 4 files changed, 571 insertions(+), 505 deletions(-) rename src/main/resources/META-INF/rewrite/{javaee-to-quarkus.yml => javaee7-to-quarkus.yml} (99%) diff --git a/.gitignore b/.gitignore index 03ed5d5..344c2c5 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ build/ .idea/ .boot-releases out/ +.vscode/ \ No newline at end of file diff --git a/src/main/resources/META-INF/rewrite/javaee-to-quarkus.yml b/src/main/resources/META-INF/rewrite/javaee7-to-quarkus.yml similarity index 99% rename from src/main/resources/META-INF/rewrite/javaee-to-quarkus.yml rename to src/main/resources/META-INF/rewrite/javaee7-to-quarkus.yml index 638b306..abf1c68 100644 --- a/src/main/resources/META-INF/rewrite/javaee-to-quarkus.yml +++ b/src/main/resources/META-INF/rewrite/javaee7-to-quarkus.yml @@ -75,17 +75,17 @@ recipeList: - org.openrewrite.maven.AddPlugin: groupId: org.apache.maven.plugins artifactId: maven-compiler-plugin - version: '3.10.1' + version: '3.13.0' configuration: -parameters - org.openrewrite.maven.AddPlugin: groupId: org.apache.maven.plugins artifactId: maven-surefire-plugin - version: '3.0.0-M7' + version: '3.2.5' configuration: org.jboss.logmanager.LogManager${maven.home} - org.openrewrite.maven.AddPlugin: groupId: org.apache.maven.plugins artifactId: maven-failsafe-plugin - version: '3.0.0-M7' + version: '3.2.5' executions: integration-testverify configuration: ${project.build.directory}/${project.build.finalName}-runnerorg.jboss.logmanager.LogManager${maven.home} - org.openrewrite.maven.AddProfile: diff --git a/src/test/java/org/openrewrite/quarkus/quarkus2/JavaEEtoQuarkus2CodeTranformationsTest.java b/src/test/java/org/openrewrite/quarkus/quarkus2/JavaEEtoQuarkus2CodeTranformationsTest.java index 25b0508..b830b66 100644 --- a/src/test/java/org/openrewrite/quarkus/quarkus2/JavaEEtoQuarkus2CodeTranformationsTest.java +++ b/src/test/java/org/openrewrite/quarkus/quarkus2/JavaEEtoQuarkus2CodeTranformationsTest.java @@ -28,141 +28,139 @@ class JavaEEtoQuarkus2CodeTranformationsTest implements RewriteTest { @Override public void defaults(RecipeSpec spec) { spec.parser(JavaParser.fromJavaVersion() - .logCompilationWarningsAndErrors(true) - .classpath("javaee-api")) - .recipeFromResources("org.openrewrite.quarkus.quarkus2.JavaEEtoQuarkus2CodeMigration"); + .logCompilationWarningsAndErrors(true) + .classpath("javaee-api")) + .recipeFromResources("org.openrewrite.quarkus.quarkus2.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++; - } - } - """ - ) - ); + 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++; + } + } + """)); } } diff --git a/src/test/java/org/openrewrite/quarkus/quarkus2/JavaEEtoQuarkus2MavenDependenciesMigrationTest.java b/src/test/java/org/openrewrite/quarkus/quarkus2/JavaEEtoQuarkus2MavenDependenciesMigrationTest.java index d85d929..40810f9 100644 --- a/src/test/java/org/openrewrite/quarkus/quarkus2/JavaEEtoQuarkus2MavenDependenciesMigrationTest.java +++ b/src/test/java/org/openrewrite/quarkus/quarkus2/JavaEEtoQuarkus2MavenDependenciesMigrationTest.java @@ -23,382 +23,449 @@ import static org.openrewrite.maven.Assertions.pomXml; class JavaEEtoQuarkus2MavenDependenciesMigrationTest implements RewriteTest { - @Override - public void defaults(RecipeSpec spec) { - spec.recipeFromResources("org.openrewrite.quarkus.quarkus2.JavaEEtoQuarkus2MavenDependencyMigration"); - } + @Override + public void defaults(RecipeSpec spec) { + spec.recipeFromResources("org.openrewrite.quarkus.quarkus2.JavaEEtoQuarkus2MavenDependencyMigration"); + } - @Test - @DocumentExample - void convertJavaEEToQuarkusDependencies1() { - rewriteRun( - spec -> spec.expectedCyclesThatMakeChanges(2), - //language=xml - pomXml( - """ - - - 4.0.0 - org.openrewrite.sample - Sample Java EE7 EJB Module - ee7-ejb - 1.0-SNAPSHOT - war - - - UTF-8 - UTF-8 - 1.8 - 1.8 - - - - - javax - javaee-api - 7.0 - provided - - - javax.annotation - javax.annotation-api - 1.3.2 - provided - - - - """, - """ - - - 4.0.0 - org.openrewrite.sample - ee7-ejb - 1.0-SNAPSHOT - Sample Java EE7 EJB Module + @Test + @DocumentExample + void convertJavaEEToQuarkusDependencies1() { + rewriteRun( + spec -> spec.expectedCyclesThatMakeChanges(2), + // language=xml + pomXml( + """ + + + 4.0.0 + org.openrewrite.sample + Sample Java EE7 EJB Module + ee7-ejb + 1.0-SNAPSHOT + war - - UTF-8 - UTF-8 - 11 - 11 - - - - - io.quarkus.platform - quarkus-bom - 2.16.12.Final - pom - import - - - - - - - io.quarkus.platform - quarkus-maven-plugin - 2.16.12.Final - - - - build - generate-code - generate-code-tests - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.10.1 - - - -parameters - - - - - org.apache.maven.plugins - maven-surefire-plugin - 3.0.0-M7 - - - org.jboss.logmanager.LogManager - ${maven.home} - - - - - org.apache.maven.plugins - maven-failsafe-plugin - 3.0.0-M7 - - - - integration-test - verify - - - - - - ${project.build.directory}/${project.build.finalName}-runner - org.jboss.logmanager.LogManager - ${maven.home} - - - - - - - - native - - - native - - - - false - native - - - - - """ - ) - ); - } + + UTF-8 + UTF-8 + 1.8 + 1.8 + - @Test - void convertJavaEEToQuarkusDependencies2() { - rewriteRun( - spec -> spec.expectedCyclesThatMakeChanges(2), - //language=xml - pomXml( - """ - - - 4.0.0 - com.dummyapp - oms-winter - 0.0.1-SNAPSHOT - oms-winter - war - Demo project for Java EE 7 JAX-RS, CDI, EJB, JPA, JTA + + + javax + javaee-api + 7.0 + provided + + + javax.annotation + javax.annotation-api + 1.3.2 + provided + + + + """, + """ + + + 4.0.0 + org.openrewrite.sample + ee7-ejb + 1.0-SNAPSHOT + Sample Java EE7 EJB Module - - - - org.apache.maven.plugins - maven-compiler-plugin - - 8 - 8 - - - - org.apache.maven.plugins - maven-war-plugin - 3.2.3 - - false - - - - - - - javax - javaee-api - 7.0 - provided - - - org.apache.commons - commons-lang3 - 3.12.0 - - - commons-beanutils - commons-beanutils - 1.9.4 - - - org.projectlombok - lombok - 1.18.30 - provided - - - com.fasterxml.jackson.jaxrs - jackson-jaxrs-json-provider - 2.12.3 - - - junit - junit - 4.13 - test - - - org.mockito - mockito-core - 3.2.4 - test - - - - """, - """ - - - 4.0.0 - com.dummyapp - oms-winter - 0.0.1-SNAPSHOT - oms-winter - Demo project for Java EE 7 JAX-RS, CDI, EJB, JPA, JTA - - 11 - 11 - - - - - io.quarkus.platform - quarkus-bom - 2.16.12.Final - pom - import - - - + + UTF-8 + UTF-8 + 11 + 11 + + + + + io.quarkus.platform + quarkus-bom + 2.16.12.Final + pom + import + + + - - - org.apache.commons - commons-lang3 - 3.12.0 - - - commons-beanutils - commons-beanutils - 1.9.4 - - - org.projectlombok - lombok - 1.18.30 - provided - - - com.fasterxml.jackson.jaxrs - jackson-jaxrs-json-provider - 2.12.3 - - - junit - junit - 4.13 - test - - - org.mockito - mockito-core - 3.2.4 - test - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.10.1 - - 8 - 8 - - - - org.apache.maven.plugins - maven-war-plugin - 3.2.3 - - false - - - - io.quarkus.platform - quarkus-maven-plugin - 2.16.12.Final - - - - build - generate-code - generate-code-tests - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 3.0.0-M7 - - - org.jboss.logmanager.LogManager - ${maven.home} - - - - - org.apache.maven.plugins - maven-failsafe-plugin - 3.0.0-M7 - - - - integration-test - verify - - - - - - ${project.build.directory}/${project.build.finalName}-runner - org.jboss.logmanager.LogManager - ${maven.home} - - - - - - - - native - - - native - - - - false - native - - - - - """ - ) - ); - } + + + io.quarkus + quarkus-arc + + + io.quarkus + quarkus-hibernate-orm + + + io.quarkus + quarkus-jdbc-h2 + + + io.quarkus + quarkus-resteasy + + + io.quarkus + quarkus-resteasy-jackson + + + io.quarkus + quarkus-undertow + + + io.quarkus + quarkus-junit5 + test + + + io.rest-assured + rest-assured + test + + + + + + io.quarkus.platform + quarkus-maven-plugin + 2.16.12.Final + + + + build + generate-code + generate-code-tests + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.13.0 + + + -parameters + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.2.5 + + + org.jboss.logmanager.LogManager + ${maven.home} + + + + + org.apache.maven.plugins + maven-failsafe-plugin + 3.2.5 + + + + integration-test + verify + + + + + + ${project.build.directory}/${project.build.finalName}-runner + org.jboss.logmanager.LogManager + ${maven.home} + + + + + + + + native + + + native + + + + false + native + + + + + """)); + } + + @Test + void convertJavaEEToQuarkusDependencies2() { + rewriteRun( + spec -> spec.expectedCyclesThatMakeChanges(2), + // language=xml + pomXml( + """ + + + 4.0.0 + com.dummyapp + oms-winter + 0.0.1-SNAPSHOT + oms-winter + war + Demo project for Java EE 7 JAX-RS, CDI, EJB, JPA, JTA + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 8 + 8 + + + + org.apache.maven.plugins + maven-war-plugin + 3.2.3 + + false + + + + + + + javax + javaee-api + 7.0 + provided + + + org.apache.commons + commons-lang3 + 3.12.0 + + + commons-beanutils + commons-beanutils + 1.9.4 + + + org.projectlombok + lombok + 1.18.30 + provided + + + com.fasterxml.jackson.jaxrs + jackson-jaxrs-json-provider + 2.12.3 + + + junit + junit + 4.13 + test + + + org.mockito + mockito-core + 3.2.4 + test + + + + """, + """ + + + 4.0.0 + com.dummyapp + oms-winter + 0.0.1-SNAPSHOT + oms-winter + Demo project for Java EE 7 JAX-RS, CDI, EJB, JPA, JTA + + 11 + 11 + + + + + io.quarkus.platform + quarkus-bom + 2.16.12.Final + pom + import + + + + + + + org.apache.commons + commons-lang3 + 3.12.0 + + + commons-beanutils + commons-beanutils + 1.9.4 + + + io.quarkus + quarkus-arc + + + io.quarkus + quarkus-hibernate-orm + + + io.quarkus + quarkus-jdbc-h2 + + + io.quarkus + quarkus-resteasy + + + io.quarkus + quarkus-resteasy-jackson + + + io.quarkus + quarkus-undertow + + + org.projectlombok + lombok + 1.18.30 + provided + + + io.quarkus + quarkus-junit5 + test + + + io.rest-assured + rest-assured + test + + + com.fasterxml.jackson.jaxrs + jackson-jaxrs-json-provider + 2.12.3 + + + junit + junit + 4.13 + test + + + org.mockito + mockito-core + 3.2.4 + test + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.13.0 + + 8 + 8 + + + + org.apache.maven.plugins + maven-war-plugin + 3.2.3 + + false + + + + io.quarkus.platform + quarkus-maven-plugin + 2.16.12.Final + + + + build + generate-code + generate-code-tests + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.2.5 + + + org.jboss.logmanager.LogManager + ${maven.home} + + + + + org.apache.maven.plugins + maven-failsafe-plugin + 3.2.5 + + + + integration-test + verify + + + + + + ${project.build.directory}/${project.build.finalName}-runner + org.jboss.logmanager.LogManager + ${maven.home} + + + + + + + + native + + + native + + + + false + native + + + + + """)); + } } From 23ef2d31afaf50354a5d16dda21b66fd3f2de466 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Fri, 12 Jul 2024 23:44:24 +0200 Subject: [PATCH 11/13] Move recipes and reformat tests --- .../META-INF/rewrite/javaee7-to-quarkus.yml | 10 +- ...avaEEtoQuarkus2CodeTranformationsTest.java | 162 ++++++ ...uarkus2MavenDependenciesMigrationTest.java | 475 ++++++++++++++++++ ...avaEEtoQuarkus2CodeTranformationsTest.java | 166 ------ ...uarkus2MavenDependenciesMigrationTest.java | 471 ----------------- 5 files changed, 642 insertions(+), 642 deletions(-) create mode 100644 src/test/java/org/openrewrite/quarkus/migrate/javaee/JavaEEtoQuarkus2CodeTranformationsTest.java create mode 100644 src/test/java/org/openrewrite/quarkus/migrate/javaee/JavaEEtoQuarkus2MavenDependenciesMigrationTest.java delete mode 100644 src/test/java/org/openrewrite/quarkus/quarkus2/JavaEEtoQuarkus2CodeTranformationsTest.java delete mode 100644 src/test/java/org/openrewrite/quarkus/quarkus2/JavaEEtoQuarkus2MavenDependenciesMigrationTest.java diff --git a/src/main/resources/META-INF/rewrite/javaee7-to-quarkus.yml b/src/main/resources/META-INF/rewrite/javaee7-to-quarkus.yml index abf1c68..2b50bc3 100644 --- a/src/main/resources/META-INF/rewrite/javaee7-to-quarkus.yml +++ b/src/main/resources/META-INF/rewrite/javaee7-to-quarkus.yml @@ -14,19 +14,19 @@ # limitations under the License. # type: specs.openrewrite.org/v1beta/recipe -name: org.openrewrite.quarkus.quarkus2.JavaEEtoQuarkus2Migration +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: # Migrate Maven Dependencies - - org.openrewrite.quarkus.quarkus2.JavaEEtoQuarkus2MavenDependencyMigration + - org.openrewrite.quarkus.migrate.javaee.JavaEEtoQuarkus2MavenDependencyMigration # TODO Migrate Gradle Dependencies # Migrate Code - - org.openrewrite.quarkus.quarkus2.JavaEEtoQuarkus2CodeMigration + - org.openrewrite.quarkus.migrate.javaee.JavaEEtoQuarkus2CodeMigration --- type: specs.openrewrite.org/v1beta/recipe -name: org.openrewrite.quarkus.quarkus2.JavaEEtoQuarkus2MavenDependencyMigration +name: org.openrewrite.quarkus.migrate.javaee.JavaEEtoQuarkus2MavenDependencyMigration displayName: Migrate JavaEE Maven Dependencies to Quarkus 2 description: Upgrade Standard JavaEE dependencies to Quarkus 2 dependencies. recipeList: @@ -120,7 +120,7 @@ recipeList: --- type: specs.openrewrite.org/v1beta/recipe -name: org.openrewrite.quarkus.quarkus2.JavaEEtoQuarkus2CodeMigration +name: org.openrewrite.quarkus.migrate.javaee.JavaEEtoQuarkus2CodeMigration displayName: Migrate JavaEE Code to Quarkus 2 description: Migrate Standard JavaEE Code to Quarkus 2 recipeList: diff --git a/src/test/java/org/openrewrite/quarkus/migrate/javaee/JavaEEtoQuarkus2CodeTranformationsTest.java b/src/test/java/org/openrewrite/quarkus/migrate/javaee/JavaEEtoQuarkus2CodeTranformationsTest.java new file mode 100644 index 0000000..8374b7f --- /dev/null +++ b/src/test/java/org/openrewrite/quarkus/migrate/javaee/JavaEEtoQuarkus2CodeTranformationsTest.java @@ -0,0 +1,162 @@ +/* + * Copyright 2024 the original author or authors. + *

+ * 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 + *

+ * https://www.apache.org/licenses/LICENSE-2.0 + *

+ * 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++; + } + } + """ + ) + ); + } +} diff --git a/src/test/java/org/openrewrite/quarkus/migrate/javaee/JavaEEtoQuarkus2MavenDependenciesMigrationTest.java b/src/test/java/org/openrewrite/quarkus/migrate/javaee/JavaEEtoQuarkus2MavenDependenciesMigrationTest.java new file mode 100644 index 0000000..6d99376 --- /dev/null +++ b/src/test/java/org/openrewrite/quarkus/migrate/javaee/JavaEEtoQuarkus2MavenDependenciesMigrationTest.java @@ -0,0 +1,475 @@ +/* + * Copyright 2024 the original author or authors. + *

+ * 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 + *

+ * https://www.apache.org/licenses/LICENSE-2.0 + *

+ * 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.test.RecipeSpec; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.maven.Assertions.pomXml; + +class JavaEEtoQuarkus2MavenDependenciesMigrationTest implements RewriteTest { + @Override + public void defaults(RecipeSpec spec) { + spec.recipeFromResources("org.openrewrite.quarkus.migrate.javaee.JavaEEtoQuarkus2MavenDependencyMigration"); + } + + @Test + @DocumentExample + void convertJavaEEToQuarkusDependencies1() { + rewriteRun( + spec -> spec.expectedCyclesThatMakeChanges(2), + // language=xml + pomXml( + """ + + + 4.0.0 + org.openrewrite.sample + Sample Java EE7 EJB Module + ee7-ejb + 1.0-SNAPSHOT + war + + + UTF-8 + UTF-8 + 1.8 + 1.8 + + + + + javax + javaee-api + 7.0 + provided + + + javax.annotation + javax.annotation-api + 1.3.2 + provided + + + + """, + """ + + + 4.0.0 + org.openrewrite.sample + ee7-ejb + 1.0-SNAPSHOT + Sample Java EE7 EJB Module + + + UTF-8 + UTF-8 + 11 + 11 + + + + + io.quarkus.platform + quarkus-bom + 2.16.12.Final + pom + import + + + + + + + io.quarkus + quarkus-arc + + + io.quarkus + quarkus-hibernate-orm + + + io.quarkus + quarkus-jdbc-h2 + + + io.quarkus + quarkus-resteasy + + + io.quarkus + quarkus-resteasy-jackson + + + io.quarkus + quarkus-undertow + + + io.quarkus + quarkus-junit5 + test + + + io.rest-assured + rest-assured + test + + + + + + io.quarkus.platform + quarkus-maven-plugin + 2.16.12.Final + + + + build + generate-code + generate-code-tests + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.13.0 + + + -parameters + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.2.5 + + + org.jboss.logmanager.LogManager + ${maven.home} + + + + + org.apache.maven.plugins + maven-failsafe-plugin + 3.2.5 + + + + integration-test + verify + + + + + + ${project.build.directory}/${project.build.finalName}-runner + org.jboss.logmanager.LogManager + ${maven.home} + + + + + + + + native + + + native + + + + false + native + + + + + """ + ) + ); + } + + @Test + void convertJavaEEToQuarkusDependencies2() { + rewriteRun( + spec -> spec.expectedCyclesThatMakeChanges(2), + // language=xml + pomXml( + """ + + + 4.0.0 + com.dummyapp + oms-winter + 0.0.1-SNAPSHOT + oms-winter + war + Demo project for Java EE 7 JAX-RS, CDI, EJB, JPA, JTA + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 8 + 8 + + + + org.apache.maven.plugins + maven-war-plugin + 3.2.3 + + false + + + + + + + javax + javaee-api + 7.0 + provided + + + org.apache.commons + commons-lang3 + 3.12.0 + + + commons-beanutils + commons-beanutils + 1.9.4 + + + org.projectlombok + lombok + 1.18.30 + provided + + + com.fasterxml.jackson.jaxrs + jackson-jaxrs-json-provider + 2.12.3 + + + junit + junit + 4.13 + test + + + org.mockito + mockito-core + 3.2.4 + test + + + + """, + """ + + + 4.0.0 + com.dummyapp + oms-winter + 0.0.1-SNAPSHOT + oms-winter + Demo project for Java EE 7 JAX-RS, CDI, EJB, JPA, JTA + + 11 + 11 + + + + + io.quarkus.platform + quarkus-bom + 2.16.12.Final + pom + import + + + + + + + org.apache.commons + commons-lang3 + 3.12.0 + + + commons-beanutils + commons-beanutils + 1.9.4 + + + io.quarkus + quarkus-arc + + + io.quarkus + quarkus-hibernate-orm + + + io.quarkus + quarkus-jdbc-h2 + + + io.quarkus + quarkus-resteasy + + + io.quarkus + quarkus-resteasy-jackson + + + io.quarkus + quarkus-undertow + + + org.projectlombok + lombok + 1.18.30 + provided + + + io.quarkus + quarkus-junit5 + test + + + io.rest-assured + rest-assured + test + + + com.fasterxml.jackson.jaxrs + jackson-jaxrs-json-provider + 2.12.3 + + + junit + junit + 4.13 + test + + + org.mockito + mockito-core + 3.2.4 + test + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.13.0 + + 8 + 8 + + + + org.apache.maven.plugins + maven-war-plugin + 3.2.3 + + false + + + + io.quarkus.platform + quarkus-maven-plugin + 2.16.12.Final + + + + build + generate-code + generate-code-tests + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.2.5 + + + org.jboss.logmanager.LogManager + ${maven.home} + + + + + org.apache.maven.plugins + maven-failsafe-plugin + 3.2.5 + + + + integration-test + verify + + + + + + ${project.build.directory}/${project.build.finalName}-runner + org.jboss.logmanager.LogManager + ${maven.home} + + + + + + + + native + + + native + + + + false + native + + + + + """ + ) + ); + } + +} diff --git a/src/test/java/org/openrewrite/quarkus/quarkus2/JavaEEtoQuarkus2CodeTranformationsTest.java b/src/test/java/org/openrewrite/quarkus/quarkus2/JavaEEtoQuarkus2CodeTranformationsTest.java deleted file mode 100644 index b830b66..0000000 --- a/src/test/java/org/openrewrite/quarkus/quarkus2/JavaEEtoQuarkus2CodeTranformationsTest.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright 2024 the original author or authors. - *

- * 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 - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * 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.quarkus2; - -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.quarkus2.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++; - } - } - """)); - } -} diff --git a/src/test/java/org/openrewrite/quarkus/quarkus2/JavaEEtoQuarkus2MavenDependenciesMigrationTest.java b/src/test/java/org/openrewrite/quarkus/quarkus2/JavaEEtoQuarkus2MavenDependenciesMigrationTest.java deleted file mode 100644 index 40810f9..0000000 --- a/src/test/java/org/openrewrite/quarkus/quarkus2/JavaEEtoQuarkus2MavenDependenciesMigrationTest.java +++ /dev/null @@ -1,471 +0,0 @@ -/* - * Copyright 2024 the original author or authors. - *

- * 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 - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * 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.quarkus2; - -import org.junit.jupiter.api.Test; -import org.openrewrite.DocumentExample; -import org.openrewrite.test.RecipeSpec; -import org.openrewrite.test.RewriteTest; - -import static org.openrewrite.maven.Assertions.pomXml; - -class JavaEEtoQuarkus2MavenDependenciesMigrationTest implements RewriteTest { - @Override - public void defaults(RecipeSpec spec) { - spec.recipeFromResources("org.openrewrite.quarkus.quarkus2.JavaEEtoQuarkus2MavenDependencyMigration"); - } - - @Test - @DocumentExample - void convertJavaEEToQuarkusDependencies1() { - rewriteRun( - spec -> spec.expectedCyclesThatMakeChanges(2), - // language=xml - pomXml( - """ - - - 4.0.0 - org.openrewrite.sample - Sample Java EE7 EJB Module - ee7-ejb - 1.0-SNAPSHOT - war - - - UTF-8 - UTF-8 - 1.8 - 1.8 - - - - - javax - javaee-api - 7.0 - provided - - - javax.annotation - javax.annotation-api - 1.3.2 - provided - - - - """, - """ - - - 4.0.0 - org.openrewrite.sample - ee7-ejb - 1.0-SNAPSHOT - Sample Java EE7 EJB Module - - - UTF-8 - UTF-8 - 11 - 11 - - - - - io.quarkus.platform - quarkus-bom - 2.16.12.Final - pom - import - - - - - - - io.quarkus - quarkus-arc - - - io.quarkus - quarkus-hibernate-orm - - - io.quarkus - quarkus-jdbc-h2 - - - io.quarkus - quarkus-resteasy - - - io.quarkus - quarkus-resteasy-jackson - - - io.quarkus - quarkus-undertow - - - io.quarkus - quarkus-junit5 - test - - - io.rest-assured - rest-assured - test - - - - - - io.quarkus.platform - quarkus-maven-plugin - 2.16.12.Final - - - - build - generate-code - generate-code-tests - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.13.0 - - - -parameters - - - - - org.apache.maven.plugins - maven-surefire-plugin - 3.2.5 - - - org.jboss.logmanager.LogManager - ${maven.home} - - - - - org.apache.maven.plugins - maven-failsafe-plugin - 3.2.5 - - - - integration-test - verify - - - - - - ${project.build.directory}/${project.build.finalName}-runner - org.jboss.logmanager.LogManager - ${maven.home} - - - - - - - - native - - - native - - - - false - native - - - - - """)); - } - - @Test - void convertJavaEEToQuarkusDependencies2() { - rewriteRun( - spec -> spec.expectedCyclesThatMakeChanges(2), - // language=xml - pomXml( - """ - - - 4.0.0 - com.dummyapp - oms-winter - 0.0.1-SNAPSHOT - oms-winter - war - Demo project for Java EE 7 JAX-RS, CDI, EJB, JPA, JTA - - - - - org.apache.maven.plugins - maven-compiler-plugin - - 8 - 8 - - - - org.apache.maven.plugins - maven-war-plugin - 3.2.3 - - false - - - - - - - javax - javaee-api - 7.0 - provided - - - org.apache.commons - commons-lang3 - 3.12.0 - - - commons-beanutils - commons-beanutils - 1.9.4 - - - org.projectlombok - lombok - 1.18.30 - provided - - - com.fasterxml.jackson.jaxrs - jackson-jaxrs-json-provider - 2.12.3 - - - junit - junit - 4.13 - test - - - org.mockito - mockito-core - 3.2.4 - test - - - - """, - """ - - - 4.0.0 - com.dummyapp - oms-winter - 0.0.1-SNAPSHOT - oms-winter - Demo project for Java EE 7 JAX-RS, CDI, EJB, JPA, JTA - - 11 - 11 - - - - - io.quarkus.platform - quarkus-bom - 2.16.12.Final - pom - import - - - - - - - org.apache.commons - commons-lang3 - 3.12.0 - - - commons-beanutils - commons-beanutils - 1.9.4 - - - io.quarkus - quarkus-arc - - - io.quarkus - quarkus-hibernate-orm - - - io.quarkus - quarkus-jdbc-h2 - - - io.quarkus - quarkus-resteasy - - - io.quarkus - quarkus-resteasy-jackson - - - io.quarkus - quarkus-undertow - - - org.projectlombok - lombok - 1.18.30 - provided - - - io.quarkus - quarkus-junit5 - test - - - io.rest-assured - rest-assured - test - - - com.fasterxml.jackson.jaxrs - jackson-jaxrs-json-provider - 2.12.3 - - - junit - junit - 4.13 - test - - - org.mockito - mockito-core - 3.2.4 - test - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.13.0 - - 8 - 8 - - - - org.apache.maven.plugins - maven-war-plugin - 3.2.3 - - false - - - - io.quarkus.platform - quarkus-maven-plugin - 2.16.12.Final - - - - build - generate-code - generate-code-tests - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 3.2.5 - - - org.jboss.logmanager.LogManager - ${maven.home} - - - - - org.apache.maven.plugins - maven-failsafe-plugin - 3.2.5 - - - - integration-test - verify - - - - - - ${project.build.directory}/${project.build.finalName}-runner - org.jboss.logmanager.LogManager - ${maven.home} - - - - - - - - native - - - native - - - - false - native - - - - - """)); - } - -} From f1cb466241bec7ac6aef8947abfc0e4fb6a4fb53 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Sat, 13 Jul 2024 00:13:55 +0200 Subject: [PATCH 12/13] Break up dependency & maven recipes; expect to remove war plugin --- .../META-INF/rewrite/javaee7-to-quarkus.yml | 72 +++++++++++-------- ...uarkus2MavenDependenciesMigrationTest.java | 18 ++--- 2 files changed, 47 insertions(+), 43 deletions(-) diff --git a/src/main/resources/META-INF/rewrite/javaee7-to-quarkus.yml b/src/main/resources/META-INF/rewrite/javaee7-to-quarkus.yml index 2b50bc3..36fc68c 100644 --- a/src/main/resources/META-INF/rewrite/javaee7-to-quarkus.yml +++ b/src/main/resources/META-INF/rewrite/javaee7-to-quarkus.yml @@ -18,26 +18,19 @@ 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: - # Migrate Maven Dependencies - - org.openrewrite.quarkus.migrate.javaee.JavaEEtoQuarkus2MavenDependencyMigration - # TODO Migrate Gradle Dependencies - # Migrate Code + - 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.JavaEEtoQuarkus2MavenDependencyMigration -displayName: Migrate JavaEE Maven Dependencies to Quarkus 2 -description: Upgrade Standard JavaEE dependencies to Quarkus 2 dependencies. +name: org.openrewrite.quarkus.migrate.javaee.AddQuarkus2Dependencies +displayName: Add Quarkus 2 dependencies +description: Add Quarkus 2 dependencies to the project. recipeList: - # Add Quarkus BOM - - org.openrewrite.maven.AddManagedDependency: - groupId: io.quarkus.platform - artifactId: quarkus-bom - version: '2.x' - type: pom - scope: import - # Add Basic Quarkus Extensions - org.openrewrite.java.dependencies.AddDependency: groupId: io.quarkus @@ -66,6 +59,37 @@ recipeList: 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 @@ -95,17 +119,6 @@ recipeList: - org.openrewrite.quarkus.ConfigureQuarkusMavenPluginWithReasonableDefaults - org.openrewrite.maven.BestPractices - # 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* - # Prep for Java 11 upgrade - org.openrewrite.maven.AddProperty: key: maven.compiler.source @@ -118,6 +131,10 @@ recipeList: 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 @@ -177,6 +194,3 @@ recipeList: - org.openrewrite.java.ChangeType: oldFullyQualifiedTypeName: javax.persistence.PersistenceContext newFullyQualifiedTypeName: javax.inject.Inject - - # Migrate to Java 11 - - org.openrewrite.java.migrate.Java8toJava11 diff --git a/src/test/java/org/openrewrite/quarkus/migrate/javaee/JavaEEtoQuarkus2MavenDependenciesMigrationTest.java b/src/test/java/org/openrewrite/quarkus/migrate/javaee/JavaEEtoQuarkus2MavenDependenciesMigrationTest.java index 6d99376..e424ef3 100644 --- a/src/test/java/org/openrewrite/quarkus/migrate/javaee/JavaEEtoQuarkus2MavenDependenciesMigrationTest.java +++ b/src/test/java/org/openrewrite/quarkus/migrate/javaee/JavaEEtoQuarkus2MavenDependenciesMigrationTest.java @@ -25,7 +25,7 @@ class JavaEEtoQuarkus2MavenDependenciesMigrationTest implements RewriteTest { @Override public void defaults(RecipeSpec spec) { - spec.recipeFromResources("org.openrewrite.quarkus.migrate.javaee.JavaEEtoQuarkus2MavenDependencyMigration"); + spec.recipeFromResources("org.openrewrite.quarkus.migrate.javaee.JavaEEtoQuarkus2Migration"); } @Test @@ -294,7 +294,7 @@ void convertJavaEEToQuarkusDependencies2() { """ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 com.dummyapp oms-winter @@ -321,7 +321,6 @@ void convertJavaEEToQuarkusDependencies2() { org.apache.commons commons-lang3 - 3.12.0 commons-beanutils @@ -355,7 +354,7 @@ void convertJavaEEToQuarkusDependencies2() { org.projectlombok lombok - 1.18.30 + 1.18.34 provided @@ -393,16 +392,7 @@ void convertJavaEEToQuarkusDependencies2() { maven-compiler-plugin 3.13.0 - 8 - 8 - - - - org.apache.maven.plugins - maven-war-plugin - 3.2.3 - - false + 11 From b25b2de41be8515aa2c8ed423972106e0f2b870b Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Sat, 13 Jul 2024 00:24:36 +0200 Subject: [PATCH 13/13] Bump failsafe and surefire plugin versions --- .../resources/META-INF/rewrite/javaee7-to-quarkus.yml | 4 ++-- .../JavaEEtoQuarkus2MavenDependenciesMigrationTest.java | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/resources/META-INF/rewrite/javaee7-to-quarkus.yml b/src/main/resources/META-INF/rewrite/javaee7-to-quarkus.yml index 36fc68c..2001bad 100644 --- a/src/main/resources/META-INF/rewrite/javaee7-to-quarkus.yml +++ b/src/main/resources/META-INF/rewrite/javaee7-to-quarkus.yml @@ -104,12 +104,12 @@ recipeList: - org.openrewrite.maven.AddPlugin: groupId: org.apache.maven.plugins artifactId: maven-surefire-plugin - version: '3.2.5' + version: '3.3.1' configuration: org.jboss.logmanager.LogManager${maven.home} - org.openrewrite.maven.AddPlugin: groupId: org.apache.maven.plugins artifactId: maven-failsafe-plugin - version: '3.2.5' + version: '3.3.1' executions: integration-testverify configuration: ${project.build.directory}/${project.build.finalName}-runnerorg.jboss.logmanager.LogManager${maven.home} - org.openrewrite.maven.AddProfile: diff --git a/src/test/java/org/openrewrite/quarkus/migrate/javaee/JavaEEtoQuarkus2MavenDependenciesMigrationTest.java b/src/test/java/org/openrewrite/quarkus/migrate/javaee/JavaEEtoQuarkus2MavenDependenciesMigrationTest.java index e424ef3..206f5b2 100644 --- a/src/test/java/org/openrewrite/quarkus/migrate/javaee/JavaEEtoQuarkus2MavenDependenciesMigrationTest.java +++ b/src/test/java/org/openrewrite/quarkus/migrate/javaee/JavaEEtoQuarkus2MavenDependenciesMigrationTest.java @@ -160,7 +160,7 @@ void convertJavaEEToQuarkusDependencies1() { org.apache.maven.plugins maven-surefire-plugin - 3.2.5 + 3.3.1 org.jboss.logmanager.LogManager @@ -171,7 +171,7 @@ void convertJavaEEToQuarkusDependencies1() { org.apache.maven.plugins maven-failsafe-plugin - 3.2.5 + 3.3.1 @@ -412,7 +412,7 @@ void convertJavaEEToQuarkusDependencies2() { org.apache.maven.plugins maven-surefire-plugin - 3.2.5 + 3.3.1 org.jboss.logmanager.LogManager @@ -423,7 +423,7 @@ void convertJavaEEToQuarkusDependencies2() { org.apache.maven.plugins maven-failsafe-plugin - 3.2.5 + 3.3.1