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