use of org.gradle.internal.snapshot.SnapshotHierarchy in project gradle by gradle.
the class NonHierarchicalFileWatcherUpdater method handleVirtualFileSystemContentsChanged.
@Override
protected boolean handleVirtualFileSystemContentsChanged(Collection<FileSystemLocationSnapshot> removedSnapshots, Collection<FileSystemLocationSnapshot> addedSnapshots, SnapshotHierarchy root) {
Map<String, Integer> changedWatchedDirectories = new HashMap<>();
removedSnapshots.stream().filter(watchableHierarchies::shouldWatch).forEach(snapshot -> {
String previousWatchedRoot = watchedDirectoryForSnapshot.remove(snapshot.getAbsolutePath());
decrement(previousWatchedRoot, changedWatchedDirectories);
snapshot.accept(new SubdirectoriesToWatchVisitor(path -> decrement(path, changedWatchedDirectories)));
});
addedSnapshots.stream().filter(watchableHierarchies::shouldWatch).forEach(snapshot -> {
File directoryToWatchForRoot = SnapshotWatchedDirectoryFinder.getDirectoryToWatch(snapshot);
String pathToWatchForRoot = directoryToWatchForRoot.getAbsolutePath();
if (!watchableHierarchies.isInWatchableHierarchy(pathToWatchForRoot)) {
return;
}
watchedDirectoryForSnapshot.put(snapshot.getAbsolutePath(), pathToWatchForRoot);
increment(pathToWatchForRoot, changedWatchedDirectories);
snapshot.accept(new SubdirectoriesToWatchVisitor(path -> increment(path, changedWatchedDirectories)));
});
if (changedWatchedDirectories.isEmpty()) {
return false;
}
updateWatchedDirectories(changedWatchedDirectories);
return true;
}
use of org.gradle.internal.snapshot.SnapshotHierarchy in project gradle by gradle.
the class WatchableHierarchies method removeUnwatchableContentOnBuildFinished.
@CheckReturnValue
public SnapshotHierarchy removeUnwatchableContentOnBuildFinished(SnapshotHierarchy root, Predicate<File> isWatchedHierarchy, int maximumNumberOfWatchedHierarchies, List<File> unsupportedFileSystems, Invalidator invalidator) {
SnapshotHierarchy newRoot;
newRoot = removeWatchedHierarchiesOverLimit(root, isWatchedHierarchy, maximumNumberOfWatchedHierarchies, invalidator);
newRoot = removeUnwatchedSnapshots(newRoot, invalidator);
if (!unsupportedFileSystems.isEmpty()) {
newRoot = removeUnwatchableFileSystems(newRoot, unsupportedFileSystems, invalidator);
}
watchableHierarchiesSinceLastBuildFinish.clear();
return newRoot;
}
use of org.gradle.internal.snapshot.SnapshotHierarchy in project gradle by gradle.
the class WatchableHierarchies method removeWatchedHierarchiesOverLimit.
@CheckReturnValue
private SnapshotHierarchy removeWatchedHierarchiesOverLimit(SnapshotHierarchy root, Predicate<File> isWatchedHierarchy, int maximumNumberOfWatchedHierarchies, Invalidator invalidator) {
hierarchies.removeIf(hierarchy -> !isWatchedHierarchy.test(hierarchy));
SnapshotHierarchy result = root;
int toRemove = hierarchies.size() - maximumNumberOfWatchedHierarchies;
if (toRemove > 0) {
LOGGER.info("Watching too many directories in the file system (watching {}, limit {}), dropping some state from the virtual file system", hierarchies.size(), maximumNumberOfWatchedHierarchies);
for (int i = 0; i < toRemove; i++) {
File locationToRemove = hierarchies.removeLast();
result = invalidator.invalidate(locationToRemove.toString(), result);
}
}
watchableFiles = buildWatchableFilesFromHierarchies(hierarchies);
return result;
}
use of org.gradle.internal.snapshot.SnapshotHierarchy in project gradle by gradle.
the class WatchingVirtualFileSystem method updateNotifyingListeners.
@Override
protected SnapshotHierarchy updateNotifyingListeners(UpdateFunction updateFunction) {
if (watchRegistry == null) {
return updateFunction.update(SnapshotHierarchy.NodeDiffListener.NOOP);
} else {
SnapshotCollectingDiffListener diffListener = new SnapshotCollectingDiffListener();
SnapshotHierarchy newRoot = updateFunction.update(diffListener);
return withWatcherChangeErrorHandling(newRoot, () -> diffListener.publishSnapshotDiff((removedSnapshots, addedSnapshots) -> watchRegistry.virtualFileSystemContentsChanged(removedSnapshots, addedSnapshots, newRoot)));
}
}
use of org.gradle.internal.snapshot.SnapshotHierarchy in project gradle by gradle.
the class WatchingVirtualFileSystem method afterBuildStarted.
@Override
public boolean afterBuildStarted(WatchMode watchMode, VfsLogging vfsLogging, WatchLogging watchLogging, BuildOperationRunner buildOperationRunner) {
warningLogger = watchMode.loggerForWarnings(LOGGER);
stateInvalidatedAtStartOfBuild = false;
reasonForNotWatchingFiles = null;
rootReference.update(currentRoot -> buildOperationRunner.call(new CallableBuildOperation<SnapshotHierarchy>() {
@Override
public SnapshotHierarchy call(BuildOperationContext context) {
if (watchMode.isEnabled()) {
SnapshotHierarchy newRoot;
boolean couldDetectUnsupportedFileSystems;
try {
unsupportedFileSystems.clear();
if (watchMode == WatchMode.DEFAULT) {
watchableFileSystemDetector.detectUnsupportedFileSystems().forEach(unsupportedFileSystems::add);
}
couldDetectUnsupportedFileSystems = true;
} catch (NativeException e) {
couldDetectUnsupportedFileSystems = false;
LOGGER.info("Unable to list file systems to check whether they can be watched. Disabling watching. Reason: {}", e.getMessage());
}
FileSystemWatchingStatistics statisticsSinceLastBuild;
if (watchRegistry == null) {
if (couldDetectUnsupportedFileSystems) {
context.setStatus("Starting file system watching");
newRoot = startWatching(currentRoot, watchMode, unsupportedFileSystems);
} else {
newRoot = currentRoot.empty();
}
statisticsSinceLastBuild = null;
} else {
FileWatcherRegistry.FileWatchingStatistics statistics = watchRegistry.getAndResetStatistics();
if (hasDroppedStateBecauseOfErrorsReceivedWhileWatching(statistics) || !couldDetectUnsupportedFileSystems) {
newRoot = stopWatchingAndInvalidateHierarchyAfterError(currentRoot);
} else {
newRoot = watchRegistry.updateVfsOnBuildStarted(currentRoot, watchMode, unsupportedFileSystems);
}
stateInvalidatedAtStartOfBuild = newRoot != currentRoot;
statisticsSinceLastBuild = new DefaultFileSystemWatchingStatistics(statistics, newRoot);
if (vfsLogging == VfsLogging.VERBOSE) {
LOGGER.warn("Received {} file system events since last build while watching {} locations", statisticsSinceLastBuild.getNumberOfReceivedEvents(), statisticsSinceLastBuild.getNumberOfWatchedHierarchies());
LOGGER.warn("Virtual file system retained information about {} files, {} directories and {} missing files since last build", statisticsSinceLastBuild.getRetainedRegularFiles(), statisticsSinceLastBuild.getRetainedDirectories(), statisticsSinceLastBuild.getRetainedMissingFiles());
if (stateInvalidatedAtStartOfBuild) {
LOGGER.warn("Parts of the virtual file system have been invalidated since they didn't support watching");
}
}
}
if (watchRegistry != null) {
watchRegistry.setDebugLoggingEnabled(watchLogging == WatchLogging.DEBUG);
}
context.setResult(new BuildStartedFileSystemWatchingBuildOperationType.Result() {
@Override
public boolean isWatchingEnabled() {
return true;
}
@Override
public boolean isStartedWatching() {
return statisticsSinceLastBuild == null;
}
@Override
public FileSystemWatchingStatistics getStatistics() {
return statisticsSinceLastBuild;
}
});
return newRoot;
} else {
context.setResult(BuildStartedFileSystemWatchingBuildOperationType.Result.WATCHING_DISABLED);
return stopWatchingAndInvalidateHierarchy(currentRoot);
}
}
@Override
public BuildOperationDescriptor.Builder description() {
return BuildOperationDescriptor.displayName(BuildStartedFileSystemWatchingBuildOperationType.DISPLAY_NAME).details(BuildStartedFileSystemWatchingBuildOperationType.Details.INSTANCE);
}
}));
return watchRegistry != null;
}
Aggregations