Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class DevToolsHomePropertiesPostProcessor implements EnvironmentPostProce
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
if (DevToolsEnablementDeducer.shouldEnable(Thread.currentThread())) {
File home = getHomeFolder();
File home = getProjectRootFolder();
File propertyFile = (home != null) ? new File(home, FILE_NAME) : null;
if (propertyFile != null && propertyFile.exists() && propertyFile.isFile()) {
FileSystemResource resource = new FileSystemResource(propertyFile);
Expand All @@ -61,6 +61,17 @@ public void postProcessEnvironment(ConfigurableEnvironment environment, SpringAp
}
}

protected File getProjectRootFolder() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems a breaking change.
When PropertyFile of HomeFolder have a property which not exist in ProjectRootFolder, after this change the property will be invalid.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is a breaking change as you have to opt in to looking in the new location by setting that system property or environment variable.

String rootFolder = System.getenv("PROJECT_ROOT_FOLDER");
if (rootFolder == null) {
rootFolder = System.getProperty("PROJECT_ROOT_FOLDER");
}
if (StringUtils.hasLength(rootFolder)) {
return new File(rootFolder);
}
return getHomeFolder();
}

protected File getHomeFolder() {
String home = System.getProperty("user.home");
if (StringUtils.hasLength(home)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,26 @@ class DevToolsHomePropertiesPostProcessorTests {

private File home;

private File rootDir;

@BeforeEach
void setup(@TempDir File tempDir) throws IOException {
void setup(@TempDir File tempDir, @TempDir File rootDir) throws IOException {
this.home = tempDir;
this.rootDir = rootDir;
}

@Test
void loadsRootFolderProperties() throws Exception {
System.setProperty("PROJECT_ROOT_FOLDER", rootDir.getAbsolutePath());
Properties properties = new Properties();
properties.put("uvw", "xyz");
OutputStream out = new FileOutputStream(new File(this.rootDir, ".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
Expand Down