Skip to content

Commit 8ba21db

Browse files
authored
Migrate JAXB XJC binding files declaring version 2.0/2.1/2.2 (#1098)
* Add reproducer: JAXB XJC binding migration ignores version 2.0/2.1/2.2 The JavaxXmlToJakartaXmlXJCBinding recipe only matches version="1.0" on the <jxb:bindings> root, leaving 2.x bindings with a now-mismatched namespace and a stale version attribute. See moderneinc/customer-requests#2359. * Migrate JAXB binding files declaring version 2.0, 2.1, or 2.2 The JavaxXmlToJakartaXmlXJCBinding recipe matched version="1.0" only, silently leaving real-world .xjb files that declare 2.0/2.1/2.2 with a stale version attribute after the namespace was rewritten. JAXB 3 then rejects them at build time. Broaden the version rule to a regex that matches exactly the spec-defined pre-3.0 binding versions (1.0, 2.0, 2.1, 2.2). Fixes moderneinc/customer-requests#2359
1 parent d845f4d commit 8ba21db

2 files changed

Lines changed: 31 additions & 3 deletions

File tree

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,13 +1041,14 @@ recipeList:
10411041
attributeName: xmlns:jxb
10421042
oldValue: http://java.sun.com/xml/ns/jaxb
10431043
newValue: https://jakarta.ee/xml/ns/jaxb
1044-
# Update version
1044+
# Update version (covers JAXB 1.x and 2.x bindings authored before Jakarta EE 9)
10451045
- org.openrewrite.xml.ChangeTagAttribute:
10461046
#language=xpath
10471047
elementName: "//*[namespace-uri() = 'https://jakarta.ee/xml/ns/jaxb' and local-name() = 'bindings']"
10481048
attributeName: version
1049-
oldValue: 1.0
1050-
newValue: 3.0
1049+
oldValue: "1\\.0|2\\.[0-2]"
1050+
newValue: "3.0"
1051+
regex: true
10511052
---
10521053
type: specs.openrewrite.org/v1beta/recipe
10531054
name: org.openrewrite.java.migrate.jakarta.JavaxXmlSoapToJakartaXmlSoap

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
import org.junit.jupiter.api.Nested;
1919
import org.junit.jupiter.api.Test;
20+
import org.junit.jupiter.params.ParameterizedTest;
21+
import org.junit.jupiter.params.provider.ValueSource;
2022
import org.openrewrite.DocumentExample;
2123
import org.openrewrite.Issue;
2224
import org.openrewrite.test.RecipeSpec;
@@ -113,6 +115,31 @@ void version() {
113115
);
114116
}
115117

118+
@Issue("https://github.com/moderneinc/customer-requests/issues/2359")
119+
@ParameterizedTest
120+
@ValueSource(strings = {"2.0", "2.1", "2.2"})
121+
void versionTwoX(String oldVersion) {
122+
rewriteRun(
123+
//language=xml
124+
xml(
125+
"""
126+
<?xml version="1.0" encoding="UTF-8"?>
127+
<jxb:bindings version="%s"
128+
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
129+
xmlns:xs="http://www.w3.org/2001/XMLSchema">
130+
</jxb:bindings>
131+
""".formatted(oldVersion),
132+
"""
133+
<?xml version="1.0" encoding="UTF-8"?>
134+
<jxb:bindings version="3.0"
135+
xmlns:jxb="https://jakarta.ee/xml/ns/jaxb"
136+
xmlns:xs="http://www.w3.org/2001/XMLSchema">
137+
</jxb:bindings>
138+
"""
139+
)
140+
);
141+
}
142+
116143
@Test
117144
void namespace() {
118145
rewriteRun(

0 commit comments

Comments
 (0)