|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2022 the original author or authors. |
| 2 | + * Copyright 2002-2024 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
23 | 23 | import java.util.stream.Collectors;
|
24 | 24 | import java.util.stream.Stream;
|
25 | 25 |
|
| 26 | +import org.springframework.core.env.Environment; |
26 | 27 | import org.springframework.core.io.Resource;
|
27 | 28 | import org.springframework.core.io.ResourceLoader;
|
28 | 29 | import org.springframework.core.io.support.ResourcePatternUtils;
|
@@ -145,6 +146,28 @@ public static List<Resource> convertToResourceList(ResourceLoader resourceLoader
|
145 | 146 | return stream(resourceLoader, paths).collect(Collectors.toCollection(ArrayList::new));
|
146 | 147 | }
|
147 | 148 |
|
| 149 | + /** |
| 150 | + * Convert the supplied paths to a list of {@link Resource} handles using the given |
| 151 | + * {@link ResourceLoader} and {@link Environment}. |
| 152 | + * @param resourceLoader the {@code ResourceLoader} to use to convert the paths |
| 153 | + * @param environment the {@code Environment} to use to resolve property placeholders |
| 154 | + * in the paths |
| 155 | + * @param paths the paths to be converted |
| 156 | + * @return a new, mutable list of resources |
| 157 | + * @since 6.2 |
| 158 | + * @see #convertToResources(ResourceLoader, String...) |
| 159 | + * @see #convertToClasspathResourcePaths |
| 160 | + * @see Environment#resolveRequiredPlaceholders(String) |
| 161 | + */ |
| 162 | + public static List<Resource> convertToResourceList( |
| 163 | + ResourceLoader resourceLoader, Environment environment, String... paths) { |
| 164 | + |
| 165 | + return Arrays.stream(paths) |
| 166 | + .map(environment::resolveRequiredPlaceholders) |
| 167 | + .map(resourceLoader::getResource) |
| 168 | + .collect(Collectors.toCollection(ArrayList::new)); |
| 169 | + } |
| 170 | + |
148 | 171 | private static Stream<Resource> stream(ResourceLoader resourceLoader, String... paths) {
|
149 | 172 | return Arrays.stream(paths).map(resourceLoader::getResource);
|
150 | 173 | }
|
|
0 commit comments