Search in sources :

Example 1 with SnapshotHierarchy

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);
    });
}
Also used : FileWatcherUpdater(org.gradle.internal.watch.registry.FileWatcherUpdater) ImmutableSet(com.google.common.collect.ImmutableSet) FileHierarchySet(org.gradle.internal.file.FileHierarchySet) Logger(org.slf4j.Logger) WatchMode(org.gradle.internal.watch.registry.WatchMode) FileSystemLocationSnapshot(org.gradle.internal.snapshot.FileSystemLocationSnapshot) Collection(java.util.Collection) FileMetadata(org.gradle.internal.file.FileMetadata) LoggerFactory(org.slf4j.LoggerFactory) SnapshotHierarchy(org.gradle.internal.snapshot.SnapshotHierarchy) File(java.io.File) CheckReturnValue(javax.annotation.CheckReturnValue) List(java.util.List) Stream(java.util.stream.Stream) FileWatcherProbeRegistry(org.gradle.internal.watch.registry.FileWatcherProbeRegistry) FileType(org.gradle.internal.file.FileType) VisibleForTesting(com.google.common.annotations.VisibleForTesting) FileHierarchySet(org.gradle.internal.file.FileHierarchySet) File(java.io.File)

Example 2 with SnapshotHierarchy

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;
}
Also used : SnapshotHierarchy(org.gradle.internal.snapshot.SnapshotHierarchy)

Example 3 with SnapshotHierarchy

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;
}
Also used : BuildOperationContext(org.gradle.internal.operations.BuildOperationContext) FileSystemWatchingStatistics(org.gradle.internal.watch.vfs.FileSystemWatchingStatistics) BuildOperationDescriptor(org.gradle.internal.operations.BuildOperationDescriptor) BuildFinishedFileSystemWatchingBuildOperationType(org.gradle.internal.watch.vfs.BuildFinishedFileSystemWatchingBuildOperationType) SnapshotHierarchy(org.gradle.internal.snapshot.SnapshotHierarchy) CallableBuildOperation(org.gradle.internal.operations.CallableBuildOperation) FileWatcherRegistry(org.gradle.internal.watch.registry.FileWatcherRegistry)

Example 4 with SnapshotHierarchy

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();
    }
}
Also used : SnapshotHierarchy(org.gradle.internal.snapshot.SnapshotHierarchy) WatchingNotSupportedException(org.gradle.internal.watch.WatchingNotSupportedException) IOException(java.io.IOException) InotifyWatchesLimitTooLowException(net.rubygrapefruit.platform.internal.jni.InotifyWatchesLimitTooLowException) NativeException(net.rubygrapefruit.platform.NativeException) InotifyInstanceLimitTooLowException(net.rubygrapefruit.platform.internal.jni.InotifyInstanceLimitTooLowException) CheckReturnValue(javax.annotation.CheckReturnValue)

Example 5 with SnapshotHierarchy

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;
}
Also used : SnapshotHierarchy(org.gradle.internal.snapshot.SnapshotHierarchy) CheckReturnValue(javax.annotation.CheckReturnValue)

Aggregations

SnapshotHierarchy (org.gradle.internal.snapshot.SnapshotHierarchy)15 CheckReturnValue (javax.annotation.CheckReturnValue)8 File (java.io.File)6 NativeException (net.rubygrapefruit.platform.NativeException)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 FileHierarchySet (org.gradle.internal.file.FileHierarchySet)3 BuildOperationContext (org.gradle.internal.operations.BuildOperationContext)3 BuildOperationDescriptor (org.gradle.internal.operations.BuildOperationDescriptor)3 CallableBuildOperation (org.gradle.internal.operations.CallableBuildOperation)3 FileSystemLocationSnapshot (org.gradle.internal.snapshot.FileSystemLocationSnapshot)3 WatchingNotSupportedException (org.gradle.internal.watch.WatchingNotSupportedException)3 FileWatcherRegistry (org.gradle.internal.watch.registry.FileWatcherRegistry)3 FileSystemWatchingStatistics (org.gradle.internal.watch.vfs.FileSystemWatchingStatistics)3 IOException (java.io.IOException)2 Collection (java.util.Collection)2 List (java.util.List)2 Set (java.util.Set)2 Nullable (javax.annotation.Nullable)2 InotifyInstanceLimitTooLowException (net.rubygrapefruit.platform.internal.jni.InotifyInstanceLimitTooLowException)2