-
Notifications
You must be signed in to change notification settings - Fork 90
JMS is not migrated properly when using ...migrate.jakarta.JakartaEE10 #688
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
bug
Something isn't working
Comments
melloware
added a commit
to melloware/rewrite-migrate-java
that referenced
this issue
Mar 20, 2025
melloware
added a commit
to melloware/rewrite-migrate-java
that referenced
this issue
Mar 21, 2025
timtebeek
added a commit
to melloware/rewrite-migrate-java
that referenced
this issue
Mar 21, 2025
diff --git c/src/main/java/org/openrewrite/java/migrate/jakarta/UpdateActivationConfigProperty.java i/src/main/java/org/openrewrite/java/migrate/jakarta/UpdateActivationConfigProperty.java deleted file mode 100644 index b3d0875..00000000 --- c/src/main/java/org/openrewrite/java/migrate/jakarta/UpdateActivationConfigProperty.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2024 the original author or authors. - * <p> - * Licensed under the Moderne Source Available License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * <p> - * https://docs.moderne.io/licensing/moderne-source-available-license - * <p> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.openrewrite.java.migrate.jakarta; - -import org.openrewrite.ExecutionContext; -import org.openrewrite.Preconditions; -import org.openrewrite.Recipe; -import org.openrewrite.TreeVisitor; -import org.openrewrite.internal.ListUtils; -import org.openrewrite.java.AnnotationMatcher; -import org.openrewrite.java.JavaIsoVisitor; -import org.openrewrite.java.search.UsesType; -import org.openrewrite.java.tree.J; -import org.openrewrite.java.tree.JavaType; - -public class UpdateActivationConfigProperty extends Recipe { - - @OverRide - public String getDisplayName() { - return "Migrate @ActivationConfigProperty annotations"; - } - - @OverRide - public String getDescription() { - return "Migrate `@ActivationConfigProperty` annotations in Java files to `jakarta` equivalents."; - } - - private static final AnnotationMatcher EJB_MATCHER = new AnnotationMatcher("@javax.ejb..*"); - - @OverRide - public TreeVisitor<?, ExecutionContext> getVisitor() { - return Preconditions.check(new UsesType<>("javax.ejb..*", true), - new JavaIsoVisitor<ExecutionContext>() { - @OverRide - public J.Annotation visitAnnotation(J.Annotation annotation, ExecutionContext ctx) { - J.Annotation a = super.visitAnnotation(annotation, ctx); - if (!EJB_MATCHER.matches(a)) { - return a; - } - return a.withArguments(ListUtils.map(a.getArguments(), arg -> { - if (arg instanceof J.Assignment) { - J.Assignment as = (J.Assignment) arg; - if (as.getAssignment() instanceof J.Literal) { - return as.withAssignment(maybeReplaceLiteralValue((J.Literal) as.getAssignment())); - } - } else if (arg instanceof J.Literal) { - return maybeReplaceLiteralValue((J.Literal) arg); - } - return arg; - })); - } - - private J.Literal maybeReplaceLiteralValue(J.Literal arg) { - if (arg.getType() == JavaType.Primitive.String) { - String oldValue = (String) arg.getValue(); - if (oldValue.contains("javax.")) { - String newValue = oldValue.replace("javax.", "jakarta."); - return arg.withValue(newValue).withValueSource('"' + newValue + '"'); - } - } - return arg; - } - } - ); - } -} diff --git c/src/main/java/org/openrewrite/java/migrate/jakarta/UpdateAnnotationAttributeJavaxToJakarta.java i/src/main/java/org/openrewrite/java/migrate/jakarta/UpdateAnnotationAttributeJavaxToJakarta.java new file mode 100644 index 00000000..fa4d263 --- /dev/null +++ i/src/main/java/org/openrewrite/java/migrate/jakarta/UpdateAnnotationAttributeJavaxToJakarta.java @@ -0,0 +1,77 @@ +/* + * Copyright 2025 the original author or authors. + * <p> + * Licensed under the Moderne Source Available License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * <p> + * https://docs.moderne.io/licensing/moderne-source-available-license + * <p> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openrewrite.java.migrate.jakarta; + +import lombok.EqualsAndHashCode; +import lombok.Value; +import org.openrewrite.ExecutionContext; +import org.openrewrite.Option; +import org.openrewrite.Recipe; +import org.openrewrite.TreeVisitor; +import org.openrewrite.internal.ListUtils; +import org.openrewrite.java.trait.Traits; +import org.openrewrite.java.tree.J; +import org.openrewrite.java.tree.JavaType; + +@value +@EqualsAndHashCode(callSuper = false) +public class UpdateAnnotationAttributeJavaxToJakarta extends Recipe { + + @OverRide + public String getDisplayName() { + return "Update annotation attributes using `javax` to `jakarta`"; + } + + @OverRide + public String getDescription() { + return "Replace `javax` with `jakarta` in annotation attributes for matching annotation signatures."; + } + + @option( + displayName = "Annotation signature", + description = "An annotation signature to match.", + example = "@javax.jms..*", + required = false + ) + String signature; + + @OverRide + public TreeVisitor<?, ExecutionContext> getVisitor() { + return Traits.annotated(signature).asVisitor(ann -> ann.getTree() + .withArguments(ListUtils.map(ann.getTree().getArguments(), arg -> { + if (arg instanceof J.Assignment) { + J.Assignment as = (J.Assignment) arg; + if (as.getAssignment() instanceof J.Literal) { + return as.withAssignment(maybeReplaceLiteralValue((J.Literal) as.getAssignment())); + } + } else if (arg instanceof J.Literal) { + return maybeReplaceLiteralValue((J.Literal) arg); + } + return arg; + }))); + } + + private J.Literal maybeReplaceLiteralValue(J.Literal arg) { + if (arg.getType() == JavaType.Primitive.String && arg.getValue() instanceof String) { + String oldValue = (String) arg.getValue(); + if (oldValue.contains("javax.")) { + String newValue = oldValue.replace("javax.", "jakarta."); + return arg.withValue(newValue).withValueSource('"' + newValue + '"'); + } + } + return arg; + } +} diff --git c/src/main/java/org/openrewrite/java/migrate/jakarta/UpdateJmsDestinations.java i/src/main/java/org/openrewrite/java/migrate/jakarta/UpdateJmsDestinations.java deleted file mode 100644 index cb13706..00000000 --- c/src/main/java/org/openrewrite/java/migrate/jakarta/UpdateJmsDestinations.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2024 the original author or authors. - * <p> - * Licensed under the Moderne Source Available License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * <p> - * https://docs.moderne.io/licensing/moderne-source-available-license - * <p> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.openrewrite.java.migrate.jakarta; - -import org.openrewrite.ExecutionContext; -import org.openrewrite.Preconditions; -import org.openrewrite.Recipe; -import org.openrewrite.TreeVisitor; -import org.openrewrite.internal.ListUtils; -import org.openrewrite.java.AnnotationMatcher; -import org.openrewrite.java.JavaIsoVisitor; -import org.openrewrite.java.search.UsesType; -import org.openrewrite.java.tree.J; -import org.openrewrite.java.tree.JavaType; - -public class UpdateJmsDestinations extends Recipe { - - @OverRide - public String getDisplayName() { - return "Migrate JMS destinations"; - } - - @OverRide - public String getDescription() { - return "Migrate `@JMSDestinationDefinition` annotations in Java files to `jakarta` equivalents."; - } - - private static final AnnotationMatcher JMS_MATCHER = new AnnotationMatcher("@javax.jms..*"); - - @OverRide - public TreeVisitor<?, ExecutionContext> getVisitor() { - return Preconditions.check(new UsesType<>("javax.jms..*", true), - new JavaIsoVisitor<ExecutionContext>() { - @OverRide - public J.Annotation visitAnnotation(J.Annotation annotation, ExecutionContext ctx) { - J.Annotation a = super.visitAnnotation(annotation, ctx); - if (!JMS_MATCHER.matches(a)) { - return a; - } - return a.withArguments(ListUtils.map(a.getArguments(), arg -> { - if (arg instanceof J.Assignment) { - J.Assignment as = (J.Assignment) arg; - if (as.getAssignment() instanceof J.Literal) { - return as.withAssignment(maybeReplaceLiteralValue((J.Literal) as.getAssignment())); - } - } else if (arg instanceof J.Literal) { - return maybeReplaceLiteralValue((J.Literal) arg); - } - return arg; - })); - } - - private J.Literal maybeReplaceLiteralValue(J.Literal arg) { - if (arg.getType() == JavaType.Primitive.String) { - String oldValue = (String) arg.getValue(); - if (oldValue.contains("javax.")) { - String newValue = oldValue.replace("javax.", "jakarta."); - return arg.withValue(newValue).withValueSource('"' + newValue + '"'); - } - } - return arg; - } - } - ); - } -} diff --git c/src/main/resources/META-INF/rewrite/jakarta-ee-10.yml i/src/main/resources/META-INF/rewrite/jakarta-ee-10.yml index fa02383..60f5b82 100644 --- c/src/main/resources/META-INF/rewrite/jakarta-ee-10.yml +++ i/src/main/resources/META-INF/rewrite/jakarta-ee-10.yml @@ -33,8 +33,10 @@ recipeList: - org.openrewrite.java.migrate.jakarta.DeprecatedCDIAPIsRemoved40 - org.openrewrite.java.migrate.BeanDiscovery - org.openrewrite.java.migrate.jakarta.BeanValidationMessages - - org.openrewrite.java.migrate.jakarta.UpdateJmsDestinations - - org.openrewrite.java.migrate.jakarta.UpdateActivationConfigProperty + - org.openrewrite.java.migrate.jakarta.UpdateAnnotationAttributeJavaxToJakarta: + signature: "@jakarta.ejb..*" + - org.openrewrite.java.migrate.jakarta.UpdateAnnotationAttributeJavaxToJakarta: + signature: "@jakarta.jms..*" - org.openrewrite.java.migrate.jakarta.JavaxBeansXmlToJakartaBeansXml - org.openrewrite.java.migrate.jakarta.JavaxEjbJarXmlToJakartaEjbJarXml - org.openrewrite.java.migrate.jakarta.JavaxBeanValidationXmlToJakartaBeanValidationXml @@ -463,4 +465,4 @@ recipeList: groupId: org.eclipse.persistence artifactId: "*" newVersion: 4.x ---- \ No newline at end of file +--- diff --git c/src/test/java/org/openrewrite/java/migrate/jakarta/UpdateActivationConfigPropertyTest.java i/src/test/java/org/openrewrite/java/migrate/jakarta/UpdateActivationConfigPropertyTest.java deleted file mode 100644 index 1672c8e..00000000 --- c/src/test/java/org/openrewrite/java/migrate/jakarta/UpdateActivationConfigPropertyTest.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright 2024 the original author or authors. - * <p> - * Licensed under the Moderne Source Available License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * <p> - * https://docs.moderne.io/licensing/moderne-source-available-license - * <p> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.openrewrite.java.migrate.jakarta; - -import org.junit.jupiter.api.Test; -import org.openrewrite.DocumentExample; -import org.openrewrite.Issue; -import org.openrewrite.java.JavaParser; -import org.openrewrite.test.RecipeSpec; -import org.openrewrite.test.RewriteTest; - -import static org.openrewrite.java.Assertions.java; - -class UpdateActivationConfigPropertyTest implements RewriteTest { - - @OverRide - public void defaults(RecipeSpec spec) { - spec.recipe(new UpdateActivationConfigProperty()) - .parser(JavaParser.fromJavaVersion() - //language=java - .dependsOn( - """ - package javax.ejb; - - import java.lang.annotation.ElementType; - import java.lang.annotation.Retention; - import java.lang.annotation.RetentionPolicy; - import java.lang.annotation.Target; - - /** - * Specifies a name/value pair for a configuration property that is passed to - * the endpoint deployment. - * - * @SInCE EJB 3.0 - */ - @target({ ElementType.METHOD, ElementType.TYPE }) - @retention(RetentionPolicy.RUNTIME) - public @interface ActivationConfigProperty { - /** - * Name of the configuration property. - */ - String propertyName(); - - /** - * Value of the configuration property. - */ - String propertyValue(); - } - """, - """ - package jakarta.ejb; - - import java.lang.annotation.ElementType; - import java.lang.annotation.Retention; - import java.lang.annotation.RetentionPolicy; - import java.lang.annotation.Target; - - /** - * Specifies a name/value pair for a configuration property that is passed to - * the endpoint deployment. - * - * @SInCE EJB 3.0 - */ - @target({ ElementType.METHOD, ElementType.TYPE }) - @retention(RetentionPolicy.RUNTIME) - public @interface ActivationConfigProperty { - /** - * Name of the configuration property. - */ - String propertyName(); - - /** - * Value of the configuration property. - */ - String propertyValue(); - } - """ - ) - ); - } - - @test - @DocumentExample - @issue("openrewrite#688") - void replacePropertyValue() { - rewriteRun( - //language=java - java( - """ - import javax.ejb.*; - - @ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue") - class Test { - } - """, - """ - import javax.ejb.*; - - @ActivationConfigProperty(propertyName="destinationType", propertyValue="jakarta.jms.Queue") - class Test { - } - """ - ) - ); - } -} diff --git c/src/test/java/org/openrewrite/java/migrate/jakarta/UpdateAnnotationAttributeJavaxToJakartaTest.java i/src/test/java/org/openrewrite/java/migrate/jakarta/UpdateAnnotationAttributeJavaxToJakartaTest.java new file mode 100644 index 00000000..c217158 --- /dev/null +++ i/src/test/java/org/openrewrite/java/migrate/jakarta/UpdateAnnotationAttributeJavaxToJakartaTest.java @@ -0,0 +1,171 @@ +/* + * Copyright 2025 the original author or authors. + * <p> + * Licensed under the Moderne Source Available License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * <p> + * https://docs.moderne.io/licensing/moderne-source-available-license + * <p> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openrewrite.java.migrate.jakarta; + +import org.junit.jupiter.api.Test; +import org.openrewrite.DocumentExample; +import org.openrewrite.Issue; +import org.openrewrite.java.JavaParser; +import org.openrewrite.test.RecipeSpec; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.java.Assertions.java; + +class UpdateAnnotationAttributeJavaxToJakartaTest implements RewriteTest { + + @OverRide + public void defaults(RecipeSpec spec) { + spec.recipeFromResources("org.openrewrite.java.migrate.jakarta.JakartaEE10") + .parser(JavaParser.fromJavaVersion() + //language=java + .dependsOn( + """ + package javax.jms; + + import java.lang.annotation.ElementType; + import java.lang.annotation.Repeatable; + import java.lang.annotation.Retention; + import java.lang.annotation.RetentionPolicy; + import java.lang.annotation.Target; + import javax.annotation.sql.DataSourceDefinition; + + /** + * Used to define a JMS destination resource that will be created + * and made available for JNDI lookup at runtime. + * + * @SInCE JMS 2.0 + */ + @target(ElementType.TYPE) + @retention(RetentionPolicy.RUNTIME) + @repeatable(JMSDestinationDefinitions.class) + public @interface JMSDestinationDefinition { + + /** + * The name of the JNDI location where the destination will be bound. + */ + String name(); + + /** + * The type of destination, either javax.jms.Queue or javax.jms.Topic. + */ + String interfaceName(); + + /** + * The class name of the implementation for the destination. + */ + String className() default ""; + + /** + * The name of the destination. + */ + String destinationName() default ""; + + /** + * Specifies whether the destination is durable. + */ + boolean durable() default false; + + /** + * Description of this destination. + */ + String description() default ""; + } + """, + """ + package javax.ejb; + + import java.lang.annotation.ElementType; + import java.lang.annotation.Retention; + import java.lang.annotation.RetentionPolicy; + import java.lang.annotation.Target; + + /** + * Specifies a name/value pair for a configuration property that is passed to + * the endpoint deployment. + * + * @SInCE EJB 3.0 + */ + @target({ ElementType.METHOD, ElementType.TYPE }) + @retention(RetentionPolicy.RUNTIME) + public @interface ActivationConfigProperty { + /** + * Name of the configuration property. + */ + String propertyName(); + + /** + * Value of the configuration property. + */ + String propertyValue(); + } + """ + ) + ); + } + + @test + @DocumentExample + @issue("openrewrite#688") + void replaceInterfaceName() { + rewriteRun( + //language=java + java( + """ + import javax.jms.*; + + @JMSDestinationDefinition(name = "Testing", + interfaceName = "javax.jms.Topic", + destinationName = "Testing") + class Test { + } + """, + """ + import jakarta.jms.*; + + @JMSDestinationDefinition(name = "Testing", + interfaceName = "jakarta.jms.Topic", + destinationName = "Testing") + class Test { + } + """ + ) + ); + } + + @test + @issue("openrewrite#688") + void replacePropertyValue() { + rewriteRun( + //language=java + java( + """ + import javax.ejb.*; + + @ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue") + class Test { + } + """, + """ + import jakarta.ejb.*; + + @ActivationConfigProperty(propertyName="destinationType", propertyValue="jakarta.jms.Queue") + class Test { + } + """ + ) + ); + } +} diff --git c/src/test/java/org/openrewrite/java/migrate/jakarta/UpdateJmsDestinationsTest.java i/src/test/java/org/openrewrite/java/migrate/jakarta/UpdateJmsDestinationsTest.java deleted file mode 100644 index 88302ac..00000000 --- c/src/test/java/org/openrewrite/java/migrate/jakarta/UpdateJmsDestinationsTest.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Copyright 2024 the original author or authors. - * <p> - * Licensed under the Moderne Source Available License (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * <p> - * https://docs.moderne.io/licensing/moderne-source-available-license - * <p> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.openrewrite.java.migrate.jakarta; - -import org.junit.jupiter.api.Test; -import org.openrewrite.DocumentExample; -import org.openrewrite.Issue; -import org.openrewrite.java.JavaParser; -import org.openrewrite.test.RecipeSpec; -import org.openrewrite.test.RewriteTest; - -import static org.openrewrite.java.Assertions.java; - -class UpdateJmsDestinationsTest implements RewriteTest { - - @OverRide - public void defaults(RecipeSpec spec) { - spec.recipe(new UpdateJmsDestinations()) - .parser(JavaParser.fromJavaVersion() - //language=java - .dependsOn( - """ - package javax.jms; - - import java.lang.annotation.ElementType; - import java.lang.annotation.Repeatable; - import java.lang.annotation.Retention; - import java.lang.annotation.RetentionPolicy; - import java.lang.annotation.Target; - import javax.annotation.sql.DataSourceDefinition; - - /** - * Used to define a JMS destination resource that will be created - * and made available for JNDI lookup at runtime. - * - * @SInCE JMS 2.0 - */ - @target(ElementType.TYPE) - @retention(RetentionPolicy.RUNTIME) - @repeatable(JMSDestinationDefinitions.class) - public @interface JMSDestinationDefinition { - - /** - * The name of the JNDI location where the destination will be bound. - */ - String name(); - - /** - * The type of destination, either javax.jms.Queue or javax.jms.Topic. - */ - String interfaceName(); - - /** - * The class name of the implementation for the destination. - */ - String className() default ""; - - /** - * The name of the destination. - */ - String destinationName() default ""; - - /** - * Specifies whether the destination is durable. - */ - boolean durable() default false; - - /** - * Description of this destination. - */ - String description() default ""; - } - """, - """ - package jakarta.jms; - - import java.lang.annotation.ElementType; - import java.lang.annotation.Repeatable; - import java.lang.annotation.Retention; - import java.lang.annotation.RetentionPolicy; - import java.lang.annotation.Target; - import javax.annotation.sql.DataSourceDefinition; - - /** - * Used to define a JMS destination resource that will be created - * and made available for JNDI lookup at runtime. - * - * @SInCE JMS 2.0 - */ - @target(ElementType.TYPE) - @retention(RetentionPolicy.RUNTIME) - @repeatable(JMSDestinationDefinitions.class) - public @interface JMSDestinationDefinition { - - /** - * The name of the JNDI location where the destination will be bound. - */ - String name(); - - /** - * The type of destination, either jakarta.jms.Queue or jakarta.jms.Topic. - */ - String interfaceName(); - - /** - * The class name of the implementation for the destination. - */ - String className() default ""; - - /** - * The name of the destination. - */ - String destinationName() default ""; - - /** - * Specifies whether the destination is durable. - */ - boolean durable() default false; - - /** - * Description of this destination. - */ - String description() default ""; - } - """ - ) - ); - } - - @test - @DocumentExample - @issue("openrewrite#688") - void replaceInterfaceName() { - rewriteRun( - //language=java - java( - """ - import javax.jms.*; - - @JMSDestinationDefinition(name = "Testing", - interfaceName = "javax.jms.Topic", - destinationName = "Testing") - class Test { - } - """, - """ - import javax.jms.*; - - @JMSDestinationDefinition(name = "Testing", - interfaceName = "jakarta.jms.Topic", - destinationName = "Testing") - class Test { - } - """ - ) - ); - } -}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I ran
And found some issues when running the application after migrating:
I'm not sure how the rewrite rules work for Java code. It seems that it's not a full replace of
javax.
byjakarta.
for the general migration (as we are left with somejavax.
instances). In this case I think a full replace ofjavax.jms.
byjakarta.jms.
would do.CC @melloware
The text was updated successfully, but these errors were encountered: