use of org.gradle.internal.execution.history.AfterExecutionState 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();
}
};
}
use of org.gradle.internal.execution.history.AfterExecutionState 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));
}
use of org.gradle.internal.execution.history.AfterExecutionState in project gradle by gradle.
the class CaptureStateAfterExecutionStep method execute.
@Override
public AfterExecutionResult execute(UnitOfWork work, C context) {
Result result = delegate.execute(work, context);
final Duration duration = result.getDuration();
Optional<AfterExecutionState> afterExecutionState = context.getBeforeExecutionState().flatMap(beforeExecutionState -> captureStateAfterExecution(work, context, beforeExecutionState, duration));
return new AfterExecutionResult() {
@Override
public Optional<AfterExecutionState> getAfterExecutionState() {
return afterExecutionState;
}
@Override
public Try<ExecutionResult> getExecutionResult() {
return result.getExecutionResult();
}
@Override
public Duration getDuration() {
return duration;
}
};
}
use of org.gradle.internal.execution.history.AfterExecutionState in project gradle by gradle.
the class ResolveCachingStateStep method execute.
@Override
public CachingResult execute(UnitOfWork work, C context) {
CachingState cachingState;
if (!buildCache.isEnabled() && !buildScansEnabled) {
cachingState = BUILD_CACHE_DISABLED_STATE;
} else if (context.getValidationProblems().isPresent()) {
cachingState = VALIDATION_FAILED_STATE;
} else {
cachingState = context.getBeforeExecutionState().map(beforeExecutionState -> calculateCachingState(work, beforeExecutionState)).orElseGet(() -> calculateCachingStateWithNoCapturedInputs(work));
}
cachingState.apply(enabled -> logCacheKey(enabled.getKey(), work), disabled -> logDisabledReasons(disabled.getDisabledReasons(), work));
UpToDateResult result = delegate.execute(work, new CachingContext() {
@Override
public CachingState getCachingState() {
return cachingState;
}
@Override
public Optional<String> getNonIncrementalReason() {
return context.getNonIncrementalReason();
}
@Override
public WorkValidationContext getValidationContext() {
return context.getValidationContext();
}
@Override
public ImmutableSortedMap<String, ValueSnapshot> getInputProperties() {
return context.getInputProperties();
}
@Override
public ImmutableSortedMap<String, CurrentFileCollectionFingerprint> getInputFileProperties() {
return context.getInputFileProperties();
}
@Override
public UnitOfWork.Identity getIdentity() {
return context.getIdentity();
}
@Override
public File getWorkspace() {
return context.getWorkspace();
}
@Override
public Optional<ExecutionHistoryStore> getHistory() {
return context.getHistory();
}
@Override
public Optional<PreviousExecutionState> getPreviousExecutionState() {
return context.getPreviousExecutionState();
}
@Override
public Optional<ValidationResult> getValidationProblems() {
return context.getValidationProblems();
}
@Override
public Optional<BeforeExecutionState> getBeforeExecutionState() {
return context.getBeforeExecutionState();
}
});
return new CachingResult() {
@Override
public CachingState getCachingState() {
return cachingState;
}
@Override
public ImmutableList<String> getExecutionReasons() {
return result.getExecutionReasons();
}
@Override
public Optional<AfterExecutionState> getAfterExecutionState() {
return result.getAfterExecutionState();
}
@Override
public Optional<OriginMetadata> getReusedOutputOriginMetadata() {
return result.getReusedOutputOriginMetadata();
}
@Override
public Try<ExecutionResult> getExecutionResult() {
return result.getExecutionResult();
}
@Override
public Duration getDuration() {
return result.getDuration();
}
};
}
use of org.gradle.internal.execution.history.AfterExecutionState 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();
}
};
}
Aggregations