langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/Profile.java
author mcimadamore
Fri, 16 Dec 2016 15:27:34 +0000
changeset 42827 36468b5fa7f4
parent 42817 6545638adc59
permissions -rw-r--r--
8181370: Convert anonymous inner classes into lambdas/method references Reviewed-by: jjg, rfield, mchung
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;
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    29
import java.lang.module.ModuleDescriptor;
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    30
import java.util.Arrays;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36493
diff changeset
    31
import java.util.Comparator;
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    32
import java.util.HashMap;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36493
diff changeset
    33
import java.util.HashSet;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36493
diff changeset
    34
import java.util.Map;
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    35
import java.util.Optional;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36493
diff changeset
    36
import java.util.Set;
16550
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    37
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    38
/**
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
    39
 * Build the profile information.
16550
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    40
 */
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    41
enum Profile {
42817
6545638adc59 8171201: Drop java.compact$N aggregator modules
mchung
parents: 38524
diff changeset
    42
    COMPACT1("compact1", 1, "java.logging",
6545638adc59 8171201: Drop java.compact$N aggregator modules
mchung
parents: 38524
diff changeset
    43
                            "java.scripting"),
6545638adc59 8171201: Drop java.compact$N aggregator modules
mchung
parents: 38524
diff changeset
    44
    COMPACT2("compact2", 2, "java.rmi",
6545638adc59 8171201: Drop java.compact$N aggregator modules
mchung
parents: 38524
diff changeset
    45
                            "java.sql",
6545638adc59 8171201: Drop java.compact$N aggregator modules
mchung
parents: 38524
diff changeset
    46
                            "java.xml",
6545638adc59 8171201: Drop java.compact$N aggregator modules
mchung
parents: 38524
diff changeset
    47
                            "jdk.xml.dom",
6545638adc59 8171201: Drop java.compact$N aggregator modules
mchung
parents: 38524
diff changeset
    48
                            "jdk.httpserver"),
6545638adc59 8171201: Drop java.compact$N aggregator modules
mchung
parents: 38524
diff changeset
    49
    COMPACT3("compact3", 3, "java.smartcardio",
6545638adc59 8171201: Drop java.compact$N aggregator modules
mchung
parents: 38524
diff changeset
    50
                            "java.compiler",
6545638adc59 8171201: Drop java.compact$N aggregator modules
mchung
parents: 38524
diff changeset
    51
                            "java.instrument",
6545638adc59 8171201: Drop java.compact$N aggregator modules
mchung
parents: 38524
diff changeset
    52
                            "java.management",
6545638adc59 8171201: Drop java.compact$N aggregator modules
mchung
parents: 38524
diff changeset
    53
                            "java.naming",
6545638adc59 8171201: Drop java.compact$N aggregator modules
mchung
parents: 38524
diff changeset
    54
                            "java.prefs",
6545638adc59 8171201: Drop java.compact$N aggregator modules
mchung
parents: 38524
diff changeset
    55
                            "java.security.jgss",
6545638adc59 8171201: Drop java.compact$N aggregator modules
mchung
parents: 38524
diff changeset
    56
                            "java.security.sasl",
6545638adc59 8171201: Drop java.compact$N aggregator modules
mchung
parents: 38524
diff changeset
    57
                            "java.sql.rowset",
6545638adc59 8171201: Drop java.compact$N aggregator modules
mchung
parents: 38524
diff changeset
    58
                            "java.xml.crypto",
6545638adc59 8171201: Drop java.compact$N aggregator modules
mchung
parents: 38524
diff changeset
    59
                            "jdk.management",
6545638adc59 8171201: Drop java.compact$N aggregator modules
mchung
parents: 38524
diff changeset
    60
                            "jdk.naming.dns",
6545638adc59 8171201: Drop java.compact$N aggregator modules
mchung
parents: 38524
diff changeset
    61
                            "jdk.naming.rmi",
6545638adc59 8171201: Drop java.compact$N aggregator modules
mchung
parents: 38524
diff changeset
    62
                            "jdk.sctp",
6545638adc59 8171201: Drop java.compact$N aggregator modules
mchung
parents: 38524
diff changeset
    63
                            "jdk.security.auth");
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    64
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    65
    final String name;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    66
    final int profile;
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
    67
    final String[] mnames;
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    68
    final Map<String, Module> modules = new HashMap<>();
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    69
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
    70
    Profile(String name, int profile, String... mnames) {
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    71
        this.name = name;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    72
        this.profile = profile;
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
    73
        this.mnames = mnames;
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    74
    }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    75
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 21503
diff changeset
    76
    public String profileName() {
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    77
        return name;
16550
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    78
    }
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    79
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    80
    @Override
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    81
    public String toString() {
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
    82
        return mnames[0];
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    83
    }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    84
16550
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    85
    public static int getProfileCount() {
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    86
        return JDK.isEmpty() ? 0 : Profile.values().length;
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    87
    }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    88
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    89
    /**
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    90
     * 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
    91
     */
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    92
    public static Profile getProfile(String pn) {
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    93
        for (Profile p : Profile.values()) {
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
    94
            for (Module m : p.modules.values()) {
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    95
                if (m.packages().contains(pn)) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    96
                    return p;
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    97
                }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    98
            }
16550
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    99
        }
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   100
        return null;
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   101
    }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   102
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   103
    /*
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   104
     * Returns the Profile for a given Module; null if not found.
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   105
     */
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   106
    public static Profile getProfile(Module m) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   107
        for (Profile p : Profile.values()) {
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   108
            if (p.modules.containsValue(m)) {
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   109
                return p;
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   110
            }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   111
        }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   112
        return null;
16550
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
   113
    }
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
   114
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
   115
    private final static Set<Module> JDK = new HashSet<>();
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   116
    static synchronized void init(Map<String, Module> systemModules) {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   117
        Arrays.stream(Profile.values()).forEach(p ->
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   118
            // this includes platform-dependent module that may not exist
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   119
            Arrays.stream(p.mnames)
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   120
                  .filter(systemModules::containsKey)
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   121
                  .map(systemModules::get)
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   122
                  .forEach(m -> p.addModule(systemModules, m)));
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36493
diff changeset
   123
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36493
diff changeset
   124
        // JDK modules should include full JRE plus other jdk.* modules
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36493
diff changeset
   125
        // Just include all installed modules.  Assume jdeps is running
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36493
diff changeset
   126
        // in JDK image
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   127
        JDK.addAll(systemModules.values());
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   128
    }
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
   129
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   130
    private void addModule(Map<String, Module> systemModules, Module module) {
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   131
        modules.put(module.name(), module);
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   132
        module.descriptor().requires().stream()
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   133
              .map(ModuleDescriptor.Requires::name)
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   134
              .map(systemModules::get)
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   135
              .forEach(m -> modules.put(m.name(), m));
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
   136
    }
38524
badd925c1d2f 8156680: jdeps implementation refresh
mchung
parents: 36526
diff changeset
   137
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   138
    // for debugging
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   139
    public static void main(String[] args) throws IOException {
42817
6545638adc59 8171201: Drop java.compact$N aggregator modules
mchung
parents: 38524
diff changeset
   140
        // initialize Profiles
6545638adc59 8171201: Drop java.compact$N aggregator modules
mchung
parents: 38524
diff changeset
   141
        new JdepsConfiguration.Builder().allModules().build();
6545638adc59 8171201: Drop java.compact$N aggregator modules
mchung
parents: 38524
diff changeset
   142
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   143
        // find platform modules
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   144
        if (Profile.getProfileCount() == 0) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   145
            System.err.println("No profile is present in this JDK");
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   146
        }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   147
        for (Profile p : Profile.values()) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   148
            String profileName = p.name;
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   149
            System.out.format("%2d: %-10s  %s%n", p.profile, profileName, p.modules);
16550
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))
42827
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 42817
diff changeset
   153
           .forEach(System.out::println);
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
}