Search in sources :

Example 1 with GraphNodeRenderer

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

the class NativeDependentBinariesResolutionStrategy method onCircularDependencies.

private void onCircularDependencies(final State state, final Deque<NativeBinarySpecInternal> stack, NativeBinarySpecInternal target) {
    GraphNodeRenderer<NativeBinarySpecInternal> nodeRenderer = new GraphNodeRenderer<NativeBinarySpecInternal>() {

        @Override
        public void renderTo(NativeBinarySpecInternal node, StyledTextOutput output) {
            String name = DependentComponentsUtils.getBuildScopedTerseName(node.getId());
            output.withStyle(StyledTextOutput.Style.Identifier).text(name);
        }
    };
    DirectedGraph<NativeBinarySpecInternal, Object> directedGraph = new DirectedGraph<NativeBinarySpecInternal, Object>() {

        @Override
        public void getNodeValues(NativeBinarySpecInternal node, Collection<? super Object> values, Collection<? super NativeBinarySpecInternal> connectedNodes) {
            for (NativeBinarySpecInternal binary : stack) {
                if (state.getDependents(node).contains(binary)) {
                    connectedNodes.add(binary);
                }
            }
        }
    };
    DirectedGraphRenderer<NativeBinarySpecInternal> graphRenderer = new DirectedGraphRenderer<NativeBinarySpecInternal>(nodeRenderer, directedGraph);
    StringWriter writer = new StringWriter();
    graphRenderer.renderTo(target, writer);
    throw new CircularReferenceException(String.format("Circular dependency between the following binaries:%n%s", writer.toString()));
}
Also used : StyledTextOutput(org.gradle.internal.logging.text.StyledTextOutput) CircularReferenceException(org.gradle.api.CircularReferenceException) DirectedGraph(org.gradle.internal.graph.DirectedGraph) StringWriter(java.io.StringWriter) DirectedGraphRenderer(org.gradle.internal.graph.DirectedGraphRenderer) Collection(java.util.Collection) GraphNodeRenderer(org.gradle.internal.graph.GraphNodeRenderer)

Aggregations

StringWriter (java.io.StringWriter)1 Collection (java.util.Collection)1 CircularReferenceException (org.gradle.api.CircularReferenceException)1 DirectedGraph (org.gradle.internal.graph.DirectedGraph)1 DirectedGraphRenderer (org.gradle.internal.graph.DirectedGraphRenderer)1 GraphNodeRenderer (org.gradle.internal.graph.GraphNodeRenderer)1 StyledTextOutput (org.gradle.internal.logging.text.StyledTextOutput)1