use of org.gradle.internal.watch.WatchingNotSupportedException in project gradle by gradle.
the class NonHierarchicalFileWatcherUpdater method updateWatchedDirectories.
private void updateWatchedDirectories(Map<String, Integer> changedWatchDirectories) {
Set<File> directoriesToStopWatching = new HashSet<>();
Set<File> directoriesToStartWatching = new HashSet<>();
changedWatchDirectories.forEach((absolutePath, value) -> {
int count = value;
if (count < 0) {
int toRemove = -count;
int contained = watchedDirectories.remove(absolutePath, toRemove);
if (contained <= toRemove) {
directoriesToStopWatching.add(new File(absolutePath));
}
} else if (count > 0) {
int contained = watchedDirectories.add(absolutePath, count);
if (contained == 0) {
directoriesToStartWatching.add(new File(absolutePath));
}
}
});
LOGGER.info("Watching {} directories to track changes", watchedDirectories.entrySet().size());
try {
if (!directoriesToStopWatching.isEmpty()) {
if (!fileWatcher.stopWatching(directoriesToStopWatching)) {
LOGGER.debug("Couldn't stop watching directories: {}", directoriesToStopWatching);
}
}
if (!directoriesToStartWatching.isEmpty()) {
fileWatcher.startWatching(directoriesToStartWatching);
}
} catch (NativeException e) {
if (e.getMessage().contains("Already watching path: ")) {
throw new WatchingNotSupportedException("Unable to watch same file twice via different paths: " + e.getMessage(), e);
}
throw e;
}
}
use of org.gradle.internal.watch.WatchingNotSupportedException in project gradle by gradle.
the class DarwinFileWatcherRegistryFactory method validateLocationToWatch.
/**
* The macOS native watcher reports the canonical path for watched paths.
* That means that we would not invalidate the right locations in the virtual file system on macOS.
* Therefore, we disable file system watching when we try to watch a directory whose parent is a symlink.
*
* Note that the project directory is canonicalized by Gradle, so the project directory can always be watched.
*/
private static void validateLocationToWatch(File location) {
try {
String canonicalPath = location.getCanonicalPath();
String absolutePath = location.getAbsolutePath();
if (!canonicalPath.equals(absolutePath)) {
throw new WatchingNotSupportedException(String.format("Unable to watch '%s' since itself or one of its parent is a symbolic link (canonical path: '%s')", absolutePath, canonicalPath));
}
} catch (IOException e) {
throw new WatchingNotSupportedException("Unable to watch '%s' since its canonical path can't be resolved: " + e.getMessage(), e);
}
}
Aggregations