Skip to content

Commit 9c559d4

Browse files
fix: #40342 Add static locations for livereload
1 parent 97a62cd commit 9c559d4

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsProperties.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
*
3131
* @author Phillip Webb
3232
* @author Stephane Nicoll
33+
* @author Akshay Dubey
3334
* @since 1.3.0
3435
*/
3536
@ConfigurationProperties(prefix = "spring.devtools")
@@ -198,6 +199,22 @@ public static class Livereload {
198199
*/
199200
private int port = 35729;
200201

202+
/**
203+
* Additional paths to watch for changes.
204+
*/
205+
private List<File> additionalPaths = new ArrayList<>();
206+
207+
/**
208+
* Amount of time to wait between polling for classpath changes.
209+
*/
210+
private Duration pollInterval = Duration.ofSeconds(1);
211+
212+
/**
213+
* Amount of quiet time required without any classpath changes before a reload is
214+
* triggered.
215+
*/
216+
private Duration quietPeriod = Duration.ofMillis(400);
217+
201218
public boolean isEnabled() {
202219
return this.enabled;
203220
}
@@ -214,6 +231,30 @@ public void setPort(int port) {
214231
this.port = port;
215232
}
216233

234+
public List<File> getAdditionalPaths() {
235+
return this.additionalPaths;
236+
}
237+
238+
public void setAdditionalPaths(List<File> additionalPaths) {
239+
this.additionalPaths = additionalPaths;
240+
}
241+
242+
public Duration getPollInterval() {
243+
return this.pollInterval;
244+
}
245+
246+
public void setPollInterval(Duration pollInterval) {
247+
this.pollInterval = pollInterval;
248+
}
249+
250+
public Duration getQuietPeriod() {
251+
return this.quietPeriod;
252+
}
253+
254+
public void setQuietPeriod(Duration quietPeriod) {
255+
this.quietPeriod = quietPeriod;
256+
}
257+
217258
}
218259

219260
}

spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.commons.logging.Log;
2424
import org.apache.commons.logging.LogFactory;
2525

26+
import org.springframework.beans.factory.DisposableBean;
2627
import org.springframework.boot.autoconfigure.AutoConfiguration;
2728
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
2829
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
@@ -57,6 +58,7 @@
5758
* @author Phillip Webb
5859
* @author Andy Wilkinson
5960
* @author Vladimir Tsanev
61+
* @author Akshay Dubey
6062
* @since 1.3.0
6163
*/
6264
@AutoConfiguration
@@ -89,6 +91,21 @@ LiveReloadServerEventListener liveReloadServerEventListener(OptionalLiveReloadSe
8991
return new LiveReloadServerEventListener(liveReloadServer);
9092
}
9193

94+
@Bean
95+
LiveReloadForAdditionalPaths liveReloadForAdditionalPaths(LiveReloadServer liveReloadServer,
96+
DevToolsProperties properties, FileSystemWatcher fileSystemWatcher) {
97+
return new LiveReloadForAdditionalPaths(liveReloadServer,
98+
properties.getLivereload().getAdditionalPaths(),fileSystemWatcher);
99+
}
100+
101+
@Bean
102+
FileSystemWatcher fileSystemWatcher(DevToolsProperties properties) {
103+
return new FileSystemWatcher(true,
104+
properties.getLivereload().getPollInterval(),
105+
properties.getLivereload().getQuietPeriod()
106+
);
107+
}
108+
92109
}
93110

94111
/**
@@ -216,4 +233,27 @@ public void onApplicationEvent(ClassPathChangedEvent event) {
216233

217234
}
218235

236+
static class LiveReloadForAdditionalPaths implements DisposableBean {
237+
238+
private final FileSystemWatcher fileSystemWatcher;
239+
240+
@Override
241+
public void destroy() throws Exception {
242+
if(this.fileSystemWatcher!=null)
243+
this.fileSystemWatcher.stop();
244+
}
245+
246+
public LiveReloadForAdditionalPaths( LiveReloadServer liveReloadServer, List<File> staticLocations, FileSystemWatcher fileSystemWatcher) {
247+
this.fileSystemWatcher = fileSystemWatcher;
248+
249+
for (File path : staticLocations) {
250+
this.fileSystemWatcher.addSourceDirectory(path.getAbsoluteFile());
251+
}
252+
253+
this.fileSystemWatcher.addListener(__ -> liveReloadServer.triggerReload());
254+
255+
this.fileSystemWatcher.start();
256+
}
257+
}
258+
219259
}

0 commit comments

Comments
 (0)