diff --git a/extensions/jaxb/deployment/pom.xml b/extensions/jaxb/deployment/pom.xml index fc665ddc3fe65..a496418bac757 100644 --- a/extensions/jaxb/deployment/pom.xml +++ b/extensions/jaxb/deployment/pom.xml @@ -52,6 +52,13 @@ + + org.apache.maven.plugins + maven-surefire-plugin + + -Duser.language=en + + diff --git a/extensions/jaxb/deployment/src/main/java/io/quarkus/jaxb/deployment/JaxbProcessor.java b/extensions/jaxb/deployment/src/main/java/io/quarkus/jaxb/deployment/JaxbProcessor.java index 29255342e9a08..22ce22a0d4643 100644 --- a/extensions/jaxb/deployment/src/main/java/io/quarkus/jaxb/deployment/JaxbProcessor.java +++ b/extensions/jaxb/deployment/src/main/java/io/quarkus/jaxb/deployment/JaxbProcessor.java @@ -316,35 +316,19 @@ FilteredJaxbClassesToBeBoundBuildItem filterBoundClasses( @BuildStep @Record(ExecutionTime.STATIC_INIT) - void validateDefaultJaxbContext( + void bindClassesToJaxbContext( JaxbConfig config, FilteredJaxbClassesToBeBoundBuildItem filteredClassesToBeBound, SynthesisFinishedBuildItem beanContainerState, JaxbContextConfigRecorder jaxbContextConfig /* Force the build time container to invoke this method */) { - if (config.validateJaxbContext) { - final BeanResolver beanResolver = beanContainerState.getBeanResolver(); - final Set beans = beanResolver - .resolveBeans(Type.create(DotName.createSimple(JAXBContext.class), org.jboss.jandex.Type.Kind.CLASS)); - if (!beans.isEmpty()) { - jaxbContextConfig.addClassesToBeBound(filteredClassesToBeBound.getClasses()); - final BeanInfo bean = beanResolver.resolveAmbiguity(beans); - if (bean.isDefaultBean()) { - /* - * Validate the default JAXB context at build time and fail early. - * Do this only if the user application actually requires the default JAXBContext bean - */ - try { - JAXBContext.newInstance(filteredClassesToBeBound.getClasses().toArray(new Class[0])); - } catch (JAXBException e) { - /* - * Producing a ValidationErrorBuildItem would perhaps be more natural here, - * but doing so causes a cycle between this and reactive JAXB extension - * Throwing from here works well too - */ - throw new DeploymentException("Failed to create or validate the default JAXBContext", e); - } - } + final BeanResolver beanResolver = beanContainerState.getBeanResolver(); + final Set beans = beanResolver + .resolveBeans(Type.create(DotName.createSimple(JAXBContext.class), org.jboss.jandex.Type.Kind.CLASS)); + if (!beans.isEmpty()) { + jaxbContextConfig.addClassesToBeBound(filteredClassesToBeBound.getClasses()); + if (config.validateJaxbContext) { + validateJaxbContext(filteredClassesToBeBound, beanResolver, beans); } } } @@ -354,6 +338,27 @@ void registerProduces(BuildProducer additionalBeans) { additionalBeans.produce(new AdditionalBeanBuildItem(JaxbContextProducer.class)); } + private void validateJaxbContext(FilteredJaxbClassesToBeBoundBuildItem filteredClassesToBeBound, BeanResolver beanResolver, + Set beans) { + final BeanInfo bean = beanResolver.resolveAmbiguity(beans); + if (bean.isDefaultBean()) { + /* + * Validate the default JAXB context at build time and fail early. + * Do this only if the user application actually requires the default JAXBContext bean + */ + try { + JAXBContext.newInstance(filteredClassesToBeBound.getClasses().toArray(new Class[0])); + } catch (JAXBException e) { + /* + * Producing a ValidationErrorBuildItem would perhaps be more natural here, + * but doing so causes a cycle between this and reactive JAXB extension + * Throwing from here works well too + */ + throw new DeploymentException("Failed to create or validate the default JAXBContext", e); + } + } + } + private void handleJaxbFile(Path p, BuildProducer resource, BuildProducer reflectiveClass, List classesToBeBound) { diff --git a/extensions/jaxb/deployment/src/test/java/io/quarkus/jaxb/deployment/ConflictingModelClassesMarshalerOnlyTest.java b/extensions/jaxb/deployment/src/test/java/io/quarkus/jaxb/deployment/ConflictingModelClassesMarshalerOnlyTest.java index 14badfff6285f..8a04c217d2a37 100644 --- a/extensions/jaxb/deployment/src/test/java/io/quarkus/jaxb/deployment/ConflictingModelClassesMarshalerOnlyTest.java +++ b/extensions/jaxb/deployment/src/test/java/io/quarkus/jaxb/deployment/ConflictingModelClassesMarshalerOnlyTest.java @@ -26,6 +26,7 @@ public class ConflictingModelClassesMarshalerOnlyTest { @RegisterExtension static final QuarkusUnitTest config = new QuarkusUnitTest() + .withConfigurationResource("application-enable-validation.properties") .withApplicationRoot((jar) -> jar .addClasses( io.quarkus.jaxb.deployment.one.Model.class, diff --git a/extensions/jaxb/deployment/src/test/java/io/quarkus/jaxb/deployment/ConflictingModelClassesTest.java b/extensions/jaxb/deployment/src/test/java/io/quarkus/jaxb/deployment/ConflictingModelClassesTest.java index bcded32283401..1c7274481b75a 100644 --- a/extensions/jaxb/deployment/src/test/java/io/quarkus/jaxb/deployment/ConflictingModelClassesTest.java +++ b/extensions/jaxb/deployment/src/test/java/io/quarkus/jaxb/deployment/ConflictingModelClassesTest.java @@ -25,6 +25,7 @@ public class ConflictingModelClassesTest { @RegisterExtension static final QuarkusUnitTest config = new QuarkusUnitTest() + .withConfigurationResource("application-enable-validation.properties") .withApplicationRoot((jar) -> jar .addClasses( io.quarkus.jaxb.deployment.one.Model.class, diff --git a/extensions/jaxb/deployment/src/test/resources/application-enable-validation.properties b/extensions/jaxb/deployment/src/test/resources/application-enable-validation.properties new file mode 100644 index 0000000000000..ab8094de90586 --- /dev/null +++ b/extensions/jaxb/deployment/src/test/resources/application-enable-validation.properties @@ -0,0 +1 @@ +quarkus.jaxb.validate-jaxb-context=true \ No newline at end of file diff --git a/extensions/jaxb/runtime/src/main/java/io/quarkus/jaxb/runtime/JaxbConfig.java b/extensions/jaxb/runtime/src/main/java/io/quarkus/jaxb/runtime/JaxbConfig.java index bd2a0114e49e6..10aee70162135 100644 --- a/extensions/jaxb/runtime/src/main/java/io/quarkus/jaxb/runtime/JaxbConfig.java +++ b/extensions/jaxb/runtime/src/main/java/io/quarkus/jaxb/runtime/JaxbConfig.java @@ -13,7 +13,7 @@ public class JaxbConfig { /** * If enabled, it will validate the default JAXB context at build time. */ - @ConfigItem(defaultValue = "true") + @ConfigItem(defaultValue = "false") public boolean validateJaxbContext; /**