Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
00a3ad0f
Commit
00a3ad0f
authored
Aug 19, 2019
by
HaiTao Zhang
Committed by
Madhura Bhave
Aug 23, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added support for devtools YAML configuration
See gh-17915
parent
b43827d6
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
164 additions
and
13 deletions
+164
-13
DevToolsHomePropertiesPostProcessor.java
...oot/devtools/env/DevToolsHomePropertiesPostProcessor.java
+31
-12
DevToolsHomePropertiesPostProcessorTests.java
...evtools/env/DevToolsHomePropertiesPostProcessorTests.java
+133
-1
No files found.
spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/env/DevToolsHomePropertiesPostProcessor.java
View file @
00a3ad0f
...
...
@@ -19,6 +19,7 @@ package org.springframework.boot.devtools.env;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.Properties
;
import
java.util.logging.Logger
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.devtools.DevToolsEnablementDeducer
;
...
...
@@ -35,29 +36,47 @@ import org.springframework.util.StringUtils;
*
* @author Phillip Webb
* @author Andy Wilkinson
* @author HaiTao Zhang
* @since 1.3.0
*/
public
class
DevToolsHomePropertiesPostProcessor
implements
EnvironmentPostProcessor
{
private
static
final
String
FILE_NAME
=
".spring-boot-devtools.properties"
;
private
static
final
String
[]
FILE_NAMES
=
new
String
[]
{
".spring-boot-devtools.yml"
,
".spring-boot-devtools.yaml"
,
".spring-boot-devtools.properties"
};
private
Logger
logger
=
Logger
.
getLogger
(
getClass
().
getName
());
@Override
public
void
postProcessEnvironment
(
ConfigurableEnvironment
environment
,
SpringApplication
application
)
{
if
(
DevToolsEnablementDeducer
.
shouldEnable
(
Thread
.
currentThread
()))
{
File
home
=
getHomeFolder
();
File
propertyFile
=
(
home
!=
null
)
?
new
File
(
home
,
FILE_NAME
)
:
null
;
Properties
properties
=
processDir
(
home
,
"/.config/spring-boot/"
,
environment
);
if
(
properties
.
isEmpty
())
{
processDir
(
home
,
""
,
environment
);
}
}
}
private
Properties
processDir
(
File
home
,
String
configPath
,
ConfigurableEnvironment
environment
)
{
Properties
properties
=
new
Properties
();
for
(
String
fileName
:
FILE_NAMES
)
{
File
propertyFile
=
(
home
!=
null
)
?
new
File
(
home
,
configPath
+
fileName
)
:
null
;
if
(
propertyFile
!=
null
&&
propertyFile
.
exists
()
&&
propertyFile
.
isFile
())
{
addProperty
(
propertyFile
,
environment
,
fileName
,
properties
);
}
}
return
properties
;
}
private
void
addProperty
(
File
propertyFile
,
ConfigurableEnvironment
environment
,
String
fileName
,
Properties
properties
)
{
FileSystemResource
resource
=
new
FileSystemResource
(
propertyFile
);
Properties
properties
;
try
{
properties
=
PropertiesLoaderUtils
.
loadProperties
(
resource
);
environment
.
getPropertySources
()
.
addFirst
(
new
PropertiesPropertySource
(
"devtools-local"
,
properties
));
PropertiesLoaderUtils
.
fillProperties
(
properties
,
resource
);
environment
.
getPropertySources
().
addFirst
(
new
PropertiesPropertySource
(
"devtools-local"
,
properties
));
}
catch
(
IOException
ex
)
{
throw
new
IllegalStateException
(
"Unable to load "
+
FILE_NAME
,
ex
);
}
}
throw
new
IllegalStateException
(
"Unable to load "
+
fileName
,
ex
);
}
}
...
...
spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/env/DevToolsHomePropertiesPostProcessorTests.java
View file @
00a3ad0f
...
...
@@ -36,6 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Phillip Webb
* @author Andy Wilkinson
* @author HaiTao Zhang
*/
class
DevToolsHomePropertiesPostProcessorTests
{
...
...
@@ -47,7 +48,7 @@ class DevToolsHomePropertiesPostProcessorTests {
}
@Test
void
loads
Home
Properties
()
throws
Exception
{
void
loads
PropertiesFromHomeFolderUsing
Properties
()
throws
Exception
{
Properties
properties
=
new
Properties
();
properties
.
put
(
"abc"
,
"def"
);
OutputStream
out
=
new
FileOutputStream
(
new
File
(
this
.
home
,
".spring-boot-devtools.properties"
));
...
...
@@ -59,6 +60,137 @@ class DevToolsHomePropertiesPostProcessorTests {
assertThat
(
environment
.
getProperty
(
"abc"
)).
isEqualTo
(
"def"
);
}
@Test
void
loadsPropertiesFromHomeFolderUsingYml
()
throws
Exception
{
Properties
properties
=
new
Properties
();
properties
.
put
(
"abc"
,
"def"
);
OutputStream
out
=
new
FileOutputStream
(
new
File
(
this
.
home
,
".spring-boot-devtools.yml"
));
properties
.
store
(
out
,
null
);
out
.
close
();
ConfigurableEnvironment
environment
=
new
MockEnvironment
();
MockDevToolHomePropertiesPostProcessor
postProcessor
=
new
MockDevToolHomePropertiesPostProcessor
();
runPostProcessor
(()
->
postProcessor
.
postProcessEnvironment
(
environment
,
null
));
assertThat
(
environment
.
getProperty
(
"abc"
)).
isEqualTo
(
"def"
);
}
@Test
void
loadsPropertiesFromHomeFolderUsingYaml
()
throws
Exception
{
Properties
properties
=
new
Properties
();
properties
.
put
(
"abc"
,
"def"
);
OutputStream
out
=
new
FileOutputStream
(
new
File
(
this
.
home
,
".spring-boot-devtools.yaml"
));
properties
.
store
(
out
,
null
);
out
.
close
();
ConfigurableEnvironment
environment
=
new
MockEnvironment
();
MockDevToolHomePropertiesPostProcessor
postProcessor
=
new
MockDevToolHomePropertiesPostProcessor
();
runPostProcessor
(()
->
postProcessor
.
postProcessEnvironment
(
environment
,
null
));
assertThat
(
environment
.
getProperty
(
"abc"
)).
isEqualTo
(
"def"
);
}
@Test
void
loadsPropertiesFromConfigFolderUsingProperties
()
throws
Exception
{
Properties
properties
=
new
Properties
();
new
File
(
this
.
home
+
"/.config/spring-boot"
).
mkdirs
();
properties
.
put
(
"abc"
,
"def"
);
OutputStream
out
=
new
FileOutputStream
(
new
File
(
this
.
home
+
"/.config/spring-boot"
,
".spring-boot-devtools.properties"
));
properties
.
store
(
out
,
null
);
out
.
close
();
ConfigurableEnvironment
environment
=
new
MockEnvironment
();
MockDevToolHomePropertiesPostProcessor
postProcessor
=
new
MockDevToolHomePropertiesPostProcessor
();
runPostProcessor
(()
->
postProcessor
.
postProcessEnvironment
(
environment
,
null
));
assertThat
(
environment
.
getProperty
(
"abc"
)).
isEqualTo
(
"def"
);
}
@Test
void
loadsPropertiesFromConfigFolderUsingYml
()
throws
Exception
{
Properties
properties
=
new
Properties
();
new
File
(
this
.
home
+
"/.config/spring-boot"
).
mkdirs
();
properties
.
put
(
"abc"
,
"def"
);
OutputStream
out
=
new
FileOutputStream
(
new
File
(
this
.
home
+
"/.config/spring-boot"
,
".spring-boot-devtools.yml"
));
properties
.
store
(
out
,
null
);
out
.
close
();
ConfigurableEnvironment
environment
=
new
MockEnvironment
();
MockDevToolHomePropertiesPostProcessor
postProcessor
=
new
MockDevToolHomePropertiesPostProcessor
();
runPostProcessor
(()
->
postProcessor
.
postProcessEnvironment
(
environment
,
null
));
assertThat
(
environment
.
getProperty
(
"abc"
)).
isEqualTo
(
"def"
);
}
@Test
void
loadsPropertiesFromConfigFolderUsingYaml
()
throws
Exception
{
Properties
properties
=
new
Properties
();
new
File
(
this
.
home
+
"/.config/spring-boot"
).
mkdirs
();
properties
.
put
(
"abc"
,
"def"
);
OutputStream
out
=
new
FileOutputStream
(
new
File
(
this
.
home
+
"/.config/spring-boot"
,
".spring-boot-devtools.yaml"
));
properties
.
store
(
out
,
null
);
out
.
close
();
ConfigurableEnvironment
environment
=
new
MockEnvironment
();
MockDevToolHomePropertiesPostProcessor
postProcessor
=
new
MockDevToolHomePropertiesPostProcessor
();
runPostProcessor
(()
->
postProcessor
.
postProcessEnvironment
(
environment
,
null
));
assertThat
(
environment
.
getProperty
(
"abc"
)).
isEqualTo
(
"def"
);
}
@Test
void
loadFromConfigFolderWithPropertiesTakingPrecedence
()
throws
Exception
{
Properties
properties
=
new
Properties
();
properties
.
put
(
"abc"
,
"def"
);
new
File
(
this
.
home
+
"/.config/spring-boot"
).
mkdirs
();
OutputStream
out
=
new
FileOutputStream
(
new
File
(
this
.
home
+
"/.config/spring-boot/"
,
".spring-boot-devtools.yaml"
));
properties
.
store
(
out
,
null
);
out
.
close
();
Properties
properties2
=
new
Properties
();
properties2
.
put
(
"abc"
,
"jkl"
);
OutputStream
out2
=
new
FileOutputStream
(
new
File
(
this
.
home
+
"/.config/spring-boot/"
,
".spring-boot-devtools.properties"
));
properties2
.
store
(
out2
,
null
);
out2
.
close
();
ConfigurableEnvironment
environment
=
new
MockEnvironment
();
MockDevToolHomePropertiesPostProcessor
postProcessor
=
new
MockDevToolHomePropertiesPostProcessor
();
runPostProcessor
(()
->
postProcessor
.
postProcessEnvironment
(
environment
,
null
));
assertThat
(
environment
.
getProperty
(
"abc"
)).
isEqualTo
(
"jkl"
);
}
@Test
void
loadFromHomeFolderWithPropertiesTakingPrecedence
()
throws
Exception
{
Properties
properties
=
new
Properties
();
properties
.
put
(
"abc"
,
"def"
);
new
File
(
this
.
home
+
"/.config/spring-boot"
).
mkdirs
();
OutputStream
out
=
new
FileOutputStream
(
new
File
(
this
.
home
,
".spring-boot-devtools.yaml"
));
properties
.
store
(
out
,
null
);
out
.
close
();
Properties
properties2
=
new
Properties
();
properties2
.
put
(
"abc"
,
"jkl"
);
OutputStream
out2
=
new
FileOutputStream
(
new
File
(
this
.
home
,
".spring-boot-devtools.properties"
));
properties2
.
store
(
out2
,
null
);
out2
.
close
();
ConfigurableEnvironment
environment
=
new
MockEnvironment
();
MockDevToolHomePropertiesPostProcessor
postProcessor
=
new
MockDevToolHomePropertiesPostProcessor
();
runPostProcessor
(()
->
postProcessor
.
postProcessEnvironment
(
environment
,
null
));
assertThat
(
environment
.
getProperty
(
"abc"
)).
isEqualTo
(
"jkl"
);
}
@Test
void
loadFromConfigFolderTakesPrecedenceOverHomeFolder
()
throws
Exception
{
Properties
properties
=
new
Properties
();
properties
.
put
(
"abc"
,
"def"
);
new
File
(
this
.
home
+
"/.config/spring-boot"
).
mkdirs
();
OutputStream
out
=
new
FileOutputStream
(
new
File
(
this
.
home
,
".spring-boot-devtools.properties"
));
properties
.
store
(
out
,
null
);
out
.
close
();
Properties
properties2
=
new
Properties
();
properties2
.
put
(
"abc"
,
"jkl"
);
OutputStream
out2
=
new
FileOutputStream
(
new
File
(
this
.
home
+
"/.config/spring-boot/"
,
".spring-boot-devtools.properties"
));
properties2
.
store
(
out2
,
null
);
out2
.
close
();
ConfigurableEnvironment
environment
=
new
MockEnvironment
();
MockDevToolHomePropertiesPostProcessor
postProcessor
=
new
MockDevToolHomePropertiesPostProcessor
();
runPostProcessor
(()
->
postProcessor
.
postProcessEnvironment
(
environment
,
null
));
assertThat
(
environment
.
getProperty
(
"abc"
)).
isEqualTo
(
"jkl"
);
}
@Test
void
ignoresMissingHomeProperties
()
throws
Exception
{
ConfigurableEnvironment
environment
=
new
MockEnvironment
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment