Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a watch-mac goal that actually watches for changes (as aposed to polling every 30 seconds) #22

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
No need to add watches for each of the sub-dirs, they are covered by …
…the watch on the 'sourceDirectory'.
danwashusen committed Mar 12, 2013
commit e0fa0b80217c8a58730b37b3943a0946c549b1dc
Original file line number Diff line number Diff line change
@@ -9,12 +9,12 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
//import java.nio.file.*;
//import java.nio.file.attribute.BasicFileAttributes;

/**
* Compile coffeescript files to javascript files, and recompile as soon as a change occurs.
* This version of the watch plugin uses com.barbarysoftware.watchservice.WatchService to watch
* for file changes because the 'official' Oracle release of the Mac runtime uses polling instead of
* hooking into Apple's file system events system.
*
* @author iron9light
* @goal watch-mac
@@ -55,12 +55,8 @@ private void watch(final CoffeeScriptCompiler compiler, final Path sourceDirecto
getLog().debug(String.format("watched %s - %s", event.kind().name(), file));
if (file.isDirectory()) {
getLog().debug("is directory");
if (event.kind().name().equals(StandardWatchEventKinds.ENTRY_CREATE.name())) {
// watch created folder.
WatchableFile watchableFile = new WatchableFile(file);
watchableFile.register(watchService, watchEvents);
getLog().debug(String.format("watch %s", file));
}
// don't need to add a watch for the dir, it's already covered by it's ancestor watch
// adding another causes the same file to be compiled several times (one for each sub-directory form it's ancestor)
continue;
}

@@ -90,16 +86,9 @@ private void watch(final CoffeeScriptCompiler compiler, final Path sourceDirecto

private WatchService startWatching(Path sourceDirectory) throws IOException {
final WatchService watchService = WatchService.newWatchService();

Files.walkFileTree(sourceDirectory, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
WatchableFile watchableFile = new WatchableFile(dir.toFile());
watchableFile.register(watchService, watchEvents);
getLog().debug(String.format("watch %s", dir));
return FileVisitResult.CONTINUE;
}
});
WatchableFile watchableFile = new WatchableFile(sourceDirectory.toFile());
watchableFile.register(watchService, watchEvents);
getLog().debug(String.format("watch %s", sourceDirectory.toString()));
return watchService;
}
}