Skip to content
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

Recipe RemovedStateManagerMethods in jakarta-ee-10 #314

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 41 additions & 4 deletions src/main/resources/META-INF/rewrite/jakarta-ee-10.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ recipeList:
- org.openrewrite.java.migrate.jakarta.JavaxMigrationToJakarta
- org.openrewrite.java.migrate.jakarta.RemovedIsParmetersProvidedMethod
- org.openrewrite.java.migrate.jakarta.RemovedSOAPElementFactory
- org.openrewrite.java.migrate.jakarta.RemovedStateManagerMethods
- org.openrewrite.java.migrate.jakarta.WsWsocServerContainerDeprecation
- org.openrewrite.java.migrate.jakarta.RemovedJakartaFacesExpressionLanguageClasses
---
Expand All @@ -35,7 +36,7 @@ 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
ignoreDefinition: true
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.ibm.websphere.wsoc.WsWsocServerContainer
newFullyQualifiedTypeName: jakarta.websocket.server.ServerContainer
Expand All @@ -51,7 +52,7 @@ recipeList:
- org.openrewrite.java.ChangeMethodName:
methodPattern: jakarta.el.MethodExpression isParmetersProvided()
newMethodName: isParametersProvided
ignoreDefinition: false
ignoreDefinition: true
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.migrate.jakarta.RemovedSOAPElementFactory
Expand All @@ -63,15 +64,51 @@ recipeList:
- org.openrewrite.java.ChangeMethodName:
methodPattern: jakarta.xml.soap.SOAPElementFactory create(String,..)
newMethodName: createElement
ignoreDefinition: false
ignoreDefinition: true
- org.openrewrite.java.ChangeMethodName:
methodPattern: jakarta.xml.soap.SOAPElementFactory create(jakarta.xml.soap.Name)
newMethodName: createElement
ignoreDefinition: false
ignoreDefinition: true
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: jakarta.xml.soap.SOAPElementFactory
newFullyQualifiedTypeName: jakarta.xml.soap.SOAPFactory
ignoreDefinition: true
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.migrate.jakarta.RemovedStateManagerMethods
displayName: Use `StateManagementStrategy`
description: >
Methods that were removed from the `jakarta.faces.application.StateManager` and `javax.faces.application.StateManager` classes in Jakarta Faces 4.0 are replaced
by `jakarta.faces.view.StateManagementStrategy` or `javax.faces.view.StateManagementStrategy` based on Jakarta10 migration in Faces 4.0
recipeList:
- org.openrewrite.java.ChangeMethodName:
methodPattern: "*.faces.application.StateManager getComponentStateToSave(*.faces.context.FacesContext)"
newMethodName: saveView
ignoreDefinition: true
- org.openrewrite.java.ChangeMethodName:
methodPattern: "*.faces.application.StateManager getTreeStructureToSave(*.faces.context.FacesContext)"
newMethodName: saveView
ignoreDefinition: true
- org.openrewrite.java.ChangeMethodName:
methodPattern: "*.faces.application.StateManager restoreComponentState(*.faces.context.FacesContext,*.faces.component.UIViewRoot,String)"
newMethodName: restoreView
ignoreDefinition: true
- org.openrewrite.java.ChangeMethodName:
methodPattern: "*.faces.application.StateManager restoreTreeStructure(*.faces.context.FacesContext,String,String)"
newMethodName: restoreView
ignoreDefinition: true
- org.openrewrite.java.ChangeMethodName:
methodPattern: "*.faces.application.StateManager saveSerializedView(*.faces.context.FacesContext)"
newMethodName: saveView
ignoreDefinition: true
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: jakarta.faces.application.StateManager
newFullyQualifiedTypeName: jakarta.faces.view.StateManagementStrategy
ignoreDefinition: true
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: javax.faces.application.StateManager
newFullyQualifiedTypeName: jakarta.faces.view.StateManagementStrategy
ignoreDefinition: true
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.migrate.jakarta.RemovedJakartaFacesExpressionLanguageClasses
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*
* 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;


public class RemovedStateManagerMethodsTest implements RewriteTest {
@Override
public void defaults(RecipeSpec spec) {
spec.parser(JavaParser.fromJavaVersion()
.classpathFromResources(new InMemoryExecutionContext(), "jakarta.faces-2.3.19", "jakarta.faces-3.0.3", "jakarta.faces-api-4.0.1"))
.recipe(Environment.builder().scanRuntimeClasspath("org.openrewrite.java.migrate.jakarta")
.build()
.activateRecipes("org.openrewrite.java.migrate.jakarta.RemovedStateManagerMethods"));
}

@Test
void stateManagerReplacement() {
rewriteRun(
//language=java
java("""
package com.test;

import jakarta.faces.application.StateManager;
import jakarta.faces.component.UIViewRoot;
import jakarta.faces.context.FacesContext;

public class StateManagerParent extends StateManager {

@Override
public UIViewRoot restoreView(FacesContext arg0, String arg1, String arg2) {
UIViewRoot uv = null;
super.getComponentStateToSave(arg0);
super.getTreeStructureToSave(arg0);
super.restoreComponentState(arg0, uv, arg2);
super.restoreTreeStructure(arg0, arg1, arg2);
return null;
}
}
""", """
package com.test;

import jakarta.faces.component.UIViewRoot;
import jakarta.faces.context.FacesContext;
import jakarta.faces.view.StateManagementStrategy;

public class StateManagerParent extends StateManagementStrategy {

@Override
public UIViewRoot restoreView(FacesContext arg0, String arg1, String arg2) {
UIViewRoot uv = null;
super.saveView(arg0);
super.saveView(arg0);
super.restoreView(arg0, uv, arg2);
super.restoreView(arg0, arg1, arg2);
return null;
}
}
"""));
}

@Test
void stateManagerRemove() {
rewriteRun(
//language=java
java("""
package com.test;

import jakarta.faces.application.StateManager;
import jakarta.faces.context.FacesContext;
import java.io.IOException;

public class StateMgrTest {

public void test() throws IOException {

StateManager st = null;
FacesContext fc = null;
String var1 = null;
String var2 = null;
st.restoreView(fc,var1,var2);
st.saveSerializedView(fc);
st.saveView(fc);
StateManager.SerializedView sv = null;
st.writeState(fc,sv);
}
}
""", """
package com.test;

import jakarta.faces.context.FacesContext;
import jakarta.faces.view.StateManagementStrategy;

import java.io.IOException;

public class StateMgrTest {

public void test() throws IOException {

StateManagementStrategy st = null;
FacesContext fc = null;
String var1 = null;
String var2 = null;
st.restoreView(fc,var1,var2);
st.saveView(fc);
st.saveView(fc);
StateManagementStrategy.SerializedView sv = null;
st.writeState(fc,sv);
}
}
"""));
}

}

Binary file not shown.