Commit 07415e16 authored by Phillip Webb's avatar Phillip Webb

Attempt to fix Windows CI test failure

parent 57179c0d
......@@ -520,8 +520,7 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor,
}
continue;
}
String name = (location.contains("*")) ? "applicationConfig: [" + resource.toString() + "]"
: "applicationConfig: [" + location + "]";
String name = "applicationConfig: [" + getLocationName(location, resource) + "]";
List<Document> documents = loadDocuments(loader, name, resource);
if (CollectionUtils.isEmpty(documents)) {
if (this.logger.isTraceEnabled()) {
......@@ -557,20 +556,20 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor,
}
}
private String getLocationName(String location, Resource resource) {
if (!location.contains("*")) {
return location;
}
if (resource instanceof FileSystemResource) {
return ((FileSystemResource) resource).getPath();
}
return resource.getDescription();
}
private Resource[] getResources(String location) {
try {
if (location.contains("*")) {
String directoryPath = location.substring(0, location.indexOf("*/"));
String fileName = location.substring(location.lastIndexOf("/") + 1);
Resource resource = this.resourceLoader.getResource(directoryPath);
File[] files = resource.getFile().listFiles(File::isDirectory);
if (files != null) {
Arrays.sort(files, FILE_COMPARATOR);
return Arrays.stream(files).map((file) -> file.listFiles((dir, name) -> name.equals(fileName)))
.filter(Objects::nonNull).flatMap((Function<File[], Stream<File>>) Arrays::stream)
.map(FileSystemResource::new).toArray(Resource[]::new);
}
return EMPTY_RESOURCES;
return getResourcesFromPatternLocation(location);
}
return new Resource[] { this.resourceLoader.getResource(location) };
}
......@@ -579,6 +578,20 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor,
}
}
private Resource[] getResourcesFromPatternLocation(String location) throws IOException {
String directoryPath = location.substring(0, location.indexOf("*/"));
String fileName = location.substring(location.lastIndexOf("/") + 1);
Resource resource = this.resourceLoader.getResource(directoryPath);
File[] files = resource.getFile().listFiles(File::isDirectory);
if (files != null) {
Arrays.sort(files, FILE_COMPARATOR);
return Arrays.stream(files).map((file) -> file.listFiles((dir, name) -> name.equals(fileName)))
.filter(Objects::nonNull).flatMap((Function<File[], Stream<File>>) Arrays::stream)
.map(FileSystemResource::new).toArray(Resource[]::new);
}
return EMPTY_RESOURCES;
}
private void addIncludedProfiles(Set<Profile> includeProfiles) {
LinkedList<Profile> existingProfiles = new LinkedList<>(this.profiles);
this.profiles.clear();
......
......@@ -1085,10 +1085,12 @@ class ConfigFileApplicationListenerTests {
List<String> sources = this.environment.getPropertySources().stream()
.filter((source) -> source.getName().contains("applicationConfig")).map((source) -> {
String name = source.getName();
return name.substring(name.indexOf("src/test/resources"));
name = name.substring(name.indexOf("src/test/resources"));
name = name.substring(0, name.length() - 1);
return name;
}).collect(Collectors.toList());
assertThat(sources).containsExactly("src/test/resources/config/1-first/testproperties.properties]]",
"src/test/resources/config/2-second/testproperties.properties]]");
assertThat(sources).containsExactly("src/test/resources/config/1-first/testproperties.properties",
"src/test/resources/config/2-second/testproperties.properties");
}
@Test
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment