Skip to content

Commit 07415e1

Browse files
committed
Attempt to fix Windows CI test failure
1 parent 57179c0 commit 07415e1

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -520,8 +520,7 @@ private void load(PropertySourceLoader loader, String location, Profile profile,
520520
}
521521
continue;
522522
}
523-
String name = (location.contains("*")) ? "applicationConfig: [" + resource.toString() + "]"
524-
: "applicationConfig: [" + location + "]";
523+
String name = "applicationConfig: [" + getLocationName(location, resource) + "]";
525524
List<Document> documents = loadDocuments(loader, name, resource);
526525
if (CollectionUtils.isEmpty(documents)) {
527526
if (this.logger.isTraceEnabled()) {
@@ -557,20 +556,20 @@ private void load(PropertySourceLoader loader, String location, Profile profile,
557556
}
558557
}
559558

559+
private String getLocationName(String location, Resource resource) {
560+
if (!location.contains("*")) {
561+
return location;
562+
}
563+
if (resource instanceof FileSystemResource) {
564+
return ((FileSystemResource) resource).getPath();
565+
}
566+
return resource.getDescription();
567+
}
568+
560569
private Resource[] getResources(String location) {
561570
try {
562571
if (location.contains("*")) {
563-
String directoryPath = location.substring(0, location.indexOf("*/"));
564-
String fileName = location.substring(location.lastIndexOf("/") + 1);
565-
Resource resource = this.resourceLoader.getResource(directoryPath);
566-
File[] files = resource.getFile().listFiles(File::isDirectory);
567-
if (files != null) {
568-
Arrays.sort(files, FILE_COMPARATOR);
569-
return Arrays.stream(files).map((file) -> file.listFiles((dir, name) -> name.equals(fileName)))
570-
.filter(Objects::nonNull).flatMap((Function<File[], Stream<File>>) Arrays::stream)
571-
.map(FileSystemResource::new).toArray(Resource[]::new);
572-
}
573-
return EMPTY_RESOURCES;
572+
return getResourcesFromPatternLocation(location);
574573
}
575574
return new Resource[] { this.resourceLoader.getResource(location) };
576575
}
@@ -579,6 +578,20 @@ private Resource[] getResources(String location) {
579578
}
580579
}
581580

581+
private Resource[] getResourcesFromPatternLocation(String location) throws IOException {
582+
String directoryPath = location.substring(0, location.indexOf("*/"));
583+
String fileName = location.substring(location.lastIndexOf("/") + 1);
584+
Resource resource = this.resourceLoader.getResource(directoryPath);
585+
File[] files = resource.getFile().listFiles(File::isDirectory);
586+
if (files != null) {
587+
Arrays.sort(files, FILE_COMPARATOR);
588+
return Arrays.stream(files).map((file) -> file.listFiles((dir, name) -> name.equals(fileName)))
589+
.filter(Objects::nonNull).flatMap((Function<File[], Stream<File>>) Arrays::stream)
590+
.map(FileSystemResource::new).toArray(Resource[]::new);
591+
}
592+
return EMPTY_RESOURCES;
593+
}
594+
582595
private void addIncludedProfiles(Set<Profile> includeProfiles) {
583596
LinkedList<Profile> existingProfiles = new LinkedList<>(this.profiles);
584597
this.profiles.clear();

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,10 +1085,12 @@ void locationsWithWildcardDirectoriesShouldSortAlphabeticallyBasedOnAbsolutePath
10851085
List<String> sources = this.environment.getPropertySources().stream()
10861086
.filter((source) -> source.getName().contains("applicationConfig")).map((source) -> {
10871087
String name = source.getName();
1088-
return name.substring(name.indexOf("src/test/resources"));
1088+
name = name.substring(name.indexOf("src/test/resources"));
1089+
name = name.substring(0, name.length() - 1);
1090+
return name;
10891091
}).collect(Collectors.toList());
1090-
assertThat(sources).containsExactly("src/test/resources/config/1-first/testproperties.properties]]",
1091-
"src/test/resources/config/2-second/testproperties.properties]]");
1092+
assertThat(sources).containsExactly("src/test/resources/config/1-first/testproperties.properties",
1093+
"src/test/resources/config/2-second/testproperties.properties");
10921094
}
10931095

10941096
@Test

0 commit comments

Comments
 (0)