Commit 1528b6c2 authored by Phillip Webb's avatar Phillip Webb

Polish

parent 9568777d
...@@ -55,37 +55,45 @@ public class DevToolsHomePropertiesPostProcessor implements EnvironmentPostProce ...@@ -55,37 +55,45 @@ public class DevToolsHomePropertiesPostProcessor implements EnvironmentPostProce
@Override @Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
if (DevToolsEnablementDeducer.shouldEnable(Thread.currentThread())) { if (DevToolsEnablementDeducer.shouldEnable(Thread.currentThread())) {
List<PropertySource> propertySources = getPropertySources(); List<PropertySource<?>> propertySources = getPropertySources();
if (propertySources.isEmpty()) { if (propertySources.isEmpty()) {
addPropertySource(LEGACY_FILE_NAME, (file) -> "devtools-local", propertySources); addPropertySource(propertySources, LEGACY_FILE_NAME, (file) -> "devtools-local");
} }
propertySources.forEach((source) -> environment.getPropertySources().addFirst(source)); propertySources.forEach(environment.getPropertySources()::addFirst);
} }
} }
private List<PropertySource> getPropertySources() { private List<PropertySource<?>> getPropertySources() {
List<PropertySource> propertySources = new ArrayList<>(); List<PropertySource<?>> propertySources = new ArrayList<>();
for (String fileName : FILE_NAMES) { for (String fileName : FILE_NAMES) {
addPropertySource(CONFIG_PATH + fileName, (file) -> "devtools-local: [" + file.toURI() + "]", addPropertySource(propertySources, CONFIG_PATH + fileName, this::getPropertySourceName);
propertySources);
} }
return propertySources; return propertySources;
} }
private void addPropertySource(String fileName, Function<File, String> propertySourceName, private String getPropertySourceName(File file) {
List<PropertySource> propertySources) { return "devtools-local: [" + file.toURI() + "]";
Properties properties; }
private void addPropertySource(List<PropertySource<?>> propertySources, String fileName,
Function<File, String> propertySourceNamer) {
File home = getHomeFolder(); File home = getHomeFolder();
File propertyFile = (home != null) ? new File(home, fileName) : null; File file = (home != null) ? new File(home, fileName) : null;
if (propertyFile != null && propertyFile.exists() && propertyFile.isFile()) { FileSystemResource resource = (file != null) ? new FileSystemResource(file) : null;
FileSystemResource resource = new FileSystemResource(propertyFile); if (resource != null && resource.exists() && resource.isFile()) {
try { addPropertySource(propertySources, resource, propertySourceNamer);
properties = PropertiesLoaderUtils.loadProperties(resource); }
propertySources.add(new PropertiesPropertySource(propertySourceName.apply(propertyFile), properties)); }
}
catch (IOException ex) { private void addPropertySource(List<PropertySource<?>> propertySources, FileSystemResource resource,
throw new IllegalStateException("Unable to load " + fileName, ex); Function<File, String> propertySourceNamer) {
} try {
Properties properties = PropertiesLoaderUtils.loadProperties(resource);
String name = propertySourceNamer.apply(resource.getFile());
propertySources.add(new PropertiesPropertySource(name, properties));
}
catch (IOException ex) {
throw new IllegalStateException("Unable to load " + resource.getFilename(), ex);
} }
} }
......
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