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;
}
};
}
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);
}
}
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;
}
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();
}
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);
}
Aggregations