Allow additional paths that trigger a reload/restart to be configured

Previously, only folders on the classpath would be watched and used
to trigger a restart/reload of the application. This commit adds a
new property spring.devtools.restart.additional-paths that can be
used to configure additional paths that should be watched for
changes. When a change occurs in one of those paths a restart or
reload will be triggered, depending on the full restart exclude
patterns configured via the existing spring.devtools.restart.exclude
property.

Closes gh-3469
This commit is contained in:
Andy Wilkinson
2015-08-05 11:44:26 +01:00
parent 2a5a32b603
commit 4a25bae143
5 changed files with 61 additions and 2 deletions

View File

@@ -16,6 +16,7 @@
package org.springframework.boot.devtools.autoconfigure;
import java.io.File;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -45,7 +46,9 @@ import org.springframework.util.SocketUtils;
import org.thymeleaf.templateresolver.TemplateResolver;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.any;
@@ -181,6 +184,24 @@ public class LocalDevToolsAutoConfigurationTests {
assertThat(filter, instanceOf(TriggerFileFilter.class));
}
@Test
public void watchingAdditionalPaths() throws Exception {
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("spring.devtools.restart.additional-paths",
"src/main/java,src/test/java");
this.context = initializeAndRun(Config.class, properties);
ClassPathFileSystemWatcher classPathWatcher = this.context
.getBean(ClassPathFileSystemWatcher.class);
Object watcher = ReflectionTestUtils.getField(classPathWatcher,
"fileSystemWatcher");
@SuppressWarnings("unchecked")
Map<File, Object> folders = (Map<File, Object>) ReflectionTestUtils.getField(
watcher, "folders");
assertThat(folders.size(), is(equalTo(2)));
assertThat(folders, hasKey(new File("src/main/java").getAbsoluteFile()));
assertThat(folders, hasKey(new File("src/test/java").getAbsoluteFile()));
}
private ConfigurableApplicationContext initializeAndRun(Class<?> config) {
return initializeAndRun(config, Collections.<String, Object> emptyMap());
}