Browse files

fix for GRAILS-9273 "DirectoryWatcher: files are incorrectly consider…

…ed "new" if their extension wasn't watched for that directory"
  • Loading branch information...
1 parent 745eee5 commit 024063d249013b8b0757fcbbfbb15f1f35556804 @graemerocher graemerocher committed Feb 19, 2013
View
17 grails-core/src/main/groovy/org/codehaus/groovy/grails/compiler/DirectoryWatcher.java
@@ -40,6 +40,7 @@
private List<FileChangeListener> listeners = new ArrayList<FileChangeListener>();
private Map<File, Long> lastModifiedMap = new ConcurrentHashMap<File, Long>();
+ private Map<File, Collection<String>> directoryToExtensionsMap = new ConcurrentHashMap<File, Collection<String>>();
private Map<File, Long> directoryWatch = new ConcurrentHashMap<File, Long>();
private boolean active = true;
private long sleepTime = 3000;
@@ -91,9 +92,20 @@ public void addWatchFile(File fileToWatch) {
* @param fileExtensions The extensions
*/
public void addWatchDirectory(File dir, List<String> fileExtensions) {
+ trackDirectoryExtensions(dir, fileExtensions);
cacheFilesForDirectory(dir, fileExtensions, false);
}
+ protected void trackDirectoryExtensions(File dir, List<String> fileExtensions) {
+ Collection<String> existingExtensions = directoryToExtensionsMap.get(dir);
+ if(existingExtensions == null) {
+ directoryToExtensionsMap.put(dir, fileExtensions);
+ }
+ else {
+ existingExtensions.addAll(fileExtensions);
+ }
+ }
+
/**
* Adds a directory to watch for the given file and extensions.
*
@@ -109,6 +121,7 @@ public void addWatchDirectory(File dir, String extension) {
else {
fileExtensions.add(extension);
}
+ trackDirectoryExtensions(dir, fileExtensions);
cacheFilesForDirectory(dir, fileExtensions, false);
}
@@ -168,6 +181,10 @@ private void checkForNewFiles() {
final Long currentTimestamp = directoryWatch.get(directory);
if (currentTimestamp < directory.lastModified()) {
+ Collection<String> extensions = directoryToExtensionsMap.get(directory);
+ if(extensions == null) {
+ extensions = this.extensions;
+ }
cacheFilesForDirectory(directory, extensions, true);
}
}

0 comments on commit 024063d

Please sign in to comment.