diff --git a/.gitignore b/.gitignore index 0f645db17d..9e5f15aa2a 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ out/ .classpath .project .settings/ -bin/ \ No newline at end of file +.DS_Store +bin/ diff --git a/src/main/resources/META-INF/rewrite/jakarta-ee-10.yml b/src/main/resources/META-INF/rewrite/jakarta-ee-10.yml new file mode 100644 index 0000000000..9dcde28649 --- /dev/null +++ b/src/main/resources/META-INF/rewrite/jakarta-ee-10.yml @@ -0,0 +1,39 @@ +# +# Copyright 2023 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.java.migrate.jakarta.JakartaEE10 +displayName: Migrate to Jakarta EE 10 +description: These recipes help with the Migration to Jakarta EE 10, flagging and updating deprecated methods. +tags: + - jakarta +recipeList: + - org.openrewrite.java.migrate.jakarta.JavaxMigrationToJakarta + - org.openrewrite.java.migrate.jakarta.WsWsocServerContainerDeprecation +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.java.migrate.jakarta.WsWsocServerContainerDeprecation +displayName: Replace `doUpgrade(..)` with `ServerContainer.upgradeHttpToWebSocket(..)` +description: Deprecated `WsWsocServerContainer.doUpgrade(..)` is replaced by the Jakarta WebSocket 2.1 specification `ServerContainer.upgradeHttpToWebSocket(..)`. +recipeList: + - org.openrewrite.java.ChangeMethodName: + methodPattern: com.ibm.websphere.wsoc.WsWsocServerContainer doUpgrade(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, com.ibm.websphere.wsoc.ServerEndpointConfig, java.util.Map) + newMethodName: upgradeHttpToWebSocket + ignoreDefinition: false + - org.openrewrite.java.ChangeType: + oldFullyQualifiedTypeName: com.ibm.websphere.wsoc.WsWsocServerContainer + newFullyQualifiedTypeName: jakarta.websocket.server.ServerContainer + ignoreDefinition: true diff --git a/src/test/java/org/openrewrite/java/migrate/jakarta/WsWsocServerContainerDeprecationTest.java b/src/test/java/org/openrewrite/java/migrate/jakarta/WsWsocServerContainerDeprecationTest.java new file mode 100644 index 0000000000..81ba156500 --- /dev/null +++ b/src/test/java/org/openrewrite/java/migrate/jakarta/WsWsocServerContainerDeprecationTest.java @@ -0,0 +1,74 @@ +/* + * Copyright 2023 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.java.migrate.jakarta; + +import org.junit.jupiter.api.Test; +import org.openrewrite.InMemoryExecutionContext; +import org.openrewrite.config.Environment; +import org.openrewrite.java.JavaParser; +import org.openrewrite.test.RecipeSpec; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.java.Assertions.java; + +class WsWsocServerContainerDeprecationTest implements RewriteTest { + + @Override + public void defaults(RecipeSpec spec) { + spec.parser(JavaParser.fromJavaVersion() + .classpathFromResources(new InMemoryExecutionContext(), "WsWsocServerContainer_test")) + .recipe(Environment.builder() + .scanRuntimeClasspath("org.openrewrite.java.migrate.jakarta") + .build() + .activateRecipes("org.openrewrite.java.migrate.jakarta.WsWsocServerContainerDeprecation")); + } + + @Test + void deprecateWsWsocServerContainer() { + rewriteRun( + //language=java + java( + """ + import javax.servlet.http.HttpServletRequest; + import javax.servlet.http.HttpServletResponse; + + import com.ibm.websphere.wsoc.ServerEndpointConfig; + import com.ibm.websphere.wsoc.WsWsocServerContainer; + + class Test { + void doX(HttpServletRequest req, HttpServletResponse res, ServerEndpointConfig sConfig, java.util.Map map){ + WsWsocServerContainer.doUpgrade(req, res, sConfig, map); + } + } + """, + """ + import javax.servlet.http.HttpServletRequest; + import javax.servlet.http.HttpServletResponse; + + import com.ibm.websphere.wsoc.ServerEndpointConfig; + import jakarta.websocket.server.ServerContainer; + + class Test { + void doX(HttpServletRequest req, HttpServletResponse res, ServerEndpointConfig sConfig, java.util.Map map){ + ServerContainer.upgradeHttpToWebSocket(req, res, sConfig, map); + } + } + """ + ) + ); + } + +} diff --git a/src/test/resources/META-INF/rewrite/classpath/WsWsocServerContainer_test.jar b/src/test/resources/META-INF/rewrite/classpath/WsWsocServerContainer_test.jar new file mode 100644 index 0000000000..4f275d56cc Binary files /dev/null and b/src/test/resources/META-INF/rewrite/classpath/WsWsocServerContainer_test.jar differ