Attempt to fix Windows CI test failure
This commit is contained in:
parent
57179c0d3d
commit
07415e1603
|
@ -520,8 +520,7 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor,
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
String name = (location.contains("*")) ? "applicationConfig: [" + resource.toString() + "]"
|
String name = "applicationConfig: [" + getLocationName(location, resource) + "]";
|
||||||
: "applicationConfig: [" + location + "]";
|
|
||||||
List<Document> documents = loadDocuments(loader, name, resource);
|
List<Document> documents = loadDocuments(loader, name, resource);
|
||||||
if (CollectionUtils.isEmpty(documents)) {
|
if (CollectionUtils.isEmpty(documents)) {
|
||||||
if (this.logger.isTraceEnabled()) {
|
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) {
|
private Resource[] getResources(String location) {
|
||||||
try {
|
try {
|
||||||
if (location.contains("*")) {
|
if (location.contains("*")) {
|
||||||
String directoryPath = location.substring(0, location.indexOf("*/"));
|
return getResourcesFromPatternLocation(location);
|
||||||
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 new Resource[] { this.resourceLoader.getResource(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) {
|
private void addIncludedProfiles(Set<Profile> includeProfiles) {
|
||||||
LinkedList<Profile> existingProfiles = new LinkedList<>(this.profiles);
|
LinkedList<Profile> existingProfiles = new LinkedList<>(this.profiles);
|
||||||
this.profiles.clear();
|
this.profiles.clear();
|
||||||
|
|
|
@ -1085,10 +1085,12 @@ class ConfigFileApplicationListenerTests {
|
||||||
List<String> sources = this.environment.getPropertySources().stream()
|
List<String> sources = this.environment.getPropertySources().stream()
|
||||||
.filter((source) -> source.getName().contains("applicationConfig")).map((source) -> {
|
.filter((source) -> source.getName().contains("applicationConfig")).map((source) -> {
|
||||||
String name = source.getName();
|
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());
|
}).collect(Collectors.toList());
|
||||||
assertThat(sources).containsExactly("src/test/resources/config/1-first/testproperties.properties]]",
|
assertThat(sources).containsExactly("src/test/resources/config/1-first/testproperties.properties",
|
||||||
"src/test/resources/config/2-second/testproperties.properties]]");
|
"src/test/resources/config/2-second/testproperties.properties");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue