Skip to content

Commit 7c4594c

Browse files
committed
Merge branch '6.2.x'
# Conflicts: # spring-core/src/main/java/org/springframework/aot/hint/ResourceHints.java # spring-core/src/main/java/org/springframework/aot/hint/support/FilePatternResourceHintsRegistrar.java
2 parents 1aea698 + 634d1dd commit 7c4594c

File tree

4 files changed

+33
-30
lines changed

4 files changed

+33
-30
lines changed

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,6 +28,7 @@
2828

2929
import org.springframework.core.io.ClassPathResource;
3030
import org.springframework.core.io.Resource;
31+
import org.springframework.util.ClassUtils;
3132

3233
/**
3334
* Gather the need for resources available at runtime.
@@ -51,14 +52,14 @@ public ResourceHints() {
5152
this.resourceBundleHints = new LinkedHashSet<>();
5253
}
5354

55+
5456
/**
5557
* Return the resources that should be made available at runtime.
5658
* @return a stream of {@link ResourcePatternHints}
5759
*/
5860
public Stream<ResourcePatternHints> resourcePatternHints() {
5961
Stream<ResourcePatternHints> patterns = this.resourcePatternHints.stream();
60-
return (this.types.isEmpty() ? patterns
61-
: Stream.concat(Stream.of(typesPatternResourceHint()), patterns));
62+
return (this.types.isEmpty() ? patterns : Stream.concat(Stream.of(typesPatternResourceHint()), patterns));
6263
}
6364

6465
/**
@@ -71,18 +72,18 @@ public Stream<ResourceBundleHint> resourceBundleHints() {
7172

7273
/**
7374
* Register a pattern if the given {@code location} is available on the
74-
* classpath. This delegates to {@link ClassLoader#getResource(String)}
75-
* which validates directories as well. The location is not included in
76-
* the hint.
77-
* @param classLoader the classloader to use
75+
* classpath. This delegates to {@link ClassLoader#getResource(String)} which
76+
* validates directories as well. The location is not included in the hint.
77+
* @param classLoader the ClassLoader to use, or {@code null} for the default
7878
* @param location a '/'-separated path name that should exist
7979
* @param resourceHint a builder to customize the resource pattern
8080
* @return {@code this}, to facilitate method chaining
8181
*/
8282
public ResourceHints registerPatternIfPresent(@Nullable ClassLoader classLoader, String location,
8383
Consumer<ResourcePatternHints.Builder> resourceHint) {
84-
ClassLoader classLoaderToUse = (classLoader != null ? classLoader : getClass().getClassLoader());
85-
if (classLoaderToUse.getResource(location) != null) {
84+
85+
ClassLoader classLoaderToUse = (classLoader != null ? classLoader : ClassUtils.getDefaultClassLoader());
86+
if (classLoaderToUse != null && classLoaderToUse.getResource(location) != null) {
8687
registerPattern(resourceHint);
8788
}
8889
return this;

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -39,8 +39,7 @@ public interface RuntimeHintsRegistrar {
3939
/**
4040
* Contribute hints to the given {@link RuntimeHints} instance.
4141
* @param hints the hints contributed so far for the deployment unit
42-
* @param classLoader the classloader, or {@code null} if even the system
43-
* ClassLoader is not accessible
42+
* @param classLoader the ClassLoader to use, or {@code null} for the default
4443
*/
4544
void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader);
4645

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@
2424

2525
import org.springframework.aot.hint.ResourceHints;
2626
import org.springframework.util.Assert;
27+
import org.springframework.util.ClassUtils;
2728
import org.springframework.util.ResourceUtils;
2829

2930
/**
@@ -58,19 +59,21 @@ private FilePatternResourceHintsRegistrar(List<String> filePrefixes, List<String
5859

5960

6061
private void registerHints(ResourceHints hints, @Nullable ClassLoader classLoader) {
61-
ClassLoader classLoaderToUse = (classLoader != null ? classLoader : getClass().getClassLoader());
62-
List<String> includes = new ArrayList<>();
63-
for (String location : this.classpathLocations) {
64-
if (classLoaderToUse.getResource(location) != null) {
65-
for (String filePrefix : this.filePrefixes) {
66-
for (String fileExtension : this.fileExtensions) {
67-
includes.add(location + filePrefix + "*" + fileExtension);
62+
ClassLoader classLoaderToUse = (classLoader != null ? classLoader : ClassUtils.getDefaultClassLoader());
63+
if (classLoaderToUse != null) {
64+
List<String> includes = new ArrayList<>();
65+
for (String location : this.classpathLocations) {
66+
if (classLoaderToUse.getResource(location) != null) {
67+
for (String filePrefix : this.filePrefixes) {
68+
for (String fileExtension : this.fileExtensions) {
69+
includes.add(location + filePrefix + "*" + fileExtension);
70+
}
6871
}
6972
}
7073
}
71-
}
72-
if (!includes.isEmpty()) {
73-
hints.registerPattern(hint -> hint.includes(includes.toArray(String[]::new)));
74+
if (!includes.isEmpty()) {
75+
hints.registerPattern(hint -> hint.includes(includes.toArray(String[]::new)));
76+
}
7477
}
7578
}
7679

@@ -257,8 +260,7 @@ private FilePatternResourceHintsRegistrar build() {
257260
* classpath location that resolves against the {@code ClassLoader}, files
258261
* with the configured file prefixes and extensions are registered.
259262
* @param hints the hints contributed so far for the deployment unit
260-
* @param classLoader the classloader, or {@code null} if even the system
261-
* ClassLoader isn't accessible
263+
* @param classLoader the ClassLoader to use, or {@code null} for the default
262264
*/
263265
public void registerHints(ResourceHints hints, @Nullable ClassLoader classLoader) {
264266
build().registerHints(hints, classLoader);

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -48,10 +48,11 @@ class SpringFactoriesLoaderRuntimeHints implements RuntimeHintsRegistrar {
4848

4949
@Override
5050
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
51-
ClassLoader classLoaderToUse = (classLoader != null ? classLoader :
52-
SpringFactoriesLoaderRuntimeHints.class.getClassLoader());
53-
for (String resourceLocation : RESOURCE_LOCATIONS) {
54-
registerHints(hints, classLoaderToUse, resourceLocation);
51+
ClassLoader classLoaderToUse = (classLoader != null ? classLoader : ClassUtils.getDefaultClassLoader());
52+
if (classLoaderToUse != null) {
53+
for (String resourceLocation : RESOURCE_LOCATIONS) {
54+
registerHints(hints, classLoaderToUse, resourceLocation);
55+
}
5556
}
5657
}
5758

0 commit comments

Comments
 (0)