Skip to content

Commit

Permalink
Check the resource bundle is around before adding it to native image
Browse files Browse the repository at this point in the history
Fixes #21694

(cherry picked from commit 0a1eda3)
  • Loading branch information
gsmet committed Dec 22, 2021
1 parent 09ae969 commit 42bd800
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,28 @@ public void build(HibernateValidatorRecorder recorder, RecorderContext recorderC

@BuildStep
NativeImageConfigBuildItem nativeImageConfig() {
return NativeImageConfigBuildItem.builder()
.addResourceBundle(AbstractMessageInterpolator.DEFAULT_VALIDATION_MESSAGES)
.addResourceBundle(AbstractMessageInterpolator.USER_VALIDATION_MESSAGES)
.addResourceBundle(AbstractMessageInterpolator.CONTRIBUTOR_VALIDATION_MESSAGES)
.build();
List<String> potentialHibernateValidatorResourceBundles = List.of(
AbstractMessageInterpolator.DEFAULT_VALIDATION_MESSAGES,
AbstractMessageInterpolator.USER_VALIDATION_MESSAGES,
AbstractMessageInterpolator.CONTRIBUTOR_VALIDATION_MESSAGES);
List<String> userDefinedHibernateValidatorResourceBundles = new ArrayList<>();

for (String potentialHibernateValidatorResourceBundle : potentialHibernateValidatorResourceBundles) {
if (Thread.currentThread().getContextClassLoader().getResource(potentialHibernateValidatorResourceBundle) != null) {
userDefinedHibernateValidatorResourceBundles.add(potentialHibernateValidatorResourceBundle);
}
}

if (userDefinedHibernateValidatorResourceBundles.isEmpty()) {
return null;
}

NativeImageConfigBuildItem.Builder builder = NativeImageConfigBuildItem.builder();
for (String hibernateValidatorResourceBundle : userDefinedHibernateValidatorResourceBundles) {
builder.addResourceBundle(hibernateValidatorResourceBundle);
}

return builder.build();
}

@BuildStep
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public class ResteasyServerCommonProcessor {
private static final Logger log = Logger.getLogger("io.quarkus.resteasy");

private static final String JAX_RS_APPLICATION_PARAMETER_NAME = "javax.ws.rs.Application";
private static final String MESSAGES_RESOURCE_BUNDLE = "messages";

private static final DotName JSONB_ANNOTATION = DotName.createSimple("javax.json.bind.annotation.JsonbAnnotation");

Expand Down Expand Up @@ -181,8 +182,12 @@ static final class ResteasyConfig {

@BuildStep
NativeImageConfigBuildItem config() {
if (Thread.currentThread().getContextClassLoader().getResource(MESSAGES_RESOURCE_BUNDLE) == null) {
return null;
}

return NativeImageConfigBuildItem.builder()
.addResourceBundle("messages")
.addResourceBundle(MESSAGES_RESOURCE_BUNDLE)
.build();
}

Expand Down

0 comments on commit 42bd800

Please sign in to comment.