blob: 09f8d7eb91446853f3b4917d3d0dda93b9fd5767 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.component.chain.dependencies.ordering;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/**
* Signals that the dependency graph contains cycles. A DOT language
* representation of the cycle is available to help solve the problem (<a
* href="http://graphviz.org/">GraphViz</a>).
*
* @author tonytv
*/
@SuppressWarnings("serial")
public class CycleDependenciesException extends RuntimeException {
public Map<String, NameProvider> cycleNodes;
CycleDependenciesException(Map<String, NameProvider> cycleNodes) {
super("The following set of dependencies lead to a cycle:\n"
+ createDotString(cycleNodes));
this.cycleNodes = cycleNodes;
}
private static String createDotString(Map<String, NameProvider> cycleNodes) {
StringBuilder res = new StringBuilder();
res.append("digraph dependencyGraph {\n");
Set<Node> used = new HashSet<>();
for (Node node: cycleNodes.values()) {
if (!node.ready())
node.dotDependenciesString(res, used);
}
res.append("}");
return res.toString();
}
public String dotString() {
return createDotString(cycleNodes);
}
}
|