use of org.gradle.internal.snapshot.FileSystemSnapshot in project gradle by gradle.
the class CaptureStateBeforeExecutionStep method captureExecutionState.
@Nonnull
private Optional<BeforeExecutionState> captureExecutionState(UnitOfWork work, PreviousExecutionContext context) {
return operation(operationContext -> {
ImmutableSortedMap<String, FileSystemSnapshot> unfilteredOutputSnapshots;
try {
unfilteredOutputSnapshots = outputSnapshotter.snapshotOutputs(work, context.getWorkspace());
} catch (OutputFileSnapshottingException e) {
work.handleUnreadableOutputs(e);
operationContext.setResult(Operation.Result.INSTANCE);
return Optional.empty();
}
try {
BeforeExecutionState executionState = captureExecutionStateWithOutputs(work, context, unfilteredOutputSnapshots);
operationContext.setResult(Operation.Result.INSTANCE);
return Optional.of(executionState);
} catch (InputFileFingerprintingException e) {
// Note that we let InputFingerprintException fall through as we've already
// been failing for non-file value fingerprinting problems even for tasks
work.handleUnreadableInputs(e);
operationContext.setResult(Operation.Result.INSTANCE);
return Optional.empty();
}
}, BuildOperationDescriptor.displayName("Snapshot inputs and outputs before executing " + work.getDisplayName()).details(Operation.Details.INSTANCE));
}
use of org.gradle.internal.snapshot.FileSystemSnapshot in project gradle by gradle.
the class RemovePreviousOutputsStep method cleanupOverlappingOutputs.
private void cleanupOverlappingOutputs(BeforeExecutionContext context, UnitOfWork work) {
context.getPreviousExecutionState().ifPresent(previousOutputs -> {
Set<File> outputDirectoriesToPreserve = new HashSet<>();
work.visitOutputs(context.getWorkspace(), new UnitOfWork.OutputVisitor() {
@Override
public void visitOutputProperty(String propertyName, TreeType type, File root, FileCollection contents) {
switch(type) {
case FILE:
File parentFile = root.getParentFile();
if (parentFile != null) {
outputDirectoriesToPreserve.add(parentFile);
}
break;
case DIRECTORY:
outputDirectoriesToPreserve.add(root);
break;
default:
throw new AssertionError();
}
}
});
OutputsCleaner cleaner = new OutputsCleaner(deleter, file -> true, dir -> !outputDirectoriesToPreserve.contains(dir));
for (FileSystemSnapshot snapshot : previousOutputs.getOutputFilesProducedByWork().values()) {
try {
// Previous outputs can be in a different place than the current outputs
outputChangeListener.beforeOutputChange(SnapshotUtil.rootIndex(snapshot).keySet());
cleaner.cleanupOutputs(snapshot);
} catch (IOException e) {
throw new UncheckedIOException("Failed to clean up output files for " + work.getDisplayName(), e);
}
}
});
}
use of org.gradle.internal.snapshot.FileSystemSnapshot in project gradle by gradle.
the class SkipEmptyWorkStep method skipExecutionWithEmptySources.
@Nonnull
private CachingResult skipExecutionWithEmptySources(UnitOfWork work, PreviousExecutionContext context) {
ImmutableSortedMap<String, FileSystemSnapshot> outputFilesAfterPreviousExecution = context.getPreviousExecutionState().map(PreviousExecutionState::getOutputFilesProducedByWork).orElse(ImmutableSortedMap.of());
ExecutionOutcome skipOutcome;
Timer timer = Time.startTimer();
if (outputFilesAfterPreviousExecution.isEmpty()) {
LOGGER.info("Skipping {} as it has no source files and no previous output files.", work.getDisplayName());
skipOutcome = ExecutionOutcome.SHORT_CIRCUITED;
} else {
boolean didWork = cleanPreviousTaskOutputs(outputFilesAfterPreviousExecution);
if (didWork) {
LOGGER.info("Cleaned previous output of {} as it has no source files.", work.getDisplayName());
skipOutcome = ExecutionOutcome.EXECUTED_NON_INCREMENTALLY;
} else {
skipOutcome = ExecutionOutcome.SHORT_CIRCUITED;
}
}
Duration duration = skipOutcome == ExecutionOutcome.SHORT_CIRCUITED ? Duration.ZERO : Duration.ofMillis(timer.getElapsedMillis());
broadcastWorkInputs(work, true);
return new CachingResult() {
@Override
public Duration getDuration() {
return duration;
}
@Override
public Try<ExecutionResult> getExecutionResult() {
return Try.successful(new ExecutionResult() {
@Override
public ExecutionOutcome getOutcome() {
return skipOutcome;
}
@Override
public Object getOutput() {
return work.loadRestoredOutput(context.getWorkspace());
}
});
}
@Override
public CachingState getCachingState() {
return CachingState.NOT_DETERMINED;
}
@Override
public ImmutableList<String> getExecutionReasons() {
return ImmutableList.of();
}
@Override
public Optional<AfterExecutionState> getAfterExecutionState() {
return Optional.empty();
}
@Override
public Optional<OriginMetadata> getReusedOutputOriginMetadata() {
return Optional.empty();
}
};
}
use of org.gradle.internal.snapshot.FileSystemSnapshot in project gradle by gradle.
the class SkipEmptyWorkStep method cleanPreviousTaskOutputs.
private boolean cleanPreviousTaskOutputs(Map<String, FileSystemSnapshot> outputFileSnapshots) {
OutputsCleaner outputsCleaner = outputsCleanerSupplier.get();
for (FileSystemSnapshot outputFileSnapshot : outputFileSnapshots.values()) {
try {
outputChangeListener.beforeOutputChange(SnapshotUtil.rootIndex(outputFileSnapshot).keySet());
outputsCleaner.cleanupOutputs(outputFileSnapshot);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
return outputsCleaner.getDidWork();
}
use of org.gradle.internal.snapshot.FileSystemSnapshot in project gradle by gradle.
the class DefaultPreviousExecutionStateSerializer method read.
@Override
public PreviousExecutionState read(Decoder decoder) throws Exception {
OriginMetadata originMetadata = new OriginMetadata(decoder.readString(), Duration.ofMillis(decoder.readLong()));
ImplementationSnapshot taskImplementation = implementationSnapshotSerializer.read(decoder);
// We can't use an immutable list here because some hashes can be null
int taskActionsCount = decoder.readSmallInt();
ImmutableList.Builder<ImplementationSnapshot> taskActionImplementationsBuilder = ImmutableList.builder();
for (int j = 0; j < taskActionsCount; j++) {
ImplementationSnapshot actionImpl = implementationSnapshotSerializer.read(decoder);
taskActionImplementationsBuilder.add(actionImpl);
}
ImmutableList<ImplementationSnapshot> taskActionImplementations = taskActionImplementationsBuilder.build();
ImmutableSortedMap<String, ValueSnapshot> inputProperties = readInputProperties(decoder);
ImmutableSortedMap<String, FileCollectionFingerprint> inputFilesFingerprints = readFingerprints(decoder);
ImmutableSortedMap<String, FileSystemSnapshot> outputFilesSnapshots = readSnapshots(decoder);
boolean successful = decoder.readBoolean();
return new DefaultPreviousExecutionState(originMetadata, taskImplementation, taskActionImplementations, inputProperties, inputFilesFingerprints, outputFilesSnapshots, successful);
}
Aggregations