Search in sources :

Example 1 with FileSystemSnapshot

use of org.gradle.internal.snapshot.FileSystemSnapshot in project gradle by gradle.

the class DefaultFileCollectionSnapshotter method snapshot.

@Override
public Result snapshot(FileCollection fileCollection) {
    SnapshottingVisitor visitor = new SnapshottingVisitor();
    ((FileCollectionInternal) fileCollection).visitStructure(visitor);
    FileSystemSnapshot snapshot = CompositeFileSystemSnapshot.of(visitor.getRoots());
    boolean fileTreeOnly = visitor.isFileTreeOnly();
    boolean containsArchiveTrees = visitor.containsArchiveTrees();
    return new Result() {

        @Override
        public FileSystemSnapshot getSnapshot() {
            return snapshot;
        }

        @Override
        public boolean isFileTreeOnly() {
            return fileTreeOnly;
        }

        @Override
        public boolean containsArchiveTrees() {
            return containsArchiveTrees;
        }
    };
}
Also used : FileCollectionInternal(org.gradle.api.internal.file.FileCollectionInternal) CompositeFileSystemSnapshot(org.gradle.internal.snapshot.CompositeFileSystemSnapshot) FileSystemSnapshot(org.gradle.internal.snapshot.FileSystemSnapshot)

Example 2 with FileSystemSnapshot

use of org.gradle.internal.snapshot.FileSystemSnapshot in project gradle by gradle.

the class DefaultExecutionStateChangeDetector method detectChanges.

@Override
public ExecutionStateChanges detectChanges(Describable executable, PreviousExecutionState lastExecution, BeforeExecutionState thisExecution, IncrementalInputProperties incrementalInputProperties) {
    // Capture changes in execution outcome
    ChangeContainer previousSuccessState = new PreviousSuccessChanges(lastExecution.isSuccessful());
    // Capture changes to implementation
    // After validation, the current implementations can't be unknown when detecting changes.
    // Previous implementations can still be unknown, since we store the inputs in the task history even if validation fails.
    // When we fail the build for unknown implementations, then the previous implementations also can't be unknown.
    KnownImplementationSnapshot currentImplementation = Cast.uncheckedNonnullCast(thisExecution.getImplementation());
    ImmutableList<KnownImplementationSnapshot> currentAdditionalImplementations = Cast.uncheckedNonnullCast(thisExecution.getAdditionalImplementations());
    ChangeContainer implementationChanges = new ImplementationChanges(lastExecution.getImplementation(), lastExecution.getAdditionalImplementations(), currentImplementation, currentAdditionalImplementations, executable);
    // Capture non-file input changes
    ChangeContainer inputPropertyChanges = new PropertyChanges(lastExecution.getInputProperties().keySet(), thisExecution.getInputProperties().keySet(), "Input", executable);
    ChangeContainer inputPropertyValueChanges = new InputValueChanges(lastExecution.getInputProperties(), thisExecution.getInputProperties(), executable);
    // Capture input files state
    ChangeContainer inputFilePropertyChanges = new PropertyChanges(lastExecution.getInputFileProperties().keySet(), thisExecution.getInputFileProperties().keySet(), "Input file", executable);
    InputFileChanges nonIncrementalInputFileChanges = incrementalInputProperties.nonIncrementalChanges(lastExecution.getInputFileProperties(), thisExecution.getInputFileProperties());
    // Capture output files state
    ChangeContainer outputFilePropertyChanges = new PropertyChanges(lastExecution.getOutputFilesProducedByWork().keySet(), thisExecution.getOutputFileLocationSnapshots().keySet(), "Output", executable);
    ImmutableSortedMap<String, FileSystemSnapshot> remainingPreviouslyProducedOutputs = thisExecution.getDetectedOverlappingOutputs().isPresent() ? findOutputsStillPresentSincePreviousExecution(lastExecution.getOutputFilesProducedByWork(), thisExecution.getOutputFileLocationSnapshots()) : thisExecution.getOutputFileLocationSnapshots();
    OutputFileChanges outputFileChanges = new OutputFileChanges(lastExecution.getOutputFilesProducedByWork(), remainingPreviouslyProducedOutputs);
    // Collect changes that would trigger a rebuild
    ChangeContainer rebuildTriggeringChanges = errorHandling(executable, new SummarizingChangeContainer(previousSuccessState, implementationChanges, inputPropertyChanges, inputPropertyValueChanges, outputFilePropertyChanges, outputFileChanges, inputFilePropertyChanges, nonIncrementalInputFileChanges));
    ImmutableList<String> rebuildReasons = collectChanges(rebuildTriggeringChanges);
    if (!rebuildReasons.isEmpty()) {
        return ExecutionStateChanges.nonIncremental(rebuildReasons, thisExecution, incrementalInputProperties);
    } else {
        // Collect incremental input changes
        InputFileChanges directIncrementalInputFileChanges = incrementalInputProperties.incrementalChanges(lastExecution.getInputFileProperties(), thisExecution.getInputFileProperties());
        InputFileChanges incrementalInputFileChanges = errorHandling(executable, caching(directIncrementalInputFileChanges));
        ImmutableList<String> incrementalInputFileChangeMessages = collectChanges(incrementalInputFileChanges);
        return ExecutionStateChanges.incremental(incrementalInputFileChangeMessages, thisExecution, incrementalInputFileChanges, incrementalInputProperties);
    }
}
Also used : FileSystemSnapshot(org.gradle.internal.snapshot.FileSystemSnapshot) KnownImplementationSnapshot(org.gradle.internal.snapshot.impl.KnownImplementationSnapshot)

Example 3 with FileSystemSnapshot

use of org.gradle.internal.snapshot.FileSystemSnapshot in project gradle by gradle.

the class DefaultOverlappingOutputDetector method detect.

@Override
@Nullable
public OverlappingOutputs detect(ImmutableSortedMap<String, FileSystemSnapshot> previous, ImmutableSortedMap<String, FileSystemSnapshot> current) {
    for (Map.Entry<String, FileSystemSnapshot> entry : current.entrySet()) {
        String propertyName = entry.getKey();
        FileSystemSnapshot currentSnapshot = entry.getValue();
        FileSystemSnapshot previousSnapshot = previous.getOrDefault(propertyName, FileSystemSnapshot.EMPTY);
        // If the root hashes are the same there are no overlapping outputs
        if (getRootHashes(previousSnapshot).equals(getRootHashes(currentSnapshot))) {
            continue;
        }
        OverlappingOutputs overlappingOutputs = detect(propertyName, previousSnapshot, currentSnapshot);
        if (overlappingOutputs != null) {
            return overlappingOutputs;
        }
    }
    return null;
}
Also used : OverlappingOutputs(org.gradle.internal.execution.history.OverlappingOutputs) Map(java.util.Map) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) FileSystemSnapshot(org.gradle.internal.snapshot.FileSystemSnapshot) Nullable(javax.annotation.Nullable)

Example 4 with FileSystemSnapshot

use of org.gradle.internal.snapshot.FileSystemSnapshot in project gradle by gradle.

the class DefaultPreviousExecutionStateSerializer method readSnapshots.

private ImmutableSortedMap<String, FileSystemSnapshot> readSnapshots(Decoder decoder) throws Exception {
    int count = decoder.readSmallInt();
    ImmutableSortedMap.Builder<String, FileSystemSnapshot> builder = ImmutableSortedMap.naturalOrder();
    for (int snapshotIdx = 0; snapshotIdx < count; snapshotIdx++) {
        String property = decoder.readString();
        FileSystemSnapshot snapshot = fileSystemSnapshotSerializer.read(decoder);
        builder.put(property, snapshot);
    }
    return builder.build();
}
Also used : ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) FileCollectionFingerprint(org.gradle.internal.fingerprint.FileCollectionFingerprint) FileSystemSnapshot(org.gradle.internal.snapshot.FileSystemSnapshot)

Example 5 with FileSystemSnapshot

use of org.gradle.internal.snapshot.FileSystemSnapshot in project gradle by gradle.

the class CaptureStateBeforeExecutionStep method captureExecutionStateWithOutputs.

private BeforeExecutionState captureExecutionStateWithOutputs(UnitOfWork work, PreviousExecutionContext context, ImmutableSortedMap<String, FileSystemSnapshot> unfilteredOutputSnapshots) {
    Optional<PreviousExecutionState> previousExecutionState = context.getPreviousExecutionState();
    ImplementationsBuilder implementationsBuilder = new ImplementationsBuilder(classLoaderHierarchyHasher);
    work.visitImplementations(implementationsBuilder);
    ImplementationSnapshot implementation = implementationsBuilder.getImplementation();
    ImmutableList<ImplementationSnapshot> additionalImplementations = implementationsBuilder.getAdditionalImplementations();
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Implementation for {}: {}", work.getDisplayName(), implementation);
        LOGGER.debug("Additional implementations for {}: {}", work.getDisplayName(), additionalImplementations);
    }
    ImmutableSortedMap<String, ValueSnapshot> previousInputProperties = previousExecutionState.map(InputExecutionState::getInputProperties).orElse(ImmutableSortedMap.of());
    ImmutableSortedMap<String, ? extends FileCollectionFingerprint> previousInputFileFingerprints = previousExecutionState.map(InputExecutionState::getInputFileProperties).orElse(ImmutableSortedMap.of());
    ImmutableSortedMap<String, FileSystemSnapshot> previousOutputSnapshots = previousExecutionState.map(PreviousExecutionState::getOutputFilesProducedByWork).orElse(ImmutableSortedMap.of());
    OverlappingOutputs overlappingOutputs;
    switch(work.getOverlappingOutputHandling()) {
        case DETECT_OVERLAPS:
            overlappingOutputs = overlappingOutputDetector.detect(previousOutputSnapshots, unfilteredOutputSnapshots);
            break;
        case IGNORE_OVERLAPS:
            overlappingOutputs = null;
            break;
        default:
            throw new AssertionError();
    }
    InputFingerprinter.Result newInputs = work.getInputFingerprinter().fingerprintInputProperties(previousInputProperties, previousInputFileFingerprints, context.getInputProperties(), context.getInputFileProperties(), work::visitRegularInputs);
    return new DefaultBeforeExecutionState(implementation, additionalImplementations, newInputs.getAllValueSnapshots(), newInputs.getAllFileFingerprints(), unfilteredOutputSnapshots, overlappingOutputs);
}
Also used : ValueSnapshot(org.gradle.internal.snapshot.ValueSnapshot) DefaultBeforeExecutionState(org.gradle.internal.execution.history.impl.DefaultBeforeExecutionState) OverlappingOutputs(org.gradle.internal.execution.history.OverlappingOutputs) PreviousExecutionState(org.gradle.internal.execution.history.PreviousExecutionState) FileSystemSnapshot(org.gradle.internal.snapshot.FileSystemSnapshot) InputFingerprinter(org.gradle.internal.execution.fingerprint.InputFingerprinter) ImplementationSnapshot(org.gradle.internal.snapshot.impl.ImplementationSnapshot)

Aggregations

FileSystemSnapshot (org.gradle.internal.snapshot.FileSystemSnapshot)12 IOException (java.io.IOException)3 UncheckedIOException (java.io.UncheckedIOException)3 OriginMetadata (org.gradle.caching.internal.origin.OriginMetadata)3 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)2 Duration (java.time.Duration)2 Nonnull (javax.annotation.Nonnull)2 AfterExecutionState (org.gradle.internal.execution.history.AfterExecutionState)2 OutputsCleaner (org.gradle.internal.execution.history.OutputsCleaner)2 OverlappingOutputs (org.gradle.internal.execution.history.OverlappingOutputs)2 DefaultBeforeExecutionState (org.gradle.internal.execution.history.impl.DefaultBeforeExecutionState)2 FileCollectionFingerprint (org.gradle.internal.fingerprint.FileCollectionFingerprint)2 ValueSnapshot (org.gradle.internal.snapshot.ValueSnapshot)2 ImplementationSnapshot (org.gradle.internal.snapshot.impl.ImplementationSnapshot)2 Timer (org.gradle.internal.time.Timer)2 ImmutableList (com.google.common.collect.ImmutableList)1 File (java.io.File)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1