author | mchung |
Wed, 15 Feb 2017 16:18:22 -0800 | |
changeset 43808 | c0a93657773d |
parent 43712 | 5dfd0950317c |
child 44417 | a431edba1629 |
permissions | -rw-r--r-- |
36511 | 1 |
/* |
43539
b7c4265f40e7
8173604: Rename module 8173604 java.annotations.common to java.xml.ws.annoations
lancea
parents:
42708
diff
changeset
|
2 |
* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved. |
36511 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package build.tools.jigsaw; |
|
27 |
||
43808
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
28 |
import com.sun.tools.jdeps.ModuleDotGraph; |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
29 |
import com.sun.tools.jdeps.ModuleDotGraph.DotGraphBuilder; |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
30 |
|
36511 | 31 |
import java.io.IOException; |
32 |
import java.lang.module.Configuration; |
|
33 |
import java.lang.module.ModuleDescriptor; |
|
34 |
import java.lang.module.ModuleFinder; |
|
35 |
import java.lang.module.ModuleReference; |
|
36 |
import java.nio.file.Files; |
|
37 |
import java.nio.file.Path; |
|
38 |
import java.nio.file.Paths; |
|
39 |
import java.util.HashMap; |
|
40 |
import java.util.HashSet; |
|
41 |
import java.util.Map; |
|
42 |
import java.util.Set; |
|
43 |
||
44 |
/** |
|
45 |
* Generate the DOT file for a module graph for each module in the JDK |
|
46 |
* after transitive reduction. |
|
47 |
*/ |
|
48 |
public class GenGraphs { |
|
49 |
||
50 |
public static void main(String[] args) throws Exception { |
|
43808
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
51 |
Path dir = null; |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
52 |
boolean spec = false; |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
53 |
for (int i=0; i < args.length; i++) { |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
54 |
String arg = args[i]; |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
55 |
if (arg.equals("--spec")) { |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
56 |
spec = true; |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
57 |
} else if (arg.equals("--output")) { |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
58 |
i++; |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
59 |
dir = i < args.length ? Paths.get(args[i]) : null; |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
60 |
} else if (arg.startsWith("-")) { |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
61 |
throw new IllegalArgumentException("Invalid option: " + arg); |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
62 |
} |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
63 |
} |
36511 | 64 |
|
43808
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
65 |
if (dir == null) { |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
66 |
System.err.println("ERROR: must specify --output argument"); |
36511 | 67 |
System.exit(1); |
68 |
} |
|
43808
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
69 |
|
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
70 |
// setup and configure the dot graph attributes |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
71 |
initDotGraphAttributes(); |
36511 | 72 |
Files.createDirectories(dir); |
73 |
||
43808
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
74 |
GenGraphs genGraphs = new GenGraphs(dir, spec); |
36511 | 75 |
|
43808
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
76 |
// print dot file for each module |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
77 |
Map<String, Configuration> configurations = new HashMap<>(); |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
78 |
Set<String> modules = new HashSet<>(); |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
79 |
ModuleFinder finder = ModuleFinder.ofSystem(); |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
80 |
for (ModuleReference mref : finder.findAll()) { |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
81 |
String name = (mref.descriptor().name()); |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
82 |
modules.add(name); |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
83 |
if (genGraphs.accept(name, mref.descriptor())) { |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
84 |
configurations.put(name, Configuration.empty() |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
85 |
.resolve(finder, |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
86 |
ModuleFinder.of(), |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
87 |
Set.of(name))); |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
88 |
} |
36511 | 89 |
} |
90 |
||
43808
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
91 |
if (genGraphs.accept("jdk", null)) { |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
92 |
// print a graph of all JDK modules |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
93 |
configurations.put("jdk", Configuration.empty() |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
94 |
.resolve(finder, |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
95 |
ModuleFinder.of(), |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
96 |
modules)); |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
97 |
} |
36511 | 98 |
|
43808
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
99 |
genGraphs.genDotFiles(configurations); |
36511 | 100 |
} |
101 |
||
43808
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
102 |
static void initDotGraphAttributes() { |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
103 |
int h = 1000; |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
104 |
DotGraphBuilder.weight("java.se", "java.sql.rowset", h * 10); |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
105 |
DotGraphBuilder.weight("java.sql.rowset", "java.sql", h * 10); |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
106 |
DotGraphBuilder.weight("java.sql", "java.xml", h * 10); |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
107 |
DotGraphBuilder.weight("java.xml", "java.base", h * 10); |
36511 | 108 |
|
43808
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
109 |
DotGraphBuilder.sameRankNodes(Set.of("java.logging", "java.scripting", "java.xml")); |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
110 |
DotGraphBuilder.sameRankNodes(Set.of("java.sql")); |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
111 |
DotGraphBuilder.sameRankNodes(Set.of("java.compiler", "java.instrument")); |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
112 |
DotGraphBuilder.sameRankNodes(Set.of("java.desktop", "java.management")); |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
113 |
DotGraphBuilder.sameRankNodes(Set.of("java.corba", "java.xml.ws")); |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
114 |
DotGraphBuilder.sameRankNodes(Set.of("java.xml.bind", "java.xml.ws.annotation")); |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
115 |
DotGraphBuilder.setRankSep(0.7); |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
116 |
DotGraphBuilder.setFontSize(12); |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
117 |
DotGraphBuilder.setArrowSize(1); |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
118 |
DotGraphBuilder.setArrowWidth(2); |
36511 | 119 |
} |
120 |
||
42701
274434f1297c
8171323: generate dot file for java.se and java.se.ee with only API dependences
mchung
parents:
42693
diff
changeset
|
121 |
private final Path dir; |
43808
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
122 |
private final boolean spec; |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
123 |
GenGraphs(Path dir, boolean spec) { |
42701
274434f1297c
8171323: generate dot file for java.se and java.se.ee with only API dependences
mchung
parents:
42693
diff
changeset
|
124 |
this.dir = dir; |
43808
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
125 |
this.spec = spec; |
42701
274434f1297c
8171323: generate dot file for java.se and java.se.ee with only API dependences
mchung
parents:
42693
diff
changeset
|
126 |
} |
274434f1297c
8171323: generate dot file for java.se and java.se.ee with only API dependences
mchung
parents:
42693
diff
changeset
|
127 |
|
43808
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
128 |
void genDotFiles(Map<String, Configuration> configurations) throws IOException { |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
129 |
ModuleDotGraph dotGraph = new ModuleDotGraph(configurations, spec); |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
130 |
dotGraph.genDotFiles(dir); |
42701
274434f1297c
8171323: generate dot file for java.se and java.se.ee with only API dependences
mchung
parents:
42693
diff
changeset
|
131 |
} |
274434f1297c
8171323: generate dot file for java.se and java.se.ee with only API dependences
mchung
parents:
42693
diff
changeset
|
132 |
|
43808
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
133 |
boolean accept(String name, ModuleDescriptor descriptor) { |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
134 |
if (!spec) return true; |
42693 | 135 |
|
43808
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
136 |
if (name.equals("jdk")) |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
137 |
return false; |
36511 | 138 |
|
43808
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
139 |
if (name.equals("java.se") || name.equals("java.se.ee")) |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
140 |
return true; |
36511 | 141 |
|
43808
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
142 |
// only the module that has exported API |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
143 |
return descriptor.exports().stream() |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
144 |
.filter(e -> !e.isQualified()) |
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
145 |
.findAny().isPresent(); |
36511 | 146 |
} |
43808
c0a93657773d
8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents:
43712
diff
changeset
|
147 |
} |