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

Replace com.sun.xml.internal.bind.* packages with com.sun.xml.bind.* packages #508

Merged
merged 10 commits into from
Jul 12, 2024
17 changes: 9 additions & 8 deletions src/main/resources/META-INF/rewrite/java-version-11.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,13 @@ recipeList:
- org.openrewrite.java.migrate.util.OptionalNotPresentToIsEmpty
- org.openrewrite.java.migrate.util.OptionalNotEmptyToIsPresent
- org.openrewrite.java.migrate.util.OptionalStreamRecipe
- org.openrewrite.java.migrate.InternalBindContextFactory
- org.openrewrite.java.migrate.InternalBindPackages
- org.openrewrite.java.migrate.RemovedSecurityManagerMethods
- org.openrewrite.java.migrate.UpgradePluginsForJava11
- org.openrewrite.java.migrate.RemovedPolicy
- org.openrewrite.java.migrate.ReferenceCloneMethod
- org.openrewrite.java.migrate.ThreadStopDestroy

---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.migrate.UpgradeBuildToJava11
Expand Down Expand Up @@ -228,16 +229,16 @@ recipeList:
onlyIfVersionsMatch: true
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.migrate.InternalBindContextFactory
displayName: Use `com.sun.xml.bind.v2.ContextFactory` instead of `com.sun.xml.internal.bind.v2.ContextFactory`
description: Do not use the `com.sun.xml.internal.bind.v2.ContextFactory` class.
name: org.openrewrite.java.migrate.InternalBindPackages
displayName: Use `com.sun.xml.bind.*` instead of `com.sun.xml.internal.bind.*`
description: Do not use APIs from `com.sun.xml.internal.bind.*` packages.
tags:
- java11
recipeList:
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.sun.xml.internal.bind.v2.ContextFactory
newFullyQualifiedTypeName: com.sun.xml.bind.v2.ContextFactory
ignoreDefinition: true
- org.openrewrite.java.ChangePackage:
oldPackageName: com.sun.xml.internal.bind
newPackageName: com.sun.xml.bind
recursive: true
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.migrate.RemovedPolicy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@

import static org.openrewrite.java.Assertions.java;

class Java8ToJava11Test implements RewriteTest {
class InternalBindPackagesTest implements RewriteTest {
@Override
public void defaults(RecipeSpec spec) {
spec
.parser(JavaParser.fromJavaVersion()
.classpathFromResources(new InMemoryExecutionContext(), "sun.internal.new"))
.recipeFromResources("org.openrewrite.java.migrate.Java8toJava11");
.classpathFromResources(new InMemoryExecutionContext(), "sun.internal.newClass"))
.recipeFromResources("org.openrewrite.java.migrate.InternalBindPackages");
}

@DocumentExample
@Test
void internalBindContextFactory() {
void contextFactoryImportVariants() {
//language=java
rewriteRun(
java(
Expand Down Expand Up @@ -91,8 +91,7 @@ void bar() {
}
""",
"""
import com.sun.xml.bind.v2.ContextFactory;
import com.sun.xml.internal.bind.v2.*;
import com.sun.xml.bind.v2.*;

class Foo3 {
void bar() {
Expand All @@ -105,4 +104,31 @@ void bar() {
)
);
}

@Test
void wellKnownNamespace() {
rewriteRun(
//language=java
java(
"""
package com.ibm.test;
public class TestInternalBindPackages {
public void testInternalBindPackages() {
com.sun.xml.internal.bind.v2.WellKnownNamespace namespace = null;
namespace.hashCode();
}
}
""",
"""
package com.ibm.test;
public class TestInternalBindPackages {
public void testInternalBindPackages() {
com.sun.xml.bind.v2.WellKnownNamespace namespace = null;
namespace.hashCode();
}
}
"""
)
);
}
}
Binary file not shown.