Search in sources :

Example 6 with FileSystemSnapshot

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));
}
Also used : InputFileFingerprintingException(org.gradle.internal.execution.fingerprint.InputFingerprinter.InputFileFingerprintingException) OutputFileSnapshottingException(org.gradle.internal.execution.OutputSnapshotter.OutputFileSnapshottingException) FileSystemSnapshot(org.gradle.internal.snapshot.FileSystemSnapshot) BeforeExecutionState(org.gradle.internal.execution.history.BeforeExecutionState) DefaultBeforeExecutionState(org.gradle.internal.execution.history.impl.DefaultBeforeExecutionState) Nonnull(javax.annotation.Nonnull)

Example 7 with FileSystemSnapshot

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);
            }
        }
    });
}
Also used : OutputsCleaner(org.gradle.internal.execution.history.OutputsCleaner) UnitOfWork(org.gradle.internal.execution.UnitOfWork) TreeType(org.gradle.internal.file.TreeType) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) FileCollection(org.gradle.api.file.FileCollection) FileSystemSnapshot(org.gradle.internal.snapshot.FileSystemSnapshot) File(java.io.File) HashSet(java.util.HashSet)

Example 8 with FileSystemSnapshot

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();
        }
    };
}
Also used : ExecutionOutcome(org.gradle.internal.execution.ExecutionOutcome) AfterExecutionState(org.gradle.internal.execution.history.AfterExecutionState) Duration(java.time.Duration) ExecutionResult(org.gradle.internal.execution.ExecutionResult) OriginMetadata(org.gradle.caching.internal.origin.OriginMetadata) FileSystemSnapshot(org.gradle.internal.snapshot.FileSystemSnapshot) Timer(org.gradle.internal.time.Timer) Nonnull(javax.annotation.Nonnull)

Example 9 with FileSystemSnapshot

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();
}
Also used : OutputsCleaner(org.gradle.internal.execution.history.OutputsCleaner) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) FileSystemSnapshot(org.gradle.internal.snapshot.FileSystemSnapshot)

Example 10 with FileSystemSnapshot

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);
}
Also used : ValueSnapshot(org.gradle.internal.snapshot.ValueSnapshot) ImmutableList(com.google.common.collect.ImmutableList) OriginMetadata(org.gradle.caching.internal.origin.OriginMetadata) FileCollectionFingerprint(org.gradle.internal.fingerprint.FileCollectionFingerprint) FileSystemSnapshot(org.gradle.internal.snapshot.FileSystemSnapshot) FileCollectionFingerprint(org.gradle.internal.fingerprint.FileCollectionFingerprint) 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