Make dev tools' home directory configurable

This allows separate projects to keep their own settings where common
settings such as spring.* or server.* don't conflict.

See gh-17924
This commit is contained in:
sfeldstein
2019-08-20 14:13:11 -07:00
committed by Andy Wilkinson
parent 48db35bf8d
commit b9dbfad473
2 changed files with 31 additions and 2 deletions

View File

@@ -47,9 +47,12 @@ class DevToolsHomePropertiesPostProcessorTests {
private File home;
private File rootDir;
@BeforeEach
void setup(@TempDir File tempDir) {
void setup(@TempDir File tempDir, @TempDir File rootDir) {
this.home = tempDir;
this.rootDir = rootDir;
this.configDir = this.home + "/.config/spring-boot/";
new File(this.configDir).mkdirs();
}
@@ -63,6 +66,21 @@ class DevToolsHomePropertiesPostProcessorTests {
assertThat(environment.getProperty("abc")).isEqualTo("def");
}
@Test
void loadsRootFolderProperties() throws Exception {
System.setProperty("PROJECT_ROOT_FOLDER", this.rootDir.getAbsolutePath());
Properties properties = new Properties();
properties.put("uvw", "xyz");
OutputStream out = new FileOutputStream(
new File(this.rootDir, ".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("uvw")).isEqualTo("xyz");
}
@Test
void loadsPropertiesFromConfigDirectoryUsingProperties() throws Exception {
Properties properties = new Properties();