< prev index next >
jdk/make/src/classes/build/tools/jigsaw/GenGraphs.java
Print this page
*** 24,45 ****
*/
package build.tools.jigsaw;
import com.sun.tools.jdeps.ModuleDotGraph;
- import com.sun.tools.jdeps.ModuleDotGraph.DotGraphBuilder;
import java.io.IOException;
import java.lang.module.Configuration;
import java.lang.module.ModuleDescriptor;
import java.lang.module.ModuleFinder;
import java.lang.module.ModuleReference;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/**
* Generate the DOT file for a module graph for each module in the JDK
--- 24,46 ----
*/
package build.tools.jigsaw;
import com.sun.tools.jdeps.ModuleDotGraph;
import java.io.IOException;
import java.lang.module.Configuration;
import java.lang.module.ModuleDescriptor;
import java.lang.module.ModuleFinder;
import java.lang.module.ModuleReference;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
+ import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
+ import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Generate the DOT file for a module graph for each module in the JDK
*** 65,78 ****
if (dir == null) {
System.err.println("ERROR: must specify --output argument");
System.exit(1);
}
- // setup and configure the dot graph attributes
- initDotGraphAttributes();
Files.createDirectories(dir);
-
GenGraphs genGraphs = new GenGraphs(dir, spec);
// print dot file for each module
Map<String, Configuration> configurations = new HashMap<>();
Set<String> modules = new HashSet<>();
--- 66,76 ----
*** 97,147 ****
}
genGraphs.genDotFiles(configurations);
}
! static void initDotGraphAttributes() {
int h = 1000;
! DotGraphBuilder.weight("java.se", "java.sql.rowset", h * 10);
! DotGraphBuilder.weight("java.sql.rowset", "java.sql", h * 10);
! DotGraphBuilder.weight("java.sql", "java.xml", h * 10);
! DotGraphBuilder.weight("java.xml", "java.base", h * 10);
!
! DotGraphBuilder.sameRankNodes(Set.of("java.logging", "java.scripting", "java.xml"));
! DotGraphBuilder.sameRankNodes(Set.of("java.sql"));
! DotGraphBuilder.sameRankNodes(Set.of("java.compiler", "java.instrument"));
! DotGraphBuilder.sameRankNodes(Set.of("java.desktop", "java.management"));
! DotGraphBuilder.sameRankNodes(Set.of("java.corba", "java.xml.ws"));
! DotGraphBuilder.sameRankNodes(Set.of("java.xml.bind", "java.xml.ws.annotation"));
! DotGraphBuilder.setRankSep(0.7);
! DotGraphBuilder.setFontSize(12);
! DotGraphBuilder.setArrowSize(1);
! DotGraphBuilder.setArrowWidth(2);
}
private final Path dir;
private final boolean spec;
GenGraphs(Path dir, boolean spec) {
this.dir = dir;
this.spec = spec;
}
void genDotFiles(Map<String, Configuration> configurations) throws IOException {
ModuleDotGraph dotGraph = new ModuleDotGraph(configurations, spec);
! dotGraph.genDotFiles(dir);
}
boolean accept(String name, ModuleDescriptor descriptor) {
! if (!spec) return true;
!
! if (name.equals("jdk"))
! return false;
!
! if (name.equals("java.se") || name.equals("java.se.ee"))
return true;
! // only the module that has exported API
! return descriptor.exports().stream()
! .filter(e -> !e.isQualified())
! .findAny().isPresent();
}
}
\ No newline at end of file
--- 95,217 ----
}
genGraphs.genDotFiles(configurations);
}
! /**
! * Custom dot file attributes.
! */
! static class ModuleGraphAttributes implements ModuleDotGraph.Attributes {
! final Map<String, Integer> weights = new HashMap<>();
! final List<Set<String>> ranks = new ArrayList<>();
!
! ModuleGraphAttributes() {
int h = 1000;
! weight("java.se", "java.sql.rowset", h * 10);
! weight("java.sql.rowset", "java.sql", h * 10);
! weight("java.sql", "java.xml", h * 10);
! weight("java.xml", "java.base", h * 10);
!
! ranks.add(Set.of("java.logging", "java.scripting", "java.xml"));
! ranks.add(Set.of("java.sql"));
! ranks.add(Set.of("java.compiler", "java.instrument"));
! ranks.add(Set.of("java.desktop", "java.management"));
! ranks.add(Set.of("java.corba", "java.xml.ws"));
! ranks.add(Set.of("java.xml.bind", "java.xml.ws.annotation"));
! }
!
! @Override
! public double rankSep() {
! return 0.6;
! }
!
! @Override
! public int fontSize() {
! return 12;
! }
!
! @Override
! public String fontName() {
! return "DejaVuSans bold";
! }
!
! @Override
! public String fontColor() {
! return BLACK;
! }
!
! @Override
! public int arrowSize() {
! return 1;
! }
!
! @Override
! public int arrowWidth() {
! return 2;
! }
!
! @Override
! public String arrowColor() {
! return DARK_GRAY;
}
+ @Override
+ public List<Set<String>> ranks() {
+ return ranks;
+ }
+
+ @Override
+ public String requiresMandatedColor() {
+ return LIGHT_GRAY;
+ }
+
+ @Override
+ public String javaSubgraphColor() {
+ return ORANGE;
+ }
+
+ @Override
+ public String jdkSubgraphColor() {
+ return BLUE;
+ }
+
+ @Override
+ public int weightOf(String s, String t) {
+ int w = weights.getOrDefault(s + ":" + t, 1);
+ if (w != 1)
+ return w;
+ if (s.startsWith("java.") && t.startsWith("java."))
+ return 10;
+ return 1;
+ }
+
+ public void weight(String s, String t, int w) {
+ weights.put(s + ":" + t, w);
+ }
+ }
+
+ private static final ModuleGraphAttributes ATTRIBUTES =
+ new ModuleGraphAttributes();
+
private final Path dir;
private final boolean spec;
GenGraphs(Path dir, boolean spec) {
this.dir = dir;
this.spec = spec;
}
void genDotFiles(Map<String, Configuration> configurations) throws IOException {
ModuleDotGraph dotGraph = new ModuleDotGraph(configurations, spec);
! dotGraph.genDotFiles(dir, ATTRIBUTES);
}
+ /**
+ * Returns true for any name if generating graph for non-spec;
+ * otherwise, returns true except "jdk" and name with "jdk.internal." prefix
+ */
boolean accept(String name, ModuleDescriptor descriptor) {
! if (!spec)
return true;
! return !name.equals("jdk") && !name.startsWith("jdk.internal.");
}
}
\ No newline at end of file
< prev index next >