Skip to content

Commit 78159d1

Browse files
BhavanaPidapabhavanapidapagithub-actions[bot]timtebeek
authored
Replace com.sun.xml.internal.bind.* packages with com.sun.xml.bind.* packages (#508)
* Java11 Recipe ThreadStopDestroy * Java11 Recipe InternalBindPackages * Delete src/test/java/org/openrewrite/java/migrate/ThreadStopDestroy.java It is not part of my latest commit * Update src/test/java/org/openrewrite/java/migrate/InternalBindPackages.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Minimize the newClass.jar & format test * Apply suggestions from code review * Add missing test name suffix * Merge into the previous Java8ToJava11Test.java --------- Co-authored-by: bhavanapidapa <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Tim te Beek <[email protected]> Co-authored-by: Tim te Beek <[email protected]>
1 parent 7412e34 commit 78159d1

File tree

3 files changed

+41
-14
lines changed

3 files changed

+41
-14
lines changed

src/main/resources/META-INF/rewrite/java-version-11.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,13 @@ recipeList:
6363
- org.openrewrite.java.migrate.util.OptionalNotPresentToIsEmpty
6464
- org.openrewrite.java.migrate.util.OptionalNotEmptyToIsPresent
6565
- org.openrewrite.java.migrate.util.OptionalStreamRecipe
66-
- org.openrewrite.java.migrate.InternalBindContextFactory
66+
- org.openrewrite.java.migrate.InternalBindPackages
6767
- org.openrewrite.java.migrate.RemovedSecurityManagerMethods
6868
- org.openrewrite.java.migrate.UpgradePluginsForJava11
6969
- org.openrewrite.java.migrate.RemovedPolicy
7070
- org.openrewrite.java.migrate.ReferenceCloneMethod
7171
- org.openrewrite.java.migrate.ThreadStopDestroy
72+
7273
---
7374
type: specs.openrewrite.org/v1beta/recipe
7475
name: org.openrewrite.java.migrate.UpgradeBuildToJava11
@@ -228,16 +229,16 @@ recipeList:
228229
onlyIfVersionsMatch: true
229230
---
230231
type: specs.openrewrite.org/v1beta/recipe
231-
name: org.openrewrite.java.migrate.InternalBindContextFactory
232-
displayName: Use `com.sun.xml.bind.v2.ContextFactory` instead of `com.sun.xml.internal.bind.v2.ContextFactory`
233-
description: Do not use the `com.sun.xml.internal.bind.v2.ContextFactory` class.
232+
name: org.openrewrite.java.migrate.InternalBindPackages
233+
displayName: Use `com.sun.xml.bind.*` instead of `com.sun.xml.internal.bind.*`
234+
description: Do not use APIs from `com.sun.xml.internal.bind.*` packages.
234235
tags:
235236
- java11
236237
recipeList:
237-
- org.openrewrite.java.ChangeType:
238-
oldFullyQualifiedTypeName: com.sun.xml.internal.bind.v2.ContextFactory
239-
newFullyQualifiedTypeName: com.sun.xml.bind.v2.ContextFactory
240-
ignoreDefinition: true
238+
- org.openrewrite.java.ChangePackage:
239+
oldPackageName: com.sun.xml.internal.bind
240+
newPackageName: com.sun.xml.bind
241+
recursive: true
241242
---
242243
type: specs.openrewrite.org/v1beta/recipe
243244
name: org.openrewrite.java.migrate.RemovedPolicy

src/test/java/org/openrewrite/java/migrate/Java8ToJava11Test.java renamed to src/test/java/org/openrewrite/java/migrate/InternalBindPackagesTest.java

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@
2424

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

27-
class Java8ToJava11Test implements RewriteTest {
27+
class InternalBindPackagesTest implements RewriteTest {
2828
@Override
2929
public void defaults(RecipeSpec spec) {
3030
spec
3131
.parser(JavaParser.fromJavaVersion()
32-
.classpathFromResources(new InMemoryExecutionContext(), "sun.internal.new"))
33-
.recipeFromResources("org.openrewrite.java.migrate.Java8toJava11");
32+
.classpathFromResources(new InMemoryExecutionContext(), "sun.internal.newClass"))
33+
.recipeFromResources("org.openrewrite.java.migrate.InternalBindPackages");
3434
}
3535

3636
@DocumentExample
3737
@Test
38-
void internalBindContextFactory() {
38+
void contextFactoryImportVariants() {
3939
//language=java
4040
rewriteRun(
4141
java(
@@ -91,8 +91,7 @@ void bar() {
9191
}
9292
""",
9393
"""
94-
import com.sun.xml.bind.v2.ContextFactory;
95-
import com.sun.xml.internal.bind.v2.*;
94+
import com.sun.xml.bind.v2.*;
9695
9796
class Foo3 {
9897
void bar() {
@@ -105,4 +104,31 @@ void bar() {
105104
)
106105
);
107106
}
107+
108+
@Test
109+
void wellKnownNamespace() {
110+
rewriteRun(
111+
//language=java
112+
java(
113+
"""
114+
package com.ibm.test;
115+
public class TestInternalBindPackages {
116+
public void testInternalBindPackages() {
117+
com.sun.xml.internal.bind.v2.WellKnownNamespace namespace = null;
118+
namespace.hashCode();
119+
}
120+
}
121+
""",
122+
"""
123+
package com.ibm.test;
124+
public class TestInternalBindPackages {
125+
public void testInternalBindPackages() {
126+
com.sun.xml.bind.v2.WellKnownNamespace namespace = null;
127+
namespace.hashCode();
128+
}
129+
}
130+
"""
131+
)
132+
);
133+
}
108134
}
Binary file not shown.

0 commit comments

Comments
 (0)