Skip to content

Commit 65a65ad

Browse files
authored
Merge pull request #158 from SentryMan/resources
Add JDK 22 support/fix custom bundle loading
2 parents e5ac72f + 5e87567 commit 65a65ad

File tree

7 files changed

+27
-9
lines changed

7 files changed

+27
-9
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>org.avaje</groupId>
77
<artifactId>java11-oss</artifactId>
8-
<version>3.10</version>
8+
<version>3.12</version>
99
</parent>
1010

1111
<groupId>io.avaje</groupId>

validator-generator/src/main/java/io/avaje/validation/generator/ValidationProcessor.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
9090
getElements(round, ValidMethodPrism.PRISM_TYPE)
9191
.map(ElementFilter::methodsIn)
9292
.ifPresent(this::writeParamProviderForMethod);
93-
94-
writeAdaptersForImported(
95-
round.getElementsAnnotatedWith(typeElement(ImportValidPojoPrism.PRISM_TYPE)));
93+
getElements(round, ImportValidPojoPrism.PRISM_TYPE).ifPresent(this::writeAdaptersForImported);
9694
initialiseComponent();
9795
cascadeTypes();
9896
writeComponent(round.processingOver());

validator-http-plugin/src/main/java/io/avaje/validation/http/BeanValidator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void validate(Object bean, String acceptLanguage, Class<?>... groups) thr
2929
}
3030

3131
@PostConstruct
32-
void setValidator(BeanScope scope) {
32+
public void setValidator(BeanScope scope) {
3333
this.validator = scope.get(Validator.class);
3434
}
3535

validator/pom.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@
1818
<artifactId>avaje-lang</artifactId>
1919
<version>1.0</version>
2020
</dependency>
21-
21+
22+
<dependency>
23+
<groupId>io.avaje</groupId>
24+
<artifactId>avaje-applog</artifactId>
25+
<version>1.0</version>
26+
</dependency>
27+
2228
<dependency>
2329
<groupId>io.avaje</groupId>
2430
<artifactId>avaje-validator-http-plugin</artifactId>

validator/src/main/java/io/avaje/validation/Validator.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,10 @@ interface Builder {
113113
/** Add a AnnotationValidationAdapter to use for the given type. */
114114
<T> Builder add(Class<? extends Annotation> type, ValidationAdapter<T> adapter);
115115

116-
/** Lookup ResourceBundles with the given names for error message interpolation */
116+
/**
117+
* Lookup ResourceBundles with the given names for error message interpolation. This will
118+
* attempt to load the bundles for every locale configured with this builder
119+
*/
117120
Builder addResourceBundles(String... bundleName);
118121

119122
/** Add ResourceBundles for error message interpolation */

validator/src/main/java/io/avaje/validation/core/ResourceBundleManager.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,21 @@
22

33
import static java.util.ResourceBundle.getBundle;
44

5+
import java.lang.System.Logger.Level;
56
import java.util.ArrayList;
67
import java.util.HashMap;
78
import java.util.List;
89
import java.util.Locale;
910
import java.util.Map;
11+
import java.util.MissingResourceException;
1012
import java.util.ResourceBundle;
1113

14+
import io.avaje.applog.AppLog;
1215
import io.avaje.lang.Nullable;
1316

1417
final class ResourceBundleManager {
15-
18+
private static final System.Logger logger =
19+
AppLog.getLogger(ResourceBundleManager.class);
1620
private final Map<Locale, List<ResourceBundle>> map = new HashMap<>();
1721
private static final List<ResourceBundle> EMPTY = List.of();
1822
private static final String DEFAULT_BUNDLE = "io.avaje.validation.Messages";
@@ -37,7 +41,13 @@ final class ResourceBundleManager {
3741
}
3842

3943
private void addBundle(final String name, final Locale locale) {
40-
map.computeIfAbsent(locale, key -> new ArrayList<>()).add(getBundle(name, locale));
44+
45+
try {
46+
map.computeIfAbsent(locale, key -> new ArrayList<>()).add(getBundle(name, locale));
47+
48+
} catch (MissingResourceException e) {
49+
logger.log(Level.ERROR, "failed to load " + name + " with locale " + locale);
50+
}
4151
}
4252

4353
@Nullable

validator/src/main/java/module-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
exports io.avaje.validation.spi;
55

66
requires io.avaje.lang;
7+
requires io.avaje.applog;
78
requires static io.avaje.inject;
89

910
uses io.avaje.validation.Validator.GeneratedComponent;

0 commit comments

Comments
 (0)