use of org.eclipse.jetty.util.PathWatcher.PathWatchEvent in project jetty.project by eclipse.
the class JettyRunWarExplodedMojo method configureScanner.
/**
* @see AbstractJettyMojo#configureScanner()
*/
public void configureScanner() throws MojoExecutionException {
scanner.watch(project.getFile().toPath());
File webInfDir = new File(war, "WEB-INF");
File webXml = new File(webInfDir, "web.xml");
if (webXml.exists())
scanner.watch(webXml.toPath());
File jettyWebXmlFile = findJettyWebXmlFile(webInfDir);
if (jettyWebXmlFile != null)
scanner.watch(jettyWebXmlFile.toPath());
File jettyEnvXmlFile = new File(webInfDir, "jetty-env.xml");
if (jettyEnvXmlFile.exists())
scanner.watch(jettyEnvXmlFile.toPath());
File classes = new File(webInfDir, "classes");
if (classes.exists()) {
PathWatcher.Config classesConfig = new PathWatcher.Config(classes.toPath());
classesConfig.setRecurseDepth(PathWatcher.Config.UNLIMITED_DEPTH);
scanner.watch(classesConfig);
}
File lib = new File(webInfDir, "lib");
if (lib.exists()) {
PathWatcher.Config libConfig = new PathWatcher.Config(lib.toPath());
libConfig.setRecurseDepth(PathWatcher.Config.UNLIMITED_DEPTH);
scanner.watch(libConfig);
}
scanner.addListener(new PathWatcher.EventListListener() {
@Override
public void onPathWatchEvents(List<PathWatchEvent> events) {
try {
boolean reconfigure = false;
for (PathWatchEvent e : events) {
if (e.getPath().equals(project.getFile().toPath())) {
reconfigure = true;
break;
}
}
restartWebApp(reconfigure);
} catch (Exception e) {
getLog().error("Error reconfiguring/restarting webapp after change in watched files", e);
}
}
});
}
use of org.eclipse.jetty.util.PathWatcher.PathWatchEvent in project jetty.project by eclipse.
the class PathWatcherDemo method run.
public void run(List<Path> paths) throws Exception {
PathWatcher watcher = new PathWatcher();
//watcher.addListener(new PathWatcherDemo());
watcher.addListener(new PathWatcher.EventListListener() {
@Override
public void onPathWatchEvents(List<PathWatchEvent> events) {
if (events == null)
LOG.warn("Null events received");
if (events.isEmpty())
LOG.warn("Empty events received");
LOG.info("Bulk notification received");
for (PathWatchEvent e : events) onPathWatchEvent(e);
}
});
watcher.setNotifyExistingOnStart(false);
List<String> excludes = new ArrayList<>();
// ignore backup files
excludes.add("glob:*.bak");
// ignore scratch files
excludes.add("regex:^.*/\\~[^/]*$");
for (Path path : paths) {
if (Files.isDirectory(path)) {
PathWatcher.Config config = new PathWatcher.Config(path);
config.addExcludeHidden();
config.addExcludes(excludes);
config.setRecurseDepth(4);
watcher.watch(config);
} else {
watcher.watch(path);
}
}
watcher.start();
Thread.currentThread().join();
}
Aggregations