author | serb |
Sat, 09 Jun 2018 13:33:35 -0700 | |
changeset 50647 | a98ff7c2103d |
parent 50467 | e0a32b178e6f |
child 52649 | e00cf18e2593 |
permissions | -rw-r--r-- |
43873
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
1 |
/* |
48841 | 2 |
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. |
43873
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
4 |
* |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
10 |
* |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
15 |
* accompanied this code). |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
16 |
* |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
20 |
* |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
23 |
* questions. |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
24 |
*/ |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
25 |
package com.sun.tools.jdeps; |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
26 |
|
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
27 |
import static java.lang.module.ModuleDescriptor.Requires.Modifier.*; |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
28 |
import static java.util.stream.Collectors.*; |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
29 |
|
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
30 |
import java.io.BufferedWriter; |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
31 |
import java.io.IOException; |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
32 |
import java.io.PrintWriter; |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
33 |
import java.lang.module.Configuration; |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
34 |
import java.lang.module.ModuleDescriptor; |
44452
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
35 |
import java.lang.module.ModuleDescriptor.*; |
43873
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
36 |
import java.lang.module.ModuleFinder; |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
37 |
import java.lang.module.ModuleReference; |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
38 |
import java.lang.module.ResolvedModule; |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
39 |
import java.nio.file.Files; |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
40 |
import java.nio.file.Path; |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
41 |
import java.util.ArrayDeque; |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
42 |
import java.util.ArrayList; |
44452
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
43 |
import java.util.Collections; |
43873
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
44 |
import java.util.Deque; |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
45 |
import java.util.HashSet; |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
46 |
import java.util.List; |
50467
e0a32b178e6f
8204584: jdeps generates illegal dot file containing ranksep=0,600000
mchung
parents:
48841
diff
changeset
|
47 |
import java.util.Locale; |
43873
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
48 |
import java.util.Map; |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
49 |
import java.util.Objects; |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
50 |
import java.util.Set; |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
51 |
import java.util.TreeSet; |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
52 |
import java.util.function.Function; |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
53 |
import java.util.stream.Collectors; |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
54 |
import java.util.stream.Stream; |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
55 |
|
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
56 |
/** |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
57 |
* Generate dot graph for modules |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
58 |
*/ |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
59 |
public class ModuleDotGraph { |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
60 |
private final Map<String, Configuration> configurations; |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
61 |
private final boolean apiOnly; |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
62 |
public ModuleDotGraph(JdepsConfiguration config, boolean apiOnly) { |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
63 |
this(config.rootModules().stream() |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
64 |
.map(Module::name) |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
65 |
.sorted() |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
66 |
.collect(toMap(Function.identity(), mn -> config.resolve(Set.of(mn)))), |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
67 |
apiOnly); |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
68 |
} |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
69 |
|
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
70 |
public ModuleDotGraph(Map<String, Configuration> configurations, boolean apiOnly) { |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
71 |
this.configurations = configurations; |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
72 |
this.apiOnly = apiOnly; |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
73 |
} |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
74 |
|
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
75 |
/** |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
76 |
* Generate dotfile for all modules |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
77 |
* |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
78 |
* @param dir output directory |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
79 |
*/ |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
80 |
public boolean genDotFiles(Path dir) throws IOException { |
44452
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
81 |
return genDotFiles(dir, DotGraphAttributes.DEFAULT); |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
82 |
} |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
83 |
|
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
84 |
public boolean genDotFiles(Path dir, Attributes attributes) |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
85 |
throws IOException |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
86 |
{ |
43873
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
87 |
Files.createDirectories(dir); |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
88 |
for (String mn : configurations.keySet()) { |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
89 |
Path path = dir.resolve(mn + ".dot"); |
44452
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
90 |
genDotFile(path, mn, configurations.get(mn), attributes); |
43873
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
91 |
} |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
92 |
return true; |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
93 |
} |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
94 |
|
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
95 |
/** |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
96 |
* Generate dotfile of the given path |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
97 |
*/ |
44452
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
98 |
public void genDotFile(Path path, String name, |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
99 |
Configuration configuration, |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
100 |
Attributes attributes) |
43873
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
101 |
throws IOException |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
102 |
{ |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
103 |
// transitive reduction |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
104 |
Graph<String> graph = apiOnly |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
105 |
? requiresTransitiveGraph(configuration, Set.of(name)) |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
106 |
: gengraph(configuration); |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
107 |
|
44452
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
108 |
DotGraphBuilder builder = new DotGraphBuilder(name, graph, attributes); |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
109 |
builder.subgraph("se", "java", attributes.javaSubgraphColor(), |
43873
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
110 |
DotGraphBuilder.JAVA_SE_SUBGRAPH) |
44452
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
111 |
.subgraph("jdk", "jdk", attributes.jdkSubgraphColor(), |
43873
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
112 |
DotGraphBuilder.JDK_SUBGRAPH) |
44452
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
113 |
.modules(graph.nodes().stream() |
43873
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
114 |
.map(mn -> configuration.findModule(mn).get() |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
115 |
.reference().descriptor())); |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
116 |
// build dot file |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
117 |
builder.build(path); |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
118 |
} |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
119 |
|
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
120 |
/** |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
121 |
* Returns a Graph of the given Configuration after transitive reduction. |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
122 |
* |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
123 |
* Transitive reduction of requires transitive edge and requires edge have |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
124 |
* to be applied separately to prevent the requires transitive edges |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
125 |
* (e.g. U -> V) from being reduced by a path (U -> X -> Y -> V) |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
126 |
* in which V would not be re-exported from U. |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
127 |
*/ |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
128 |
private Graph<String> gengraph(Configuration cf) { |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
129 |
Graph.Builder<String> builder = new Graph.Builder<>(); |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
130 |
cf.modules().stream() |
44452
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
131 |
.forEach(rm -> { |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
132 |
String mn = rm.name(); |
43873
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
133 |
builder.addNode(mn); |
44452
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
134 |
rm.reads().stream() |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
135 |
.map(ResolvedModule::name) |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
136 |
.forEach(target -> builder.addEdge(mn, target)); |
43873
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
137 |
}); |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
138 |
|
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
139 |
Graph<String> rpg = requiresTransitiveGraph(cf, builder.nodes); |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
140 |
return builder.build().reduce(rpg); |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
141 |
} |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
142 |
|
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
143 |
|
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
144 |
/** |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
145 |
* Returns a Graph containing only requires transitive edges |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
146 |
* with transitive reduction. |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
147 |
*/ |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
148 |
public Graph<String> requiresTransitiveGraph(Configuration cf, |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
149 |
Set<String> roots) |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
150 |
{ |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
151 |
Deque<String> deque = new ArrayDeque<>(roots); |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
152 |
Set<String> visited = new HashSet<>(); |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
153 |
Graph.Builder<String> builder = new Graph.Builder<>(); |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
154 |
|
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
155 |
while (deque.peek() != null) { |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
156 |
String mn = deque.pop(); |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
157 |
if (visited.contains(mn)) |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
158 |
continue; |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
159 |
|
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
160 |
visited.add(mn); |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
161 |
builder.addNode(mn); |
44452
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
162 |
cf.findModule(mn).get() |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
163 |
.reference().descriptor().requires().stream() |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
164 |
.filter(d -> d.modifiers().contains(TRANSITIVE) |
43873
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
165 |
|| d.name().equals("java.base")) |
44452
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
166 |
.map(Requires::name) |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
167 |
.forEach(d -> { |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
168 |
deque.add(d); |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
169 |
builder.addEdge(mn, d); |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
170 |
}); |
43873
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
171 |
} |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
172 |
|
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
173 |
return builder.build().reduce(); |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
174 |
} |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
175 |
|
44452
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
176 |
public interface Attributes { |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
177 |
static final String ORANGE = "#e76f00"; |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
178 |
static final String BLUE = "#437291"; |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
179 |
static final String BLACK = "#000000"; |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
180 |
static final String DARK_GRAY = "#999999"; |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
181 |
static final String LIGHT_GRAY = "#dddddd"; |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
182 |
|
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
183 |
int fontSize(); |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
184 |
String fontName(); |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
185 |
String fontColor(); |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
186 |
|
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
187 |
int arrowSize(); |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
188 |
int arrowWidth(); |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
189 |
String arrowColor(); |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
190 |
|
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
191 |
default double rankSep() { |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
192 |
return 1; |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
193 |
} |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
194 |
|
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
195 |
default List<Set<String>> ranks() { |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
196 |
return Collections.emptyList(); |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
197 |
} |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
198 |
|
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
199 |
default int weightOf(String s, String t) { |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
200 |
return 1; |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
201 |
} |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
202 |
|
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
203 |
default String requiresMandatedColor() { |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
204 |
return LIGHT_GRAY; |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
205 |
} |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
206 |
|
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
207 |
default String javaSubgraphColor() { |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
208 |
return ORANGE; |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
209 |
} |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
210 |
|
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
211 |
default String jdkSubgraphColor() { |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
212 |
return BLUE; |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
213 |
} |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
214 |
} |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
215 |
|
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
216 |
static class DotGraphAttributes implements Attributes { |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
217 |
static final DotGraphAttributes DEFAULT = new DotGraphAttributes(); |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
218 |
|
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
219 |
static final String FONT_NAME = "DejaVuSans"; |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
220 |
static final int FONT_SIZE = 12; |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
221 |
static final int ARROW_SIZE = 1; |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
222 |
static final int ARROW_WIDTH = 2; |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
223 |
|
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
224 |
@Override |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
225 |
public int fontSize() { |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
226 |
return FONT_SIZE; |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
227 |
} |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
228 |
|
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
229 |
@Override |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
230 |
public String fontName() { |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
231 |
return FONT_NAME; |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
232 |
} |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
233 |
|
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
234 |
@Override |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
235 |
public String fontColor() { |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
236 |
return BLACK; |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
237 |
} |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
238 |
|
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
239 |
@Override |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
240 |
public int arrowSize() { |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
241 |
return ARROW_SIZE; |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
242 |
} |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
243 |
|
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
244 |
@Override |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
245 |
public int arrowWidth() { |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
246 |
return ARROW_WIDTH; |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
247 |
} |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
248 |
|
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
249 |
@Override |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
250 |
public String arrowColor() { |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
251 |
return DARK_GRAY; |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
252 |
} |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
253 |
} |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
254 |
|
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
255 |
private static class DotGraphBuilder { |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
256 |
static final String REEXPORTS = ""; |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
257 |
static final String REQUIRES = "style=\"dashed\""; |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
258 |
|
43873
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
259 |
static final Set<String> JAVA_SE_SUBGRAPH = javaSE(); |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
260 |
static final Set<String> JDK_SUBGRAPH = jdk(); |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
261 |
|
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
262 |
private static Set<String> javaSE() { |
48841 | 263 |
String root = "java.se"; |
43873
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
264 |
ModuleFinder system = ModuleFinder.ofSystem(); |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
265 |
if (system.find(root).isPresent()) { |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
266 |
return Stream.concat(Stream.of(root), |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
267 |
Configuration.empty().resolve(system, |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
268 |
ModuleFinder.of(), |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
269 |
Set.of(root)) |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
270 |
.findModule(root).get() |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
271 |
.reads().stream() |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
272 |
.map(ResolvedModule::name)) |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
273 |
.collect(toSet()); |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
274 |
} else { |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
275 |
// approximation |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
276 |
return system.findAll().stream() |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
277 |
.map(ModuleReference::descriptor) |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
278 |
.map(ModuleDescriptor::name) |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
279 |
.filter(name -> name.startsWith("java.") && |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
280 |
!name.equals("java.smartcardio")) |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
281 |
.collect(Collectors.toSet()); |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
282 |
} |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
283 |
} |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
284 |
|
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
285 |
private static Set<String> jdk() { |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
286 |
return ModuleFinder.ofSystem().findAll().stream() |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
287 |
.map(ModuleReference::descriptor) |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
288 |
.map(ModuleDescriptor::name) |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
289 |
.filter(name -> !JAVA_SE_SUBGRAPH.contains(name) && |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
290 |
(name.startsWith("java.") || |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
291 |
name.startsWith("jdk.") || |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
292 |
name.startsWith("javafx."))) |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
293 |
.collect(Collectors.toSet()); |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
294 |
} |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
295 |
|
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
296 |
static class SubGraph { |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
297 |
final String name; |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
298 |
final String group; |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
299 |
final String color; |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
300 |
final Set<String> nodes; |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
301 |
SubGraph(String name, String group, String color, Set<String> nodes) { |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
302 |
this.name = Objects.requireNonNull(name); |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
303 |
this.group = Objects.requireNonNull(group); |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
304 |
this.color = Objects.requireNonNull(color); |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
305 |
this.nodes = Objects.requireNonNull(nodes); |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
306 |
} |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
307 |
} |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
308 |
|
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
309 |
private final String name; |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
310 |
private final Graph<String> graph; |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
311 |
private final Set<ModuleDescriptor> descriptors = new TreeSet<>(); |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
312 |
private final List<SubGraph> subgraphs = new ArrayList<>(); |
44452
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
313 |
private final Attributes attributes; |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
314 |
public DotGraphBuilder(String name, |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
315 |
Graph<String> graph, |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
316 |
Attributes attributes) { |
43873
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
317 |
this.name = name; |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
318 |
this.graph = graph; |
44452
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
319 |
this.attributes = attributes; |
43873
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
320 |
} |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
321 |
|
44452
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
322 |
public DotGraphBuilder modules(Stream<ModuleDescriptor> descriptors) { |
43873
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
323 |
descriptors.forEach(this.descriptors::add); |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
324 |
return this; |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
325 |
} |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
326 |
|
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
327 |
public void build(Path filename) throws IOException { |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
328 |
try (BufferedWriter writer = Files.newBufferedWriter(filename); |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
329 |
PrintWriter out = new PrintWriter(writer)) { |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
330 |
|
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
331 |
out.format("digraph \"%s\" {%n", name); |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
332 |
out.format(" nodesep=.5;%n"); |
50467
e0a32b178e6f
8204584: jdeps generates illegal dot file containing ranksep=0,600000
mchung
parents:
48841
diff
changeset
|
333 |
out.format((Locale)null, " ranksep=%f;%n", attributes.rankSep()); |
43873
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
334 |
out.format(" pencolor=transparent;%n"); |
44452
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
335 |
out.format(" node [shape=plaintext, fontcolor=\"%s\", fontname=\"%s\"," |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
336 |
+ " fontsize=%d, margin=\".2,.2\"];%n", |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
337 |
attributes.fontColor(), |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
338 |
attributes.fontName(), |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
339 |
attributes.fontSize()); |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
340 |
out.format(" edge [penwidth=%d, color=\"%s\", arrowhead=open, arrowsize=%d];%n", |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
341 |
attributes.arrowWidth(), |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
342 |
attributes.arrowColor(), |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
343 |
attributes.arrowSize()); |
43873
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
344 |
|
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
345 |
// same RANKS |
44452
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
346 |
attributes.ranks().stream() |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
347 |
.map(nodes -> descriptors.stream() |
43873
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
348 |
.map(ModuleDescriptor::name) |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
349 |
.filter(nodes::contains) |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
350 |
.map(mn -> "\"" + mn + "\"") |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
351 |
.collect(joining(","))) |
44452
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
352 |
.filter(group -> group.length() > 0) |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
353 |
.forEach(group -> out.format(" {rank=same %s}%n", group)); |
43873
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
354 |
|
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
355 |
subgraphs.forEach(subgraph -> { |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
356 |
out.format(" subgraph %s {%n", subgraph.name); |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
357 |
descriptors.stream() |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
358 |
.map(ModuleDescriptor::name) |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
359 |
.filter(subgraph.nodes::contains) |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
360 |
.forEach(mn -> printNode(out, mn, subgraph.color, subgraph.group)); |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
361 |
out.format(" }%n"); |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
362 |
}); |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
363 |
|
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
364 |
descriptors.stream() |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
365 |
.filter(md -> graph.contains(md.name()) && |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
366 |
!graph.adjacentNodes(md.name()).isEmpty()) |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
367 |
.forEach(md -> printNode(out, md, graph.adjacentNodes(md.name()))); |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
368 |
|
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
369 |
out.println("}"); |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
370 |
} |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
371 |
} |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
372 |
|
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
373 |
public DotGraphBuilder subgraph(String name, String group, String color, |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
374 |
Set<String> nodes) { |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
375 |
subgraphs.add(new SubGraph(name, group, color, nodes)); |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
376 |
return this; |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
377 |
} |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
378 |
|
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
379 |
public void printNode(PrintWriter out, String node, String color, String group) { |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
380 |
out.format(" \"%s\" [fontcolor=\"%s\", group=%s];%n", |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
381 |
node, color, group); |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
382 |
} |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
383 |
|
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
384 |
public void printNode(PrintWriter out, ModuleDescriptor md, Set<String> edges) { |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
385 |
Set<String> requiresTransitive = md.requires().stream() |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
386 |
.filter(d -> d.modifiers().contains(TRANSITIVE)) |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
387 |
.map(d -> d.name()) |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
388 |
.collect(toSet()); |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
389 |
|
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
390 |
String mn = md.name(); |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
391 |
edges.stream().forEach(dn -> { |
44452
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
392 |
String attr; |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
393 |
if (dn.equals("java.base")) { |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
394 |
attr = "color=\"" + attributes.requiresMandatedColor() + "\""; |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
395 |
} else { |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
396 |
attr = (requiresTransitive.contains(dn) ? REEXPORTS : REQUIRES); |
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
397 |
} |
43873
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
398 |
|
44452
93f6470b1045
8173303: Add module-subgraph images to main platform documentation
mchung
parents:
43873
diff
changeset
|
399 |
int w = attributes.weightOf(mn, dn); |
43873
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
400 |
if (w > 1) { |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
401 |
if (!attr.isEmpty()) |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
402 |
attr += ", "; |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
403 |
|
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
404 |
attr += "weight=" + w; |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
405 |
} |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
406 |
out.format(" \"%s\" -> \"%s\" [%s];%n", mn, dn, attr); |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
407 |
}); |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
408 |
} |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
409 |
|
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
410 |
} |
705d732d3715
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
diff
changeset
|
411 |
} |