langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/Profile.java
author alanb
Thu, 17 Mar 2016 19:04:28 +0000
changeset 36526 3b41f1c69604
parent 36493 1e87cd35c980
child 38524 badd925c1d2f
permissions -rw-r--r--
8142968: Module System implementation Summary: Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282 Reviewed-by: jjg, jlahoda, vromero, mcimadamore, bpatel, ksrini, darcy, anazarov, dfuchs Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, jan.lahoda@oracle.com, vicente.romero@oracle.com, andreas.lundblad@oracle.com, andrey.x.nazarov@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, kumar.x.srinivasan@oracle.com, sundararajan.athijegannathan@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16550
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
     1
/*
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36493
diff changeset
     2
 * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
16550
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
     4
 *
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    10
 *
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    15
 * accompanied this code).
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    16
 *
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    20
 *
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    23
 * questions.
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    24
 */
34752
9c262a013456 8145342: Some copyright notices are inconsistently and ill formatted
vasya
parents: 30846
diff changeset
    25
16550
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    26
package com.sun.tools.jdeps;
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    27
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    28
import java.io.IOException;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36493
diff changeset
    29
import java.util.Comparator;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36493
diff changeset
    30
import java.util.HashSet;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36493
diff changeset
    31
import java.util.Map;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36493
diff changeset
    32
import java.util.Set;
16550
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    33
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    34
/**
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
    35
 * Build the profile information.
16550
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    36
 */
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    37
enum Profile {
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    38
    COMPACT1("compact1", 1, "java.compact1"),
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    39
    COMPACT2("compact2", 2, "java.compact2"),
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
    40
    COMPACT3("compact3", 3, "java.compact3", "java.smartcardio", "jdk.sctp",
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
    41
                            "jdk.httpserver", "jdk.security.auth",
30407
74a552051c9f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents: 27579
diff changeset
    42
                            "jdk.naming.dns", "jdk.naming.rmi",
74a552051c9f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents: 27579
diff changeset
    43
                            "jdk.management"),
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36493
diff changeset
    44
    // need a way to determine JRE modules
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36493
diff changeset
    45
    SE_JRE("Java SE JRE", 4, "java.se", "jdk.charsets",
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36493
diff changeset
    46
                            "jdk.crypto.ec", "jdk.crypto.pkcs11",
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36493
diff changeset
    47
                            "jdk.crypto.mscapi", "jdk.crypto.ucrypto", "jdk.jvmstat",
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36493
diff changeset
    48
                            "jdk.localedata", "jdk.scripting.nashorn", "jdk.zipfs"),
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36493
diff changeset
    49
    FULL_JRE("Full JRE", 5, "java.se.ee", "jdk.charsets",
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
    50
                            "jdk.crypto.ec", "jdk.crypto.pkcs11",
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
    51
                            "jdk.crypto.mscapi", "jdk.crypto.ucrypto", "jdk.jvmstat",
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
    52
                            "jdk.localedata", "jdk.scripting.nashorn", "jdk.zipfs");
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    53
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    54
    final String name;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    55
    final int profile;
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
    56
    final String[] mnames;
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    57
    final Set<Module> modules = new HashSet<>();
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    58
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
    59
    Profile(String name, int profile, String... mnames) {
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    60
        this.name = name;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    61
        this.profile = profile;
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
    62
        this.mnames = mnames;
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    63
    }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    64
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 21503
diff changeset
    65
    public String profileName() {
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    66
        return name;
16550
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    67
    }
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    68
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    69
    @Override
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    70
    public String toString() {
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
    71
        return mnames[0];
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    72
    }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    73
16550
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    74
    public static int getProfileCount() {
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    75
        return JDK.isEmpty() ? 0 : Profile.values().length;
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    76
    }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    77
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    78
    /**
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    79
     * Returns the Profile for the given package name; null if not found.
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    80
     */
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    81
    public static Profile getProfile(String pn) {
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    82
        for (Profile p : Profile.values()) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    83
            for (Module m : p.modules) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    84
                if (m.packages().contains(pn)) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    85
                    return p;
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    86
                }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    87
            }
16550
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    88
        }
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    89
        return null;
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    90
    }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    91
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    92
    /*
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    93
     * Returns the Profile for a given Module; null if not found.
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    94
     */
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    95
    public static Profile getProfile(Module m) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    96
        for (Profile p : Profile.values()) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    97
            if (p.modules.contains(m)) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    98
                return p;
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    99
            }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   100
        }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   101
        return null;
16550
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
   102
    }
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
   103
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
   104
    private final static Set<Module> JDK = new HashSet<>();
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36493
diff changeset
   105
    static synchronized void init(Map<String, Module> installed) {
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   106
        for (Profile p : Profile.values()) {
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
   107
            for (String mn : p.mnames) {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
   108
                // this includes platform-dependent module that may not exist
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36493
diff changeset
   109
                Module m = installed.get(mn);
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
   110
                if (m != null) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36493
diff changeset
   111
                    p.addModule(installed, m);
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
   112
                }
16550
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
   113
            }
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   114
        }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36493
diff changeset
   115
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36493
diff changeset
   116
        // JDK modules should include full JRE plus other jdk.* modules
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36493
diff changeset
   117
        // Just include all installed modules.  Assume jdeps is running
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36493
diff changeset
   118
        // in JDK image
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36493
diff changeset
   119
        JDK.addAll(installed.values());
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   120
    }
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
   121
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36493
diff changeset
   122
    private void addModule(Map<String, Module> installed, Module m) {
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
   123
        modules.add(m);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
   124
        for (String n : m.requires().keySet()) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36493
diff changeset
   125
            Module d = installed.get(n);
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
   126
            if (d == null) {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
   127
                throw new InternalError("module " + n + " required by " +
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
   128
                        m.name() + " doesn't exist");
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
   129
            }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
   130
            modules.add(d);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
   131
        }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
   132
    }
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   133
    // for debugging
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   134
    public static void main(String[] args) throws IOException {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   135
        // find platform modules
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   136
        if (Profile.getProfileCount() == 0) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   137
            System.err.println("No profile is present in this JDK");
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   138
        }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   139
        for (Profile p : Profile.values()) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   140
            String profileName = p.name;
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   141
            System.out.format("%2d: %-10s  %s%n", p.profile, profileName, p.modules);
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   142
            for (Module m: p.modules) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   143
                System.out.format("module %s%n", m.name());
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   144
                System.out.format("   requires %s%n", m.requires());
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   145
                for (Map.Entry<String,Set<String>> e: m.exports().entrySet()) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   146
                    System.out.format("   exports %s %s%n", e.getKey(),
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   147
                        e.getValue().isEmpty() ? "" : "to " + e.getValue());
16550
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
   148
                }
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
   149
            }
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
   150
        }
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   151
        System.out.println("All JDK modules:-");
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   152
        JDK.stream().sorted(Comparator.comparing(Module::name))
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   153
           .forEach(m -> System.out.println(m));
16550
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
   154
    }
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
   155
}