Search in sources :

Example 6 with TaskInternal

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

the class DefaultTaskExecutionPlan method canRunWithWithCurrentlyExecutedTasks.

private boolean canRunWithWithCurrentlyExecutedTasks(TaskInfo taskInfo) {
    TaskInternal task = taskInfo.getTask();
    String projectPath = task.getProject().getPath();
    if (isParallelizable(task)) {
        if (projectsWithRunningNonParallelizableTasks.contains(projectPath)) {
            return false;
        }
    } else {
        if (projectsWithRunningTasks.contains(projectPath)) {
            return false;
        }
    }
    Pair<TaskInternal, String> overlap = firstTaskWithOverlappingOutput(task);
    if (overlap == null) {
        return true;
    } else {
        LOGGER.info("Cannot execute task {} in parallel with task {} due to overlapping output: {}", task.getPath(), overlap.left.getPath(), overlap.right);
    }
    return false;
}
Also used : TaskInternal(org.gradle.api.internal.TaskInternal)

Example 7 with TaskInternal

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

the class TaskFactory method createTask.

public TaskInternal createTask(Map<String, ?> args) {
    Map<String, Object> actualArgs = new HashMap<String, Object>(args);
    checkTaskArgsAndCreateDefaultValues(actualArgs);
    String name = actualArgs.get(Task.TASK_NAME).toString();
    if (!GUtil.isTrue(name)) {
        throw new InvalidUserDataException("The task name must be provided.");
    }
    Class<? extends TaskInternal> type = (Class) actualArgs.get(Task.TASK_TYPE);
    TaskInternal task = create(name, 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 = (Action<? super Task>) action;
        task.doFirst(taskAction);
    } else if (action != null) {
        Closure closure = (Closure) action;
        task.doFirst(closure);
    }
    return task;
}
Also used : Action(org.gradle.api.Action) AbstractTask(org.gradle.api.internal.AbstractTask) Task(org.gradle.api.Task) DefaultTask(org.gradle.api.DefaultTask) Closure(groovy.lang.Closure) HashMap(java.util.HashMap) InvalidUserDataException(org.gradle.api.InvalidUserDataException) TaskInternal(org.gradle.api.internal.TaskInternal)

Example 8 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 = graph.addNode(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();
            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);
            for (Task dependsOnTask : dependsOnTasks) {
                TaskInfo targetNode = graph.addNode(dependsOnTask);
                node.addDependencySuccessor(targetNode);
                if (!visiting.contains(targetNode)) {
                    queue.add(0, targetNode);
                }
            }
            for (Task finalizerTask : task.getFinalizedBy().getDependencies(task)) {
                TaskInfo targetNode = graph.addNode(finalizerTask);
                addFinalizerNode(node, targetNode);
                if (!visiting.contains(targetNode)) {
                    queue.add(0, targetNode);
                }
            }
            for (Task mustRunAfter : task.getMustRunAfter().getDependencies(task)) {
                TaskInfo targetNode = graph.addNode(mustRunAfter);
                node.addMustSuccessor(targetNode);
            }
            for (Task shouldRunAfter : task.getShouldRunAfter().getDependencies(task)) {
                TaskInfo targetNode = graph.addNode(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) ParallelizableTask(org.gradle.api.tasks.ParallelizableTask) TaskInternal(org.gradle.api.internal.TaskInternal) TaskContainerInternal(org.gradle.api.internal.tasks.TaskContainerInternal)

Example 9 with TaskInternal

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

the class DefaultTaskExecutionPlan method recordTaskCompleted.

private void recordTaskCompleted(TaskInfo taskInfo) {
    TaskInternal task = taskInfo.getTask();
    String projectPath = task.getProject().getPath();
    if (!isParallelizable(task)) {
        projectsWithRunningNonParallelizableTasks.remove(projectPath);
    }
    projectsWithRunningTasks.remove(projectPath);
    canonicalizedOutputCache.remove(task);
    isParallelSafeCache.remove(task);
    runningTasks.remove(task);
}
Also used : TaskInternal(org.gradle.api.internal.TaskInternal)

Example 10 with TaskInternal

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

the class DefaultTaskExecutionPlan method recordTaskStarted.

private void recordTaskStarted(TaskInfo taskInfo) {
    TaskInternal task = taskInfo.getTask();
    String projectPath = task.getProject().getPath();
    if (!isParallelizable(task)) {
        projectsWithRunningNonParallelizableTasks.add(projectPath);
    }
    projectsWithRunningTasks.add(projectPath);
    runningTasks.add(task);
}
Also used : TaskInternal(org.gradle.api.internal.TaskInternal)

Aggregations

TaskInternal (org.gradle.api.internal.TaskInternal)15 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 Task (org.gradle.api.Task)2 TaskExecutionContext (org.gradle.api.internal.tasks.TaskExecutionContext)2 Closure (groovy.lang.Closure)1 File (java.io.File)1 HashMap (java.util.HashMap)1 Action (org.gradle.api.Action)1 DefaultTask (org.gradle.api.DefaultTask)1 InvalidUserDataException (org.gradle.api.InvalidUserDataException)1 TaskInputsListener (org.gradle.api.execution.internal.TaskInputsListener)1 FileCollection (org.gradle.api.file.FileCollection)1 AbstractTask (org.gradle.api.internal.AbstractTask)1 TaskInputsInternal (org.gradle.api.internal.TaskInputsInternal)1 FileCollectionInternal (org.gradle.api.internal.file.FileCollectionInternal)1 FileSystemSubset (org.gradle.api.internal.file.FileSystemSubset)1