use of org.gradle.internal.snapshot.SnapshotHierarchy in project gradle by gradle.
the class AbstractFileWatcherUpdater method update.
private void update(SnapshotHierarchy root) {
FileHierarchySet oldWatchedFiles = watchedFiles;
watchedFiles = resolveWatchedFiles(watchableHierarchies, root);
if (!watchedFiles.equals(oldWatchedFiles)) {
updateWatchesOnChangedWatchedFiles(watchedFiles);
}
// Probe every hierarchy that is watched, even ones nested inside others
ImmutableSet<File> oldProbedHierarchies = probedHierarchies;
probedHierarchies = watchableHierarchies.stream().filter(watchedFiles::contains).collect(ImmutableSet.toImmutableSet());
if (oldProbedHierarchies.equals(probedHierarchies)) {
return;
}
oldProbedHierarchies.stream().filter(oldProbedHierarchy -> !probedHierarchies.contains(oldProbedHierarchy)).forEach(probedHierarchy -> {
File probeDirectory = probeRegistry.getProbeDirectory(probedHierarchy);
probeRegistry.disarmWatchProbe(probedHierarchy);
stopWatchingProbeDirectory(probeDirectory);
});
probedHierarchies.stream().filter(newProbedHierarchy -> !oldProbedHierarchies.contains(newProbedHierarchy)).forEach(probedHierarchy -> {
File probeDirectory = probeRegistry.getProbeDirectory(probedHierarchy);
// Make sure the directory exists, this can be necessary when
// included builds are evaluated with configuration cache
// noinspection ResultOfMethodCallIgnored
probeDirectory.mkdirs();
startWatchingProbeDirectory(probeDirectory);
probeRegistry.armWatchProbe(probedHierarchy);
});
}
use of org.gradle.internal.snapshot.SnapshotHierarchy in project gradle by gradle.
the class AbstractFileWatcherUpdater method updateVfsOnBuildStarted.
@Override
public final SnapshotHierarchy updateVfsOnBuildStarted(SnapshotHierarchy root, WatchMode watchMode, List<File> unsupportedFileSystems) {
SnapshotHierarchy newRoot = watchableHierarchies.removeUnwatchableContentOnBuildStart(root, createInvalidator(), watchMode, unsupportedFileSystems);
newRoot = invalidateMovedDirectoriesOnBuildStarted(newRoot);
if (root != newRoot) {
update(newRoot);
}
return newRoot;
}
use of org.gradle.internal.snapshot.SnapshotHierarchy in project gradle by gradle.
the class WatchingVirtualFileSystem method beforeBuildFinished.
@Override
public void beforeBuildFinished(WatchMode watchMode, VfsLogging vfsLogging, WatchLogging watchLogging, BuildOperationRunner buildOperationRunner, int maximumNumberOfWatchedHierarchies) {
rootReference.update(currentRoot -> buildOperationRunner.call(new CallableBuildOperation<SnapshotHierarchy>() {
@Override
public SnapshotHierarchy call(BuildOperationContext context) {
watchableHierarchiesRegisteredEarly.clear();
if (watchMode.isEnabled()) {
if (reasonForNotWatchingFiles != null) {
// Log exception again so it doesn't get lost.
logWatchingError(reasonForNotWatchingFiles, FILE_WATCHING_ERROR_MESSAGE_AT_END_OF_BUILD, watchMode);
reasonForNotWatchingFiles = null;
}
SnapshotHierarchy newRoot;
FileSystemWatchingStatistics statisticsDuringBuild;
if (watchRegistry == null) {
statisticsDuringBuild = null;
newRoot = currentRoot.empty();
} else {
FileWatcherRegistry.FileWatchingStatistics statistics = watchRegistry.getAndResetStatistics();
if (hasDroppedStateBecauseOfErrorsReceivedWhileWatching(statistics)) {
newRoot = stopWatchingAndInvalidateHierarchyAfterError(currentRoot);
} else {
newRoot = withWatcherChangeErrorHandling(currentRoot, () -> watchRegistry.updateVfsOnBuildFinished(currentRoot, watchMode, maximumNumberOfWatchedHierarchies, unsupportedFileSystems));
}
statisticsDuringBuild = new DefaultFileSystemWatchingStatistics(statistics, newRoot);
if (vfsLogging == VfsLogging.VERBOSE) {
LOGGER.warn("Received {} file system events during the current build while watching {} locations", statisticsDuringBuild.getNumberOfReceivedEvents(), statisticsDuringBuild.getNumberOfWatchedHierarchies());
LOGGER.warn("Virtual file system retains information about {} files, {} directories and {} missing files until next build", statisticsDuringBuild.getRetainedRegularFiles(), statisticsDuringBuild.getRetainedDirectories(), statisticsDuringBuild.getRetainedMissingFiles());
if (stateInvalidatedAtStartOfBuild) {
LOGGER.warn("Parts of the virtual file system have been removed at the start of the build since they didn't support watching");
}
}
}
boolean stoppedWatchingDuringTheBuild = watchRegistry == null;
context.setResult(new BuildFinishedFileSystemWatchingBuildOperationType.Result() {
private final boolean stateInvalidatedAtStartOfBuild = WatchingVirtualFileSystem.this.stateInvalidatedAtStartOfBuild;
@Override
public boolean isWatchingEnabled() {
return true;
}
@Override
public boolean isStoppedWatchingDuringTheBuild() {
return stoppedWatchingDuringTheBuild;
}
@Override
public boolean isStateInvalidatedAtStartOfBuild() {
return stateInvalidatedAtStartOfBuild;
}
@Override
public FileSystemWatchingStatistics getStatistics() {
return statisticsDuringBuild;
}
});
return newRoot;
} else {
context.setResult(BuildFinishedFileSystemWatchingBuildOperationType.Result.WATCHING_DISABLED);
return currentRoot.empty();
}
}
@Override
public BuildOperationDescriptor.Builder description() {
return BuildOperationDescriptor.displayName(BuildFinishedFileSystemWatchingBuildOperationType.DISPLAY_NAME).details(BuildFinishedFileSystemWatchingBuildOperationType.Details.INSTANCE);
}
}));
// Log problems to daemon log
warningLogger = LOGGER;
}
use of org.gradle.internal.snapshot.SnapshotHierarchy in project gradle by gradle.
the class WatchingVirtualFileSystem method startWatching.
/**
* Start watching the known areas of the file system for changes.
*/
@CheckReturnValue
private SnapshotHierarchy startWatching(SnapshotHierarchy currentRoot, WatchMode watchMode, List<File> unsupportedFileSystems) {
try {
watchRegistry = watcherRegistryFactory.createFileWatcherRegistry(new FilterChangesToOutputsChangesHandler(locationsWrittenByCurrentBuild, new CompositeChangeHandler(new InvalidateVfsChangeHandler(), new BroadcastingChangeHandler())));
SnapshotHierarchy newRoot = watchRegistry.updateVfsOnBuildStarted(currentRoot.empty(), watchMode, unsupportedFileSystems);
watchableHierarchiesRegisteredEarly.forEach(watchableHierarchy -> watchRegistry.registerWatchableHierarchy(watchableHierarchy, newRoot));
watchableHierarchiesRegisteredEarly.clear();
return newRoot;
} catch (Exception ex) {
logWatchingError(ex, FILE_WATCHING_ERROR_MESSAGE_DURING_BUILD, null);
closeUnderLock();
return currentRoot.empty();
}
}
use of org.gradle.internal.snapshot.SnapshotHierarchy in project gradle by gradle.
the class WatchableHierarchies method removeUnwatchableContentOnBuildStart.
@CheckReturnValue
public SnapshotHierarchy removeUnwatchableContentOnBuildStart(SnapshotHierarchy root, Invalidator invalidator, WatchMode watchMode, List<File> unsupportedFileSystems) {
SnapshotHierarchy newRoot = root;
newRoot = removeUnprovenHierarchies(newRoot, invalidator, watchMode);
newRoot = updateUnwatchableFilesOnBuildStart(newRoot, invalidator, unsupportedFileSystems);
return newRoot;
}
Aggregations