Search in sources :

Example 1 with Node

use of org.gradle.execution.plan.Node in project gradle by gradle.

the class DefaultBuildController method visitDependenciesOf.

private void visitDependenciesOf(TaskInternal task, Consumer<TaskInternal> consumer) {
    TaskNodeFactory taskNodeFactory = ((GradleInternal) task.getProject().getGradle()).getServices().get(TaskNodeFactory.class);
    TaskNode node = taskNodeFactory.getOrCreateNode(task);
    for (Node dependency : node.getAllSuccessors()) {
        if (dependency instanceof TaskNode) {
            consumer.accept(((TaskNode) dependency).getTask());
        }
    }
}
Also used : TaskNode(org.gradle.execution.plan.TaskNode) ExportedTaskNode(org.gradle.internal.build.ExportedTaskNode) TaskNodeFactory(org.gradle.execution.plan.TaskNodeFactory) TaskNode(org.gradle.execution.plan.TaskNode) Node(org.gradle.execution.plan.Node) ExportedTaskNode(org.gradle.internal.build.ExportedTaskNode)

Example 2 with Node

use of org.gradle.execution.plan.Node in project gradle by gradle.

the class DefaultTaskExecutionGraph method getDependencies.

@Override
public Set<Task> getDependencies(Task task) {
    Node node = executionPlan.getNode(task);
    ImmutableSet.Builder<Task> builder = ImmutableSet.builder();
    for (Node dependencyNode : node.getDependencySuccessors()) {
        if (dependencyNode instanceof TaskNode) {
            builder.add(((TaskNode) dependencyNode).getTask());
        }
    }
    return builder.build();
}
Also used : Task(org.gradle.api.Task) TaskNode(org.gradle.execution.plan.TaskNode) ImmutableSet(com.google.common.collect.ImmutableSet) TaskNode(org.gradle.execution.plan.TaskNode) Node(org.gradle.execution.plan.Node)

Example 3 with Node

use of org.gradle.execution.plan.Node in project gradle by gradle.

the class TransformationNode method processDependencies.

protected void processDependencies(Action<Node> processHardSuccessor, Set<Node> dependencies) {
    for (Node dependency : dependencies) {
        addDependencySuccessor(dependency);
        processHardSuccessor.execute(dependency);
    }
}
Also used : Node(org.gradle.execution.plan.Node) SelfExecutingNode(org.gradle.execution.plan.SelfExecutingNode)

Example 4 with Node

use of org.gradle.execution.plan.Node 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);
}
Also used : TaskNodeFactory(org.gradle.execution.plan.TaskNodeFactory) BuildLifecycleController(org.gradle.internal.build.BuildLifecycleController) BuildState(org.gradle.internal.build.BuildState) BuildOperationRef(org.gradle.internal.operations.BuildOperationRef) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) TaskNode(org.gradle.execution.plan.TaskNode) UncheckedException(org.gradle.internal.UncheckedException) LinkedHashSet(java.util.LinkedHashSet) ExecutorService(java.util.concurrent.ExecutorService) CircularReferenceException(org.gradle.api.CircularReferenceException) TaskInternal(org.gradle.api.internal.TaskInternal) Node(org.gradle.execution.plan.Node) GradleInternal(org.gradle.api.internal.GradleInternal) DirectedGraphRenderer(org.gradle.internal.graph.DirectedGraphRenderer) ReentrantLock(java.util.concurrent.locks.ReentrantLock) StringWriter(java.io.StringWriter) BuildWorkGraph(org.gradle.internal.build.BuildWorkGraph) Set(java.util.Set) ExecutionResult(org.gradle.internal.build.ExecutionResult) StyledTextOutput(org.gradle.internal.logging.text.StyledTextOutput) ExportedTaskNode(org.gradle.internal.build.ExportedTaskNode) Consumer(java.util.function.Consumer) List(java.util.List) Condition(java.util.concurrent.locks.Condition) Lock(java.util.concurrent.locks.Lock) CurrentBuildOperationRef(org.gradle.internal.operations.CurrentBuildOperationRef) CachingDirectedGraphWalker(org.gradle.internal.graph.CachingDirectedGraphWalker) WorkerLeaseService(org.gradle.internal.work.WorkerLeaseService) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) StringWriter(java.io.StringWriter) TaskInternal(org.gradle.api.internal.TaskInternal) DirectedGraphRenderer(org.gradle.internal.graph.DirectedGraphRenderer) CircularReferenceException(org.gradle.api.CircularReferenceException) CachingDirectedGraphWalker(org.gradle.internal.graph.CachingDirectedGraphWalker)

Aggregations

Node (org.gradle.execution.plan.Node)4 TaskNode (org.gradle.execution.plan.TaskNode)3 TaskNodeFactory (org.gradle.execution.plan.TaskNodeFactory)2 ExportedTaskNode (org.gradle.internal.build.ExportedTaskNode)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Set (java.util.Set)1 ExecutorService (java.util.concurrent.ExecutorService)1 Condition (java.util.concurrent.locks.Condition)1 Lock (java.util.concurrent.locks.Lock)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 Consumer (java.util.function.Consumer)1 CircularReferenceException (org.gradle.api.CircularReferenceException)1 Task (org.gradle.api.Task)1 GradleInternal (org.gradle.api.internal.GradleInternal)1 TaskInternal (org.gradle.api.internal.TaskInternal)1