Skip to content

Commit f194fa2

Browse files
committed
LiveReload does not work with Gradle Project fix #848
1 parent 45ff7b0 commit f194fa2

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

modules/jooby-livereload/src/main/java/org/jooby/livereload/LiveReload.java

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,6 @@ public class LiveReload implements Module {
328328

329329
private List<Object[]> paths = new ArrayList<>();
330330

331-
/**
332-
* Creates a new {@link LiveReload} module.
333-
*/
334-
public LiveReload() {
335-
}
336-
337331
/**
338332
* Add the given path to the watcher.
339333
*
@@ -415,7 +409,8 @@ public void configure(final Env env, final Config conf, final Binder binder) thr
415409
}).consumes(MediaType.json).produces(MediaType.json);
416410

417411
if (paths.isEmpty()) {
418-
register(Paths.get("public"),
412+
Path basedir = Paths.get(System.getProperty("user.dir"));
413+
register(basedir.resolve("public"),
419414
"**/*.css",
420415
"**/*.scss",
421416
"**/*.sass",
@@ -424,33 +419,37 @@ public void configure(final Env env, final Config conf, final Binder binder) thr
424419
"**/*.js",
425420
"**/*.coffee",
426421
"**/*.ts");
427-
register(Paths.get("target"),
422+
register(basedir.resolve("target"),
428423
"**/*.class",
429424
"**/*.conf",
430425
"**/*.properties");
431-
register(Paths.get("build"),
426+
register(basedir.resolve("build"),
432427
"**/*.class",
433428
"**/*.conf",
434429
"**/*.properties");
435430
}
436431

437-
FileWatcher watcher = new FileWatcher();
438-
paths.forEach(it -> watcher.register((Path) it[0], (kind, path) -> {
439-
Path relative = relative(paths, path.toAbsolutePath());
440-
log.debug("file changed {}: {}", relative, File.separator);
441-
Map<String, Object> reload = reload(
442-
Route.normalize("/" + relative.toString().replace(File.separator, "/")),
443-
css.test(relative));
444-
for (WebSocket ws : broadcast) {
445-
try {
446-
log.info("sending: {}", reload);
447-
ws.send(reload);
448-
} catch (Exception x) {
449-
log.debug("execution of {} resulted in exception", reload, x);
432+
if (paths.size() > 0) {
433+
FileWatcher watcher = new FileWatcher();
434+
paths.forEach(it -> watcher.register((Path) it[0], (kind, path) -> {
435+
Path relative = relative(paths, path.toAbsolutePath());
436+
log.debug("file changed {}: {}", relative, File.separator);
437+
Map<String, Object> reload = reload(
438+
Route.normalize("/" + relative.toString().replace(File.separator, "/")),
439+
css.test(relative));
440+
for (WebSocket ws : broadcast) {
441+
try {
442+
log.debug("sending: {}", reload);
443+
ws.send(reload);
444+
} catch (Exception x) {
445+
log.debug("execution of {} resulted in exception", reload, x);
446+
}
450447
}
451-
}
452-
}, options -> ((List<String>) it[1]).forEach(options::includes)));
453-
watcher.configure(env, conf, binder);
448+
}, options -> ((List<String>) it[1]).forEach(options::includes)));
449+
watcher.configure(env, conf, binder);
450+
} else {
451+
log.warn("File watcher is off");
452+
}
454453
}
455454
}
456455

0 commit comments

Comments
 (0)