Skip to content

Commit

Permalink
Adding WsWsocServerContainerDeprecationRecipe (#298)
Browse files Browse the repository at this point in the history
* adding WsWsocServerContainerDeprecationRecipe

* adding description

* Slight polish: move jar to tests; update name & description

* Slight polish: Add recipe name; chain in jakarta-ee-9 upgrade

* Newline before after text block

---------

Co-authored-by: anuram <ranuradh@us.ibm.com>
Co-authored-by: Tim te Beek <tim@moderne.io>
  • Loading branch information
3 people authored Sep 21, 2023
1 parent 19e5bc7 commit 4f1ad79
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ out/
.classpath
.project
.settings/
bin/
.DS_Store
bin/
39 changes: 39 additions & 0 deletions src/main/resources/META-INF/rewrite/jakarta-ee-10.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#
# Copyright 2023 the original author or authors.
# <p>
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# <p>
# https://www.apache.org/licenses/LICENSE-2.0
# <p>
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.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
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright 2023 the original author or authors.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* https://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openrewrite.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<String,String> 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<String,String> map){
ServerContainer.upgradeHttpToWebSocket(req, res, sConfig, map);
}
}
"""
)
);
}

}
Binary file not shown.

0 comments on commit 4f1ad79

Please sign in to comment.