Attempt to fix Windows CI test failure

This commit is contained in:
Phillip Webb 2020-04-30 18:17:29 -07:00
parent 57179c0d3d
commit 07415e1603
2 changed files with 31 additions and 16 deletions

View File

@ -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,9 +556,29 @@ 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("*")) {
return getResourcesFromPatternLocation(location);
}
return new Resource[] { this.resourceLoader.getResource(location) };
}
catch (Exception ex) {
return EMPTY_RESOURCES;
}
}
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);
@ -572,12 +591,6 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor,
}
return EMPTY_RESOURCES;
}
return new Resource[] { this.resourceLoader.getResource(location) };
}
catch (Exception ex) {
return EMPTY_RESOURCES;
}
}
private void addIncludedProfiles(Set<Profile> includeProfiles) {
LinkedList<Profile> existingProfiles = new LinkedList<>(this.profiles);

View File

@ -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