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 71ab8cf211..ec8a2215b8 100644 --- a/src/main/resources/META-INF/rewrite/jakarta-ee-9.yml +++ b/src/main/resources/META-INF/rewrite/jakarta-ee-9.yml @@ -1127,10 +1127,6 @@ recipeList: groupId: jakarta.xml.ws artifactId: jakarta.xml.ws-api newVersion: 3.0.x - - org.openrewrite.maven.ChangeDependencyScope: - groupId: jakarta.xml.ws - artifactId: jakarta.xml.ws-api - newScope: provided - org.openrewrite.java.dependencies.UpgradeDependencyVersion: groupId: com.sun.xml.ws artifactId: jaxws-rt @@ -1139,6 +1135,11 @@ recipeList: groupId: com.sun.xml.ws artifactId: jaxws-rt newScope: provided + - org.openrewrite.java.migrate.javax.AddApiDependencyForImports: + packageName: jakarta.xml.ws + groupId: jakarta.xml.ws + artifactId: jakarta.xml.ws-api + version: 3.0.x - org.openrewrite.java.dependencies.AddDependency: groupId: com.sun.xml.ws artifactId: jaxws-rt diff --git a/src/test/java/org/openrewrite/java/migrate/jakarta/JavaxXmlWsMigrationToJakartaXmlWsTest.java b/src/test/java/org/openrewrite/java/migrate/jakarta/JavaxXmlWsMigrationToJakartaXmlWsTest.java new file mode 100644 index 0000000000..0a7a9fe5ad --- /dev/null +++ b/src/test/java/org/openrewrite/java/migrate/jakarta/JavaxXmlWsMigrationToJakartaXmlWsTest.java @@ -0,0 +1,89 @@ +/* + * 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.config.Environment; +import org.openrewrite.java.JavaIsoVisitor; +import org.openrewrite.java.JavaParser; +import org.openrewrite.java.tree.J; +import org.openrewrite.java.tree.JavaType; +import org.openrewrite.test.RecipeSpec; +import org.openrewrite.test.RewriteTest; +import org.openrewrite.test.TypeValidation; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.openrewrite.java.Assertions.*; +import static org.openrewrite.maven.Assertions.pomXml; + +class JavaxXmlWsMigrationToJakartaXmlWsTest implements RewriteTest { + @Override + public void defaults(RecipeSpec spec) { + spec.recipe(Environment.builder().scanRuntimeClasspath("org.openrewrite.java.migrate") + .build().activateRecipes("org.openrewrite.java.migrate.jakarta.JavaxXmlWsMigrationToJakartaXmlWs")) + .parser(JavaParser.fromJavaVersion().dependsOn( + "package javax.xml.ws.http; public class HTTPException extends RuntimeException {}")); + } + + @Test + void addApiForTypesPreviouslySuppliedByJavaEight() { + rewriteRun( + spec -> spec.typeValidationOptions(TypeValidation.none()), + mavenProject("app", + pomXml( + """ + + 4.0.0 + com.example + app + 1 + + """, + spec -> spec.after(pom -> assertThat(pom) + .contains("jakarta.xml.ws-api") + .actual()) + ), + srcMainJava( + java( + """ + import javax.xml.ws.http.HTTPException; + class A { HTTPException error; } + """, + """ + import jakarta.xml.ws.http.HTTPException; + class A { HTTPException error; } + """, + source -> source.mapBeforeRecipe(cu -> (J.CompilationUnit) + new JavaIsoVisitor() { + @Override + public J.Identifier visitIdentifier(J.Identifier id, Integer p) { + return id.getType() != null && id.getType().toString().startsWith("javax.xml.ws") ? + id.withType(JavaType.Unknown.getInstance()) : id; + } + + @Override + public J.FieldAccess visitFieldAccess(J.FieldAccess fa, Integer p) { + J.FieldAccess f = super.visitFieldAccess(fa, p); + return f.getType() != null && f.getType().toString().startsWith("javax.xml.ws") ? + f.withType(JavaType.Unknown.getInstance()) : f; + } + }.visit(cu, 0)) + ) + ) + ) + ); + } +}