Skip to content

Commit 1528b6c

Browse files
committed
Polish
1 parent 9568777 commit 1528b6c

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/env/DevToolsHomePropertiesPostProcessor.java

+28-20
Original file line numberDiff line numberDiff line change
@@ -55,37 +55,45 @@ public class DevToolsHomePropertiesPostProcessor implements EnvironmentPostProce
5555
@Override
5656
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
5757
if (DevToolsEnablementDeducer.shouldEnable(Thread.currentThread())) {
58-
List<PropertySource> propertySources = getPropertySources();
58+
List<PropertySource<?>> propertySources = getPropertySources();
5959
if (propertySources.isEmpty()) {
60-
addPropertySource(LEGACY_FILE_NAME, (file) -> "devtools-local", propertySources);
60+
addPropertySource(propertySources, LEGACY_FILE_NAME, (file) -> "devtools-local");
6161
}
62-
propertySources.forEach((source) -> environment.getPropertySources().addFirst(source));
62+
propertySources.forEach(environment.getPropertySources()::addFirst);
6363
}
6464
}
6565

66-
private List<PropertySource> getPropertySources() {
67-
List<PropertySource> propertySources = new ArrayList<>();
66+
private List<PropertySource<?>> getPropertySources() {
67+
List<PropertySource<?>> propertySources = new ArrayList<>();
6868
for (String fileName : FILE_NAMES) {
69-
addPropertySource(CONFIG_PATH + fileName, (file) -> "devtools-local: [" + file.toURI() + "]",
70-
propertySources);
69+
addPropertySource(propertySources, CONFIG_PATH + fileName, this::getPropertySourceName);
7170
}
7271
return propertySources;
7372
}
7473

75-
private void addPropertySource(String fileName, Function<File, String> propertySourceName,
76-
List<PropertySource> propertySources) {
77-
Properties properties;
74+
private String getPropertySourceName(File file) {
75+
return "devtools-local: [" + file.toURI() + "]";
76+
}
77+
78+
private void addPropertySource(List<PropertySource<?>> propertySources, String fileName,
79+
Function<File, String> propertySourceNamer) {
7880
File home = getHomeFolder();
79-
File propertyFile = (home != null) ? new File(home, fileName) : null;
80-
if (propertyFile != null && propertyFile.exists() && propertyFile.isFile()) {
81-
FileSystemResource resource = new FileSystemResource(propertyFile);
82-
try {
83-
properties = PropertiesLoaderUtils.loadProperties(resource);
84-
propertySources.add(new PropertiesPropertySource(propertySourceName.apply(propertyFile), properties));
85-
}
86-
catch (IOException ex) {
87-
throw new IllegalStateException("Unable to load " + fileName, ex);
88-
}
81+
File file = (home != null) ? new File(home, fileName) : null;
82+
FileSystemResource resource = (file != null) ? new FileSystemResource(file) : null;
83+
if (resource != null && resource.exists() && resource.isFile()) {
84+
addPropertySource(propertySources, resource, propertySourceNamer);
85+
}
86+
}
87+
88+
private void addPropertySource(List<PropertySource<?>> propertySources, FileSystemResource resource,
89+
Function<File, String> propertySourceNamer) {
90+
try {
91+
Properties properties = PropertiesLoaderUtils.loadProperties(resource);
92+
String name = propertySourceNamer.apply(resource.getFile());
93+
propertySources.add(new PropertiesPropertySource(name, properties));
94+
}
95+
catch (IOException ex) {
96+
throw new IllegalStateException("Unable to load " + resource.getFilename(), ex);
8997
}
9098
}
9199

0 commit comments

Comments
 (0)