Skip to content

Commit 7f7f458

Browse files
committed
Polish ResourceHintsPredicates
As of #28620, `ResourcePatternHint` exposes its `toRegex` method. The predicates should use it directly and mirror the exact matching behavior. See gh-28555
1 parent aa48dec commit 7f7f458

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

spring-core/src/main/java/org/springframework/aot/hint/ResourceHintsPredicates.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
*/
3131
public class ResourceHintsPredicates {
3232

33-
private static final ConcurrentLruCache<String, Pattern> CACHED_RESOURCE_PATTERNS = new ConcurrentLruCache<>(32, Pattern::compile);
33+
private static final ConcurrentLruCache<ResourcePatternHint, Pattern> CACHED_RESOURCE_PATTERNS = new ConcurrentLruCache<>(32, ResourcePatternHint::toRegex);
3434

3535
ResourceHintsPredicates() {
3636
}
@@ -80,12 +80,12 @@ public Predicate<RuntimeHints> forResource(String resourceName) {
8080
return hints -> hints.resources().resourcePatterns().reduce(ResourcePatternHints::merge)
8181
.map(hint -> {
8282
boolean isExcluded = hint.getExcludes().stream()
83-
.anyMatch(excluded -> CACHED_RESOURCE_PATTERNS.get(excluded.getPattern()).matcher(resourceName).matches());
83+
.anyMatch(excluded -> CACHED_RESOURCE_PATTERNS.get(excluded).matcher(resourceName).matches());
8484
if (isExcluded) {
8585
return false;
8686
}
8787
return hint.getIncludes().stream()
88-
.anyMatch(included -> CACHED_RESOURCE_PATTERNS.get(included.getPattern()).matcher(resourceName).matches());
88+
.anyMatch(included -> CACHED_RESOURCE_PATTERNS.get(included).matcher(resourceName).matches());
8989
}).orElse(false);
9090
}
9191

spring-core/src/test/java/org/springframework/aot/hint/ResourceHintsPredicatesTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void setup() {
4242

4343
@Test
4444
void resourcePatternMatchesResourceName() {
45-
this.runtimeHints.resources().registerPattern("/test/spring.*");
45+
this.runtimeHints.resources().registerPattern("/test/*");
4646
assertPredicateMatches(resources.forResource("/test/spring.properties"));
4747
}
4848

0 commit comments

Comments
 (0)