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());
}
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();
}
use of org.gradle.api.internal.TaskInternal in project gradle by gradle.
the class IvyPublishPlugin method disableGradleMetadataGenerationIfCustomLayout.
private void disableGradleMetadataGenerationIfCustomLayout(NamedDomainObjectList<IvyArtifactRepository> repositories, GenerateModuleMetadata generateTask) {
AtomicBoolean didWarn = new AtomicBoolean();
Spec<? super Task> checkStandardLayout = task -> {
boolean standard = repositories.stream().allMatch(this::hasStandardPattern);
if (!standard && !didWarn.getAndSet(true)) {
LOGGER.warn("Publication of Gradle Module Metadata is disabled because you have configured an Ivy repository with a non-standard layout");
}
return standard;
};
Spec<TaskInternal> spec = new AndSpec<TaskInternal>(generateTask.getOnlyIf(), checkStandardLayout);
generateTask.setOnlyIf(Cast.<Spec<? super Task>>uncheckedCast(spec));
}
use of org.gradle.api.internal.TaskInternal in project gradle by gradle.
the class TaskOperationMapper method createFinishedEvent.
@Override
public InternalOperationFinishedProgressEvent createFinishedEvent(DefaultTaskDescriptor descriptor, ExecuteTaskBuildOperationDetails details, OperationFinishEvent finishEvent) {
TaskInternal task = details.getTask();
AbstractTaskResult taskResult = operationResultPostProcessor.process(toTaskResult(task, finishEvent), descriptor.getId());
return new DefaultTaskFinishedProgressEvent(finishEvent.getEndTime(), descriptor, taskResult);
}
use of org.gradle.api.internal.TaskInternal in project gradle by gradle.
the class DefaultBuildController method checkForCyclesFor.
private void checkForCyclesFor(TaskInternal task, Set<TaskInternal> visited, Set<TaskInternal> visiting) {
if (visited.contains(task)) {
// Already checked
return;
}
if (!visiting.add(task)) {
// Visiting dependencies -> have found a cycle
CachingDirectedGraphWalker<TaskInternal, Void> graphWalker = new CachingDirectedGraphWalker<>((node, values, connectedNodes) -> visitDependenciesOf(node, connectedNodes::add));
graphWalker.add(task);
List<Set<TaskInternal>> cycles = graphWalker.findCycles();
Set<TaskInternal> cycle = cycles.get(0);
DirectedGraphRenderer<TaskInternal> graphRenderer = new DirectedGraphRenderer<>((node, output) -> output.withStyle(StyledTextOutput.Style.Identifier).text(node.getIdentityPath()), (node, values, connectedNodes) -> visitDependenciesOf(node, dep -> {
if (cycle.contains(dep)) {
connectedNodes.add(dep);
}
}));
StringWriter writer = new StringWriter();
graphRenderer.renderTo(task, writer);
throw new CircularReferenceException(String.format("Circular dependency between the following tasks:%n%s", writer));
}
visitDependenciesOf(task, dep -> checkForCyclesFor(dep, visited, visiting));
visiting.remove(task);
visited.add(task);
}
Aggregations