Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix JAXB usage in native executables #3411

Merged
merged 1 commit into from
Aug 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters;

import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationTarget.Kind;
import org.jboss.jandex.DotName;
import org.jboss.jandex.IndexView;

import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
Expand Down Expand Up @@ -98,7 +100,14 @@ class JaxbProcessor {
"text",
"xml",
"unknown");
private static final DotName XML_ROOT = DotName.createSimple("javax.xml.bind.annotation.XmlRootElement");

private static final DotName XML_ROOT_ELEMENT = DotName.createSimple(XmlRootElement.class.getName());
private static final DotName XML_TYPE = DotName.createSimple(XmlType.class.getName());
private static final DotName XML_REGISTRY = DotName.createSimple(XmlRegistry.class.getName());
private static final DotName XML_SCHEMA = DotName.createSimple(XmlSchema.class.getName());
private static final DotName XML_JAVA_TYPE_ADAPTER = DotName.createSimple(XmlJavaTypeAdapter.class.getName());

private static final List<DotName> REGISTER_TYPE_FOR_REFLECTION_ANNOTATIONS = Arrays.asList(XML_TYPE, XML_REGISTRY);

@Inject
BuildProducer<ReflectiveClassBuildItem> reflectiveClass;
Expand All @@ -122,16 +131,44 @@ void process(BuildProducer<SubstrateSystemPropertyBuildItem> substrateProps,
return;
}

Collection<AnnotationInstance> xmlRoot = combinedIndexBuildItem.getIndex().getAnnotations(XML_ROOT);
for (AnnotationInstance i : xmlRoot) {
addReflectiveClass(false, true, i.target().asClass().name().toString());
IndexView index = combinedIndexBuildItem.getIndex();

Collection<AnnotationInstance> xmlRootElementInstances = index.getAnnotations(XML_ROOT_ELEMENT);
for (AnnotationInstance xmlRootElementInstance : xmlRootElementInstances) {
addReflectiveClass(true, true, xmlRootElementInstance.target().asClass().name().toString());
}
if (xmlRoot.isEmpty() &&
if (xmlRootElementInstances.isEmpty() &&
fileRoots.isEmpty()) {
return;
}

// Register classes for reflection based on JAXB annotations
for (DotName registerTypeAnnotation : REGISTER_TYPE_FOR_REFLECTION_ANNOTATIONS) {
for (AnnotationInstance registerTypeForReflectionAnnotationInstance : index
.getAnnotations(registerTypeAnnotation)) {
if (registerTypeForReflectionAnnotationInstance.target().kind() == Kind.CLASS) {
addReflectiveClass(true, true,
registerTypeForReflectionAnnotationInstance.target().asClass().name().toString());
}
}
}

// Register package-infos for reflection
for (AnnotationInstance xmlSchemaInstance : index.getAnnotations(XML_SCHEMA)) {
if (xmlSchemaInstance.target().kind() == Kind.CLASS) {
reflectiveClass.produce(
new ReflectiveClassBuildItem(false, false, xmlSchemaInstance.target().asClass().name().toString()));
}
}

// Register XML Java type adapters for reflection
for (AnnotationInstance xmlJavaTypeAdapterInstance : index.getAnnotations(XML_JAVA_TYPE_ADAPTER)) {
reflectiveClass.produce(
new ReflectiveClassBuildItem(true, true, xmlJavaTypeAdapterInstance.value().asClass().name().toString()));
}

addReflectiveClass(false, false, "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");
addReflectiveClass(false, false, "com.sun.org.apache.xerces.internal.jaxp.datatype.DatatypeFactoryImpl");
addReflectiveClass(false, false, "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl");
addReflectiveClass(false, false, "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl");
addReflectiveClass(true, false, "com.sun.xml.bind.v2.ContextFactory");
Expand Down
4 changes: 4 additions & 0 deletions integration-tests/main/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-elytron-security</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jaxb</artifactId>
</dependency>

<!-- JAX-RS -->
<dependency>
Expand Down
Loading