make/jdk/src/classes/build/tools/jigsaw/GenGraphs.java
author tschatzl
Fri, 22 Nov 2019 10:03:38 +0100
changeset 59220 72e15d757e6c
parent 49126 f29637bb390e
permissions -rw-r--r--
8234000: Make HeapRegion::bottom/end/hrm_index const Reviewed-by: kbarrett, sjohanss
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
48841
0937e5f799df 8190378: Removal of CORBA and Java EE modules
lancea
parents: 47216
diff changeset
     2
 * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * accompanied this code).
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    23
 * questions.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    24
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    25
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    26
package build.tools.jigsaw;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    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
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    30
import java.io.IOException;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    31
import java.lang.module.Configuration;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    32
import java.lang.module.ModuleDescriptor;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    33
import java.lang.module.ModuleFinder;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    34
import java.lang.module.ModuleReference;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    35
import java.nio.file.Files;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    36
import java.nio.file.Path;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    37
import java.nio.file.Paths;
44417
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
    38
import java.util.ArrayList;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    39
import java.util.HashMap;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    40
import java.util.HashSet;
44417
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
    41
import java.util.List;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    42
import java.util.Map;
44417
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
    43
import java.util.Properties;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    44
import java.util.Set;
44417
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
    45
import java.util.function.Function;
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
    46
import java.util.stream.Collectors;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    47
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    48
/**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    49
 * Generate the DOT file for a module graph for each module in the JDK
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    50
 * after transitive reduction.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    51
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    52
public class GenGraphs {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    53
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    54
    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
    55
        Path dir = null;
c0a93657773d 8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents: 43712
diff changeset
    56
        boolean spec = false;
44417
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
    57
        Properties props = null;
43808
c0a93657773d 8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents: 43712
diff changeset
    58
        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
    59
            String arg = args[i];
c0a93657773d 8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents: 43712
diff changeset
    60
            if (arg.equals("--spec")) {
c0a93657773d 8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents: 43712
diff changeset
    61
                spec = true;
44417
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
    62
            } else if (arg.equals("--dot-attributes")) {
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
    63
                if (i++ == args.length) {
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
    64
                    throw new IllegalArgumentException("Missing argument: --dot-attributes option");
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
    65
                }
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
    66
                props = new Properties();
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
    67
                props.load(Files.newInputStream(Paths.get(args[i])));
43808
c0a93657773d 8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents: 43712
diff changeset
    68
            } else if (arg.equals("--output")) {
44417
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
    69
                dir = ++i < args.length ? Paths.get(args[i]) : null;
43808
c0a93657773d 8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents: 43712
diff changeset
    70
            } else if (arg.startsWith("-")) {
c0a93657773d 8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents: 43712
diff changeset
    71
                throw new IllegalArgumentException("Invalid option: " + arg);
c0a93657773d 8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents: 43712
diff changeset
    72
            }
c0a93657773d 8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents: 43712
diff changeset
    73
        }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    74
43808
c0a93657773d 8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents: 43712
diff changeset
    75
        if (dir == null) {
c0a93657773d 8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents: 43712
diff changeset
    76
            System.err.println("ERROR: must specify --output argument");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    77
            System.exit(1);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    78
        }
43808
c0a93657773d 8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents: 43712
diff changeset
    79
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    80
        Files.createDirectories(dir);
44417
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
    81
        ModuleGraphAttributes attributes;
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
    82
        if (props != null) {
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
    83
            attributes = new ModuleGraphAttributes(props);
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
    84
        } else {
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
    85
            attributes = new ModuleGraphAttributes();
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
    86
        }
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
    87
        GenGraphs genGraphs = new GenGraphs(dir, spec, attributes);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    88
43808
c0a93657773d 8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents: 43712
diff changeset
    89
        // print dot file for each module
c0a93657773d 8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents: 43712
diff changeset
    90
        Map<String, Configuration> configurations = new HashMap<>();
c0a93657773d 8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents: 43712
diff changeset
    91
        Set<String> modules = new HashSet<>();
c0a93657773d 8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents: 43712
diff changeset
    92
        ModuleFinder finder = ModuleFinder.ofSystem();
c0a93657773d 8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents: 43712
diff changeset
    93
        for (ModuleReference mref : finder.findAll()) {
c0a93657773d 8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents: 43712
diff changeset
    94
            String name = (mref.descriptor().name());
c0a93657773d 8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents: 43712
diff changeset
    95
            modules.add(name);
c0a93657773d 8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents: 43712
diff changeset
    96
            if (genGraphs.accept(name, mref.descriptor())) {
c0a93657773d 8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents: 43712
diff changeset
    97
                configurations.put(name, Configuration.empty()
c0a93657773d 8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents: 43712
diff changeset
    98
                                                      .resolve(finder,
c0a93657773d 8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents: 43712
diff changeset
    99
                                                               ModuleFinder.of(),
c0a93657773d 8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents: 43712
diff changeset
   100
                                                               Set.of(name)));
c0a93657773d 8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents: 43712
diff changeset
   101
            }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   102
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   103
43808
c0a93657773d 8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents: 43712
diff changeset
   104
        if (genGraphs.accept("jdk", null)) {
c0a93657773d 8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents: 43712
diff changeset
   105
            // 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
   106
            configurations.put("jdk", Configuration.empty()
c0a93657773d 8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents: 43712
diff changeset
   107
                                                   .resolve(finder,
c0a93657773d 8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents: 43712
diff changeset
   108
                                                            ModuleFinder.of(),
c0a93657773d 8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents: 43712
diff changeset
   109
                                                            modules));
c0a93657773d 8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents: 43712
diff changeset
   110
        }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   111
43808
c0a93657773d 8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents: 43712
diff changeset
   112
        genGraphs.genDotFiles(configurations);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   113
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   114
44417
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   115
    /**
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   116
     * Custom dot file attributes.
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   117
     */
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   118
    static class ModuleGraphAttributes implements ModuleDotGraph.Attributes {
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   119
        static Map<String, String> DEFAULT_ATTRIBUTES = Map.of(
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   120
            "ranksep", "0.6",
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   121
            "fontsize", "12",
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   122
            "fontcolor", BLACK,
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   123
            "fontname", "DejaVuSans",
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   124
            "arrowsize", "1",
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   125
            "arrowwidth", "2",
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   126
            "arrowcolor", DARK_GRAY,
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   127
            // custom
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   128
            "requiresMandatedColor", LIGHT_GRAY,
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   129
            "javaSubgraphColor", ORANGE,
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   130
            "jdkSubgraphColor", BLUE
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   131
        );
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   132
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   133
        final Map<String, Integer> weights = new HashMap<>();
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   134
        final List<Set<String>> ranks = new ArrayList<>();
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   135
        final Map<String, String> attrs;
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   136
        ModuleGraphAttributes(Map<String, String> attrs) {
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   137
            int h = 1000;
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   138
            weight("java.se", "java.sql.rowset", h * 10);
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   139
            weight("java.sql.rowset", "java.sql", h * 10);
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   140
            weight("java.sql", "java.xml", h * 10);
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   141
            weight("java.xml", "java.base", h * 10);
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   142
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   143
            ranks.add(Set.of("java.logging", "java.scripting", "java.xml"));
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   144
            ranks.add(Set.of("java.sql"));
49126
f29637bb390e 8197533: Move javax.transaction.xa to its own module
lancea
parents: 48841
diff changeset
   145
            ranks.add(Set.of("java.transaction.xa"));
44417
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   146
            ranks.add(Set.of("java.compiler", "java.instrument"));
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   147
            ranks.add(Set.of("java.desktop", "java.management"));
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   148
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   149
            this.attrs = attrs;
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   150
        }
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   151
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   152
        ModuleGraphAttributes() {
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   153
            this(DEFAULT_ATTRIBUTES);
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   154
        }
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   155
        ModuleGraphAttributes(Properties props) {
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   156
            this(toAttributes(props));
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   157
        }
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   158
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   159
        @Override
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   160
        public double rankSep() {
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   161
            return Double.valueOf(attrs.get("ranksep"));
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   162
        }
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   163
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   164
        @Override
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   165
        public int fontSize() {
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   166
            return Integer.valueOf(attrs.get("fontsize"));
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   167
        }
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   168
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   169
        @Override
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   170
        public String fontName() {
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   171
            return attrs.get("fontname");
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   172
        }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   173
44417
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   174
        @Override
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   175
        public String fontColor() {
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   176
            return attrs.get("fontcolor");
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   177
        }
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   178
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   179
        @Override
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   180
        public int arrowSize() {
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   181
            return Integer.valueOf(attrs.get("arrowsize"));
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   182
        }
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   183
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   184
        @Override
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   185
        public int arrowWidth() {
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   186
            return Integer.valueOf(attrs.get("arrowwidth"));
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   187
        }
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   188
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   189
        @Override
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   190
        public String arrowColor() {
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   191
            return attrs.get("arrowcolor");
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   192
        }
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   193
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   194
        @Override
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   195
        public List<Set<String>> ranks() {
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   196
            return ranks;
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   197
        }
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   198
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   199
        @Override
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   200
        public String requiresMandatedColor() {
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   201
            return attrs.get("requiresMandatedColor");
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   202
        }
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   203
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   204
        @Override
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   205
        public String javaSubgraphColor() {
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   206
            return attrs.get("javaSubgraphColor");
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   207
        }
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   208
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   209
        @Override
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   210
        public String jdkSubgraphColor() {
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   211
            return attrs.get("jdkSubgraphColor");
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   212
        }
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   213
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   214
        @Override
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   215
        public int weightOf(String s, String t) {
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   216
            int w = weights.getOrDefault(s + ":" + t, 1);
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   217
            if (w != 1)
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   218
                return w;
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   219
            if (s.startsWith("java.") && t.startsWith("java."))
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   220
                return 10;
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   221
            return 1;
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   222
        }
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   223
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   224
        public void weight(String s, String t, int w) {
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   225
            weights.put(s + ":" + t, w);
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   226
        }
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   227
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   228
        static Map<String, String> toAttributes(Properties props) {
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   229
            return DEFAULT_ATTRIBUTES.keySet().stream()
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   230
                .collect(Collectors.toMap(Function.identity(),
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   231
                    k -> props.getProperty(k, DEFAULT_ATTRIBUTES.get(k))));
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   232
        }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   233
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   234
42701
274434f1297c 8171323: generate dot file for java.se and java.se.ee with only API dependences
mchung
parents: 42693
diff changeset
   235
    private final Path dir;
43808
c0a93657773d 8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents: 43712
diff changeset
   236
    private final boolean spec;
44417
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   237
    private final ModuleGraphAttributes attributes;
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   238
    GenGraphs(Path dir, boolean spec, ModuleGraphAttributes attributes) {
42701
274434f1297c 8171323: generate dot file for java.se and java.se.ee with only API dependences
mchung
parents: 42693
diff changeset
   239
        this.dir = dir;
43808
c0a93657773d 8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents: 43712
diff changeset
   240
        this.spec = spec;
44417
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   241
        this.attributes = attributes;
42701
274434f1297c 8171323: generate dot file for java.se and java.se.ee with only API dependences
mchung
parents: 42693
diff changeset
   242
    }
274434f1297c 8171323: generate dot file for java.se and java.se.ee with only API dependences
mchung
parents: 42693
diff changeset
   243
43808
c0a93657773d 8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents: 43712
diff changeset
   244
    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
   245
        ModuleDotGraph dotGraph = new ModuleDotGraph(configurations, spec);
44417
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   246
        dotGraph.genDotFiles(dir, attributes);
42701
274434f1297c 8171323: generate dot file for java.se and java.se.ee with only API dependences
mchung
parents: 42693
diff changeset
   247
    }
274434f1297c 8171323: generate dot file for java.se and java.se.ee with only API dependences
mchung
parents: 42693
diff changeset
   248
44417
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   249
    /**
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   250
     * Returns true for any name if generating graph for non-spec;
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   251
     * otherwise, returns true except "jdk" and name with "jdk.internal." prefix
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   252
     */
43808
c0a93657773d 8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents: 43712
diff changeset
   253
    boolean accept(String name, ModuleDescriptor descriptor) {
44417
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   254
        if (!spec)
43808
c0a93657773d 8173374: Update GenGraphs tool to generate dot graph with requires transitive edges
mchung
parents: 43712
diff changeset
   255
            return true;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   256
44417
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   257
        return !name.equals("jdk") && !name.startsWith("jdk.internal.");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   258
    }
44417
a431edba1629 8173303: Add module-subgraph images to main platform documentation
mchung
parents: 43808
diff changeset
   259
}