@@ -55,37 +55,45 @@ public class DevToolsHomePropertiesPostProcessor implements EnvironmentPostProce
55
55
@ Override
56
56
public void postProcessEnvironment (ConfigurableEnvironment environment , SpringApplication application ) {
57
57
if (DevToolsEnablementDeducer .shouldEnable (Thread .currentThread ())) {
58
- List <PropertySource > propertySources = getPropertySources ();
58
+ List <PropertySource <?> > propertySources = getPropertySources ();
59
59
if (propertySources .isEmpty ()) {
60
- addPropertySource (LEGACY_FILE_NAME , (file ) -> "devtools-local" , propertySources );
60
+ addPropertySource (propertySources , LEGACY_FILE_NAME , (file ) -> "devtools-local" );
61
61
}
62
- propertySources .forEach (( source ) -> environment .getPropertySources (). addFirst ( source ) );
62
+ propertySources .forEach (environment .getPropertySources ():: addFirst );
63
63
}
64
64
}
65
65
66
- private List <PropertySource > getPropertySources () {
67
- List <PropertySource > propertySources = new ArrayList <>();
66
+ private List <PropertySource <?> > getPropertySources () {
67
+ List <PropertySource <?> > propertySources = new ArrayList <>();
68
68
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 );
71
70
}
72
71
return propertySources ;
73
72
}
74
73
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 ) {
78
80
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 );
89
97
}
90
98
}
91
99
0 commit comments