Skip to content

Commit 83ce1c6

Browse files
authored
Add recipe to migrate XJC bindings to Jakarta EE (#704)
1 parent ef12efa commit 83ce1c6

File tree

2 files changed

+141
-0
lines changed

2 files changed

+141
-0
lines changed

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

+23
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,29 @@ recipeList:
699699
groupId: org.codehaus.mojo
700700
artifactId: jaxb-maven-plugin
701701
newVersion: 4.x
702+
- org.openrewrite.java.migrate.jakarta.JavaxXmlToJakartaXmlXJCBinding
703+
---
704+
type: specs.openrewrite.org/v1beta/recipe
705+
name: org.openrewrite.java.migrate.jakarta.JavaxXmlToJakartaXmlXJCBinding
706+
displayName: Migrate XJC Bindings to Jakata XML
707+
description: Java EE has been rebranded to Jakarta EE, migrates the namespace and version in XJC bindings.
708+
tags:
709+
- jaxb
710+
- javax
711+
- jakarta
712+
recipeList:
713+
- org.openrewrite.xml.ChangeTagAttribute:
714+
#language=xpath
715+
elementName: "//*[namespace-uri() = 'http://java.sun.com/xml/ns/jaxb' and local-name() = 'bindings']"
716+
attributeName: version
717+
oldValue: 1.0
718+
newValue: 3.0
719+
- org.openrewrite.xml.ChangeTagAttribute:
720+
#language=xpath
721+
elementName: "//*[namespace-uri() = 'http://java.sun.com/xml/ns/jaxb' and local-name() = 'bindings']"
722+
attributeName: xmlns:jxb
723+
oldValue: http://java.sun.com/xml/ns/jaxb
724+
newValue: https://jakarta.ee/xml/ns/jaxb
702725
---
703726
type: specs.openrewrite.org/v1beta/recipe
704727
name: org.openrewrite.java.migrate.jakarta.JavaxXmlSoapToJakartaXmlSoap
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
* Copyright 2025 the original author or authors.
3+
* <p>
4+
* Licensed under the Moderne Source Available License (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* https://docs.moderne.io/licensing/moderne-source-available-license
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.openrewrite.java.migrate.jakarta;
17+
18+
import org.junit.jupiter.api.Nested;
19+
import org.junit.jupiter.api.Test;
20+
import org.openrewrite.test.RecipeSpec;
21+
import org.openrewrite.test.RewriteTest;
22+
23+
import static org.openrewrite.xml.Assertions.xml;
24+
25+
public class UpdateXJCBindingsToJakartaEE implements RewriteTest {
26+
@Override
27+
public void defaults(RecipeSpec spec) {
28+
spec.recipeFromResources("org.openrewrite.java.migrate.jakarta.JavaxXmlToJakartaXmlXJCBinding");
29+
}
30+
31+
@Test
32+
void noMigrate() {
33+
rewriteRun(
34+
xml(
35+
//language=xml
36+
"""
37+
<?xml version="1.0" encoding="UTF-8"?>
38+
<jxb:bindings version="3.0"
39+
xmlns:jxb="https://jakarta.ee/xml/ns/jaxb"
40+
xmlns:xs="http://www.w3.org/2001/XMLSchema">
41+
</jxb:bindings>
42+
"""
43+
)
44+
);
45+
}
46+
47+
@Nested
48+
class Migrate {
49+
@Test
50+
void version() {
51+
rewriteRun(
52+
//language=xml
53+
xml(
54+
"""
55+
<?xml version="1.0" encoding="UTF-8"?>
56+
<jxb:bindings version="1.0"
57+
xmlns:jxb="https://jakarta.ee/xml/ns/jaxb"
58+
xmlns:xs="http://www.w3.org/2001/XMLSchema">
59+
</jxb:bindings>
60+
""",
61+
"""
62+
<?xml version="1.0" encoding="UTF-8"?>
63+
<jxb:bindings version="3.0"
64+
xmlns:jxb="https://jakarta.ee/xml/ns/jaxb"
65+
xmlns:xs="http://www.w3.org/2001/XMLSchema">
66+
</jxb:bindings>
67+
"""
68+
)
69+
);
70+
}
71+
72+
@Test
73+
void namespace() {
74+
rewriteRun(
75+
//language=xml
76+
xml(
77+
"""
78+
<?xml version="1.0" encoding="UTF-8"?>
79+
<jxb:bindings version="3.0"
80+
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
81+
xmlns:xs="http://www.w3.org/2001/XMLSchema">
82+
</jxb:bindings>
83+
""",
84+
"""
85+
<?xml version="1.0" encoding="UTF-8"?>
86+
<jxb:bindings version="3.0"
87+
xmlns:jxb="https://jakarta.ee/xml/ns/jaxb"
88+
xmlns:xs="http://www.w3.org/2001/XMLSchema">
89+
</jxb:bindings>
90+
"""
91+
)
92+
);
93+
}
94+
95+
@Test
96+
void both() {
97+
rewriteRun(
98+
//language=xml
99+
xml(
100+
"""
101+
<?xml version="1.0" encoding="UTF-8"?>
102+
<jxb:bindings version="1.0"
103+
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
104+
xmlns:xs="http://www.w3.org/2001/XMLSchema">
105+
</jxb:bindings>
106+
""",
107+
"""
108+
<?xml version="1.0" encoding="UTF-8"?>
109+
<jxb:bindings version="3.0"
110+
xmlns:jxb="https://jakarta.ee/xml/ns/jaxb"
111+
xmlns:xs="http://www.w3.org/2001/XMLSchema">
112+
</jxb:bindings>
113+
"""
114+
)
115+
);
116+
}
117+
}
118+
}

0 commit comments

Comments
 (0)