Search in sources :

Example 26 with TaskInternal

use of org.gradle.api.internal.TaskInternal 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 27 with TaskInternal

use of org.gradle.api.internal.TaskInternal in project gradle by gradle.

the class DefaultTaskContainer method doCreate.

private Task doCreate(Map<String, ?> options, final Action<? super Task> configureAction) {
    Map<String, ?> factoryOptions = options;
    final boolean replace;
    if (options.containsKey(Task.TASK_OVERWRITE)) {
        factoryOptions = new HashMap<String, Object>(options);
        Object replaceStr = factoryOptions.remove(Task.TASK_OVERWRITE);
        replace = "true".equals(replaceStr.toString());
    } else {
        replace = false;
    }
    final Map<String, ?> actualArgs = checkTaskArgsAndCreateDefaultValues(factoryOptions);
    final String name = actualArgs.get(Task.TASK_NAME).toString();
    if (!GUtil.isTrue(name)) {
        throw new InvalidUserDataException("The task name must be provided.");
    }
    final Class<? extends TaskInternal> type = Cast.uncheckedCast(actualArgs.get(Task.TASK_TYPE));
    final TaskIdentity<? extends TaskInternal> identity = TaskIdentity.create(name, type, project);
    return buildOperationExecutor.call(new CallableBuildOperation<Task>() {

        @Override
        public BuildOperationDescriptor.Builder description() {
            return realizeDescriptor(identity, replace, true);
        }

        @Override
        public Task call(BuildOperationContext context) {
            try {
                Object[] constructorArgs = getConstructorArgs(actualArgs);
                TaskInternal task = createTask(identity, constructorArgs);
                statistics.eagerTask(type);
                Object dependsOnTasks = actualArgs.get(Task.TASK_DEPENDS_ON);
                if (dependsOnTasks != null) {
                    task.dependsOn(dependsOnTasks);
                }
                Object description = actualArgs.get(Task.TASK_DESCRIPTION);
                if (description != null) {
                    task.setDescription(description.toString());
                }
                Object group = actualArgs.get(Task.TASK_GROUP);
                if (group != null) {
                    task.setGroup(group.toString());
                }
                Object action = actualArgs.get(Task.TASK_ACTION);
                if (action instanceof Action) {
                    Action<? super Task> taskAction = Cast.uncheckedCast(action);
                    task.doFirst(taskAction);
                } else if (action != null) {
                    Closure closure = (Closure) action;
                    task.doFirst(closure);
                }
                addTask(task, replace);
                configureAction.execute(task);
                context.setResult(REALIZE_RESULT);
                return task;
            } catch (Throwable t) {
                throw taskCreationException(name, t);
            }
        }
    });
}
Also used : BuildOperationContext(org.gradle.internal.operations.BuildOperationContext) Task(org.gradle.api.Task) DefaultTask(org.gradle.api.DefaultTask) Action(org.gradle.api.Action) Closure(groovy.lang.Closure) TaskInternal(org.gradle.api.internal.TaskInternal) InvalidUserDataException(org.gradle.api.InvalidUserDataException) DynamicObject(org.gradle.internal.metaobject.DynamicObject)

Example 28 with TaskInternal

use of org.gradle.api.internal.TaskInternal 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)28 Task (org.gradle.api.Task)7 TaskStateInternal (org.gradle.api.internal.tasks.TaskStateInternal)5 TaskOperationDescriptor (org.gradle.api.execution.internal.TaskOperationDescriptor)4 TaskExecutionContext (org.gradle.api.internal.tasks.TaskExecutionContext)4 Closure (groovy.lang.Closure)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 LinkedHashSet (java.util.LinkedHashSet)3 List (java.util.List)3 Action (org.gradle.api.Action)3 InvalidUserDataException (org.gradle.api.InvalidUserDataException)3 Set (java.util.Set)2 DefaultTask (org.gradle.api.DefaultTask)2 ProjectInternal (org.gradle.api.internal.project.ProjectInternal)2 DefaultTaskOutputs (org.gradle.api.internal.tasks.DefaultTaskOutputs)2 TaskExecuter (org.gradle.api.internal.tasks.TaskExecuter)2 PropertyWalker (org.gradle.api.internal.tasks.properties.PropertyWalker)2 TaskOutputs (org.gradle.api.tasks.TaskOutputs)2 ServiceRegistry (org.gradle.internal.service.ServiceRegistry)2