Search in sources :

Example 1 with CachingState

use of org.gradle.internal.execution.caching.CachingState 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 2 with CachingState

use of org.gradle.internal.execution.caching.CachingState in project gradle by gradle.

the class ExecuteActionsTaskExecuter method executeIfValid.

private TaskExecuterResult executeIfValid(TaskInternal task, TaskStateInternal state, TaskExecutionContext context, TaskExecution work) {
    ExecutionEngine.Request request = executionEngine.createRequest(work);
    context.getTaskExecutionMode().getRebuildReason().ifPresent(request::forceNonIncremental);
    request.withValidationContext(context.getValidationContext());
    Result result = request.execute();
    result.getExecutionResult().ifSuccessfulOrElse(executionResult -> state.setOutcome(TaskExecutionOutcome.valueOf(executionResult.getOutcome())), failure -> state.setOutcome(new TaskExecutionException(task, failure)));
    return new TaskExecuterResult() {

        @Override
        public Optional<OriginMetadata> getReusedOutputOriginMetadata() {
            return result.getReusedOutputOriginMetadata();
        }

        @Override
        public boolean executedIncrementally() {
            return result.getExecutionResult().map(executionResult -> executionResult.getOutcome() == ExecutionOutcome.EXECUTED_INCREMENTALLY).getOrMapFailure(throwable -> false);
        }

        @Override
        public List<String> getExecutionReasons() {
            return result.getExecutionReasons();
        }

        @Override
        public CachingState getCachingState() {
            return result.getCachingState();
        }
    };
}
Also used : TaskExecutionException(org.gradle.api.tasks.TaskExecutionException) Result(org.gradle.internal.execution.ExecutionEngine.Result) WorkValidationException(org.gradle.internal.execution.WorkValidationException) TaskInternal(org.gradle.api.internal.TaskInternal) ListenerManager(org.gradle.internal.event.ListenerManager) ExecutionOutcome(org.gradle.internal.execution.ExecutionOutcome) TaskExecutionException(org.gradle.api.tasks.TaskExecutionException) TaskExecuterResult(org.gradle.api.internal.tasks.TaskExecuterResult) TaskStateInternal(org.gradle.api.internal.tasks.TaskStateInternal) AsyncWorkTracker(org.gradle.internal.work.AsyncWorkTracker) ClassLoaderHierarchyHasher(org.gradle.internal.hash.ClassLoaderHierarchyHasher) TaskExecutionContext(org.gradle.api.internal.tasks.TaskExecutionContext) ExecutionEngine(org.gradle.internal.execution.ExecutionEngine) List(java.util.List) InputFingerprinter(org.gradle.internal.execution.fingerprint.InputFingerprinter) FileCollectionFactory(org.gradle.api.internal.file.FileCollectionFactory) ExecutionHistoryStore(org.gradle.internal.execution.history.ExecutionHistoryStore) BuildOperationExecutor(org.gradle.internal.operations.BuildOperationExecutor) TaskExecuter(org.gradle.api.internal.tasks.TaskExecuter) FileOperations(org.gradle.api.internal.file.FileOperations) Optional(java.util.Optional) TaskExecutionOutcome(org.gradle.api.internal.tasks.TaskExecutionOutcome) OriginMetadata(org.gradle.caching.internal.origin.OriginMetadata) CachingState(org.gradle.internal.execution.caching.CachingState) ReservedFileSystemLocationRegistry(org.gradle.internal.file.ReservedFileSystemLocationRegistry) ExecutionEngine(org.gradle.internal.execution.ExecutionEngine) TaskExecuterResult(org.gradle.api.internal.tasks.TaskExecuterResult) OriginMetadata(org.gradle.caching.internal.origin.OriginMetadata) Result(org.gradle.internal.execution.ExecutionEngine.Result) TaskExecuterResult(org.gradle.api.internal.tasks.TaskExecuterResult)

Aggregations

List (java.util.List)2 Optional (java.util.Optional)2 OriginMetadata (org.gradle.caching.internal.origin.OriginMetadata)2 CachingState (org.gradle.internal.execution.caching.CachingState)2 ExecutionHistoryStore (org.gradle.internal.execution.history.ExecutionHistoryStore)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 File (java.io.File)1 Duration (java.time.Duration)1 Formatter (java.util.Formatter)1 TaskInternal (org.gradle.api.internal.TaskInternal)1 FileCollectionFactory (org.gradle.api.internal.file.FileCollectionFactory)1 FileOperations (org.gradle.api.internal.file.FileOperations)1 TaskExecuter (org.gradle.api.internal.tasks.TaskExecuter)1 TaskExecuterResult (org.gradle.api.internal.tasks.TaskExecuterResult)1 TaskExecutionContext (org.gradle.api.internal.tasks.TaskExecutionContext)1 TaskExecutionOutcome (org.gradle.api.internal.tasks.TaskExecutionOutcome)1 TaskStateInternal (org.gradle.api.internal.tasks.TaskStateInternal)1 TaskExecutionException (org.gradle.api.tasks.TaskExecutionException)1 BuildCacheKey (org.gradle.caching.BuildCacheKey)1