use of org.gradle.internal.execution.history.PreviousExecutionState 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.PreviousExecutionState in project gradle by gradle.
the class CaptureStateBeforeExecutionStep method captureExecutionStateWithOutputs.
private BeforeExecutionState captureExecutionStateWithOutputs(UnitOfWork work, PreviousExecutionContext context, ImmutableSortedMap<String, FileSystemSnapshot> unfilteredOutputSnapshots) {
Optional<PreviousExecutionState> previousExecutionState = context.getPreviousExecutionState();
ImplementationsBuilder implementationsBuilder = new ImplementationsBuilder(classLoaderHierarchyHasher);
work.visitImplementations(implementationsBuilder);
ImplementationSnapshot implementation = implementationsBuilder.getImplementation();
ImmutableList<ImplementationSnapshot> additionalImplementations = implementationsBuilder.getAdditionalImplementations();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Implementation for {}: {}", work.getDisplayName(), implementation);
LOGGER.debug("Additional implementations for {}: {}", work.getDisplayName(), additionalImplementations);
}
ImmutableSortedMap<String, ValueSnapshot> previousInputProperties = previousExecutionState.map(InputExecutionState::getInputProperties).orElse(ImmutableSortedMap.of());
ImmutableSortedMap<String, ? extends FileCollectionFingerprint> previousInputFileFingerprints = previousExecutionState.map(InputExecutionState::getInputFileProperties).orElse(ImmutableSortedMap.of());
ImmutableSortedMap<String, FileSystemSnapshot> previousOutputSnapshots = previousExecutionState.map(PreviousExecutionState::getOutputFilesProducedByWork).orElse(ImmutableSortedMap.of());
OverlappingOutputs overlappingOutputs;
switch(work.getOverlappingOutputHandling()) {
case DETECT_OVERLAPS:
overlappingOutputs = overlappingOutputDetector.detect(previousOutputSnapshots, unfilteredOutputSnapshots);
break;
case IGNORE_OVERLAPS:
overlappingOutputs = null;
break;
default:
throw new AssertionError();
}
InputFingerprinter.Result newInputs = work.getInputFingerprinter().fingerprintInputProperties(previousInputProperties, previousInputFileFingerprints, context.getInputProperties(), context.getInputFileProperties(), work::visitRegularInputs);
return new DefaultBeforeExecutionState(implementation, additionalImplementations, newInputs.getAllValueSnapshots(), newInputs.getAllFileFingerprints(), unfilteredOutputSnapshots, overlappingOutputs);
}
use of org.gradle.internal.execution.history.PreviousExecutionState 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.PreviousExecutionState in project gradle by gradle.
the class ValidateStep method execute.
@Override
public R execute(UnitOfWork work, C context) {
WorkValidationContext validationContext = context.getValidationContext();
work.validate(validationContext);
context.getBeforeExecutionState().ifPresent(beforeExecutionState -> validateImplementations(work, beforeExecutionState, validationContext));
Map<Severity, List<String>> problems = validationContext.getProblems().stream().collect(groupingBy(BaseProblem::getSeverity, mapping(ValidateStep::renderedMessage, toList())));
ImmutableCollection<String> warnings = ImmutableList.copyOf(problems.getOrDefault(Severity.WARNING, ImmutableList.of()));
ImmutableCollection<String> errors = ImmutableList.copyOf(problems.getOrDefault(Severity.ERROR, ImmutableList.of()));
if (!warnings.isEmpty()) {
warningReporter.recordValidationWarnings(work, warnings);
}
if (!errors.isEmpty()) {
int maxErrCount = Integer.getInteger(MAX_NB_OF_ERRORS, 5);
ImmutableSortedSet<String> uniqueSortedErrors = ImmutableSortedSet.copyOf(errors);
throw WorkValidationException.forProblems(uniqueSortedErrors).limitTo(maxErrCount).withSummary(helper -> String.format("%s found with the configuration of %s (%s).", helper.size() == 1 ? "A problem was" : "Some problems were", work.getDisplayName(), describeTypesChecked(validationContext.getValidatedTypes()))).get();
}
if (!warnings.isEmpty()) {
LOGGER.info("Invalidating VFS because {} failed validation", work.getDisplayName());
virtualFileSystem.invalidateAll();
}
return delegate.execute(work, new ValidationFinishedContext() {
@Override
public Optional<BeforeExecutionState> getBeforeExecutionState() {
return context.getBeforeExecutionState();
}
@Override
public Optional<ValidationResult> getValidationProblems() {
return warnings.isEmpty() ? Optional.empty() : Optional.of(() -> warnings);
}
@Override
public Optional<PreviousExecutionState> getPreviousExecutionState() {
return context.getPreviousExecutionState();
}
@Override
public File getWorkspace() {
return context.getWorkspace();
}
@Override
public Optional<ExecutionHistoryStore> getHistory() {
return context.getHistory();
}
@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 Optional<String> getNonIncrementalReason() {
return context.getNonIncrementalReason();
}
@Override
public WorkValidationContext getValidationContext() {
return context.getValidationContext();
}
});
}
use of org.gradle.internal.execution.history.PreviousExecutionState 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));
}
Aggregations