Search in sources :

Example 1 with DefaultAfterExecutionState

use of org.gradle.internal.execution.history.impl.DefaultAfterExecutionState in project gradle by gradle.

the class SkipUpToDateStep method skipExecution.

private UpToDateResult skipExecution(UnitOfWork work, BeforeExecutionState beforeExecutionState, C context) {
    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("Skipping {} as it is up-to-date.", work.getDisplayName());
    }
    @SuppressWarnings("OptionalGetWithoutIsPresent") PreviousExecutionState previousExecutionState = context.getPreviousExecutionState().get();
    AfterExecutionState afterExecutionState = new DefaultAfterExecutionState(beforeExecutionState, previousExecutionState.getOutputFilesProducedByWork(), previousExecutionState.getOriginMetadata(), true);
    return new UpToDateResult() {

        @Override
        public ImmutableList<String> getExecutionReasons() {
            return ImmutableList.of();
        }

        @Override
        public Optional<AfterExecutionState> getAfterExecutionState() {
            return Optional.of(afterExecutionState);
        }

        @Override
        public Optional<OriginMetadata> getReusedOutputOriginMetadata() {
            return Optional.of(previousExecutionState.getOriginMetadata());
        }

        @Override
        public Try<ExecutionResult> getExecutionResult() {
            return Try.successful(new ExecutionResult() {

                @Override
                public ExecutionOutcome getOutcome() {
                    return ExecutionOutcome.UP_TO_DATE;
                }

                @Override
                public Object getOutput() {
                    return work.loadRestoredOutput(context.getWorkspace());
                }
            });
        }

        @Override
        public Duration getDuration() {
            return previousExecutionState.getOriginMetadata().getExecutionTime();
        }
    };
}
Also used : DefaultAfterExecutionState(org.gradle.internal.execution.history.impl.DefaultAfterExecutionState) AfterExecutionState(org.gradle.internal.execution.history.AfterExecutionState) ExecutionOutcome(org.gradle.internal.execution.ExecutionOutcome) DefaultAfterExecutionState(org.gradle.internal.execution.history.impl.DefaultAfterExecutionState) ExecutionResult(org.gradle.internal.execution.ExecutionResult) PreviousExecutionState(org.gradle.internal.execution.history.PreviousExecutionState) OriginMetadata(org.gradle.caching.internal.origin.OriginMetadata)

Example 2 with DefaultAfterExecutionState

use of org.gradle.internal.execution.history.impl.DefaultAfterExecutionState in project gradle by gradle.

the class CaptureStateAfterExecutionStep method captureStateAfterExecution.

private Optional<AfterExecutionState> captureStateAfterExecution(UnitOfWork work, BeforeExecutionContext context, BeforeExecutionState beforeExecutionState, Duration duration) {
    return operation(operationContext -> {
        try {
            Timer timer = Time.startTimer();
            ImmutableSortedMap<String, FileSystemSnapshot> outputsProducedByWork = captureOutputs(work, context, beforeExecutionState);
            long snapshotOutputDuration = timer.getElapsedMillis();
            // The origin execution time is recorded as “work duration” + “output snapshotting duration”,
            // As this is _roughly_ the amount of time that is avoided by reusing the outputs,
            // which is currently the _only_ thing this value is used for.
            Duration originExecutionTime = duration.plus(Duration.ofMillis(snapshotOutputDuration));
            OriginMetadata originMetadata = new OriginMetadata(buildInvocationScopeId.asString(), originExecutionTime);
            AfterExecutionState afterExecutionState = new DefaultAfterExecutionState(beforeExecutionState, outputsProducedByWork, originMetadata, false);
            operationContext.setResult(Operation.Result.INSTANCE);
            return Optional.of(afterExecutionState);
        } catch (OutputSnapshotter.OutputFileSnapshottingException e) {
            work.handleUnreadableOutputs(e);
            operationContext.setResult(Operation.Result.INSTANCE);
            return Optional.empty();
        }
    }, BuildOperationDescriptor.displayName("Snapshot outputs after executing " + work.getDisplayName()).details(Operation.Details.INSTANCE));
}
Also used : DefaultAfterExecutionState(org.gradle.internal.execution.history.impl.DefaultAfterExecutionState) AfterExecutionState(org.gradle.internal.execution.history.AfterExecutionState) Timer(org.gradle.internal.time.Timer) OutputSnapshotter(org.gradle.internal.execution.OutputSnapshotter) DefaultAfterExecutionState(org.gradle.internal.execution.history.impl.DefaultAfterExecutionState) Duration(java.time.Duration) OriginMetadata(org.gradle.caching.internal.origin.OriginMetadata) FileSystemSnapshot(org.gradle.internal.snapshot.FileSystemSnapshot)

Aggregations

OriginMetadata (org.gradle.caching.internal.origin.OriginMetadata)2 AfterExecutionState (org.gradle.internal.execution.history.AfterExecutionState)2 DefaultAfterExecutionState (org.gradle.internal.execution.history.impl.DefaultAfterExecutionState)2 Duration (java.time.Duration)1 ExecutionOutcome (org.gradle.internal.execution.ExecutionOutcome)1 ExecutionResult (org.gradle.internal.execution.ExecutionResult)1 OutputSnapshotter (org.gradle.internal.execution.OutputSnapshotter)1 PreviousExecutionState (org.gradle.internal.execution.history.PreviousExecutionState)1 FileSystemSnapshot (org.gradle.internal.snapshot.FileSystemSnapshot)1 Timer (org.gradle.internal.time.Timer)1