Skip to content

Commit 3ff5a16

Browse files
authored
Merge pull request #25838 from gastaldi/jaxb
2 parents 3fa3b67 + 6d08bb0 commit 3ff5a16

File tree

7 files changed

+357
-131
lines changed

7 files changed

+357
-131
lines changed

extensions/jaxb/deployment/src/main/java/io/quarkus/jaxb/deployment/JaxbProcessor.java

Lines changed: 68 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import java.lang.annotation.Annotation;
66
import java.nio.file.Files;
77
import java.nio.file.Path;
8-
import java.util.Arrays;
9-
import java.util.Collections;
108
import java.util.List;
119
import java.util.stream.Stream;
1210

@@ -67,7 +65,7 @@
6765

6866
class JaxbProcessor {
6967

70-
private static final List<Class<? extends Annotation>> JAXB_ANNOTATIONS = Arrays.asList(
68+
private static final List<Class<? extends Annotation>> JAXB_ANNOTATIONS = List.of(
7169
XmlAccessorType.class,
7270
XmlAnyAttribute.class,
7371
XmlAnyElement.class,
@@ -100,7 +98,7 @@ class JaxbProcessor {
10098
XmlJavaTypeAdapter.class,
10199
XmlJavaTypeAdapters.class);
102100

103-
private static final List<Class<?>> JAXB_REFLECTIVE_CLASSES = Collections.singletonList(XmlAccessOrder.class);
101+
private static final List<Class<?>> JAXB_REFLECTIVE_CLASSES = List.of(XmlAccessOrder.class);
104102

105103
private static final DotName XML_ROOT_ELEMENT = DotName.createSimple(XmlRootElement.class.getName());
106104
private static final DotName XML_TYPE = DotName.createSimple(XmlType.class.getName());
@@ -110,10 +108,60 @@ class JaxbProcessor {
110108
private static final DotName XML_ANY_ELEMENT = DotName.createSimple(XmlAnyElement.class.getName());
111109
private static final DotName XML_SEE_ALSO = DotName.createSimple(XmlSeeAlso.class.getName());
112110

113-
private static final List<DotName> JAXB_ROOT_ANNOTATIONS = Arrays.asList(XML_ROOT_ELEMENT, XML_TYPE, XML_REGISTRY);
114-
115-
private static final List<DotName> IGNORE_TYPES = Collections
116-
.singletonList(DotName.createSimple("javax.xml.datatype.XMLGregorianCalendar"));
111+
private static final List<DotName> JAXB_ROOT_ANNOTATIONS = List.of(XML_ROOT_ELEMENT, XML_TYPE, XML_REGISTRY);
112+
113+
private static final List<DotName> IGNORE_TYPES = List.of(DotName.createSimple("javax.xml.datatype.XMLGregorianCalendar"));
114+
115+
private static final List<String> NATIVE_PROXY_DEFINITIONS = List.of(
116+
"com.sun.xml.bind.marshaller.CharacterEscapeHandler",
117+
"com.sun.xml.txw2.output.CharacterEscapeHandler",
118+
"com.sun.xml.bind.v2.schemagen.episode.Bindings",
119+
"com.sun.xml.bind.v2.schemagen.episode.SchemaBindings",
120+
"com.sun.xml.bind.v2.schemagen.episode.Klass",
121+
"com.sun.xml.bind.v2.schemagen.episode.Package",
122+
"com.sun.xml.bind.v2.schemagen.xmlschema.Annotated",
123+
"com.sun.xml.bind.v2.schemagen.xmlschema.Annotation",
124+
"com.sun.xml.bind.v2.schemagen.xmlschema.Any",
125+
"com.sun.xml.bind.v2.schemagen.xmlschema.Appinfo",
126+
"com.sun.xml.bind.v2.schemagen.xmlschema.AttrDecls",
127+
"com.sun.xml.bind.v2.schemagen.xmlschema.AttributeType",
128+
"com.sun.xml.bind.v2.schemagen.xmlschema.ComplexContent",
129+
"com.sun.xml.bind.v2.schemagen.xmlschema.ComplexExtension",
130+
"com.sun.xml.bind.v2.schemagen.xmlschema.ComplexRestriction",
131+
"com.sun.xml.bind.v2.schemagen.xmlschema.ComplexType",
132+
"com.sun.xml.bind.v2.schemagen.xmlschema.ComplexTypeHost",
133+
"com.sun.xml.bind.v2.schemagen.xmlschema.ComplexTypeModel",
134+
"com.sun.xml.bind.v2.schemagen.xmlschema.ContentModelContainer",
135+
"com.sun.xml.bind.v2.schemagen.xmlschema.Documentation",
136+
"com.sun.xml.bind.v2.schemagen.xmlschema.Element",
137+
"com.sun.xml.bind.v2.schemagen.xmlschema.ExplicitGroup",
138+
"com.sun.xml.bind.v2.schemagen.xmlschema.ExtensionType",
139+
"com.sun.xml.bind.v2.schemagen.xmlschema.FixedOrDefault",
140+
"com.sun.xml.bind.v2.schemagen.xmlschema.Import",
141+
"com.sun.xml.bind.v2.schemagen.xmlschema.List",
142+
"com.sun.xml.bind.v2.schemagen.xmlschema.LocalAttribute",
143+
"com.sun.xml.bind.v2.schemagen.xmlschema.LocalElement",
144+
"com.sun.xml.bind.v2.schemagen.xmlschema.NestedParticle",
145+
"com.sun.xml.bind.v2.schemagen.xmlschema.NoFixedFacet",
146+
"com.sun.xml.bind.v2.schemagen.xmlschema.Occurs",
147+
"com.sun.xml.bind.v2.schemagen.xmlschema.Particle",
148+
"com.sun.xml.bind.v2.schemagen.xmlschema.Redefinable",
149+
"com.sun.xml.bind.v2.schemagen.xmlschema.Schema",
150+
"com.sun.xml.bind.v2.schemagen.xmlschema.SchemaTop",
151+
"com.sun.xml.bind.v2.schemagen.xmlschema.SimpleContent",
152+
"com.sun.xml.bind.v2.schemagen.xmlschema.SimpleDerivation",
153+
"com.sun.xml.bind.v2.schemagen.xmlschema.SimpleExtension",
154+
"com.sun.xml.bind.v2.schemagen.xmlschema.SimpleRestriction",
155+
"com.sun.xml.bind.v2.schemagen.xmlschema.SimpleRestrictionModel",
156+
"com.sun.xml.bind.v2.schemagen.xmlschema.SimpleType",
157+
"com.sun.xml.bind.v2.schemagen.xmlschema.SimpleTypeHost",
158+
"com.sun.xml.bind.v2.schemagen.xmlschema.TopLevelAttribute",
159+
"com.sun.xml.bind.v2.schemagen.xmlschema.TopLevelElement",
160+
"com.sun.xml.bind.v2.schemagen.xmlschema.TypeDefParticle",
161+
"com.sun.xml.bind.v2.schemagen.xmlschema.TypeHost",
162+
"com.sun.xml.bind.v2.schemagen.xmlschema.Union",
163+
"com.sun.xml.bind.v2.schemagen.xmlschema.Wildcard",
164+
"com.sun.xml.txw2.TypedXmlWriter");
117165

118166
@BuildStep
119167
void processAnnotationsAndIndexFiles(
@@ -169,128 +217,27 @@ void processAnnotationsAndIndexFiles(
169217
JAXB_ANNOTATIONS.stream()
170218
.map(Class::getName)
171219
.forEach(className -> {
172-
proxyDefinitions.produce(new NativeImageProxyDefinitionBuildItem(className,
173-
"com.sun.xml.bind.v2.model.annotation.Locatable"));
174220
addReflectiveClass(reflectiveClass, true, false, className);
175221
});
176222

177-
proxyDefinitions
178-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.marshaller.CharacterEscapeHandler"));
179-
proxyDefinitions
180-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.txw2.output.CharacterEscapeHandler"));
181-
proxyDefinitions
182-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.v2.schemagen.episode.Bindings"));
183-
proxyDefinitions
184-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.v2.schemagen.episode.SchemaBindings"));
185-
proxyDefinitions
186-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.v2.schemagen.episode.Klass"));
187-
proxyDefinitions
188-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.v2.schemagen.episode.Package"));
189-
proxyDefinitions
190-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.v2.schemagen.xmlschema.Annotated"));
191-
proxyDefinitions
192-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.v2.schemagen.xmlschema.Annotation"));
193-
proxyDefinitions
194-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.v2.schemagen.xmlschema.Any"));
195-
proxyDefinitions
196-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.v2.schemagen.xmlschema.Appinfo"));
197-
proxyDefinitions
198-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.v2.schemagen.xmlschema.AttrDecls"));
199-
proxyDefinitions
200-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.v2.schemagen.xmlschema.AttributeType"));
201-
proxyDefinitions
202-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.v2.schemagen.xmlschema.ComplexContent"));
203-
proxyDefinitions
204-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.v2.schemagen.xmlschema.ComplexExtension"));
205-
proxyDefinitions
206-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.v2.schemagen.xmlschema.ComplexRestriction"));
207-
proxyDefinitions
208-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.v2.schemagen.xmlschema.ComplexType"));
209-
proxyDefinitions
210-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.v2.schemagen.xmlschema.ComplexTypeHost"));
211-
proxyDefinitions
212-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.v2.schemagen.xmlschema.ComplexTypeModel"));
213-
proxyDefinitions
214-
.produce(new NativeImageProxyDefinitionBuildItem(
215-
"com.sun.xml.bind.v2.schemagen.xmlschema.ContentModelContainer"));
216-
proxyDefinitions
217-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.v2.schemagen.xmlschema.Documentation"));
218-
proxyDefinitions
219-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.v2.schemagen.xmlschema.Element"));
220-
proxyDefinitions
221-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.v2.schemagen.xmlschema.ExplicitGroup"));
222-
proxyDefinitions
223-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.v2.schemagen.xmlschema.ExtensionType"));
224-
proxyDefinitions
225-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.v2.schemagen.xmlschema.FixedOrDefault"));
226-
proxyDefinitions
227-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.v2.schemagen.xmlschema.Import"));
228-
proxyDefinitions
229-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.v2.schemagen.xmlschema.List"));
230-
proxyDefinitions
231-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.v2.schemagen.xmlschema.LocalAttribute"));
232-
proxyDefinitions
233-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.v2.schemagen.xmlschema.LocalElement"));
234-
proxyDefinitions
235-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.v2.schemagen.xmlschema.NestedParticle"));
236-
proxyDefinitions
237-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.v2.schemagen.xmlschema.NoFixedFacet"));
238-
proxyDefinitions
239-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.v2.schemagen.xmlschema.Occurs"));
240-
proxyDefinitions
241-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.v2.schemagen.xmlschema.Particle"));
242-
proxyDefinitions
243-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.v2.schemagen.xmlschema.Redefinable"));
244-
proxyDefinitions
245-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.v2.schemagen.xmlschema.Schema"));
246-
proxyDefinitions
247-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.v2.schemagen.xmlschema.SchemaTop"));
248-
proxyDefinitions
249-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.v2.schemagen.xmlschema.SimpleContent"));
250-
proxyDefinitions
251-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.v2.schemagen.xmlschema.SimpleDerivation"));
252-
proxyDefinitions
253-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.v2.schemagen.xmlschema.SimpleExtension"));
254-
proxyDefinitions
255-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.v2.schemagen.xmlschema.SimpleRestriction"));
256-
proxyDefinitions
257-
.produce(new NativeImageProxyDefinitionBuildItem(
258-
"com.sun.xml.bind.v2.schemagen.xmlschema.SimpleRestrictionModel"));
259-
proxyDefinitions
260-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.v2.schemagen.xmlschema.SimpleType"));
261-
proxyDefinitions
262-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.v2.schemagen.xmlschema.SimpleTypeHost"));
263-
proxyDefinitions
264-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.v2.schemagen.xmlschema.TopLevelAttribute"));
265-
proxyDefinitions
266-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.v2.schemagen.xmlschema.TopLevelElement"));
267-
proxyDefinitions
268-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.v2.schemagen.xmlschema.TypeDefParticle"));
269-
proxyDefinitions
270-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.v2.schemagen.xmlschema.TypeHost"));
271-
proxyDefinitions
272-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.v2.schemagen.xmlschema.Union"));
273-
proxyDefinitions
274-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.bind.v2.schemagen.xmlschema.Wildcard"));
275-
proxyDefinitions
276-
.produce(new NativeImageProxyDefinitionBuildItem("com.sun.xml.txw2.TypedXmlWriter"));
277-
278-
for (JaxbFileRootBuildItem i : fileRoots) {
279-
iterateResources(applicationArchivesBuildItem, i.getFileRoot(), resource, reflectiveClass);
280-
}
281-
}
282-
283-
@BuildStep
284-
void seeAlso(CombinedIndexBuildItem combinedIndexBuildItem,
285-
BuildProducer<ReflectiveClassBuildItem> reflectiveItems) {
286-
IndexView index = combinedIndexBuildItem.getIndex();
223+
// Register @XmlSeeAlso
224+
proxyDefinitions.produce(new NativeImageProxyDefinitionBuildItem(XmlSeeAlso.class.getName(),
225+
"com.sun.xml.bind.v2.model.annotation.Locatable"));
287226
for (AnnotationInstance xmlSeeAlsoAnn : index.getAnnotations(XML_SEE_ALSO)) {
288227
AnnotationValue value = xmlSeeAlsoAnn.value();
289228
Type[] types = value.asClassArray();
290229
for (Type t : types) {
291-
reflectiveItems.produce(new ReflectiveClassBuildItem(false, false, t.name().toString()));
230+
addReflectiveClass(reflectiveClass, false, false, t.name().toString());
292231
}
293232
}
233+
// Register Native proxy definitions
234+
for (String s : NATIVE_PROXY_DEFINITIONS) {
235+
proxyDefinitions.produce(new NativeImageProxyDefinitionBuildItem(s));
236+
}
237+
238+
for (JaxbFileRootBuildItem i : fileRoots) {
239+
iterateResources(applicationArchivesBuildItem, i.getFileRoot(), resource, reflectiveClass);
240+
}
294241
}
295242

296243
@BuildStep

extensions/jaxb/runtime/src/main/java/io/quarkus/jaxb/runtime/graal/JAXBSubstitutions.java

Lines changed: 64 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,17 @@
33
import java.lang.annotation.Annotation;
44
import java.lang.reflect.Field;
55
import java.lang.reflect.Method;
6+
import java.util.HashMap;
7+
import java.util.Map;
68

9+
import javax.xml.bind.annotation.XmlSeeAlso;
10+
11+
import com.oracle.svm.core.annotate.Alias;
12+
import com.oracle.svm.core.annotate.RecomputeFieldValue;
713
import com.oracle.svm.core.annotate.Substitute;
814
import com.oracle.svm.core.annotate.TargetClass;
15+
import com.sun.xml.bind.v2.model.annotation.Locatable;
16+
import com.sun.xml.bind.v2.model.annotation.LocatableAnnotation;
917

1018
@TargetClass(className = "com.sun.xml.bind.v2.model.nav.ReflectionNavigator")
1119
final class Target_com_sun_xml_bind_v2_model_nav_ReflectionNavigator {
@@ -45,24 +53,72 @@ public static Class<?> prepare(
4553

4654
}
4755

48-
@TargetClass(className = "com.sun.xml.bind.v2.model.annotation.LocatableAnnotation")
49-
final class Target_com_sun_xml_bind_v2_model_annotation_LocatableAnnotation {
56+
@TargetClass(className = "com.sun.xml.bind.v2.model.annotation.RuntimeInlineAnnotationReader")
57+
final class Target_com_sun_xml_bind_v2_model_annotation_RuntimeInlineAnnotationReader {
58+
59+
@Alias
60+
@RecomputeFieldValue(kind = RecomputeFieldValue.Kind.FromAlias)
61+
private Map<Class<? extends Annotation>, Map<Package, Annotation>> packageCache = new HashMap<>();
62+
63+
@Substitute
64+
public <A extends Annotation> A getFieldAnnotation(Class<A> annotation, Field field, Locatable srcPos) {
65+
return field.getAnnotation(annotation);
66+
}
5067

5168
@Substitute
52-
public static <A extends Annotation> A create(A annotation, Locatable parentSourcePos) {
53-
return annotation;
69+
public Annotation[] getAllFieldAnnotations(Field field, Locatable srcPos) {
70+
return field.getAnnotations();
5471
}
5572

5673
@Substitute
57-
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
58-
throw new RuntimeException("Not implemented");
74+
public <A extends Annotation> A getMethodAnnotation(Class<A> annotation, Method method, Locatable srcPos) {
75+
return method.getAnnotation(annotation);
5976
}
6077

61-
@TargetClass(className = "com.sun.xml.bind.v2.model.annotation.Locatable")
62-
static final class Locatable {
78+
@Substitute
79+
public Annotation[] getAllMethodAnnotations(Method method, Locatable srcPos) {
80+
return method.getAnnotations();
81+
}
6382

83+
@Substitute
84+
@SuppressWarnings("unchecked")
85+
public <A extends Annotation> A getMethodParameterAnnotation(Class<A> annotation, Method method, int paramIndex,
86+
Locatable srcPos) {
87+
Annotation[] pa = method.getParameterAnnotations()[paramIndex];
88+
for (Annotation a : pa) {
89+
if (a.annotationType() == annotation)
90+
return (A) a;
91+
}
92+
return null;
6493
}
6594

95+
@Substitute
96+
public <A extends Annotation> A getClassAnnotation(Class<A> a, Class clazz, Locatable srcPos) {
97+
A ann = ((Class<?>) clazz).getAnnotation(a);
98+
return (ann != null && ann.annotationType() == XmlSeeAlso.class) ? LocatableAnnotation.create(ann, srcPos) : ann;
99+
}
100+
101+
@Substitute
102+
@SuppressWarnings("unchecked")
103+
public <A extends Annotation> A getPackageAnnotation(Class<A> a, Class clazz, Locatable srcPos) {
104+
Package p = clazz.getPackage();
105+
if (p == null)
106+
return null;
107+
108+
Map<Package, Annotation> cache = packageCache.get(a);
109+
if (cache == null) {
110+
cache = new HashMap<>();
111+
packageCache.put(a, cache);
112+
}
113+
114+
if (cache.containsKey(p))
115+
return (A) cache.get(p);
116+
else {
117+
A ann = p.getAnnotation(a);
118+
cache.put(p, ann);
119+
return ann;
120+
}
121+
}
66122
}
67123

68124
class JAXBSubstitutions {
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
//
2+
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.3.2
3+
// See <a href="https://javaee.github.io/jaxb-v2/">https://javaee.github.io/jaxb-v2/</a>
4+
// Any modifications to this file will be lost upon recompilation of the source schema.
5+
// Generated on: 2022.05.27 at 03:05:42 PM BRT
6+
//
7+
8+
package io.quarkus.it.jaxb;
9+
10+
import javax.xml.bind.annotation.XmlAccessType;
11+
import javax.xml.bind.annotation.XmlAccessorType;
12+
import javax.xml.bind.annotation.XmlSeeAlso;
13+
import javax.xml.bind.annotation.XmlType;
14+
15+
/**
16+
* <p>
17+
* Java class for BaseObj complex type.
18+
*
19+
* <p>
20+
* The following schema fragment specifies the expected content contained within this class.
21+
*
22+
* <pre>
23+
* &lt;complexType name="BaseObj"&gt;
24+
* &lt;complexContent&gt;
25+
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
26+
* &lt;sequence&gt;
27+
* &lt;element name="zeep" type="{http://www.w3.org/2001/XMLSchema}int"/&gt;
28+
* &lt;/sequence&gt;
29+
* &lt;/restriction&gt;
30+
* &lt;/complexContent&gt;
31+
* &lt;/complexType&gt;
32+
* </pre>
33+
*
34+
*
35+
*/
36+
@XmlAccessorType(XmlAccessType.FIELD)
37+
@XmlType(name = "BaseObj", propOrder = {
38+
"zeep"
39+
})
40+
@XmlSeeAlso({
41+
ExtensionOfBaseObj.class
42+
})
43+
public class BaseObj {
44+
45+
protected int zeep;
46+
47+
/**
48+
* Gets the value of the zeep property.
49+
*
50+
*/
51+
public int getZeep() {
52+
return zeep;
53+
}
54+
55+
/**
56+
* Sets the value of the zeep property.
57+
*
58+
*/
59+
public void setZeep(int value) {
60+
this.zeep = value;
61+
}
62+
63+
}

0 commit comments

Comments
 (0)