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;
}
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;
}
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();
}
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);
}
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);
}
Aggregations