@@ -52,49 +52,59 @@ public class DevToolsHomePropertiesPostProcessor implements EnvironmentPostProce
52
52
53
53
private static final String CONFIG_PATH = "/.config/spring-boot/" ;
54
54
55
+ private static final File HOME_FOLDER ;
56
+ static {
57
+ String home = System .getProperty ("user.home" );
58
+ HOME_FOLDER = StringUtils .hasLength (home ) ? new File (home ) : null ;
59
+ }
60
+
55
61
@ Override
56
62
public void postProcessEnvironment (ConfigurableEnvironment environment , SpringApplication application ) {
57
63
if (DevToolsEnablementDeducer .shouldEnable (Thread .currentThread ())) {
58
- List <PropertySource > propertySources = getPropertySources ();
64
+ List <PropertySource <?> > propertySources = getPropertySources ();
59
65
if (propertySources .isEmpty ()) {
60
- addPropertySource (LEGACY_FILE_NAME , (file ) -> "devtools-local" , propertySources );
66
+ addPropertySource (propertySources , LEGACY_FILE_NAME , (file ) -> "devtools-local" );
61
67
}
62
- propertySources .forEach (( source ) -> environment .getPropertySources (). addFirst ( source ) );
68
+ propertySources .forEach (environment .getPropertySources ():: addFirst );
63
69
}
64
70
}
65
71
66
- private List <PropertySource > getPropertySources () {
67
- List <PropertySource > propertySources = new ArrayList <>();
72
+ private List <PropertySource <?> > getPropertySources () {
73
+ List <PropertySource <?> > propertySources = new ArrayList <>();
68
74
for (String fileName : FILE_NAMES ) {
69
- addPropertySource (CONFIG_PATH + fileName , (file ) -> "devtools-local: [" + file .toURI () + "]" ,
70
- propertySources );
75
+ addPropertySource (propertySources , CONFIG_PATH + fileName , this ::getPropertySourceName );
71
76
}
72
77
return propertySources ;
73
78
}
74
79
75
- private void addPropertySource (String fileName , Function <File , String > propertySourceName ,
76
- List <PropertySource > propertySources ) {
77
- Properties properties ;
80
+ private String getPropertySourceName (File file ) {
81
+ return "devtools-local: [" + file .toURI () + "]" ;
82
+ }
83
+
84
+ private void addPropertySource (List <PropertySource <?>> propertySources , String fileName ,
85
+ Function <File , String > propertySourceNamer ) {
78
86
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
- }
87
+ File file = (home != null ) ? new File (home , fileName ) : null ;
88
+ FileSystemResource resource = (file != null ) ? new FileSystemResource (file ) : null ;
89
+ if (resource != null && resource .exists () && resource .isFile ()) {
90
+ addPropertySource (propertySources , resource , propertySourceNamer );
89
91
}
90
92
}
91
93
92
- protected File getHomeFolder () {
93
- String home = System .getProperty ("user.home" );
94
- if (StringUtils .hasLength (home )) {
95
- return new File (home );
94
+ private void addPropertySource (List <PropertySource <?>> propertySources , FileSystemResource resource ,
95
+ Function <File , String > propertySourceNamer ) {
96
+ try {
97
+ Properties properties = PropertiesLoaderUtils .loadProperties (resource );
98
+ String name = propertySourceNamer .apply (resource .getFile ());
99
+ propertySources .add (new PropertiesPropertySource (name , properties ));
100
+ }
101
+ catch (IOException ex ) {
102
+ throw new IllegalStateException ("Unable to load " + resource .getFilename (), ex );
96
103
}
97
- return null ;
104
+ }
105
+
106
+ protected File getHomeFolder () {
107
+ return HOME_FOLDER ;
98
108
}
99
109
100
110
}
0 commit comments