From 356022d77c7bb2ce113014c3517c18a77d57b2c4 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Wed, 12 Mar 2025 19:02:00 +0100 Subject: [PATCH 01/12] Remove unused imports from URLConstructorsToNewURI --- .../java/migrate/net/URLConstructorsToNewURI.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/main/java/org/openrewrite/java/migrate/net/URLConstructorsToNewURI.java b/src/main/java/org/openrewrite/java/migrate/net/URLConstructorsToNewURI.java index eb49cc402a..969a3387e8 100644 --- a/src/main/java/org/openrewrite/java/migrate/net/URLConstructorsToNewURI.java +++ b/src/main/java/org/openrewrite/java/migrate/net/URLConstructorsToNewURI.java @@ -15,24 +15,16 @@ */ package org.openrewrite.java.migrate.net; -import org.jspecify.annotations.Nullable; import org.openrewrite.ExecutionContext; import org.openrewrite.Preconditions; import org.openrewrite.Recipe; import org.openrewrite.TreeVisitor; -import org.openrewrite.analysis.constantfold.ConstantFold; -import org.openrewrite.analysis.util.CursorUtil; import org.openrewrite.java.JavaParser; import org.openrewrite.java.JavaTemplate; import org.openrewrite.java.JavaVisitor; import org.openrewrite.java.MethodMatcher; import org.openrewrite.java.search.UsesType; -import org.openrewrite.java.tree.Expression; import org.openrewrite.java.tree.J; -import org.openrewrite.java.tree.JavaType; -import org.openrewrite.java.tree.TypeUtils; - -import java.net.URI; public class URLConstructorsToNewURI extends Recipe { From de14da1c4ffdd058aa7f7de3aaad7d548c2c8af4 Mon Sep 17 00:00:00 2001 From: Melloware Date: Wed, 19 Mar 2025 11:08:54 -0400 Subject: [PATCH 02/12] Fix #681: WebAPI from 8.0 -> 9.1 -> 10.0 (#683) --- src/main/resources/META-INF/rewrite/jakarta-ee-9.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/resources/META-INF/rewrite/jakarta-ee-9.yml b/src/main/resources/META-INF/rewrite/jakarta-ee-9.yml index cf4efbc22c..2e017ccbd4 100644 --- a/src/main/resources/META-INF/rewrite/jakarta-ee-9.yml +++ b/src/main/resources/META-INF/rewrite/jakarta-ee-9.yml @@ -1016,6 +1016,12 @@ recipeList: newGroupId: jakarta.platform newArtifactId: jakarta.jakartaee-api newVersion: 9.1.0 + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: javax + oldArtifactId: javaee-web-api + newGroupId: jakarta.platform + newArtifactId: jakarta.jakartaee-web-api + newVersion: 9.1.0 - org.openrewrite.java.dependencies.UpgradeDependencyVersion: groupId: jakarta.platform artifactId: "*" From 06893d033a73380c92b57bbe8aeef87474ffd621 Mon Sep 17 00:00:00 2001 From: Melloware Date: Wed, 19 Mar 2025 11:09:45 -0400 Subject: [PATCH 03/12] Fix #682: EE10 migration Jersey to 3.1.x (#684) * Fix #682: EE10 migration Jersey to 3.1.x * Fix punctuation in Jakarta EE 10 YAML --------- Co-authored-by: Tim te Beek --- .../META-INF/rewrite/jakarta-ee-10.yml | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/main/resources/META-INF/rewrite/jakarta-ee-10.yml b/src/main/resources/META-INF/rewrite/jakarta-ee-10.yml index bc5f5bb298..b298f07ea5 100644 --- a/src/main/resources/META-INF/rewrite/jakarta-ee-10.yml +++ b/src/main/resources/META-INF/rewrite/jakarta-ee-10.yml @@ -38,6 +38,7 @@ recipeList: - org.openrewrite.java.migrate.jakarta.JavaxBeanValidationXmlToJakartaBeanValidationXml - org.openrewrite.java.migrate.jakarta.JavaxToJakartaCdiExtensions - org.openrewrite.java.migrate.jakarta.UpdateJakartaPlatform10 + - org.openrewrite.java.migrate.jakarta.UpdateJerseyDependencies --- type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.java.migrate.jakarta.MigrationToJakarta10Apis @@ -404,3 +405,34 @@ recipeList: groupId: com.sun.xml.ws artifactId: jaxws-rt newVersion: 4.x +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.java.migrate.jakarta.UpdateJerseyDependencies +displayName: Update GlassFish Jersey Dependencies to 3.1.x +description: Update GlassFish Jersey Dependencies to 3.1.x. +recipeList: + - org.openrewrite.java.dependencies.UpgradeDependencyVersion: + groupId: org.glassfish.jersey.core + artifactId: "*" + newVersion: 3.1.x + - org.openrewrite.java.dependencies.UpgradeDependencyVersion: + groupId: org.glassfish.jersey.inject + artifactId: "*" + newVersion: 3.1.x + - org.openrewrite.java.dependencies.UpgradeDependencyVersion: + groupId: org.glassfish.jersey.media + artifactId: "*" + newVersion: 3.1.x + - org.openrewrite.java.dependencies.UpgradeDependencyVersion: + groupId: org.glassfish.jersey.containers + artifactId: "*" + newVersion: 3.1.x + - org.openrewrite.java.dependencies.UpgradeDependencyVersion: + groupId: org.glassfish.jersey.server + artifactId: "*" + newVersion: 3.1.x + - org.openrewrite.java.dependencies.UpgradeDependencyVersion: + groupId: org.glassfish.jersey.ext + artifactId: "*" + newVersion: 3.1.x +--- \ No newline at end of file From 01735a6fa64a2ebba652b1475d5b04b10d7c9036 Mon Sep 17 00:00:00 2001 From: Melloware Date: Thu, 20 Mar 2025 09:05:05 -0400 Subject: [PATCH 04/12] Fix #685: Apache Shiro EE10 dependencies (#686) --- .../resources/META-INF/rewrite/jakarta-ee-10.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/resources/META-INF/rewrite/jakarta-ee-10.yml b/src/main/resources/META-INF/rewrite/jakarta-ee-10.yml index b298f07ea5..2af90ce316 100644 --- a/src/main/resources/META-INF/rewrite/jakarta-ee-10.yml +++ b/src/main/resources/META-INF/rewrite/jakarta-ee-10.yml @@ -39,6 +39,7 @@ recipeList: - org.openrewrite.java.migrate.jakarta.JavaxToJakartaCdiExtensions - org.openrewrite.java.migrate.jakarta.UpdateJakartaPlatform10 - org.openrewrite.java.migrate.jakarta.UpdateJerseyDependencies + - org.openrewrite.java.migrate.jakarta.UpdateApacheShiroDependencies --- type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.java.migrate.jakarta.MigrationToJakarta10Apis @@ -435,4 +436,18 @@ recipeList: groupId: org.glassfish.jersey.ext artifactId: "*" newVersion: 3.1.x +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.java.migrate.jakarta.UpdateApacheShiroDependencies +displayName: Update Apache Shiro Dependencies to 2.0.x +description: Update Apache Shiro Dependencies to 2.0.x. +recipeList: + - org.openrewrite.maven.ChangeDependencyClassifier: + groupId: org.apache.shiro + artifactId: "*" + newClassifier: jakarta + - org.openrewrite.java.dependencies.UpgradeDependencyVersion: + groupId: org.apache.shiro + artifactId: "*" + newVersion: 2.0.x --- \ No newline at end of file From 6ead1919e6c38c3e2c4c912c806fd8412f7f1239 Mon Sep 17 00:00:00 2001 From: Melloware Date: Fri, 21 Mar 2025 06:49:27 -0400 Subject: [PATCH 05/12] Fix #687: EE10 update EclipseLink dependencies (#690) --- src/main/resources/META-INF/rewrite/jakarta-ee-10.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/resources/META-INF/rewrite/jakarta-ee-10.yml b/src/main/resources/META-INF/rewrite/jakarta-ee-10.yml index 2af90ce316..833eea9bf0 100644 --- a/src/main/resources/META-INF/rewrite/jakarta-ee-10.yml +++ b/src/main/resources/META-INF/rewrite/jakarta-ee-10.yml @@ -40,6 +40,7 @@ recipeList: - org.openrewrite.java.migrate.jakarta.UpdateJakartaPlatform10 - org.openrewrite.java.migrate.jakarta.UpdateJerseyDependencies - org.openrewrite.java.migrate.jakarta.UpdateApacheShiroDependencies + - org.openrewrite.java.migrate.jakarta.UpdateEclipseLinkDependencies --- type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.java.migrate.jakarta.MigrationToJakarta10Apis @@ -450,4 +451,14 @@ recipeList: groupId: org.apache.shiro artifactId: "*" newVersion: 2.0.x +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.java.migrate.jakarta.UpdateEclipseLinkDependencies +displayName: Update EclipseLink Dependencies to 4.x +description: Update EclipseLink Dependencies to 4.x. +recipeList: + - org.openrewrite.java.dependencies.UpgradeDependencyVersion: + groupId: org.eclipse.persistence + artifactId: "*" + newVersion: 4.x --- \ No newline at end of file From c31b8d7098e6ee56d3cac80ae644db7658bc4e25 Mon Sep 17 00:00:00 2001 From: Melloware Date: Fri, 21 Mar 2025 07:59:00 -0400 Subject: [PATCH 06/12] Fix #688: Update @ActivationConfigPropery/@JMSDestination (#691) * Fix #688: Update @ActivationConfigPropery/@JMSDestination * Update src/main/java/org/openrewrite/java/migrate/jakarta/UpdateActivationConfigProperty.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update src/main/java/org/openrewrite/java/migrate/jakarta/UpdateJmsDestinations.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update src/test/java/org/openrewrite/java/migrate/jakarta/UpdateActivationConfigPropertyTest.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update src/test/java/org/openrewrite/java/migrate/jakarta/UpdateActivationConfigPropertyTest.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update src/test/java/org/openrewrite/java/migrate/jakarta/UpdateJmsDestinationsTest.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update src/test/java/org/openrewrite/java/migrate/jakarta/UpdateJmsDestinationsTest.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Merge recipes into one, and assert they work in composite 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 b3d0875e..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. - *

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

- * https://docs.moderne.io/licensing/moderne-source-available-license - *

- * 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 getVisitor() { - return Preconditions.check(new UsesType<>("javax.ejb..*", true), - new JavaIsoVisitor() { - @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..fa4d2637 --- /dev/null +++ i/src/main/java/org/openrewrite/java/migrate/jakarta/UpdateAnnotationAttributeJavaxToJakarta.java @@ -0,0 +1,77 @@ +/* + * Copyright 2025 the original author or authors. + *

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

+ * https://docs.moderne.io/licensing/moderne-source-available-license + *

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

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

- * https://docs.moderne.io/licensing/moderne-source-available-license - *

- * 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 getVisitor() { - return Preconditions.check(new UsesType<>("javax.jms..*", true), - new JavaIsoVisitor() { - @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 fa023835..60f5b821 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 1672c8e6..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. - *

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

- * https://docs.moderne.io/licensing/moderne-source-available-license - *

- * 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("https://github.com/openrewrite/rewrite-migrate-java/issues/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..c2171580 --- /dev/null +++ i/src/test/java/org/openrewrite/java/migrate/jakarta/UpdateAnnotationAttributeJavaxToJakartaTest.java @@ -0,0 +1,171 @@ +/* + * Copyright 2025 the original author or authors. + *

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

+ * https://docs.moderne.io/licensing/moderne-source-available-license + *

+ * 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("https://github.com/openrewrite/rewrite-migrate-java/issues/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("https://github.com/openrewrite/rewrite-migrate-java/issues/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 88302ac5..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. - *

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

- * https://docs.moderne.io/licensing/moderne-source-available-license - *

- * 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("https://github.com/openrewrite/rewrite-migrate-java/issues/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 { - } - """ - ) - ); - } -} * Also remove BeanValidationMessages --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Tim te Beek --- .../jakarta/BeanValidationMessages.java | 79 ------- ...dateAnnotationAttributeJavaxToJakarta.java | 77 +++++++ .../META-INF/rewrite/jakarta-ee-10.yml | 9 +- .../jakarta/BeanValidationMessagesTest.java | 91 -------- ...AnnotationAttributeJavaxToJakartaTest.java | 210 ++++++++++++++++++ 5 files changed, 294 insertions(+), 172 deletions(-) delete mode 100644 src/main/java/org/openrewrite/java/migrate/jakarta/BeanValidationMessages.java create mode 100644 src/main/java/org/openrewrite/java/migrate/jakarta/UpdateAnnotationAttributeJavaxToJakarta.java delete mode 100644 src/test/java/org/openrewrite/java/migrate/jakarta/BeanValidationMessagesTest.java create mode 100644 src/test/java/org/openrewrite/java/migrate/jakarta/UpdateAnnotationAttributeJavaxToJakartaTest.java diff --git a/src/main/java/org/openrewrite/java/migrate/jakarta/BeanValidationMessages.java b/src/main/java/org/openrewrite/java/migrate/jakarta/BeanValidationMessages.java deleted file mode 100644 index 6fbe5975f4..0000000000 --- a/src/main/java/org/openrewrite/java/migrate/jakarta/BeanValidationMessages.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2024 the original author or authors. - *

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

- * https://docs.moderne.io/licensing/moderne-source-available-license - *

- * 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 BeanValidationMessages extends Recipe { - - @Override - public String getDisplayName() { - return "Migrate Bean Validation messages"; - } - - @Override - public String getDescription() { - return "Migrate `javax.validation.constraints` messages found in Java files to `jakarta.validation.constraints` equivalents."; - } - - private static final AnnotationMatcher JAVAX_MATCHER = new AnnotationMatcher("@javax.validation.constraints..*"); - - @Override - public TreeVisitor getVisitor() { - return Preconditions.check(new UsesType<>("javax.validation.constraints..*", true), - new JavaIsoVisitor() { - @Override - public J.Annotation visitAnnotation(J.Annotation annotation, ExecutionContext ctx) { - J.Annotation a = super.visitAnnotation(annotation, ctx); - if (!JAVAX_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 a/src/main/java/org/openrewrite/java/migrate/jakarta/UpdateAnnotationAttributeJavaxToJakarta.java b/src/main/java/org/openrewrite/java/migrate/jakarta/UpdateAnnotationAttributeJavaxToJakarta.java new file mode 100644 index 0000000000..fa4d263771 --- /dev/null +++ b/src/main/java/org/openrewrite/java/migrate/jakarta/UpdateAnnotationAttributeJavaxToJakarta.java @@ -0,0 +1,77 @@ +/* + * Copyright 2025 the original author or authors. + *

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

+ * https://docs.moderne.io/licensing/moderne-source-available-license + *

+ * 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 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 a/src/main/resources/META-INF/rewrite/jakarta-ee-10.yml b/src/main/resources/META-INF/rewrite/jakarta-ee-10.yml index 833eea9bf0..4343daaa3a 100644 --- a/src/main/resources/META-INF/rewrite/jakarta-ee-10.yml +++ b/src/main/resources/META-INF/rewrite/jakarta-ee-10.yml @@ -32,7 +32,12 @@ recipeList: - org.openrewrite.java.migrate.jakarta.RemovalsServletJakarta10 - org.openrewrite.java.migrate.jakarta.DeprecatedCDIAPIsRemoved40 - org.openrewrite.java.migrate.BeanDiscovery - - org.openrewrite.java.migrate.jakarta.BeanValidationMessages + - org.openrewrite.java.migrate.jakarta.UpdateAnnotationAttributeJavaxToJakarta: + signature: "@jakarta.ejb..*" + - org.openrewrite.java.migrate.jakarta.UpdateAnnotationAttributeJavaxToJakarta: + signature: "@jakarta.jms..*" + - org.openrewrite.java.migrate.jakarta.UpdateAnnotationAttributeJavaxToJakarta: + signature: "@jakarta.validation.constraints..*" - org.openrewrite.java.migrate.jakarta.JavaxBeansXmlToJakartaBeansXml - org.openrewrite.java.migrate.jakarta.JavaxEjbJarXmlToJakartaEjbJarXml - org.openrewrite.java.migrate.jakarta.JavaxBeanValidationXmlToJakartaBeanValidationXml @@ -461,4 +466,4 @@ recipeList: groupId: org.eclipse.persistence artifactId: "*" newVersion: 4.x ---- \ No newline at end of file +--- diff --git a/src/test/java/org/openrewrite/java/migrate/jakarta/BeanValidationMessagesTest.java b/src/test/java/org/openrewrite/java/migrate/jakarta/BeanValidationMessagesTest.java deleted file mode 100644 index 0153a0f8c1..0000000000 --- a/src/test/java/org/openrewrite/java/migrate/jakarta/BeanValidationMessagesTest.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright 2024 the original author or authors. - *

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

- * https://docs.moderne.io/licensing/moderne-source-available-license - *

- * 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 BeanValidationMessagesTest implements RewriteTest { - - @Override - public void defaults(RecipeSpec spec) { - spec.recipe(new BeanValidationMessages()) - .parser(JavaParser.fromJavaVersion() - //language=java - .dependsOn( - """ - package javax.validation.constraints; - - import java.lang.annotation.*; - import static java.lang.annotation.ElementType.*; - import static java.lang.annotation.RetentionPolicy.RUNTIME; - - @Target(value={METHOD,FIELD,ANNOTATION_TYPE,CONSTRUCTOR,PARAMETER}) - @Retention(value=RUNTIME) - public @interface NotNull { - String message() default "{javax.validation.constraints.NotNull.message}"; - } - """, - """ - package jakarta.validation.constraints; - - import java.lang.annotation.*; - import static java.lang.annotation.ElementType.*; - import static java.lang.annotation.RetentionPolicy.RUNTIME; - - @Target(value={METHOD,FIELD,ANNOTATION_TYPE,CONSTRUCTOR,PARAMETER,TYPE_USE}) - @Retention(value=RUNTIME) - public @interface NotNull { - String message() default "{jakarta.validation.constraints.NotNull.message}"; - } - """ - ) - ); - } - - @Test - @DocumentExample - @Issue("https://github.com/openrewrite/rewrite-migrate-java/pull/374") - void replaceMessage() { - rewriteRun( - //language=java - java( - """ - import javax.validation.constraints.*; - - class Test { - @NotNull(message = "Resource Code {javax.validation.constraints.NotNull.message}") - private String resourceCode; - } - """, - """ - import javax.validation.constraints.*; - - class Test { - @NotNull(message = "Resource Code {jakarta.validation.constraints.NotNull.message}") - private String resourceCode; - } - """ - ) - ); - } -} diff --git a/src/test/java/org/openrewrite/java/migrate/jakarta/UpdateAnnotationAttributeJavaxToJakartaTest.java b/src/test/java/org/openrewrite/java/migrate/jakarta/UpdateAnnotationAttributeJavaxToJakartaTest.java new file mode 100644 index 0000000000..cca18b6f99 --- /dev/null +++ b/src/test/java/org/openrewrite/java/migrate/jakarta/UpdateAnnotationAttributeJavaxToJakartaTest.java @@ -0,0 +1,210 @@ +/* + * Copyright 2025 the original author or authors. + *

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

+ * https://docs.moderne.io/licensing/moderne-source-available-license + *

+ * 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.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 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.validation.constraints; + + import java.lang.annotation.*; + import static java.lang.annotation.ElementType.*; + import static java.lang.annotation.RetentionPolicy.RUNTIME; + + @Target(value={METHOD,FIELD,ANNOTATION_TYPE,CONSTRUCTOR,PARAMETER}) + @Retention(value=RUNTIME) + public @interface NotNull { + String message() default "{javax.validation.constraints.NotNull.message}"; + } + """ + ) + ); + } + + @Test + @DocumentExample + @Issue("https://github.com/openrewrite/rewrite-migrate-java/issues/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("https://github.com/openrewrite/rewrite-migrate-java/pull/374") + void replaceMessage() { + rewriteRun( + //language=java + java( + """ + import javax.validation.constraints.*; + + class Test { + @NotNull(message = "Resource Code {javax.validation.constraints.NotNull.message}") + private String resourceCode; + } + """, + """ + import jakarta.validation.constraints.*; + + class Test { + @NotNull(message = "Resource Code {jakarta.validation.constraints.NotNull.message}") + private String resourceCode; + } + """ + ) + ); + } + + @Test + @Issue("https://github.com/openrewrite/rewrite-migrate-java/issues/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 { + } + """ + ) + ); + } +} From c1ab6887fc7fb5f4c67295485a3dc5706ddfa8db Mon Sep 17 00:00:00 2001 From: Knut Wannheden Date: Fri, 21 Mar 2025 13:41:21 +0100 Subject: [PATCH 07/12] Remove `JavaTemplate` field from `AddMissingMethodImplementation` visitor --- .../java/migrate/AddMissingMethodImplementation.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/openrewrite/java/migrate/AddMissingMethodImplementation.java b/src/main/java/org/openrewrite/java/migrate/AddMissingMethodImplementation.java index 74b0dfb9e5..6784c1ed3b 100644 --- a/src/main/java/org/openrewrite/java/migrate/AddMissingMethodImplementation.java +++ b/src/main/java/org/openrewrite/java/migrate/AddMissingMethodImplementation.java @@ -63,7 +63,6 @@ public TreeVisitor getVisitor() { public class ClassImplementationVisitor extends JavaIsoVisitor { - private final JavaTemplate methodTemplate = JavaTemplate.builder(methodTemplateString).build(); private final MethodMatcher methodMatcher = new MethodMatcher(methodPattern, true); @Override @@ -87,8 +86,10 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration cs, Execution return classDecl; } - return classDecl.withBody(methodTemplate.apply(new Cursor(getCursor(), classDecl.getBody()), - classDecl.getBody().getCoordinates().lastStatement())); + return classDecl.withBody(JavaTemplate.builder(methodTemplateString) + .build() + .apply(new Cursor(getCursor(), classDecl.getBody()), + classDecl.getBody().getCoordinates().lastStatement())); } } } From 7e3aaad9777431b7e5af68f9d594abd4d2b173b5 Mon Sep 17 00:00:00 2001 From: Knut Wannheden Date: Fri, 21 Mar 2025 15:00:54 +0100 Subject: [PATCH 08/12] Remove `JavaTemplate` fields from `UseJavaUtilBase64` visitor --- .../java/migrate/UseJavaUtilBase64.java | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/openrewrite/java/migrate/UseJavaUtilBase64.java b/src/main/java/org/openrewrite/java/migrate/UseJavaUtilBase64.java index 7f56b6633b..2034efb95b 100644 --- a/src/main/java/org/openrewrite/java/migrate/UseJavaUtilBase64.java +++ b/src/main/java/org/openrewrite/java/migrate/UseJavaUtilBase64.java @@ -72,19 +72,6 @@ public TreeVisitor getVisitor() { MethodMatcher newBase64Decoder = new MethodMatcher(sunPackage + ".BASE64Decoder ()"); return Preconditions.check(check, new JavaVisitor() { - final JavaTemplate getDecoderTemplate = JavaTemplate.builder(useMimeCoder ? "Base64.getMimeDecoder()" : "Base64.getDecoder()") - .contextSensitive() - .imports("java.util.Base64") - .build(); - - final JavaTemplate encodeToString = JavaTemplate.builder(useMimeCoder ? "Base64.getMimeEncoder().encodeToString(#{anyArray(byte)})" : "Base64.getEncoder().encodeToString(#{anyArray(byte)})") - .imports("java.util.Base64") - .build(); - - final JavaTemplate decode = JavaTemplate.builder(useMimeCoder ? "Base64.getMimeDecoder().decode(#{any(String)})" : "Base64.getDecoder().decode(#{any(String)})") - .imports("java.util.Base64") - .build(); - @Override public J visitCompilationUnit(J.CompilationUnit cu, ExecutionContext ctx) { if (alreadyUsingIncompatibleBase64(cu)) { @@ -105,12 +92,18 @@ public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) J.MethodInvocation m = (J.MethodInvocation) super.visitMethodInvocation(method, ctx); if (base64EncodeMethod.matches(m) && ("encode".equals(method.getSimpleName()) || "encodeBuffer".equals(method.getSimpleName()))) { - m = encodeToString.apply(updateCursor(m), m.getCoordinates().replace(), method.getArguments().get(0)); + m = JavaTemplate.builder(useMimeCoder ? "Base64.getMimeEncoder().encodeToString(#{anyArray(byte)})" : "Base64.getEncoder().encodeToString(#{anyArray(byte)})") + .imports("java.util.Base64") + .build() + .apply(updateCursor(m), m.getCoordinates().replace(), method.getArguments().get(0)); if (method.getSelect() instanceof J.Identifier) { m = m.withSelect(method.getSelect()); } } else if (base64DecodeBuffer.matches(method)) { - m = decode.apply(updateCursor(m), m.getCoordinates().replace(), method.getArguments().get(0)); + m = JavaTemplate.builder(useMimeCoder ? "Base64.getMimeDecoder().decode(#{any(String)})" : "Base64.getDecoder().decode(#{any(String)})") + .imports("java.util.Base64") + .build() + .apply(updateCursor(m), m.getCoordinates().replace(), method.getArguments().get(0)); if (method.getSelect() instanceof J.Identifier) { m = m.withSelect(method.getSelect()); } @@ -135,7 +128,11 @@ public J visitNewClass(J.NewClass newClass, ExecutionContext ctx) { .apply(updateCursor(c), c.getCoordinates().replace()); } else if (newBase64Decoder.matches(c)) { - return getDecoderTemplate.apply(updateCursor(c), c.getCoordinates().replace()); + return JavaTemplate.builder(useMimeCoder ? "Base64.getMimeDecoder()" : "Base64.getDecoder()") + .contextSensitive() + .imports("java.util.Base64") + .build() + .apply(updateCursor(c), c.getCoordinates().replace()); } return c; } From 00da62b3b9a29a1bc4c6f18c0030050c1544d3c5 Mon Sep 17 00:00:00 2001 From: "team-moderne[bot]" Date: Mon, 24 Mar 2025 10:15:51 +0000 Subject: [PATCH 09/12] [Auto] SDKMAN! Java candidates as of 2025-03-24T1015 --- src/main/resources/sdkman-java.csv | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/main/resources/sdkman-java.csv b/src/main/resources/sdkman-java.csv index 157b7deed1..d8b29e8743 100644 --- a/src/main/resources/sdkman-java.csv +++ b/src/main/resources/sdkman-java.csv @@ -2,7 +2,9 @@ 11.0.15-trava 11.0.25-albba 11.0.25-kona +11.0.26-albba 11.0.26-amzn +11.0.26-kona 11.0.26-librca 11.0.26-ms 11.0.26-sapmchn @@ -16,8 +18,10 @@ 17.0.13-albba 17.0.13-kona 17.0.13.crac-zulu +17.0.14-albba 17.0.14-amzn 17.0.14-jbr +17.0.14-kona 17.0.14-librca 17.0.14-ms 17.0.14-sapmchn @@ -25,6 +29,7 @@ 17.0.14-tem 17.0.14-zulu 17.0.14.crac-librca +17.0.14.crac-zulu 17.0.14.fx-librca 17.0.14.fx-zulu 17.0.9-graalce @@ -35,6 +40,7 @@ 21.0.6-amzn 21.0.6-graal 21.0.6-jbr +21.0.6-kona 21.0.6-librca 21.0.6-ms 21.0.6-oracle @@ -43,6 +49,7 @@ 21.0.6-tem 21.0.6-zulu 21.0.6.crac-librca +21.0.6.crac-zulu 21.0.6.fx-librca 21.0.6.fx-zulu 22.0.2-oracle @@ -69,19 +76,37 @@ 23.1.6.fx-nik 23.1.6.r21-mandrel 23.1.6.r21-nik +24-amzn +24-graal +24-graalce +24-librca +24-open +24-oracle +24-sapmchn +24-tem +24-zulu 24.0.2.r22-mandrel 24.1.2.r23-mandrel 24.1.2.r23-nik +24.crac-zulu 24.ea.32-graal 24.ea.36-open +24.fx-librca +24.fx-zulu 25.ea.10-open +25.ea.13-graal +25.ea.14-graal +25.ea.14-open +25.ea.15-open 25.ea.8-graal 6.0.119-zulu 7.0.352-zulu 8.0.282-trava 8.0.432-albba 8.0.432-kona +8.0.442-albba 8.0.442-amzn +8.0.442-kona 8.0.442-librca 8.0.442-sem 8.0.442-tem From f13ff2809674a9bc39fed82f605833a7ce692edf Mon Sep 17 00:00:00 2001 From: Melloware Date: Wed, 26 Mar 2025 11:28:29 -0400 Subject: [PATCH 10/12] Fix #694: Jakarta EE10 upgrade Yasson library (#696) * Fix #694: Jakarta EE10 upgrade Yasson library * Update jakarta-ee-10.yml --- src/main/resources/META-INF/rewrite/jakarta-ee-10.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/resources/META-INF/rewrite/jakarta-ee-10.yml b/src/main/resources/META-INF/rewrite/jakarta-ee-10.yml index 4343daaa3a..59892d5abb 100644 --- a/src/main/resources/META-INF/rewrite/jakarta-ee-10.yml +++ b/src/main/resources/META-INF/rewrite/jakarta-ee-10.yml @@ -46,6 +46,7 @@ recipeList: - org.openrewrite.java.migrate.jakarta.UpdateJerseyDependencies - org.openrewrite.java.migrate.jakarta.UpdateApacheShiroDependencies - org.openrewrite.java.migrate.jakarta.UpdateEclipseLinkDependencies + - org.openrewrite.java.migrate.jakarta.UpdateYassonDependencies --- type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.java.migrate.jakarta.MigrationToJakarta10Apis @@ -467,3 +468,13 @@ recipeList: artifactId: "*" newVersion: 4.x --- +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.java.migrate.jakarta.UpdateYassonDependencies +displayName: Update Eclipse Yasson Dependencies to 3.0.x +description: Update Eclipse Yasson Dependencies to 3.0.x. +recipeList: + - org.openrewrite.java.dependencies.UpgradeDependencyVersion: + groupId: org.eclipse + artifactId: yasson + newVersion: 3.0.x +--- From 35781e1f46c08ec8671e33326f6cfb11d81efa92 Mon Sep 17 00:00:00 2001 From: Melloware Date: Wed, 26 Mar 2025 11:31:22 -0400 Subject: [PATCH 11/12] Fix #695: Apache Commons Email2 (#697) --- .../META-INF/rewrite/jakarta-ee-10.yml | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/main/resources/META-INF/rewrite/jakarta-ee-10.yml b/src/main/resources/META-INF/rewrite/jakarta-ee-10.yml index 59892d5abb..91b94a3ba8 100644 --- a/src/main/resources/META-INF/rewrite/jakarta-ee-10.yml +++ b/src/main/resources/META-INF/rewrite/jakarta-ee-10.yml @@ -44,6 +44,7 @@ recipeList: - org.openrewrite.java.migrate.jakarta.JavaxToJakartaCdiExtensions - org.openrewrite.java.migrate.jakarta.UpdateJakartaPlatform10 - org.openrewrite.java.migrate.jakarta.UpdateJerseyDependencies + - org.openrewrite.java.migrate.jakarta.UpdateApacheCommonsEmailDependencies - org.openrewrite.java.migrate.jakarta.UpdateApacheShiroDependencies - org.openrewrite.java.migrate.jakarta.UpdateEclipseLinkDependencies - org.openrewrite.java.migrate.jakarta.UpdateYassonDependencies @@ -445,6 +446,31 @@ recipeList: newVersion: 3.1.x --- type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.java.migrate.jakarta.UpdateApacheCommonsEmailDependencies +displayName: Update Apache Commons Email to Email2 for Jakarta +description: Update Apache Commons Email to Email2 for Jakarta. +recipeList: + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.apache.commons + oldArtifactId: commons-email + newGroupId: org.apache.commons + newArtifactId: commons-email2-jakarta + newVersion: 2.0.x + - org.openrewrite.java.ChangeType: + oldFullyQualifiedTypeName: org.apache.commons.mail.EmailException + newFullyQualifiedTypeName: org.apache.commons.mail2.core.EmailException + - org.openrewrite.java.ChangeType: + oldFullyQualifiedTypeName: org.apache.commons.mail.EmailConstants + newFullyQualifiedTypeName: org.apache.commons.mail2.core.EmailConstants + - org.openrewrite.java.ChangeType: + oldFullyQualifiedTypeName: org.apache.commons.mail.EmailUtils + newFullyQualifiedTypeName: org.apache.commons.mail2.core.EmailUtils + - org.openrewrite.java.ChangePackage: + oldPackageName: org.apache.commons.mail + newPackageName: org.apache.commons.mail2.jakarta + recursive: true +--- +type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.java.migrate.jakarta.UpdateApacheShiroDependencies displayName: Update Apache Shiro Dependencies to 2.0.x description: Update Apache Shiro Dependencies to 2.0.x. From 8fcfbdcf6ee1db82a23d51c1a1e939c7924146a5 Mon Sep 17 00:00:00 2001 From: Knut Wannheden Date: Thu, 27 Mar 2025 18:58:46 +0100 Subject: [PATCH 12/12] Fix recipe display name capitalization --- .../migrate/lang/var/UseVarForGenericMethodInvocations.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/openrewrite/java/migrate/lang/var/UseVarForGenericMethodInvocations.java b/src/main/java/org/openrewrite/java/migrate/lang/var/UseVarForGenericMethodInvocations.java index 544d23fc15..5754427dbf 100644 --- a/src/main/java/org/openrewrite/java/migrate/lang/var/UseVarForGenericMethodInvocations.java +++ b/src/main/java/org/openrewrite/java/migrate/lang/var/UseVarForGenericMethodInvocations.java @@ -32,13 +32,13 @@ public class UseVarForGenericMethodInvocations extends Recipe { @Override public String getDisplayName() { //language=markdown - return "Apply `var` to Generic Method Invocations"; + return "Apply `var` to generic method invocations"; } @Override public String getDescription() { //language=markdown - return "Apply `var` to variables initialized by invocations of Generic Methods. " + + return "Apply `var` to variables initialized by invocations of generic methods. " + "This recipe ignores generic factory methods without parameters, because open rewrite cannot handle them correctly ATM."; }