Search in sources :

Example 1 with ExecutionOutcome

use of org.gradle.internal.execution.ExecutionOutcome 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 ExecutionOutcome

use of org.gradle.internal.execution.ExecutionOutcome 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 3 with ExecutionOutcome

use of org.gradle.internal.execution.ExecutionOutcome in project gradle by gradle.

the class ExecuteStep method executeInternal.

private static Result executeInternal(UnitOfWork work, InputChangesContext context) {
    UnitOfWork.ExecutionRequest executionRequest = new UnitOfWork.ExecutionRequest() {

        @Override
        public File getWorkspace() {
            return context.getWorkspace();
        }

        @Override
        public Optional<InputChangesInternal> getInputChanges() {
            return context.getInputChanges();
        }

        @Override
        public Optional<ImmutableSortedMap<String, FileSystemSnapshot>> getPreviouslyProducedOutputs() {
            return context.getPreviousExecutionState().map(PreviousExecutionState::getOutputFilesProducedByWork);
        }
    };
    UnitOfWork.WorkOutput workOutput;
    Timer timer = Time.startTimer();
    try {
        workOutput = work.execute(executionRequest);
    } catch (Throwable t) {
        return ResultImpl.failed(t, Duration.ofMillis(timer.getElapsedMillis()));
    }
    Duration duration = Duration.ofMillis(timer.getElapsedMillis());
    ExecutionOutcome outcome = determineOutcome(context, workOutput);
    return ResultImpl.success(duration, new ExecutionResultImpl(outcome, workOutput));
}
Also used : UnitOfWork(org.gradle.internal.execution.UnitOfWork) ExecutionOutcome(org.gradle.internal.execution.ExecutionOutcome) Timer(org.gradle.internal.time.Timer) InputChangesInternal(org.gradle.internal.execution.history.changes.InputChangesInternal) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) Duration(java.time.Duration) PreviousExecutionState(org.gradle.internal.execution.history.PreviousExecutionState)

Example 4 with ExecutionOutcome

use of org.gradle.internal.execution.ExecutionOutcome in project gradle by gradle.

the class ExecuteStep method determineOutcome.

private static ExecutionOutcome determineOutcome(InputChangesContext context, UnitOfWork.WorkOutput workOutput) {
    ExecutionOutcome outcome;
    switch(workOutput.getDidWork()) {
        case DID_NO_WORK:
            outcome = ExecutionOutcome.UP_TO_DATE;
            break;
        case DID_WORK:
            boolean incremental = context.getInputChanges().map(InputChanges::isIncremental).orElse(false);
            outcome = incremental ? ExecutionOutcome.EXECUTED_INCREMENTALLY : ExecutionOutcome.EXECUTED_NON_INCREMENTALLY;
            break;
        default:
            throw new AssertionError();
    }
    return outcome;
}
Also used : ExecutionOutcome(org.gradle.internal.execution.ExecutionOutcome)

Aggregations

ExecutionOutcome (org.gradle.internal.execution.ExecutionOutcome)4 Duration (java.time.Duration)2 OriginMetadata (org.gradle.caching.internal.origin.OriginMetadata)2 ExecutionResult (org.gradle.internal.execution.ExecutionResult)2 AfterExecutionState (org.gradle.internal.execution.history.AfterExecutionState)2 PreviousExecutionState (org.gradle.internal.execution.history.PreviousExecutionState)2 Timer (org.gradle.internal.time.Timer)2 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 Nonnull (javax.annotation.Nonnull)1 UnitOfWork (org.gradle.internal.execution.UnitOfWork)1 InputChangesInternal (org.gradle.internal.execution.history.changes.InputChangesInternal)1 DefaultAfterExecutionState (org.gradle.internal.execution.history.impl.DefaultAfterExecutionState)1 FileSystemSnapshot (org.gradle.internal.snapshot.FileSystemSnapshot)1