jdk/make/src/classes/build/tools/jigsaw/ModuleSummary.java
author alanb
Thu, 01 Dec 2016 08:57:53 +0000
changeset 42338 a60f280f803c
parent 40261 86a49ba76f52
child 43712 5dfd0950317c
permissions -rw-r--r--
8169069: Module system implementation refresh (11/2016) Reviewed-by: plevart, chegar, psandoz, mchung, alanb, dfuchs, naoto, coffeys, weijun Contributed-by: alan.bateman@oracle.com, mandy.chung@oracle.com, claes.redestad@oracle.com, mark.reinhold@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     2
 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
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
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    28
import java.io.IOException;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    29
import java.io.PrintStream;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    30
import java.lang.module.Configuration;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    31
import java.lang.module.ModuleDescriptor;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    32
import java.lang.module.ModuleFinder;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    33
import java.lang.module.ModuleReference;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    34
import java.lang.module.ResolvedModule;
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;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    38
import java.util.Arrays;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    39
import java.util.Comparator;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    40
import java.util.Date;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    41
import java.util.Enumeration;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    42
import java.util.HashMap;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    43
import java.util.HashSet;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    44
import java.util.Map;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    45
import java.util.Set;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    46
import java.util.stream.Collectors;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    47
import java.util.zip.ZipEntry;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    48
import java.util.zip.ZipFile;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    49
import static java.lang.module.ModuleDescriptor.*;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    50
import static build.tools.jigsaw.ModuleSummary.HtmlDocument.Selector.*;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    51
import static build.tools.jigsaw.ModuleSummary.HtmlDocument.Division.*;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    52
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    53
public class ModuleSummary {
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 38457
diff changeset
    54
    private static final String USAGE = "Usage: ModuleSummary --module-path <dir> -o <outfile> [--root mn]*";
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    55
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    56
    public static void main(String[] args) throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    57
        int i=0;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    58
        Path modpath = null;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    59
        Path outfile = null;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    60
        Set<String> roots = new HashSet<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    61
        while (i < args.length && args[i].startsWith("-")) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    62
            String arg = args[i++];
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    63
            switch (arg) {
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 38457
diff changeset
    64
                case "--module-path":
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    65
                    modpath = Paths.get(args[i++]);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    66
                    break;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    67
                case "-o":
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    68
                    outfile = Paths.get(args[i++]);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    69
                    break;
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 38457
diff changeset
    70
                case "--root":
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    71
                    roots.add(args[i++]);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    72
                default:
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    73
                    System.err.println(USAGE);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    74
                    System.exit(-1);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    75
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    76
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    77
        if (outfile == null || modpath == null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    78
            System.err.println(USAGE);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    79
            System.exit(1);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    80
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    81
        Path dir = outfile.getParent() != null ? outfile.getParent() : Paths.get(".");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    82
        Files.createDirectories(dir);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    83
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    84
        Map<String, ModuleSummary> modules = new HashMap<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    85
        Set<ModuleReference> mrefs = ModuleFinder.ofSystem().findAll();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    86
        for (ModuleReference mref : mrefs) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    87
            String mn = mref.descriptor().name();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    88
            Path jmod = modpath.resolve(mn + ".jmod");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    89
            modules.put(mn, new ModuleSummary(mref, jmod));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    90
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    91
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    92
        if (roots.isEmpty()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    93
            roots.addAll(modules.keySet());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    94
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    95
        genReport(outfile, modules, roots, "JDK Module Summary");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    96
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    97
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    98
    static void genReport(Path outfile, Map<String, ModuleSummary> modules, Set<String> roots, String title)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    99
        throws IOException
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   100
    {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   101
        Configuration cf = resolve(roots);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   102
        try (PrintStream out = new PrintStream(Files.newOutputStream(outfile))) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   103
            HtmlDocument doc = new HtmlDocument(title, modules);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   104
            Set<ModuleDescriptor> descriptors = cf.modules().stream()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   105
                    .map(ResolvedModule::reference)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   106
                    .map(ModuleReference::descriptor)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   107
                    .collect(Collectors.toSet());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   108
            doc.writeTo(out, descriptors);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   109
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   110
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   111
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   112
    private final String name;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   113
    private final ModuleDescriptor descriptor;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   114
    private final JmodInfo jmodInfo;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   115
    ModuleSummary(ModuleReference mref, Path jmod) throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   116
        this.name = mref.descriptor().name();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   117
        this.descriptor = mref.descriptor();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   118
        this.jmodInfo = new JmodInfo(jmod);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   119
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   120
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   121
    String name() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   122
        return name;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   123
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   124
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   125
    long uncompressedSize() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   126
        return jmodInfo.size;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   127
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   128
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   129
    long jmodFileSize() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   130
        return jmodInfo.filesize; // estimated compressed size
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   131
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   132
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   133
    ModuleDescriptor descriptor() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   134
        return descriptor;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   135
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   136
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   137
    int numClasses() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   138
        return jmodInfo.classCount;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   139
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   140
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   141
    long classBytes() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   142
        return jmodInfo.classBytes;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   143
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   144
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   145
    int numResources() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   146
        return jmodInfo.resourceCount;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   147
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   148
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   149
    long resourceBytes() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   150
        return jmodInfo.resourceBytes;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   151
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   152
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   153
    int numConfigs() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   154
        return jmodInfo.configCount;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   155
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   156
    long configBytes() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   157
        return jmodInfo.configBytes;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   158
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   159
    int numCommands() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   160
        return jmodInfo.nativeCmds.size();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   161
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   162
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   163
    long commandBytes() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   164
        return jmodInfo.nativeCmds.values().stream()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   165
                .mapToLong(l -> l.longValue()).sum() - jmodInfo.debugInfoCmdBytes;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   166
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   167
    int numCommandsDebug() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   168
        return jmodInfo.debugInfoCmdCount;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   169
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   170
    long commandDebugBytes() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   171
        return jmodInfo.debugInfoCmdBytes;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   172
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   173
    int numNativeLibraries() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   174
        return jmodInfo.nativeLibs.size();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   175
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   176
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   177
    long nativeLibrariesBytes() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   178
        return jmodInfo.nativeLibs.values().stream()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   179
                .mapToLong(l -> l.longValue()).sum() - jmodInfo.debugInfoLibBytes;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   180
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   181
    int numNativeLibrariesDebug() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   182
        return jmodInfo.debugInfoLibCount;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   183
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   184
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   185
    long nativeLibrariesDebugBytes() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   186
        return jmodInfo.debugInfoLibBytes;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   187
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   188
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   189
    Map<String,Long> commands() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   190
        return jmodInfo.nativeCmds;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   191
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   192
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   193
    Map<String,Long> nativeLibs() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   194
        return jmodInfo.nativeLibs;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   195
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   196
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   197
    Map<String,Long> configFiles() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   198
        return jmodInfo.configFiles;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   199
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   200
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   201
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   202
    static class JmodInfo {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   203
        final long size;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   204
        final long filesize;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   205
        final int  classCount;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   206
        final long classBytes;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   207
        final int  resourceCount;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   208
        final long resourceBytes;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   209
        final int  configCount;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   210
        final long configBytes;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   211
        final int  debugInfoLibCount;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   212
        final long debugInfoLibBytes;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   213
        final int  debugInfoCmdCount;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   214
        final long debugInfoCmdBytes;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   215
        final Map<String,Long> configFiles = new HashMap<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   216
        final Map<String,Long> nativeCmds = new HashMap<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   217
        final Map<String,Long> nativeLibs = new HashMap<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   218
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   219
        JmodInfo(Path jmod) throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   220
            long total = 0;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   221
            long cBytes = 0, rBytes = 0, cfBytes = 0, dizLibBytes = 0, dizCmdBytes = 0;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   222
            int  cCount = 0, rCount = 0, cfCount = 0, dizLibCount = 0, dizCmdCount = 0;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   223
            try (ZipFile zf = new ZipFile(jmod.toFile())) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   224
                for (Enumeration<? extends ZipEntry> e = zf.entries(); e.hasMoreElements(); ) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   225
                    ZipEntry ze = e.nextElement();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   226
                    String fn = ze.getName();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   227
                    int pos = fn.indexOf('/');
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   228
                    String dir = fn.substring(0, pos);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   229
                    String filename = fn.substring(fn.lastIndexOf('/') + 1);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   230
                    // name shown in the column
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   231
                    String name = filename;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   232
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   233
                    long len = ze.getSize();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   234
                    total += len;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   235
                    switch (dir) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   236
                        case NATIVE_LIBS:
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   237
                            nativeLibs.put(name, len);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   238
                            if (filename.endsWith(".diz")) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   239
                                dizLibCount++;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   240
                                dizLibBytes += len;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   241
                            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   242
                            break;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   243
                        case NATIVE_CMDS:
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   244
                            nativeCmds.put(name, len);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   245
                            if (filename.endsWith(".diz")) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   246
                                dizCmdCount++;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   247
                                dizCmdBytes += len;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   248
                            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   249
                            break;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   250
                        case CLASSES:
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   251
                            if (filename.endsWith(".class")) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   252
                                cCount++;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   253
                                cBytes += len;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   254
                            } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   255
                                rCount++;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   256
                                rBytes += len;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   257
                            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   258
                            break;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   259
                        case CONFIG:
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   260
                            configFiles.put(name, len);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   261
                            cfCount++;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   262
                            cfBytes += len;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   263
                            break;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   264
                        default:
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   265
                            break;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   266
                    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   267
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   268
                this.filesize = jmod.toFile().length();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   269
                this.classCount = cCount;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   270
                this.classBytes = cBytes;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   271
                this.resourceCount = rCount;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   272
                this.resourceBytes = rBytes;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   273
                this.configCount = cfCount;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   274
                this.configBytes = cfBytes;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   275
                this.size = total;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   276
                this.debugInfoLibCount = dizLibCount;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   277
                this.debugInfoLibBytes = dizLibBytes;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   278
                this.debugInfoCmdCount = dizCmdCount;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   279
                this.debugInfoCmdBytes = dizCmdBytes;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   280
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   281
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   282
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   283
        static final String NATIVE_LIBS = "native";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   284
        static final String NATIVE_CMDS = "bin";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   285
        static final String CLASSES     = "classes";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   286
        static final String CONFIG      = "conf";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   287
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   288
        static final String MODULE_ID = "module/id";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   289
        static final String MODULE_MAIN_CLASS = "module/main-class";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   290
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   291
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   292
    static Configuration resolve(Set<String> roots) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   293
        return Configuration.empty()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   294
            .resolveRequires(ModuleFinder.ofSystem(),
38457
3d019217e322 8152650: ModuleFinder.compose should accept varargs
alanb
parents: 36511
diff changeset
   295
                             ModuleFinder.of(),
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   296
                             roots);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   297
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   298
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   299
    static class HtmlDocument {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   300
        final String title;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   301
        final Map<String, ModuleSummary> modules;
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   302
        boolean requiresTransitiveNote = false;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   303
        boolean aggregatorNote = false;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   304
        boolean totalBytesNote = false;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   305
        HtmlDocument(String title, Map<String, ModuleSummary> modules) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   306
            this.title = title;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   307
            this.modules = modules;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   308
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   309
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   310
        void writeTo(PrintStream out, Set<ModuleDescriptor> selectedModules) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   311
            out.format("<html><head>%n");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   312
            out.format("<title>%s</title>%n", title);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   313
            // stylesheet
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   314
            Arrays.stream(HtmlDocument.STYLES).forEach(out::println);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   315
            out.format("</head>%n");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   316
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   317
            // body begins
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   318
            out.format("<body>%n");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   319
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   320
            // title and date
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   321
            out.println(DOCTITLE.toString(title));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   322
            out.println(VERSION.toString(String.format("%tc", new Date())));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   323
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   324
            // total modules and sizes
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   325
            long totalBytes = selectedModules.stream()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   326
                    .map(ModuleDescriptor::name)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   327
                    .map(modules::get)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   328
                    .mapToLong(ModuleSummary::uncompressedSize)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   329
                    .sum();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   330
            String[] sections = new String[] {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   331
                    String.format("%s: %d", "Total modules", selectedModules.size()),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   332
                    String.format("%s: %,d bytes (%s %s)", "Total size",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   333
                                  totalBytes,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   334
                                  System.getProperty("os.name"),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   335
                                  System.getProperty("os.arch"))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   336
            };
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   337
            out.println(SECTION.toString(sections));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   338
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   339
            // write table and header
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   340
            out.println(String.format("<table class=\"%s\">", MODULES));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   341
            out.println(header("Module", "Requires", "Exports",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   342
                    "Services", "Commands/Native Libraries/Configs"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   343
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   344
            // write contents - one row per module
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   345
            selectedModules.stream()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   346
                    .sorted(Comparator.comparing(ModuleDescriptor::name))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   347
                    .map(m -> modules.get(m.name()))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   348
                    .map(ModuleTableRow::new)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   349
                    .forEach(table -> table.writeTo(out));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   350
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   351
            out.format("</table>");  // end table
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   352
            out.format("</body>");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   353
            out.println("</html>");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   354
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   355
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   356
        String header(String... columns) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   357
            StringBuilder sb = new StringBuilder();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   358
            sb.append("<tr>");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   359
            Arrays.stream(columns)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   360
                    .forEach(cn -> sb.append("  <th>").append(cn).append("</th>").append("\n"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   361
            sb.append("</tr>");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   362
            return sb.toString();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   363
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   364
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   365
        static enum Selector {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   366
            MODULES("modules"),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   367
            MODULE("module"),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   368
            MODULE_DEF("code name def"),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   369
            AGGREGATOR("code name def agg"),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   370
            REQUIRES("code"),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   371
            REQUIRES_PUBLIC("code reexp"),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   372
            BR("br"),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   373
            CODE("code"),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   374
            NUMBER("number"),;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   375
            final String name;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   376
            Selector(String name) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   377
                this.name = name;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   378
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   379
            @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   380
            public String toString() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   381
                return name;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   382
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   383
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   384
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   385
        static enum Division {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   386
            DOCTITLE("doctitle"),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   387
            VERSION("versions"),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   388
            SECTION("section");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   389
            final String name;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   390
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   391
            Division(String name) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   392
                this.name = name;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   393
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   394
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   395
            public String toString(String... lines) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   396
                String value = Arrays.stream(lines).collect(Collectors.joining("<br>\n"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   397
                return "<div class=\"" + name + "\">" + value + "</div>";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   398
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   399
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   400
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   401
        class ModuleTableRow {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   402
            private final ModuleSummary ms;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   403
            private final Set<ModuleDescriptor> deps;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   404
            private final int maxRows;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   405
            private final boolean aggregator;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   406
            ModuleTableRow(ModuleSummary ms) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   407
                this.ms = ms;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   408
                Configuration cf = resolve(Set.of(ms.name()));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   409
                this.deps = cf.modules().stream()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   410
                        .map(ResolvedModule::reference)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   411
                        .map(ModuleReference::descriptor)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   412
                        .collect(Collectors.toSet());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   413
                int count = (ms.numClasses() > 0 ? 1 : 0) +
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   414
                            (ms.numResources() > 0 ? 1 : 0) +
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   415
                            (ms.numConfigs() > 0 ? 1 : 0) +
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   416
                            (ms.numNativeLibraries() > 0 ? 1 : 0) +
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   417
                            (ms.numNativeLibrariesDebug() > 0 ? 1 : 0) +
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   418
                            (ms.numCommands() > 0 ? 1 : 0) +
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   419
                            (ms.numCommandsDebug() > 0 ? 1 : 0);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   420
                this.aggregator = ms.numClasses() == 1 && count == 1; // only module-info.class
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   421
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   422
                // 5 fixed rows (name + 2 transitive count/size + 2 blank rows)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   423
                this.maxRows = 5 + count + (aggregator && !aggregatorNote ? 2 : 0);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   424
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   425
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   426
            public void writeTo(PrintStream out) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   427
                out.println(String.format("<tr id=\"%s\" class=\"%s\">", ms.name(), MODULE));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   428
                out.println(moduleColumn());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   429
                out.println(requiresColumn());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   430
                out.println(exportsColumn());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   431
                out.println(servicesColumn());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   432
                out.println(otherSectionColumn());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   433
                out.println("</td>");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   434
                out.println("</tr>");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   435
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   436
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   437
            public String moduleColumn() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   438
                // module name
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   439
                StringBuilder sb = new StringBuilder("  ");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   440
                sb.append("<td>");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   441
                sb.append(String.format("<table class=\"%s\">", MODULE)).append("\n");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   442
                sb.append(moduleName(ms.name()));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   443
                sb.append(blankRow());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   444
                // metadata
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   445
                sb.append(toTableRow("class", "classes", ms.numClasses(), ms.classBytes()));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   446
                sb.append(toTableRow("resource", "resources", ms.numResources(), ms.resourceBytes()));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   447
                sb.append(toTableRow("config", "configs", ms.numConfigs(), ms.configBytes()));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   448
                sb.append(toTableRow("native library", "native libraries",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   449
                                     ms.numNativeLibraries(), ms.nativeLibrariesBytes()));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   450
                sb.append(toTableRow("native library debug", "native libraries debug",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   451
                                     ms.numNativeLibrariesDebug(), ms.nativeLibrariesDebugBytes()));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   452
                sb.append(toTableRow("command", "commands", ms.numCommands(), ms.commandBytes()));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   453
                sb.append(toTableRow("command debug", "commands debug",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   454
                                     ms.numCommandsDebug(), ms.commandDebugBytes()));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   455
                sb.append(blankRow());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   456
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   457
                // transitive dependencies
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   458
                long reqBytes = deps.stream()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   459
                                    .filter(d -> !d.name().equals(ms.name()))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   460
                                    .mapToLong(d -> modules.get(d.name()).uncompressedSize())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   461
                                    .sum();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   462
                long reqJmodFileSize = deps.stream()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   463
                                            .mapToLong(d -> modules.get(d.name()).jmodFileSize())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   464
                                            .sum();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   465
                // size
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   466
                if (totalBytesNote) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   467
                    sb.append(toTableRow("Total bytes", ms.uncompressedSize()));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   468
                    sb.append(toTableRow("Total bytes of dependencies", reqBytes));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   469
                } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   470
                    // print footnote
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   471
                    sb.append(toTableRow("Total bytes<sup>1</sup>", ms.uncompressedSize()));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   472
                    sb.append(toTableRow("Total bytes of dependencies<sup>2</sup>", reqBytes));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   473
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   474
                String files = deps.size() == 1 ? "file" : "files";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   475
                sb.append(toTableRow(String.format("Total jmod bytes (%d %s)", deps.size(), files), reqJmodFileSize));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   476
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   477
                if (aggregator && !aggregatorNote) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   478
                    aggregatorNote = true;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   479
                    sb.append(blankRow());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   480
                    sb.append(toTableRow("<i>* aggregator is a module with module-info.class only</i>", BR));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   481
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   482
                if (!totalBytesNote) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   483
                    totalBytesNote = true;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   484
                    sb.append(blankRow());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   485
                    sb.append(toTableRow("<i><sup>1</sup>sum of all files including debug files</i>", BR));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   486
                    sb.append(toTableRow("<i><sup>2</sup>sum of direct and indirect dependencies</i>", BR));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   487
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   488
                sb.append("</table>").append("</td>");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   489
                return sb.toString();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   490
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   491
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   492
            private String moduleName(String mn) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   493
                if (aggregator) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   494
                    StringBuilder sb = new StringBuilder();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   495
                    sb.append(String.format("<tr><td colspan=\"2\"><span class=\"%s\">", AGGREGATOR))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   496
                      .append(mn)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   497
                      .append("</span>").append("&nbsp;&nbsp;");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   498
                    if (!aggregatorNote) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   499
                        sb.append("(aggregator<sup>*</sup>)");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   500
                    } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   501
                        sb.append("(aggregator)");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   502
                    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   503
                    sb.append("</td></tr>");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   504
                    return sb.toString();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   505
                } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   506
                    return toTableRow(mn, MODULE_DEF);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   507
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   508
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   509
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   510
            public String requiresColumn() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   511
                StringBuilder sb = new StringBuilder();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   512
                sb.append(String.format("<td>"));
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   513
                boolean footnote = requiresTransitiveNote;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   514
                ms.descriptor().requires().stream()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   515
                        .sorted(Comparator.comparing(Requires::name))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   516
                        .forEach(r -> {
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   517
                            boolean requiresTransitive = r.modifiers().contains(Requires.Modifier.TRANSITIVE);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   518
                            Selector sel = requiresTransitive ? REQUIRES_PUBLIC : REQUIRES;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   519
                            String req = String.format("<a class=\"%s\" href=\"#%s\">%s</a>",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   520
                                                       sel, r.name(), r.name());
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   521
                            if (!requiresTransitiveNote && requiresTransitive) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   522
                                requiresTransitiveNote = true;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   523
                                req += "<sup>*</sup>";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   524
                            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   525
                            sb.append(req).append("\n").append("<br>");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   526
                        });
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   527
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   528
                if (!ms.name().equals("java.base")) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   529
                    int directDeps = ms.descriptor().requires().size();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   530
                    int indirectDeps = deps.size()-directDeps-1;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   531
                    for (int i=directDeps; i< (maxRows-1); i++) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   532
                        sb.append("<br>");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   533
                    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   534
                    sb.append("<br>");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   535
                    sb.append("<i>+").append(indirectDeps).append(" transitive dependencies</i>");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   536
                }
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   537
                if (footnote != requiresTransitiveNote) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   538
                    sb.append("<br><br>").append("<i>* bold denotes requires transitive</i>");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   539
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   540
                sb.append("</td>");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   541
                return sb.toString();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   542
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   543
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   544
            public String exportsColumn() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   545
                StringBuilder sb = new StringBuilder();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   546
                sb.append(String.format("  <td class=\"%s\">", CODE));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   547
                ms.descriptor().exports().stream()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   548
                        .sorted(Comparator.comparing(Exports::source))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   549
                        .filter(e -> !e.isQualified())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   550
                        .forEach(e -> sb.append(e.source()).append("<br>").append("\n"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   551
                sb.append("</td>");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   552
                return sb.toString();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   553
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   554
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   555
            public String servicesColumn() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   556
                StringBuilder sb = new StringBuilder();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   557
                sb.append(String.format("  <td class=\"%s\">", CODE));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   558
                ms.descriptor().uses().stream()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   559
                        .sorted()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   560
                        .forEach(s -> sb.append("uses ").append(s).append("<br>").append("\n"));
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   561
                ms.descriptor().provides().stream()
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   562
                        .sorted(Comparator.comparing(Provides::service))
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   563
                        .map(p -> String.format("provides %s<br>&nbsp;&nbsp;&nbsp;&nbsp;with %s",
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
   564
                                                p.service(), p.providers()))
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   565
                        .forEach(p -> sb.append(p).append("<br>").append("\n"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   566
                sb.append("</td>");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   567
                return sb.toString();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   568
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   569
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   570
            public String otherSectionColumn() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   571
                StringBuilder sb = new StringBuilder();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   572
                sb.append("<td>");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   573
                sb.append(String.format("<table class=\"%s\">", MODULE)).append("\n");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   574
                // commands
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   575
                if (ms.numCommands() > 0) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   576
                    sb.append(toTableRow("bin/", CODE));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   577
                    ms.commands().entrySet().stream()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   578
                            .sorted(Map.Entry.comparingByKey())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   579
                            .forEach(e -> sb.append(toTableRow(e.getKey(), e.getValue(), CODE)));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   580
                    sb.append(blankRow());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   581
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   582
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   583
                // native libraries
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   584
                if (ms.numNativeLibraries() > 0) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   585
                    sb.append(toTableRow("lib/", CODE));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   586
                    ms.nativeLibs().entrySet().stream()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   587
                            .sorted(Map.Entry.comparingByKey())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   588
                            .forEach(e -> sb.append(toTableRow(e.getKey(), e.getValue(), CODE)));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   589
                    sb.append(blankRow());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   590
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   591
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   592
                // config files
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   593
                if (ms.numConfigs() > 0) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   594
                    sb.append(toTableRow("conf/", CODE));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   595
                    ms.configFiles().entrySet().stream()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   596
                            .sorted(Map.Entry.comparingByKey())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   597
                            .forEach(e -> sb.append(toTableRow(e.getKey(), e.getValue(), CODE)));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   598
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   599
                // totals
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   600
                sb.append("</table>").append("</td>");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   601
                return sb.toString();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   602
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   603
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   604
            private String blankRow() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   605
                return toTableRow("&nbsp;", BR);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   606
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   607
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   608
            private String toTableRow(String col, Selector selector) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   609
                TableDataBuilder builder = new TableDataBuilder();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   610
                builder.colspan(selector, 2, col);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   611
                return builder.build();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   612
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   613
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   614
            private String toTableRow(String col1, long col2) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   615
                return toTableRow(col1, col2, BR);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   616
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   617
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   618
            private String toTableRow(String col1, long col2, Selector selector) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   619
                TableDataBuilder builder = new TableDataBuilder();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   620
                builder.data(selector, col1);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   621
                builder.data(col2);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   622
                return builder.build();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   623
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   624
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   625
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   626
            private String toTableRow(String singular, String plural, int count, long bytes) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   627
                if (count == 0) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   628
                    return "";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   629
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   630
                TableDataBuilder builder = new TableDataBuilder();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   631
                if (count == 1) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   632
                    builder.data(count + " " + singular);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   633
                } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   634
                    builder.data(count + " " + plural);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   635
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   636
                builder.data(bytes);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   637
                return builder.build();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   638
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   639
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   640
            class TableDataBuilder {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   641
                private final StringBuilder sb;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   642
                TableDataBuilder() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   643
                    this.sb = new StringBuilder("<tr>");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   644
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   645
                TableDataBuilder data(String s) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   646
                    data(BR, s);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   647
                    return this;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   648
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   649
                TableDataBuilder data(long num) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   650
                    data(NUMBER, String.format("%,d", num));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   651
                    return this;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   652
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   653
                TableDataBuilder colspan(Selector selector, int columns, String data) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   654
                    sb.append("<td colspan=\"").append(columns).append("\">");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   655
                    sb.append("<span class=\"").append(selector).append("\">");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   656
                    sb.append(data).append("</span></td>");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   657
                    return this;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   658
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   659
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   660
                TableDataBuilder data(Selector selector, String data) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   661
                    sb.append("<td class=\"").append(selector).append("\">");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   662
                    sb.append(data).append("</td>");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   663
                    return this;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   664
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   665
                String build() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   666
                    sb.append("</tr>");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   667
                    return sb.toString();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   668
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   669
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   670
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   671
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   672
        private static final String[] STYLES = new String[]{
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   673
                "<link rel=\"stylesheet\" type=\"text/css\" href=\"/.fonts/dejavu.css\"/>",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   674
                "<style type=\"text/css\">",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   675
                "        HTML, BODY, DIV, SPAN, APPLET, OBJECT, IFRAME, H1, H2, H3, H4, H5, H6, P,",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   676
                "        BLOCKQUOTE, PRE, A, ABBR, ACRONYM, ADDRESS, BIG, CITE, CODE, DEL, DFN, EM,",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   677
                "        IMG, INS, KBD, Q, S, SAMP, SMALL, STRIKE, STRONG, SUB, SUP, TT, VAR, B, U,",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   678
                "        I, CENTER, DL, DT, DD, OL, UL, LI, FIELDSET, FORM, LABEL, LEGEND, TABLE,",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   679
                "        CAPTION, TBODY, TFOOT, THEAD, TR, TH, TD, ARTICLE, ASIDE, CANVAS, DETAILS,",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   680
                "        EMBED, FIGURE, FIGCAPTION, FOOTER, HEADER, HGROUP, MENU, NAV, OUTPUT, RUBY,",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   681
                "        SECTION, SUMMARY, TIME, MARK, AUDIO, VIDEO {",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   682
                "          margin: 0; padding: 0; border: 0; font-size: 100%; font: inherit;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   683
                "          vertical-align: baseline; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   684
                "        ARTICLE, ASIDE, DETAILS, FIGCAPTION, FIGURE, ",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   685
                "        FOOTER, HEADER, HGROUP, MENU, NAV, SECTION { display: block; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   686
                "        BLOCKQUOTE, Q { quotes: none; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   687
                "        BLOCKQUOTE:before, BLOCKQUOTE:after, Q:before, Q:after {",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   688
                "                content: ''; content: none; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   689
                "        TABLE { border-collapse: collapse; border-spacing: 0; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   690
                "        A { text-decoration: none; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   691
                "        A:link { color: #437291; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   692
                "        A:visited { color: #666666; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   693
                "        A.anchor:link, A.anchor:visited { color: black; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   694
                "        A[href]:hover { color: #e76f00; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   695
                "        A IMG { border-width: 0px; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   696
                "        HTML { font-size: 20px; } /* baseline grid */",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   697
                "        HTML > BODY { font-size: 14px; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   698
                "        BODY {",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   699
                "          background: white;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   700
                "          margin: 40px;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   701
                "          margin-bottom: 150%;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   702
                "          line-height: 20px;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   703
                "          -webkit-text-size-adjust: 100%; /* iOS */",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   704
                "          color: #222;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   705
                "        }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   706
                "        BODY { font-family: \"DejaVu Serif\", \"Lucida Bright\", \"Bookman Old Style\",",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   707
                "                            Georgia, serif; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   708
                "        CODE, TT, .jref, DIV.spec .open, TABLE.profiles {",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   709
                "          font-family: \"DejaVu Sans\", \"Lucida Sans\", Helvetica, sans-serif; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   710
                "        PRE, .code { font-family: \"DejaVu Sans Mono\", \"Bitstream Vera Sans Mono\",",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   711
                "                            Monaco, \"Courier New\", monospace; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   712
                "        H1, H2, H3, H4 { color: green; font-weight: bold; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   713
                "        I { font-style: italic; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   714
                "        TH { font-weight: bold; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   715
                "        P { text-indent: 40px; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   716
                "        P:first-child, UL + P, OL + P, BLOCKQUOTE + P, TABLE + P, P.subsection,",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   717
                "          P.break, DIV.profiles-table + P { text-indent: 0; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   718
                "        P.break { margin-top: 10px; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   719
                "        P.subsection { margin-top: 20px; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   720
                "        P.subsection SPAN.title { font-weight: bold; padding-right: 20px; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   721
                "        UL, OL { margin: 10px 0; padding-left: 40px; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   722
                "        LI { margin-bottom: 10px; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   723
                "        UL.compact LI { margin-bottom: 0; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   724
                "        PRE { padding: 0; margin: 10px 0 10px 20px; background: #eee; width: 45em; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   725
                "        BLOCKQUOTE { margin: 10px 0; margin-left: 20px; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   726
                "        LI BLOCKQUOTE { margin-left: 0; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   727
                "        UL LI { list-style-type: square; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   728
                "        .todo { color: darkred; text-align: right; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   729
                "        .error { color: red; font-weight: bold; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   730
                "        .warn { color: #ee0000; font-weight: bold; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   731
                "        DIV.doctitle { margin-top: -13px;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   732
                "          font-size: 22px; line-height: 40px; font-weight: bold; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   733
                "        DIV.twarn { color: #cc0000; font-weight: bold; margin-bottom: 9px; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   734
                "        DIV.subtitle { margin-top: 2px; font-size: 18px; font-weight: bold; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   735
                "        DIV.authors { margin-top: 10px; margin-bottom: 10px; font-size: 16px; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   736
                "        DIV.author A { font-style: italic; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   737
                "        DIV.version { margin-top: 10px; font-size: 12px; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   738
                "        DIV.version, DIV.legal-notice { font-size: 12px; line-height: 15px; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   739
                "        SPAN.hash { font-size: 9px; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   740
                "        DIV.version SPAN.modified { color: green; font-weight: bold; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   741
                "        DIV.head { margin-bottom: 20px; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   742
                "        DIV.section > DIV.title, DIV.section DIV.number SPAN {",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   743
                "          font-size: 15px; font-weight: bold; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   744
                "        TABLE { border-collapse: collapse; border: none; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   745
                "        TD.number { text-align: right; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   746
                "        TD, TH { text-align: left; white-space: nowrap; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   747
                "        TD.name, SPAN.name { font-weight: bold; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   748
                "        ",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   749
                "        TABLE.module { width: 100%; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   750
                "        TABLE.module TD:first-child { padding-right: 10px; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   751
                "        TR.module > TD { padding: 10px 0; border-top: 1px solid black; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   752
                "        TR > TH { padding-bottom: 10px; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   753
                "        TR.br TD { padding-top: 20px; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   754
                "        TABLE.modules { margin-top: 20px; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   755
                "        TABLE.modules > TBODY > TR > TD:nth-child(even) { background: #eee; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   756
                "        TABLE.modules > TBODY > TR > TD, TABLE.modules > TBODY > TR > TH {",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   757
                "          padding-left: 10px; padding-right: 10px; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   758
                "        .reexp, .def { font-weight: bold; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   759
                "        .agg { font-style: italic; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   760
                "        SUP { height: 0; line-height: 1; position: relative;",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   761
                "              vertical-align: baseline; bottom: 1ex; font-size: 11px; }",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   762
                "</style>",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   763
        };
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   764
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   765
}