Skip to content

Commit 53e0685

Browse files
committed
Merge branch '3.4.x'
2 parents 424d9b6 + 3531071 commit 53e0685

File tree

6 files changed

+43
-60
lines changed

6 files changed

+43
-60
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/io/ApplicationResourceLoader.java

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public static ResourceLoader get(ResourceLoader resourceLoader) {
153153
* class loader at the time this call is made.
154154
* @param resourceLoader the delegate resource loader
155155
* @param preferFileResolution if file based resolution is preferred when a suitable
156-
* {@link ResourceFilePathResolver} support the resource
156+
* {@link FilePathResolver} support the resource
157157
* @return a {@link ResourceLoader} instance
158158
* @since 3.4.1
159159
*/
@@ -182,8 +182,8 @@ private static ResourceLoader get(ResourceLoader resourceLoader, SpringFactories
182182
Assert.notNull(resourceLoader, "'resourceLoader' must not be null");
183183
Assert.notNull(springFactoriesLoader, "'springFactoriesLoader' must not be null");
184184
List<ProtocolResolver> protocolResolvers = springFactoriesLoader.load(ProtocolResolver.class);
185-
List<ResourceFilePathResolver> filePathResolvers = (preferFileResolution)
186-
? springFactoriesLoader.load(ResourceFilePathResolver.class) : Collections.emptyList();
185+
List<FilePathResolver> filePathResolvers = (preferFileResolution)
186+
? springFactoriesLoader.load(FilePathResolver.class) : Collections.emptyList();
187187
return new ProtocolResolvingResourceLoader(resourceLoader, protocolResolvers, filePathResolvers);
188188
}
189189

@@ -242,6 +242,28 @@ static ResourceLoader get(ClassLoader classLoader, Path workingDirectory) {
242242

243243
}
244244

245+
/**
246+
* Strategy interface registered in {@code spring.factories} and used by
247+
* {@link ApplicationResourceLoader} to determine the file path of loaded resource
248+
* when it can also be represented as a {@link FileSystemResource}.
249+
*
250+
* @author Phillip Webb
251+
* @since 3.4.5
252+
*/
253+
public interface FilePathResolver {
254+
255+
/**
256+
* Return the {@code path} of the given resource if it can also be represented as
257+
* a {@link FileSystemResource}.
258+
* @param location the location used to create the resource
259+
* @param resource the resource to check
260+
* @return the file path of the resource or {@code null} if the it is not possible
261+
* to represent the resource as a {@link FileSystemResource}.
262+
*/
263+
String resolveFilePath(String location, Resource resource);
264+
265+
}
266+
245267
/**
246268
* An application {@link Resource}.
247269
*/
@@ -272,10 +294,10 @@ private static class ProtocolResolvingResourceLoader implements ResourceLoader {
272294

273295
private final List<ProtocolResolver> protocolResolvers;
274296

275-
private final List<ResourceFilePathResolver> filePathResolvers;
297+
private final List<FilePathResolver> filePathResolvers;
276298

277299
ProtocolResolvingResourceLoader(ResourceLoader resourceLoader, List<ProtocolResolver> protocolResolvers,
278-
List<ResourceFilePathResolver> filePathResolvers) {
300+
List<FilePathResolver> filePathResolvers) {
279301
this.resourceLoader = resourceLoader;
280302
this.protocolResolvers = protocolResolvers;
281303
this.filePathResolvers = filePathResolvers;
@@ -297,12 +319,12 @@ public Resource getResource(String location) {
297319
}
298320
}
299321
Resource resource = this.resourceLoader.getResource(location);
300-
String fileSystemPath = getFileSystemPath(location, resource);
301-
return (fileSystemPath != null) ? new ApplicationResource(fileSystemPath) : resource;
322+
String filePath = getFilePath(location, resource);
323+
return (filePath != null) ? new ApplicationResource(filePath) : resource;
302324
}
303325

304-
private String getFileSystemPath(String location, Resource resource) {
305-
for (ResourceFilePathResolver filePathResolver : this.filePathResolvers) {
326+
private String getFilePath(String location, Resource resource) {
327+
for (FilePathResolver filePathResolver : this.filePathResolvers) {
306328
String filePath = filePathResolver.resolveFilePath(location, resource);
307329
if (filePath != null) {
308330
return filePath;

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/io/ClassPathResourceFilePathResolver.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@
1616

1717
package org.springframework.boot.io;
1818

19+
import org.springframework.boot.io.ApplicationResourceLoader.FilePathResolver;
1920
import org.springframework.core.io.ClassPathResource;
2021
import org.springframework.core.io.Resource;
2122
import org.springframework.core.io.ResourceLoader;
2223

2324
/**
24-
* {@link ResourceFilePathResolver} for {@link ClassPathResource}.
25+
* {@link FilePathResolver} for {@link ClassPathResource}.
2526
*
2627
* @author Phillip Webb
2728
*/
28-
class ClassPathResourceFilePathResolver implements ResourceFilePathResolver {
29+
class ClassPathResourceFilePathResolver implements ApplicationResourceLoader.FilePathResolver {
2930

3031
@Override
3132
public String resolveFilePath(String location, Resource resource) {

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/io/ResourceFilePathResolver.java

Lines changed: 0 additions & 42 deletions
This file was deleted.

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/context/ServletContextResourceFilePathResolver.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,18 @@
1616

1717
package org.springframework.boot.web.context;
1818

19-
import org.springframework.boot.io.ResourceFilePathResolver;
19+
import org.springframework.boot.io.ApplicationResourceLoader;
20+
import org.springframework.boot.io.ApplicationResourceLoader.FilePathResolver;
2021
import org.springframework.core.io.Resource;
2122
import org.springframework.util.ClassUtils;
2223
import org.springframework.web.context.support.ServletContextResource;
2324

2425
/**
25-
* {@link ResourceFilePathResolver} for {@link ServletContextResource}.
26+
* {@link FilePathResolver} for {@link ServletContextResource}.
2627
*
2728
* @author Phillip Webb
2829
*/
29-
class ServletContextResourceFilePathResolver implements ResourceFilePathResolver {
30+
class ServletContextResourceFilePathResolver implements ApplicationResourceLoader.FilePathResolver {
3031

3132
private static final String RESOURCE_CLASS_NAME = "org.springframework.web.context.support.ServletContextResource";
3233

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/context/FilteredReactiveWebContextResourceFilePathResolver.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@
1616

1717
package org.springframework.boot.web.reactive.context;
1818

19-
import org.springframework.boot.io.ResourceFilePathResolver;
19+
import org.springframework.boot.io.ApplicationResourceLoader;
20+
import org.springframework.boot.io.ApplicationResourceLoader.FilePathResolver;
2021
import org.springframework.core.io.Resource;
2122

2223
/**
23-
* {@link ResourceFilePathResolver} for {@link FilteredReactiveWebContextResource}.
24+
* {@link FilePathResolver} for {@link FilteredReactiveWebContextResource}.
2425
*
2526
* @author Dmytro Nosan
2627
*/
27-
class FilteredReactiveWebContextResourceFilePathResolver implements ResourceFilePathResolver {
28+
class FilteredReactiveWebContextResourceFilePathResolver implements ApplicationResourceLoader.FilePathResolver {
2829

2930
@Override
3031
public String resolveFilePath(String location, Resource resource) {

spring-boot-project/spring-boot/src/main/resources/META-INF/spring.factories

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ org.springframework.core.io.ProtocolResolver=\
109109
org.springframework.boot.io.Base64ProtocolResolver
110110

111111
# Resource File Path Resolvers
112-
org.springframework.boot.io.ResourceFilePathResolver=\
112+
org.springframework.boot.io.ApplicationResourceLoader$FilePathResolver=\
113113
org.springframework.boot.io.ClassPathResourceFilePathResolver,\
114114
org.springframework.boot.web.context.ServletContextResourceFilePathResolver,\
115115
org.springframework.boot.web.reactive.context.FilteredReactiveWebContextResourceFilePathResolver

0 commit comments

Comments
 (0)