From 97a62cdd4af1dcc4c6bb67dc0ca4ba1b4ffbf835 Mon Sep 17 00:00:00 2001 From: Akshay Dubey <38462415+itsAkshayDubey@users.noreply.github.com> Date: Sat, 20 Jul 2024 11:56:08 +0000 Subject: [PATCH 01/10] test: Add unit test for #40342 --- .../LocalDevToolsAutoConfigurationTests.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfigurationTests.java b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfigurationTests.java index 478e6ff28388..99ed063ce14e 100644 --- a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfigurationTests.java @@ -37,6 +37,7 @@ import org.springframework.boot.autoconfigure.web.WebProperties; import org.springframework.boot.autoconfigure.web.WebProperties.Resources; import org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration; +import org.springframework.boot.devtools.autoconfigure.LocalDevToolsAutoConfiguration.LiveReloadForAdditionalPaths; import org.springframework.boot.devtools.classpath.ClassPathChangedEvent; import org.springframework.boot.devtools.classpath.ClassPathFileSystemWatcher; import org.springframework.boot.devtools.livereload.LiveReloadServer; @@ -70,6 +71,7 @@ * @author Phillip Webb * @author Andy Wilkinson * @author Vladimir Tsanev + * @author Akshay Dubey */ @ExtendWith(MockRestarter.class) class LocalDevToolsAutoConfigurationTests { @@ -213,6 +215,20 @@ void watchingAdditionalPaths() throws Exception { .containsKey(new File("src/test/java").getAbsoluteFile()); } + @Test + void watchingAdditionalPathsForReload() throws Exception { + Map properties = new HashMap<>(); + properties.put("spring.devtools.livereload.additional-paths", "src/main/java,src/test/java"); + this.context = getContext(() -> initializeAndRun(Config.class, properties)); + LiveReloadForAdditionalPaths liveReloadForAdditionalPaths = this.context.getBean(LiveReloadForAdditionalPaths.class); + Object watcher = ReflectionTestUtils.getField(liveReloadForAdditionalPaths, "fileSystemWatcher"); + @SuppressWarnings("unchecked") + Map directories = (Map) ReflectionTestUtils.getField(watcher, "directories"); + assertThat(directories).hasSize(2) + .containsKey(new File("src/main/java").getAbsoluteFile()) + .containsKey(new File("src/test/java").getAbsoluteFile()); + } + @Test void devToolsSwitchesJspServletToDevelopmentMode() throws Exception { this.context = getContext(() -> initializeAndRun(Config.class)); From 9c559d489609d9583ac9a0571dd4e30cd0e13f5c Mon Sep 17 00:00:00 2001 From: Akshay Dubey <38462415+itsAkshayDubey@users.noreply.github.com> Date: Sat, 20 Jul 2024 11:59:01 +0000 Subject: [PATCH 02/10] fix: #40342 Add static locations for livereload --- .../autoconfigure/DevToolsProperties.java | 41 +++++++++++++++++++ .../LocalDevToolsAutoConfiguration.java | 40 ++++++++++++++++++ 2 files changed, 81 insertions(+) diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsProperties.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsProperties.java index 2471f19136d1..aefcc8cee35b 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsProperties.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsProperties.java @@ -30,6 +30,7 @@ * * @author Phillip Webb * @author Stephane Nicoll + * @author Akshay Dubey * @since 1.3.0 */ @ConfigurationProperties(prefix = "spring.devtools") @@ -198,6 +199,22 @@ public static class Livereload { */ private int port = 35729; + /** + * Additional paths to watch for changes. + */ + private List additionalPaths = new ArrayList<>(); + + /** + * Amount of time to wait between polling for classpath changes. + */ + private Duration pollInterval = Duration.ofSeconds(1); + + /** + * Amount of quiet time required without any classpath changes before a reload is + * triggered. + */ + private Duration quietPeriod = Duration.ofMillis(400); + public boolean isEnabled() { return this.enabled; } @@ -214,6 +231,30 @@ public void setPort(int port) { this.port = port; } + public List getAdditionalPaths() { + return this.additionalPaths; + } + + public void setAdditionalPaths(List additionalPaths) { + this.additionalPaths = additionalPaths; + } + + public Duration getPollInterval() { + return this.pollInterval; + } + + public void setPollInterval(Duration pollInterval) { + this.pollInterval = pollInterval; + } + + public Duration getQuietPeriod() { + return this.quietPeriod; + } + + public void setQuietPeriod(Duration quietPeriod) { + this.quietPeriod = quietPeriod; + } + } } diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java index 86043b6b6ce7..925273010ed2 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java @@ -23,6 +23,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.beans.factory.DisposableBean; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -57,6 +58,7 @@ * @author Phillip Webb * @author Andy Wilkinson * @author Vladimir Tsanev + * @author Akshay Dubey * @since 1.3.0 */ @AutoConfiguration @@ -89,6 +91,21 @@ LiveReloadServerEventListener liveReloadServerEventListener(OptionalLiveReloadSe return new LiveReloadServerEventListener(liveReloadServer); } + @Bean + LiveReloadForAdditionalPaths liveReloadForAdditionalPaths(LiveReloadServer liveReloadServer, + DevToolsProperties properties, FileSystemWatcher fileSystemWatcher) { + return new LiveReloadForAdditionalPaths(liveReloadServer, + properties.getLivereload().getAdditionalPaths(),fileSystemWatcher); + } + + @Bean + FileSystemWatcher fileSystemWatcher(DevToolsProperties properties) { + return new FileSystemWatcher(true, + properties.getLivereload().getPollInterval(), + properties.getLivereload().getQuietPeriod() + ); + } + } /** @@ -216,4 +233,27 @@ public void onApplicationEvent(ClassPathChangedEvent event) { } + static class LiveReloadForAdditionalPaths implements DisposableBean { + + private final FileSystemWatcher fileSystemWatcher; + + @Override + public void destroy() throws Exception { + if(this.fileSystemWatcher!=null) + this.fileSystemWatcher.stop(); + } + + public LiveReloadForAdditionalPaths( LiveReloadServer liveReloadServer, List staticLocations, FileSystemWatcher fileSystemWatcher) { + this.fileSystemWatcher = fileSystemWatcher; + + for (File path : staticLocations) { + this.fileSystemWatcher.addSourceDirectory(path.getAbsoluteFile()); + } + + this.fileSystemWatcher.addListener(__ -> liveReloadServer.triggerReload()); + + this.fileSystemWatcher.start(); + } + } + } From 4d366f8bddd56ebfa98b96c22488ba9285d48567 Mon Sep 17 00:00:00 2001 From: Akshay Dubey <38462415+itsAkshayDubey@users.noreply.github.com> Date: Sat, 20 Jul 2024 13:46:31 +0000 Subject: [PATCH 03/10] style: Remove whitespaces --- .../LocalDevToolsAutoConfiguration.java | 37 +++++++++---------- .../LocalDevToolsAutoConfigurationTests.java | 24 ++++++------ 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java index 925273010ed2..df30814eeabc 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java @@ -95,15 +95,14 @@ LiveReloadServerEventListener liveReloadServerEventListener(OptionalLiveReloadSe LiveReloadForAdditionalPaths liveReloadForAdditionalPaths(LiveReloadServer liveReloadServer, DevToolsProperties properties, FileSystemWatcher fileSystemWatcher) { return new LiveReloadForAdditionalPaths(liveReloadServer, - properties.getLivereload().getAdditionalPaths(),fileSystemWatcher); + properties.getLivereload().getAdditionalPaths(),fileSystemWatcher); } @Bean - FileSystemWatcher fileSystemWatcher(DevToolsProperties properties) { - return new FileSystemWatcher(true, - properties.getLivereload().getPollInterval(), - properties.getLivereload().getQuietPeriod() - ); + FileSystemWatcher fileSystemWatcher(DevToolsProperties properties) { + return new FileSystemWatcher(true, + properties.getLivereload().getPollInterval(), + properties.getLivereload().getQuietPeriod()); } } @@ -233,27 +232,27 @@ public void onApplicationEvent(ClassPathChangedEvent event) { } - static class LiveReloadForAdditionalPaths implements DisposableBean { + static class LiveReloadForAdditionalPaths implements DisposableBean { private final FileSystemWatcher fileSystemWatcher; @Override - public void destroy() throws Exception { - if(this.fileSystemWatcher!=null) - this.fileSystemWatcher.stop(); - } + public void destroy() throws Exception { + if(this.fileSystemWatcher!=null) + this.fileSystemWatcher.stop(); + } - public LiveReloadForAdditionalPaths( LiveReloadServer liveReloadServer, List staticLocations, FileSystemWatcher fileSystemWatcher) { - this.fileSystemWatcher = fileSystemWatcher; + public LiveReloadForAdditionalPaths( LiveReloadServer liveReloadServer, List staticLocations, FileSystemWatcher fileSystemWatcher) { + this.fileSystemWatcher = fileSystemWatcher; - for (File path : staticLocations) { - this.fileSystemWatcher.addSourceDirectory(path.getAbsoluteFile()); - } + for (File path : staticLocations) { + this.fileSystemWatcher.addSourceDirectory(path.getAbsoluteFile()); + } - this.fileSystemWatcher.addListener(__ -> liveReloadServer.triggerReload()); + this.fileSystemWatcher.addListener(__ -> liveReloadServer.triggerReload()); - this.fileSystemWatcher.start(); - } + this.fileSystemWatcher.start(); + } } } diff --git a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfigurationTests.java b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfigurationTests.java index 99ed063ce14e..fd749c12de86 100644 --- a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfigurationTests.java @@ -216,18 +216,18 @@ void watchingAdditionalPaths() throws Exception { } @Test - void watchingAdditionalPathsForReload() throws Exception { - Map properties = new HashMap<>(); - properties.put("spring.devtools.livereload.additional-paths", "src/main/java,src/test/java"); - this.context = getContext(() -> initializeAndRun(Config.class, properties)); - LiveReloadForAdditionalPaths liveReloadForAdditionalPaths = this.context.getBean(LiveReloadForAdditionalPaths.class); - Object watcher = ReflectionTestUtils.getField(liveReloadForAdditionalPaths, "fileSystemWatcher"); - @SuppressWarnings("unchecked") - Map directories = (Map) ReflectionTestUtils.getField(watcher, "directories"); - assertThat(directories).hasSize(2) - .containsKey(new File("src/main/java").getAbsoluteFile()) - .containsKey(new File("src/test/java").getAbsoluteFile()); - } + void watchingAdditionalPathsForReload() throws Exception { + Map properties = new HashMap<>(); + properties.put("spring.devtools.livereload.additional-paths", "src/main/java,src/test/java"); + this.context = getContext(() -> initializeAndRun(Config.class, properties)); + LiveReloadForAdditionalPaths liveReloadForAdditionalPaths = this.context.getBean(LiveReloadForAdditionalPaths.class); + Object watcher = ReflectionTestUtils.getField(liveReloadForAdditionalPaths, "fileSystemWatcher"); + @SuppressWarnings("unchecked") + Map directories = (Map) ReflectionTestUtils.getField(watcher, "directories"); + assertThat(directories).hasSize(2) + .containsKey(new File("src/main/java").getAbsoluteFile()) + .containsKey(new File("src/test/java").getAbsoluteFile()); + } @Test void devToolsSwitchesJspServletToDevelopmentMode() throws Exception { From f38722936bdb10ad01a766e29786ef71945935f4 Mon Sep 17 00:00:00 2001 From: Akshay Dubey <38462415+itsAkshayDubey@users.noreply.github.com> Date: Sat, 20 Jul 2024 14:05:26 +0000 Subject: [PATCH 04/10] style: Fix checkstyle issues --- .../LocalDevToolsAutoConfiguration.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java index df30814eeabc..e2826937f9fb 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java @@ -95,7 +95,7 @@ LiveReloadServerEventListener liveReloadServerEventListener(OptionalLiveReloadSe LiveReloadForAdditionalPaths liveReloadForAdditionalPaths(LiveReloadServer liveReloadServer, DevToolsProperties properties, FileSystemWatcher fileSystemWatcher) { return new LiveReloadForAdditionalPaths(liveReloadServer, - properties.getLivereload().getAdditionalPaths(),fileSystemWatcher); + properties.getLivereload().getAdditionalPaths(), fileSystemWatcher); } @Bean @@ -238,18 +238,21 @@ static class LiveReloadForAdditionalPaths implements DisposableBean { @Override public void destroy() throws Exception { - if(this.fileSystemWatcher!=null) - this.fileSystemWatcher.stop(); + if (this.fileSystemWatcher != null) { + this.fileSystemWatcher.stop(); + } } - public LiveReloadForAdditionalPaths( LiveReloadServer liveReloadServer, List staticLocations, FileSystemWatcher fileSystemWatcher) { + LiveReloadForAdditionalPaths(LiveReloadServer liveReloadServer, List staticLocations, FileSystemWatcher fileSystemWatcher) { this.fileSystemWatcher = fileSystemWatcher; for (File path : staticLocations) { this.fileSystemWatcher.addSourceDirectory(path.getAbsoluteFile()); } - this.fileSystemWatcher.addListener(__ -> liveReloadServer.triggerReload()); + this.fileSystemWatcher.addListener(__ -> { + liveReloadServer.triggerReload(); + }); this.fileSystemWatcher.start(); } From 3365dafc2abdade4f7aaf2e28537106b2017be12 Mon Sep 17 00:00:00 2001 From: Akshay Dubey <38462415+itsAkshayDubey@users.noreply.github.com> Date: Sat, 20 Jul 2024 14:19:12 +0000 Subject: [PATCH 05/10] style: Fix checkstyle issues --- .../devtools/autoconfigure/LocalDevToolsAutoConfiguration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java index e2826937f9fb..4d75ffdac080 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java @@ -250,7 +250,7 @@ public void destroy() throws Exception { this.fileSystemWatcher.addSourceDirectory(path.getAbsoluteFile()); } - this.fileSystemWatcher.addListener(__ -> { + this.fileSystemWatcher.addListener((__) -> { liveReloadServer.triggerReload(); }); From 4533f29f24d6621c6b934146776b9e7ebe8e14bb Mon Sep 17 00:00:00 2001 From: Akshay Dubey <38462415+itsAkshayDubey@users.noreply.github.com> Date: Sat, 20 Jul 2024 14:24:59 +0000 Subject: [PATCH 06/10] style: Fix lambda block as per checkstyle --- .../autoconfigure/LocalDevToolsAutoConfiguration.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java index 4d75ffdac080..0e752691fd0f 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java @@ -250,9 +250,7 @@ public void destroy() throws Exception { this.fileSystemWatcher.addSourceDirectory(path.getAbsoluteFile()); } - this.fileSystemWatcher.addListener((__) -> { - liveReloadServer.triggerReload(); - }); + this.fileSystemWatcher.addListener((__) -> liveReloadServer.triggerReload()); this.fileSystemWatcher.start(); } From e710c0ab32d2dddfffacf24a5cb6683509e5eb62 Mon Sep 17 00:00:00 2001 From: Akshay Dubey <38462415+itsAkshayDubey@users.noreply.github.com> Date: Sat, 20 Jul 2024 14:51:21 +0000 Subject: [PATCH 07/10] style: Fix code formatting --- .../autoconfigure/LocalDevToolsAutoConfiguration.java | 11 ++++++----- .../LocalDevToolsAutoConfigurationTests.java | 3 ++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java index 0e752691fd0f..088c79ab9157 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java @@ -94,14 +94,13 @@ LiveReloadServerEventListener liveReloadServerEventListener(OptionalLiveReloadSe @Bean LiveReloadForAdditionalPaths liveReloadForAdditionalPaths(LiveReloadServer liveReloadServer, DevToolsProperties properties, FileSystemWatcher fileSystemWatcher) { - return new LiveReloadForAdditionalPaths(liveReloadServer, - properties.getLivereload().getAdditionalPaths(), fileSystemWatcher); + return new LiveReloadForAdditionalPaths(liveReloadServer, properties.getLivereload().getAdditionalPaths(), + fileSystemWatcher); } @Bean FileSystemWatcher fileSystemWatcher(DevToolsProperties properties) { - return new FileSystemWatcher(true, - properties.getLivereload().getPollInterval(), + return new FileSystemWatcher(true, properties.getLivereload().getPollInterval(), properties.getLivereload().getQuietPeriod()); } @@ -243,7 +242,8 @@ public void destroy() throws Exception { } } - LiveReloadForAdditionalPaths(LiveReloadServer liveReloadServer, List staticLocations, FileSystemWatcher fileSystemWatcher) { + LiveReloadForAdditionalPaths(LiveReloadServer liveReloadServer, List staticLocations, + FileSystemWatcher fileSystemWatcher) { this.fileSystemWatcher = fileSystemWatcher; for (File path : staticLocations) { @@ -254,6 +254,7 @@ public void destroy() throws Exception { this.fileSystemWatcher.start(); } + } } diff --git a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfigurationTests.java b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfigurationTests.java index fd749c12de86..d66f892b29e0 100644 --- a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfigurationTests.java @@ -220,7 +220,8 @@ void watchingAdditionalPathsForReload() throws Exception { Map properties = new HashMap<>(); properties.put("spring.devtools.livereload.additional-paths", "src/main/java,src/test/java"); this.context = getContext(() -> initializeAndRun(Config.class, properties)); - LiveReloadForAdditionalPaths liveReloadForAdditionalPaths = this.context.getBean(LiveReloadForAdditionalPaths.class); + LiveReloadForAdditionalPaths liveReloadForAdditionalPaths = this.context + .getBean(LiveReloadForAdditionalPaths.class); Object watcher = ReflectionTestUtils.getField(liveReloadForAdditionalPaths, "fileSystemWatcher"); @SuppressWarnings("unchecked") Map directories = (Map) ReflectionTestUtils.getField(watcher, "directories"); From c7e0a475a9c215e06eed1efc416eaa37c3fd5fdc Mon Sep 17 00:00:00 2001 From: Akshay Dubey Date: Thu, 5 Sep 2024 00:04:25 +0530 Subject: [PATCH 08/10] refactor: Fix file watcher for livereload --- .../autoconfigure/DevToolsProperties.java | 27 ------------------- .../LocalDevToolsAutoConfiguration.java | 5 ++-- 2 files changed, 2 insertions(+), 30 deletions(-) diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsProperties.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsProperties.java index aefcc8cee35b..eb22e301b698 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsProperties.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsProperties.java @@ -204,17 +204,6 @@ public static class Livereload { */ private List additionalPaths = new ArrayList<>(); - /** - * Amount of time to wait between polling for classpath changes. - */ - private Duration pollInterval = Duration.ofSeconds(1); - - /** - * Amount of quiet time required without any classpath changes before a reload is - * triggered. - */ - private Duration quietPeriod = Duration.ofMillis(400); - public boolean isEnabled() { return this.enabled; } @@ -239,22 +228,6 @@ public void setAdditionalPaths(List additionalPaths) { this.additionalPaths = additionalPaths; } - public Duration getPollInterval() { - return this.pollInterval; - } - - public void setPollInterval(Duration pollInterval) { - this.pollInterval = pollInterval; - } - - public Duration getQuietPeriod() { - return this.quietPeriod; - } - - public void setQuietPeriod(Duration quietPeriod) { - this.quietPeriod = quietPeriod; - } - } } diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java index 088c79ab9157..96c9f86305c5 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java @@ -99,9 +99,8 @@ LiveReloadForAdditionalPaths liveReloadForAdditionalPaths(LiveReloadServer liveR } @Bean - FileSystemWatcher fileSystemWatcher(DevToolsProperties properties) { - return new FileSystemWatcher(true, properties.getLivereload().getPollInterval(), - properties.getLivereload().getQuietPeriod()); + FileSystemWatcher fileSystemWatcher(DevToolsProperties properties, RestartConfiguration restartConfiguration) { + return restartConfiguration.newFileSystemWatcher(); } } From eabed2575c9fd0733786216deefe2bfa2bcc5929 Mon Sep 17 00:00:00 2001 From: Akshay Dubey Date: Fri, 6 Sep 2024 16:40:38 +0530 Subject: [PATCH 09/10] refactor: FileSystemWatcher bean configuration --- .../autoconfigure/DevToolsProperties.java | 27 +++++++++++++++++++ .../LocalDevToolsAutoConfiguration.java | 10 ++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsProperties.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsProperties.java index eb22e301b698..aefcc8cee35b 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsProperties.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsProperties.java @@ -204,6 +204,17 @@ public static class Livereload { */ private List additionalPaths = new ArrayList<>(); + /** + * Amount of time to wait between polling for classpath changes. + */ + private Duration pollInterval = Duration.ofSeconds(1); + + /** + * Amount of quiet time required without any classpath changes before a reload is + * triggered. + */ + private Duration quietPeriod = Duration.ofMillis(400); + public boolean isEnabled() { return this.enabled; } @@ -228,6 +239,22 @@ public void setAdditionalPaths(List additionalPaths) { this.additionalPaths = additionalPaths; } + public Duration getPollInterval() { + return this.pollInterval; + } + + public void setPollInterval(Duration pollInterval) { + this.pollInterval = pollInterval; + } + + public Duration getQuietPeriod() { + return this.quietPeriod; + } + + public void setQuietPeriod(Duration quietPeriod) { + this.quietPeriod = quietPeriod; + } + } } diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java index 96c9f86305c5..95222e32394d 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java @@ -26,6 +26,7 @@ import org.springframework.beans.factory.DisposableBean; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; @@ -99,7 +100,14 @@ LiveReloadForAdditionalPaths liveReloadForAdditionalPaths(LiveReloadServer liveR } @Bean - FileSystemWatcher fileSystemWatcher(DevToolsProperties properties, RestartConfiguration restartConfiguration) { + @ConditionalOnMissingBean(RestartConfiguration.class) + FileSystemWatcher newFileSystemWatcher(DevToolsProperties properties) { + return new FileSystemWatcher(true, properties.getLivereload().getPollInterval(), properties.getLivereload().getQuietPeriod()); + } + + @Bean + @ConditionalOnBean(RestartConfiguration.class) + FileSystemWatcher fileSystemWatcher(RestartConfiguration restartConfiguration) { return restartConfiguration.newFileSystemWatcher(); } From 2cd9a087f80e1743898c7d193da1a01704aba997 Mon Sep 17 00:00:00 2001 From: Akshay Dubey <38462415+itsAkshayDubey@users.noreply.github.com> Date: Fri, 6 Sep 2024 12:53:53 +0000 Subject: [PATCH 10/10] style: Fix styling --- .../devtools/autoconfigure/LocalDevToolsAutoConfiguration.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java index 95222e32394d..48cddaf34478 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java @@ -102,7 +102,8 @@ LiveReloadForAdditionalPaths liveReloadForAdditionalPaths(LiveReloadServer liveR @Bean @ConditionalOnMissingBean(RestartConfiguration.class) FileSystemWatcher newFileSystemWatcher(DevToolsProperties properties) { - return new FileSystemWatcher(true, properties.getLivereload().getPollInterval(), properties.getLivereload().getQuietPeriod()); + return new FileSystemWatcher(true, properties.getLivereload().getPollInterval(), + properties.getLivereload().getQuietPeriod()); } @Bean