Skip to content

Commit e53c35b

Browse files
committed
bugfix: new directories will get walked and registered all files and directories underneath recursively
1 parent 1b9ed0e commit e53c35b

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

  • plugin/src/main/java/com/flowlogix/maven/plugins

plugin/src/main/java/com/flowlogix/maven/plugins/Watcher.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ public void watch(Path root, @NonNull Consumer<Set<Path>> onChange, int delay) {
5959
try (WatchService watchService = FileSystems.getDefault().newWatchService()) {
6060
@Cleanup("shutdown") ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
6161
Map<WatchKey, Path> keys = new ConcurrentHashMap<>();
62-
try (var stream = Files.walk(root)) {
63-
stream.filter(Files::isDirectory).forEach(path -> register(path, keys, watchService));
64-
}
62+
register(root, keys, watchService);
6563
Set<Path> pendingFiles = new ConcurrentSkipListSet<>();
6664
AtomicReference<ScheduledFuture<?>> notifyOnChangeTask = new AtomicReference<>();
6765
while (!Thread.interrupted()) {
@@ -101,7 +99,15 @@ private static void delayNextChange(Set<Path> pendingFiles, AtomicReference<Sche
10199
}
102100

103101
@SneakyThrows(IOException.class)
104-
private void register(Path path, Map<WatchKey, Path> keys, WatchService watchService) {
102+
private void register(Path root, Map<WatchKey, Path> keys, WatchService watchService) {
103+
try (var stream = Files.walk(root)) {
104+
stream.filter(Files::isDirectory)
105+
.forEach(path -> registerFile(path, keys, watchService));
106+
}
107+
}
108+
109+
@SneakyThrows(IOException.class)
110+
private void registerFile(Path path, Map<WatchKey, Path> keys, WatchService watchService) {
105111
getLog().debug("Registering path for watch: " + path);
106112
keys.put(path.register(watchService, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY), path);
107113
}

0 commit comments

Comments
 (0)