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 8822edb83b..cc153b1d89 100644 --- a/src/main/resources/META-INF/rewrite/jakarta-ee-10.yml +++ b/src/main/resources/META-INF/rewrite/jakarta-ee-10.yml @@ -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 --- @@ -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 @@ -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 @@ -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 diff --git a/src/test/java/org/openrewrite/java/migrate/jakarta/RemovedStateManagerMethodsTest.java b/src/test/java/org/openrewrite/java/migrate/jakarta/RemovedStateManagerMethodsTest.java new file mode 100644 index 0000000000..7fea1395a3 --- /dev/null +++ b/src/test/java/org/openrewrite/java/migrate/jakarta/RemovedStateManagerMethodsTest.java @@ -0,0 +1,136 @@ +/* + * 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; + + +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); + } + } + """)); + } + +} + diff --git a/src/test/resources/META-INF/rewrite/classpath/jakarta.faces-api-4.0.1.jar b/src/test/resources/META-INF/rewrite/classpath/jakarta.faces-api-4.0.1.jar new file mode 100644 index 0000000000..53567273a2 Binary files /dev/null and b/src/test/resources/META-INF/rewrite/classpath/jakarta.faces-api-4.0.1.jar differ