Skip to content

Commit 251b6f0

Browse files
evie-lauMBoegers
andauthored
Fix Java to Jakarta XJC binding migration (#741)
* Fix Java to Jakarta XJC binding migration * Prevent xjc binding migration for ibm files * Add comment * Re-enable test * Remove unused import * Change precondition to check for IBM NS, apply best practices and add `@DocumentedExample` --------- Co-authored-by: Merlin Bögershausen <[email protected]>
1 parent 0f13e9f commit 251b6f0

File tree

2 files changed

+78
-53
lines changed

2 files changed

+78
-53
lines changed

src/main/resources/META-INF/rewrite/jakarta-ee-9.yml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -721,19 +721,25 @@ tags:
721721
- jaxb
722722
- javax
723723
- jakarta
724+
preconditions:
725+
# IBM-specific exclusion
726+
- org.openrewrite.xml.search.DoesNotUseNamespaceUri:
727+
namespaceUri: http://websphere.ibm.com/xml/ns/javaee
724728
recipeList:
725-
- org.openrewrite.xml.ChangeTagAttribute:
726-
#language=xpath
727-
elementName: "//*[namespace-uri() = 'http://java.sun.com/xml/ns/jaxb' and local-name() = 'bindings']"
728-
attributeName: version
729-
oldValue: 1.0
730-
newValue: 3.0
729+
# Update namespace first
731730
- org.openrewrite.xml.ChangeTagAttribute:
732731
#language=xpath
733732
elementName: "//*[namespace-uri() = 'http://java.sun.com/xml/ns/jaxb' and local-name() = 'bindings']"
734733
attributeName: xmlns:jxb
735734
oldValue: http://java.sun.com/xml/ns/jaxb
736735
newValue: https://jakarta.ee/xml/ns/jaxb
736+
# Update version
737+
- org.openrewrite.xml.ChangeTagAttribute:
738+
#language=xpath
739+
elementName: "//*[namespace-uri() = 'https://jakarta.ee/xml/ns/jaxb' and local-name() = 'bindings']"
740+
attributeName: version
741+
oldValue: 1.0
742+
newValue: 3.0
737743
---
738744
type: specs.openrewrite.org/v1beta/recipe
739745
name: org.openrewrite.java.migrate.jakarta.JavaxXmlSoapToJakartaXmlSoap

src/test/java/org/openrewrite/java/migrate/jakarta/UpdateXJCBindingsToJakartaEE.java

Lines changed: 66 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
*/
1616
package org.openrewrite.java.migrate.jakarta;
1717

18-
import org.junit.jupiter.api.Disabled;
1918
import org.junit.jupiter.api.Nested;
2019
import org.junit.jupiter.api.Test;
20+
import org.openrewrite.DocumentExample;
21+
import org.openrewrite.Issue;
2122
import org.openrewrite.test.RecipeSpec;
2223
import org.openrewrite.test.RewriteTest;
2324

@@ -35,84 +36,102 @@ void noMigrate() {
3536
xml(
3637
//language=xml
3738
"""
38-
<?xml version="1.0" encoding="UTF-8"?>
39-
<jxb:bindings version="3.0"
40-
xmlns:jxb="https://jakarta.ee/xml/ns/jaxb"
41-
xmlns:xs="http://www.w3.org/2001/XMLSchema">
42-
</jxb:bindings>
39+
<?xml version="1.0" encoding="UTF-8"?>
40+
<jxb:bindings version="3.0"
41+
xmlns:jxb="https://jakarta.ee/xml/ns/jaxb"
42+
xmlns:xs="http://www.w3.org/2001/XMLSchema">
43+
</jxb:bindings>
44+
"""
45+
)
46+
);
47+
}
48+
49+
@Test
50+
@Issue("https://github.com/openrewrite/rewrite-migrate-java/pull/741")
51+
void noMigrateIBMFiles() {
52+
rewriteRun(
53+
//language=xml
54+
xml(
4355
"""
56+
<?xml version="1.0" encoding="UTF-8"?>
57+
<jxb:bindings version="1.0"
58+
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
59+
xmlns:xs="http://www.w3.org/2001/XMLSchema"
60+
xmlns:ibm="http://websphere.ibm.com/xml/ns/javaee">
61+
</jxb:bindings>
62+
"""
4463
)
4564
);
4665
}
4766

4867
@Nested
4968
class Migrate {
50-
@Disabled // temporarily disabling this to make the project build as we need a release.
69+
5170
@Test
52-
void version() {
71+
@DocumentExample
72+
void both() {
5373
rewriteRun(
5474
//language=xml
5575
xml(
5676
"""
57-
<?xml version="1.0" encoding="UTF-8"?>
58-
<jxb:bindings version="1.0"
59-
xmlns:jxb="https://jakarta.ee/xml/ns/jaxb"
60-
xmlns:xs="http://www.w3.org/2001/XMLSchema">
61-
</jxb:bindings>
62-
""",
63-
"""
64-
<?xml version="1.0" encoding="UTF-8"?>
65-
<jxb:bindings version="3.0"
66-
xmlns:jxb="https://jakarta.ee/xml/ns/jaxb"
67-
xmlns:xs="http://www.w3.org/2001/XMLSchema">
68-
</jxb:bindings>
77+
<?xml version="1.0" encoding="UTF-8"?>
78+
<jxb:bindings version="1.0"
79+
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
80+
xmlns:xs="http://www.w3.org/2001/XMLSchema">
81+
</jxb:bindings>
82+
""",
6983
"""
84+
<?xml version="1.0" encoding="UTF-8"?>
85+
<jxb:bindings version="3.0"
86+
xmlns:jxb="https://jakarta.ee/xml/ns/jaxb"
87+
xmlns:xs="http://www.w3.org/2001/XMLSchema">
88+
</jxb:bindings>
89+
"""
7090
)
7191
);
7292
}
73-
7493
@Test
75-
void namespace() {
94+
void version() {
7695
rewriteRun(
7796
//language=xml
7897
xml(
7998
"""
80-
<?xml version="1.0" encoding="UTF-8"?>
81-
<jxb:bindings version="3.0"
82-
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
83-
xmlns:xs="http://www.w3.org/2001/XMLSchema">
84-
</jxb:bindings>
85-
""",
86-
"""
87-
<?xml version="1.0" encoding="UTF-8"?>
88-
<jxb:bindings version="3.0"
89-
xmlns:jxb="https://jakarta.ee/xml/ns/jaxb"
90-
xmlns:xs="http://www.w3.org/2001/XMLSchema">
91-
</jxb:bindings>
99+
<?xml version="1.0" encoding="UTF-8"?>
100+
<jxb:bindings version="1.0"
101+
xmlns:jxb="https://jakarta.ee/xml/ns/jaxb"
102+
xmlns:xs="http://www.w3.org/2001/XMLSchema">
103+
</jxb:bindings>
104+
""",
92105
"""
106+
<?xml version="1.0" encoding="UTF-8"?>
107+
<jxb:bindings version="3.0"
108+
xmlns:jxb="https://jakarta.ee/xml/ns/jaxb"
109+
xmlns:xs="http://www.w3.org/2001/XMLSchema">
110+
</jxb:bindings>
111+
"""
93112
)
94113
);
95114
}
96115

97116
@Test
98-
void both() {
117+
void namespace() {
99118
rewriteRun(
100119
//language=xml
101120
xml(
102121
"""
103-
<?xml version="1.0" encoding="UTF-8"?>
104-
<jxb:bindings version="1.0"
105-
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
106-
xmlns:xs="http://www.w3.org/2001/XMLSchema">
107-
</jxb:bindings>
108-
""",
109-
"""
110-
<?xml version="1.0" encoding="UTF-8"?>
111-
<jxb:bindings version="3.0"
112-
xmlns:jxb="https://jakarta.ee/xml/ns/jaxb"
113-
xmlns:xs="http://www.w3.org/2001/XMLSchema">
114-
</jxb:bindings>
122+
<?xml version="1.0" encoding="UTF-8"?>
123+
<jxb:bindings version="3.0"
124+
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
125+
xmlns:xs="http://www.w3.org/2001/XMLSchema">
126+
</jxb:bindings>
127+
""",
115128
"""
129+
<?xml version="1.0" encoding="UTF-8"?>
130+
<jxb:bindings version="3.0"
131+
xmlns:jxb="https://jakarta.ee/xml/ns/jaxb"
132+
xmlns:xs="http://www.w3.org/2001/XMLSchema">
133+
</jxb:bindings>
134+
"""
116135
)
117136
);
118137
}

0 commit comments

Comments
 (0)