Search in sources :

Example 1 with CachingDirectedGraphWalker

use of org.gradle.internal.graph.CachingDirectedGraphWalker in project gradle by gradle.

the class DefaultTaskExecutionPlan method onOrderingCycle.

private void onOrderingCycle() {
    CachingDirectedGraphWalker<TaskInfo, Void> graphWalker = new CachingDirectedGraphWalker<TaskInfo, Void>(new DirectedGraph<TaskInfo, Void>() {

        public void getNodeValues(TaskInfo node, Collection<? super Void> values, Collection<? super TaskInfo> connectedNodes) {
            connectedNodes.addAll(node.getDependencySuccessors());
            connectedNodes.addAll(node.getMustSuccessors());
        }
    });
    graphWalker.add(entryTasks);
    final List<TaskInfo> firstCycle = new ArrayList<TaskInfo>(graphWalker.findCycles().get(0));
    Collections.sort(firstCycle);
    DirectedGraphRenderer<TaskInfo> graphRenderer = new DirectedGraphRenderer<TaskInfo>(new GraphNodeRenderer<TaskInfo>() {

        public void renderTo(TaskInfo node, StyledTextOutput output) {
            output.withStyle(StyledTextOutput.Style.Identifier).text(node.getTask().getPath());
        }
    }, new DirectedGraph<TaskInfo, Object>() {

        public void getNodeValues(TaskInfo node, Collection<? super Object> values, Collection<? super TaskInfo> connectedNodes) {
            for (TaskInfo dependency : firstCycle) {
                if (node.getDependencySuccessors().contains(dependency) || node.getMustSuccessors().contains(dependency)) {
                    connectedNodes.add(dependency);
                }
            }
        }
    });
    StringWriter writer = new StringWriter();
    graphRenderer.renderTo(firstCycle.get(0), writer);
    throw new CircularReferenceException(String.format("Circular dependency between the following tasks:%n%s", writer.toString()));
}
Also used : StyledTextOutput(org.gradle.internal.logging.text.StyledTextOutput) CachingDirectedGraphWalker(org.gradle.internal.graph.CachingDirectedGraphWalker) StringWriter(java.io.StringWriter) DirectedGraphRenderer(org.gradle.internal.graph.DirectedGraphRenderer)

Example 2 with CachingDirectedGraphWalker

use of org.gradle.internal.graph.CachingDirectedGraphWalker in project gradle by gradle.

the class DefaultLenientConfiguration method visitArtifacts.

/**
     * Recursive, includes unsuccessfully resolved artifacts
     *
     * @param dependencySpec dependency spec
     */
private void visitArtifacts(Spec<? super Dependency> dependencySpec, SelectedArtifactResults artifactResults, SelectedFileDependencyResults fileDependencyResults, ArtifactVisitor visitor) {
    //avoid traversing the graph causing the full ResolvedDependency graph to be loaded for the most typical scenario
    if (dependencySpec == Specs.SATISFIES_ALL) {
        if (visitor.includeFiles()) {
            fileDependencyResults.getArtifacts().visit(visitor);
        }
        artifactResults.getArtifacts().visit(visitor);
        return;
    }
    if (visitor.includeFiles()) {
        for (Map.Entry<FileCollectionDependency, ResolvedArtifactSet> entry : fileDependencyResults.getFirstLevelFiles().entrySet()) {
            if (dependencySpec.isSatisfiedBy(entry.getKey())) {
                entry.getValue().visit(visitor);
            }
        }
    }
    CachingDirectedGraphWalker<DependencyGraphNodeResult, ResolvedArtifact> walker = new CachingDirectedGraphWalker<DependencyGraphNodeResult, ResolvedArtifact>(new ResolvedDependencyArtifactsGraph(visitor, fileDependencyResults));
    DependencyGraphNodeResult rootNode = loadTransientGraphResults(artifactResults).getRootNode();
    for (DependencyGraphNodeResult node : getFirstLevelNodes(dependencySpec)) {
        node.getArtifactsForIncomingEdge(rootNode).visit(visitor);
        walker.add(node);
    }
    walker.findValues();
}
Also used : DependencyGraphNodeResult(org.gradle.api.internal.artifacts.DependencyGraphNodeResult) ResolvedArtifact(org.gradle.api.artifacts.ResolvedArtifact) ResolvedArtifactSet(org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvedArtifactSet) Map(java.util.Map) FileCollectionDependency(org.gradle.api.artifacts.FileCollectionDependency) CachingDirectedGraphWalker(org.gradle.internal.graph.CachingDirectedGraphWalker)

Aggregations

CachingDirectedGraphWalker (org.gradle.internal.graph.CachingDirectedGraphWalker)2 StringWriter (java.io.StringWriter)1 Map (java.util.Map)1 FileCollectionDependency (org.gradle.api.artifacts.FileCollectionDependency)1 ResolvedArtifact (org.gradle.api.artifacts.ResolvedArtifact)1 DependencyGraphNodeResult (org.gradle.api.internal.artifacts.DependencyGraphNodeResult)1 ResolvedArtifactSet (org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvedArtifactSet)1 DirectedGraphRenderer (org.gradle.internal.graph.DirectedGraphRenderer)1 StyledTextOutput (org.gradle.internal.logging.text.StyledTextOutput)1