Search in sources :

Example 6 with TaskStateInternal

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

the class ClientForwardingTaskOperationListener method toTaskResult.

private static AbstractTaskResult toTaskResult(TaskInternal task, OperationFinishEvent result) {
    TaskStateInternal state = task.getState();
    long startTime = result.getStartTime();
    long endTime = result.getEndTime();
    if (state.getUpToDate()) {
        return new DefaultTaskSuccessResult(startTime, endTime, true, state.isFromCache(), state.getSkipMessage());
    } else if (state.getSkipped()) {
        return new DefaultTaskSkippedResult(startTime, endTime, state.getSkipMessage());
    } else {
        Throwable failure = result.getFailure();
        if (failure == null) {
            return new DefaultTaskSuccessResult(startTime, endTime, false, state.isFromCache(), "SUCCESS");
        } else {
            return new DefaultTaskFailureResult(startTime, endTime, Collections.singletonList(DefaultFailure.fromThrowable(failure)));
        }
    }
}
Also used : TaskStateInternal(org.gradle.api.internal.tasks.TaskStateInternal) DefaultTaskSuccessResult(org.gradle.tooling.internal.provider.events.DefaultTaskSuccessResult) DefaultTaskSkippedResult(org.gradle.tooling.internal.provider.events.DefaultTaskSkippedResult) DefaultTaskFailureResult(org.gradle.tooling.internal.provider.events.DefaultTaskFailureResult)

Example 7 with TaskStateInternal

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

the class TaskOperationMapper method toTaskResult.

private static AbstractTaskResult toTaskResult(TaskInternal task, OperationFinishEvent finishEvent) {
    TaskStateInternal state = task.getState();
    long startTime = finishEvent.getStartTime();
    long endTime = finishEvent.getEndTime();
    ExecuteTaskBuildOperationType.Result result = (ExecuteTaskBuildOperationType.Result) finishEvent.getResult();
    boolean incremental = result != null && result.isIncremental();
    if (state.getUpToDate()) {
        return new DefaultTaskSuccessResult(startTime, endTime, true, state.isFromCache(), state.getSkipMessage(), incremental, Collections.emptyList());
    } else if (state.getSkipped()) {
        return new DefaultTaskSkippedResult(startTime, endTime, state.getSkipMessage(), incremental);
    } else {
        List<String> executionReasons = result != null ? result.getUpToDateMessages() : null;
        Throwable failure = finishEvent.getFailure();
        if (failure == null) {
            return new DefaultTaskSuccessResult(startTime, endTime, false, state.isFromCache(), "SUCCESS", incremental, executionReasons);
        } else {
            return new DefaultTaskFailureResult(startTime, endTime, singletonList(DefaultFailure.fromThrowable(failure)), incremental, executionReasons);
        }
    }
}
Also used : TaskStateInternal(org.gradle.api.internal.tasks.TaskStateInternal) DefaultTaskSuccessResult(org.gradle.internal.build.event.types.DefaultTaskSuccessResult) DefaultTaskSkippedResult(org.gradle.internal.build.event.types.DefaultTaskSkippedResult) DefaultTaskFailureResult(org.gradle.internal.build.event.types.DefaultTaskFailureResult) ExecuteTaskBuildOperationType(org.gradle.api.internal.tasks.execution.ExecuteTaskBuildOperationType) Collections.singletonList(java.util.Collections.singletonList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) DefaultTaskSkippedResult(org.gradle.internal.build.event.types.DefaultTaskSkippedResult) DefaultTaskSuccessResult(org.gradle.internal.build.event.types.DefaultTaskSuccessResult) DefaultTaskFailureResult(org.gradle.internal.build.event.types.DefaultTaskFailureResult) AbstractTaskResult(org.gradle.internal.build.event.types.AbstractTaskResult)

Example 8 with TaskStateInternal

use of org.gradle.api.internal.tasks.TaskStateInternal 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 9 with TaskStateInternal

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

TaskStateInternal (org.gradle.api.internal.tasks.TaskStateInternal)9 TaskInternal (org.gradle.api.internal.TaskInternal)5 TaskExecutionContext (org.gradle.api.internal.tasks.TaskExecutionContext)4 DefaultTaskOutputs (org.gradle.api.internal.tasks.DefaultTaskOutputs)3 TaskOutputs (org.gradle.api.tasks.TaskOutputs)3 List (java.util.List)2 TaskExecuter (org.gradle.api.internal.tasks.TaskExecuter)2 TaskExecutionOutcome (org.gradle.api.internal.tasks.TaskExecutionOutcome)2 DefaultTaskFailureResult (org.gradle.tooling.internal.provider.events.DefaultTaskFailureResult)2 DefaultTaskSkippedResult (org.gradle.tooling.internal.provider.events.DefaultTaskSkippedResult)2 DefaultTaskSuccessResult (org.gradle.tooling.internal.provider.events.DefaultTaskSuccessResult)2 Expectations (org.jmock.Expectations)2 ImmutableList (com.google.common.collect.ImmutableList)1 Collections.singletonList (java.util.Collections.singletonList)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 DefaultTaskExecutionContext (org.gradle.api.internal.tasks.execution.DefaultTaskExecutionContext)1 ExecuteTaskBuildOperationType (org.gradle.api.internal.tasks.execution.ExecuteTaskBuildOperationType)1