Search in sources :

Example 1 with TaskExecutionContext

use of org.gradle.api.internal.tasks.TaskExecutionContext 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)

Example 2 with TaskExecutionContext

use of org.gradle.api.internal.tasks.TaskExecutionContext in project gradle by gradle.

the class LocalTaskNodeExecutor method execute.

@Override
public boolean execute(Node node, NodeExecutionContext context) {
    if (node instanceof LocalTaskNode) {
        LocalTaskNode localTaskNode = (LocalTaskNode) node;
        TaskInternal task = localTaskNode.getTask();
        TaskStateInternal state = task.getState();
        if (state.getExecuted()) {
            // This should move earlier in task scheduling, so that a worker thread does not even bother trying to run this task
            return true;
        }
        ExecutionNodeAccessHierarchies.InputNodeAccessHierarchy inputHierarchy = context.getService(ExecutionNodeAccessHierarchies.InputNodeAccessHierarchy.class);
        TaskExecutionContext ctx = new DefaultTaskExecutionContext(localTaskNode, localTaskNode.getTaskProperties(), localTaskNode.getValidationContext(), (historyMaintained, typeValidationContext) -> detectMissingDependencies(localTaskNode, historyMaintained, inputHierarchy, typeValidationContext));
        TaskExecuter taskExecuter = context.getService(TaskExecuter.class);
        taskExecuter.execute(task, state, ctx);
        localTaskNode.getPostAction().execute(task);
        return true;
    } else {
        return false;
    }
}
Also used : TaskStateInternal(org.gradle.api.internal.tasks.TaskStateInternal) TaskInternal(org.gradle.api.internal.TaskInternal) TaskExecuter(org.gradle.api.internal.tasks.TaskExecuter) DefaultTaskExecutionContext(org.gradle.api.internal.tasks.execution.DefaultTaskExecutionContext) TaskExecutionContext(org.gradle.api.internal.tasks.TaskExecutionContext) DefaultTaskExecutionContext(org.gradle.api.internal.tasks.execution.DefaultTaskExecutionContext)

Aggregations

TaskInternal (org.gradle.api.internal.TaskInternal)2 TaskExecuter (org.gradle.api.internal.tasks.TaskExecuter)2 TaskExecutionContext (org.gradle.api.internal.tasks.TaskExecutionContext)2 TaskStateInternal (org.gradle.api.internal.tasks.TaskStateInternal)2 List (java.util.List)1 Optional (java.util.Optional)1 FileCollectionFactory (org.gradle.api.internal.file.FileCollectionFactory)1 FileOperations (org.gradle.api.internal.file.FileOperations)1 TaskExecuterResult (org.gradle.api.internal.tasks.TaskExecuterResult)1 TaskExecutionOutcome (org.gradle.api.internal.tasks.TaskExecutionOutcome)1 DefaultTaskExecutionContext (org.gradle.api.internal.tasks.execution.DefaultTaskExecutionContext)1 TaskExecutionException (org.gradle.api.tasks.TaskExecutionException)1 OriginMetadata (org.gradle.caching.internal.origin.OriginMetadata)1 ListenerManager (org.gradle.internal.event.ListenerManager)1 ExecutionEngine (org.gradle.internal.execution.ExecutionEngine)1 Result (org.gradle.internal.execution.ExecutionEngine.Result)1 ExecutionOutcome (org.gradle.internal.execution.ExecutionOutcome)1 WorkValidationException (org.gradle.internal.execution.WorkValidationException)1 CachingState (org.gradle.internal.execution.caching.CachingState)1 InputFingerprinter (org.gradle.internal.execution.fingerprint.InputFingerprinter)1