Search in sources :

Example 16 with TaskInternal

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

the class ClientForwardingTestOperationListener method started.

@Override
public void started(BuildOperationInternal buildOperation, OperationStartEvent startEvent) {
    if (!(buildOperation.getOperationDescriptor() instanceof TaskOperationDescriptor)) {
        return;
    }
    TaskInternal task = ((TaskOperationDescriptor) buildOperation.getOperationDescriptor()).getTask();
    if (!(task instanceof Test)) {
        return;
    }
    runningTasks.put(buildOperation.getId(), task.getPath());
}
Also used : Test(org.gradle.api.tasks.testing.Test) TaskInternal(org.gradle.api.internal.TaskInternal) TaskOperationDescriptor(org.gradle.api.execution.internal.TaskOperationDescriptor)

Example 17 with TaskInternal

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

the class TestExecutionResultEvaluator method started.

@Override
public void started(BuildOperationInternal buildOperation, OperationStartEvent startEvent) {
    if (!(buildOperation.getOperationDescriptor() instanceof TaskOperationDescriptor)) {
        return;
    }
    TaskInternal task = ((TaskOperationDescriptor) buildOperation.getOperationDescriptor()).getTask();
    runningTasks.put(buildOperation.getId(), task.getPath());
}
Also used : TaskInternal(org.gradle.api.internal.TaskInternal) TaskOperationDescriptor(org.gradle.api.execution.internal.TaskOperationDescriptor)

Example 18 with TaskInternal

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

the class DefaultTaskExecutionPlan method addToTaskGraph.

public void addToTaskGraph(Collection<? extends Task> tasks) {
    List<TaskInfo> queue = new ArrayList<TaskInfo>();
    List<Task> sortedTasks = new ArrayList<Task>(tasks);
    Collections.sort(sortedTasks);
    for (Task task : sortedTasks) {
        TaskInfo node = nodeFactory.createNode(task);
        if (node.isMustNotRun()) {
            requireWithDependencies(node);
        } else if (filter.isSatisfiedBy(task)) {
            node.require();
        }
        entryTasks.add(node);
        queue.add(node);
    }
    Set<TaskInfo> visiting = new HashSet<TaskInfo>();
    CachingTaskDependencyResolveContext context = new CachingTaskDependencyResolveContext();
    while (!queue.isEmpty()) {
        TaskInfo node = queue.get(0);
        if (node.getDependenciesProcessed()) {
            // Have already visited this task - skip it
            queue.remove(0);
            continue;
        }
        TaskInternal task = node.getTask();
        boolean filtered = !filter.isSatisfiedBy(task);
        if (filtered) {
            // Task is not required - skip it
            queue.remove(0);
            node.dependenciesProcessed();
            node.doNotRequire();
            filteredTasks.add(task);
            continue;
        }
        if (visiting.add(node)) {
            // Have not seen this task before - add its dependencies to the head of the queue and leave this
            // task in the queue
            // Make sure it has been configured
            ((TaskContainerInternal) task.getProject().getTasks()).prepareForExecution(task);
            Set<? extends Task> dependsOnTasks = context.getDependencies(task, task.getTaskDependencies());
            for (Task dependsOnTask : dependsOnTasks) {
                TaskInfo targetNode = nodeFactory.createNode(dependsOnTask);
                node.addDependencySuccessor(targetNode);
                if (!visiting.contains(targetNode)) {
                    queue.add(0, targetNode);
                }
            }
            for (Task finalizerTask : context.getDependencies(task, task.getFinalizedBy())) {
                TaskInfo targetNode = nodeFactory.createNode(finalizerTask);
                addFinalizerNode(node, targetNode);
                if (!visiting.contains(targetNode)) {
                    queue.add(0, targetNode);
                }
            }
            for (Task mustRunAfter : context.getDependencies(task, task.getMustRunAfter())) {
                TaskInfo targetNode = nodeFactory.createNode(mustRunAfter);
                node.addMustSuccessor(targetNode);
            }
            for (Task shouldRunAfter : context.getDependencies(task, task.getShouldRunAfter())) {
                TaskInfo targetNode = nodeFactory.createNode(shouldRunAfter);
                node.addShouldSuccessor(targetNode);
            }
            if (node.isRequired()) {
                for (TaskInfo successor : node.getDependencySuccessors()) {
                    if (filter.isSatisfiedBy(successor.getTask())) {
                        successor.require();
                    }
                }
            } else {
                tasksInUnknownState.add(node);
            }
        } else {
            // Have visited this task's dependencies - add it to the graph
            queue.remove(0);
            visiting.remove(node);
            node.dependenciesProcessed();
        }
    }
    resolveTasksInUnknownState();
}
Also used : CachingTaskDependencyResolveContext(org.gradle.api.internal.tasks.CachingTaskDependencyResolveContext) Task(org.gradle.api.Task) TaskInternal(org.gradle.api.internal.TaskInternal) ArrayList(java.util.ArrayList) TaskContainerInternal(org.gradle.api.internal.tasks.TaskContainerInternal) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

TaskInternal (org.gradle.api.internal.TaskInternal)18 Task (org.gradle.api.Task)4 TaskOperationDescriptor (org.gradle.api.execution.internal.TaskOperationDescriptor)4 DefaultTaskOutputs (org.gradle.api.internal.tasks.DefaultTaskOutputs)3 TaskStateInternal (org.gradle.api.internal.tasks.TaskStateInternal)3 TaskOutputs (org.gradle.api.tasks.TaskOutputs)3 Expectations (org.jmock.Expectations)3 Closure (groovy.lang.Closure)2 Action (org.gradle.api.Action)2 InvalidUserDataException (org.gradle.api.InvalidUserDataException)2 TaskExecutionContext (org.gradle.api.internal.tasks.TaskExecutionContext)2 DefaultTaskFinishedProgressEvent (org.gradle.tooling.internal.provider.events.DefaultTaskFinishedProgressEvent)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 DefaultTask (org.gradle.api.DefaultTask)1 ExecuteTaskBuildOperationDetails (org.gradle.api.execution.internal.ExecuteTaskBuildOperationDetails)1 TaskInputsListener (org.gradle.api.execution.internal.TaskInputsListener)1