Search in sources :

Example 1 with PreviousExecutionState

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();
        }
    };
}
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 PreviousExecutionState

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);
}
Also used : ValueSnapshot(org.gradle.internal.snapshot.ValueSnapshot) DefaultBeforeExecutionState(org.gradle.internal.execution.history.impl.DefaultBeforeExecutionState) OverlappingOutputs(org.gradle.internal.execution.history.OverlappingOutputs) PreviousExecutionState(org.gradle.internal.execution.history.PreviousExecutionState) FileSystemSnapshot(org.gradle.internal.snapshot.FileSystemSnapshot) InputFingerprinter(org.gradle.internal.execution.fingerprint.InputFingerprinter) ImplementationSnapshot(org.gradle.internal.snapshot.impl.ImplementationSnapshot)

Example 3 with PreviousExecutionState

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();
        }
    };
}
Also used : BeforeExecutionState(org.gradle.internal.execution.history.BeforeExecutionState) CurrentFileCollectionFingerprint(org.gradle.internal.fingerprint.CurrentFileCollectionFingerprint) LoggerFactory(org.slf4j.LoggerFactory) AfterExecutionState(org.gradle.internal.execution.history.AfterExecutionState) PreviousExecutionState(org.gradle.internal.execution.history.PreviousExecutionState) Formatter(java.util.Formatter) WorkValidationContext(org.gradle.internal.execution.WorkValidationContext) CachingStateFactory(org.gradle.internal.execution.caching.CachingStateFactory) ExecutionResult(org.gradle.internal.execution.ExecutionResult) ImmutableList(com.google.common.collect.ImmutableList) ExecutionHistoryStore(org.gradle.internal.execution.history.ExecutionHistoryStore) Duration(java.time.Duration) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) OverlappingOutputs(org.gradle.internal.execution.history.OverlappingOutputs) UnitOfWork(org.gradle.internal.execution.UnitOfWork) Logger(org.slf4j.Logger) ValueSnapshot(org.gradle.internal.snapshot.ValueSnapshot) File(java.io.File) BuildCacheKey(org.gradle.caching.BuildCacheKey) CachingDisabledReason(org.gradle.internal.execution.caching.CachingDisabledReason) List(java.util.List) BuildCacheController(org.gradle.caching.internal.controller.BuildCacheController) NOPLogger(org.slf4j.helpers.NOPLogger) Try(org.gradle.internal.Try) CachingDisabledReasonCategory(org.gradle.internal.execution.caching.CachingDisabledReasonCategory) Optional(java.util.Optional) DefaultCachingStateFactory(org.gradle.internal.execution.caching.impl.DefaultCachingStateFactory) OriginMetadata(org.gradle.caching.internal.origin.OriginMetadata) CachingState(org.gradle.internal.execution.caching.CachingState) AfterExecutionState(org.gradle.internal.execution.history.AfterExecutionState) Optional(java.util.Optional) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) ExecutionResult(org.gradle.internal.execution.ExecutionResult) OriginMetadata(org.gradle.caching.internal.origin.OriginMetadata) File(java.io.File) CachingState(org.gradle.internal.execution.caching.CachingState) WorkValidationContext(org.gradle.internal.execution.WorkValidationContext)

Example 4 with PreviousExecutionState

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();
        }
    });
}
Also used : BeforeExecutionState(org.gradle.internal.execution.history.BeforeExecutionState) TypeValidationProblemRenderer.convertToSingleLine(org.gradle.internal.reflect.validation.TypeValidationProblemRenderer.convertToSingleLine) CurrentFileCollectionFingerprint(org.gradle.internal.fingerprint.CurrentFileCollectionFingerprint) LoggerFactory(org.slf4j.LoggerFactory) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) ImmutableCollection(com.google.common.collect.ImmutableCollection) Severity(org.gradle.internal.reflect.validation.Severity) PreviousExecutionState(org.gradle.internal.execution.history.PreviousExecutionState) WorkValidationContext(org.gradle.internal.execution.WorkValidationContext) ImmutableList(com.google.common.collect.ImmutableList) ExecutionHistoryStore(org.gradle.internal.execution.history.ExecutionHistoryStore) ModelType(org.gradle.model.internal.type.ModelType) Map(java.util.Map) Collectors.mapping(java.util.stream.Collectors.mapping) BaseProblem(org.gradle.problems.BaseProblem) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) UnitOfWork(org.gradle.internal.execution.UnitOfWork) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) ValidationProblemBuilder(org.gradle.internal.reflect.validation.ValidationProblemBuilder) GeneratedSubclasses(org.gradle.api.internal.GeneratedSubclasses) TypeValidationProblemRenderer.renderMinimalInformationAbout(org.gradle.internal.reflect.validation.TypeValidationProblemRenderer.renderMinimalInformationAbout) WorkValidationException(org.gradle.internal.execution.WorkValidationException) Logger(org.slf4j.Logger) ImplementationSnapshot(org.gradle.internal.snapshot.impl.ImplementationSnapshot) Collection(java.util.Collection) ValueSnapshot(org.gradle.internal.snapshot.ValueSnapshot) TypeValidationContext(org.gradle.internal.reflect.validation.TypeValidationContext) MutableReference(org.gradle.internal.MutableReference) Collectors(java.util.stream.Collectors) File(java.io.File) VirtualFileSystem(org.gradle.internal.vfs.VirtualFileSystem) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Optional(java.util.Optional) ValidationProblemId(org.gradle.internal.reflect.problems.ValidationProblemId) Optional(java.util.Optional) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) Severity(org.gradle.internal.reflect.validation.Severity) CurrentFileCollectionFingerprint(org.gradle.internal.fingerprint.CurrentFileCollectionFingerprint) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) File(java.io.File) WorkValidationContext(org.gradle.internal.execution.WorkValidationContext)

Example 5 with PreviousExecutionState

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));
}
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)

Aggregations

PreviousExecutionState (org.gradle.internal.execution.history.PreviousExecutionState)6 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)4 File (java.io.File)3 Optional (java.util.Optional)3 UnitOfWork (org.gradle.internal.execution.UnitOfWork)3 WorkValidationContext (org.gradle.internal.execution.WorkValidationContext)3 ValueSnapshot (org.gradle.internal.snapshot.ValueSnapshot)3 ImmutableList (com.google.common.collect.ImmutableList)2 Duration (java.time.Duration)2 List (java.util.List)2 OriginMetadata (org.gradle.caching.internal.origin.OriginMetadata)2 ExecutionOutcome (org.gradle.internal.execution.ExecutionOutcome)2 ExecutionResult (org.gradle.internal.execution.ExecutionResult)2 AfterExecutionState (org.gradle.internal.execution.history.AfterExecutionState)2 BeforeExecutionState (org.gradle.internal.execution.history.BeforeExecutionState)2 ExecutionHistoryStore (org.gradle.internal.execution.history.ExecutionHistoryStore)2 CurrentFileCollectionFingerprint (org.gradle.internal.fingerprint.CurrentFileCollectionFingerprint)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 ImmutableCollection (com.google.common.collect.ImmutableCollection)1