langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/Profile.java
author mchung
Wed, 27 May 2015 13:25:18 -0700
changeset 30846 2b3f379840f0
parent 30407 langtools/src/jdk.dev/share/classes/com/sun/tools/jdeps/Profile.java@74a552051c9f
child 34752 9c262a013456
permissions -rw-r--r--
8074432: Move jdeps and javap to jdk.jdeps module Reviewed-by: jjg, alanb, erikj
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
/*
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 21503
diff changeset
     2
 * Copyright (c) 2013, 2014, 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
 */
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    25
package com.sun.tools.jdeps;
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    26
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    27
import java.io.IOException;
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    28
import java.util.*;
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    29
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    30
/**
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
    31
 * Build the profile information.
16550
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    32
 */
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    33
enum Profile {
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    34
    COMPACT1("compact1", 1, "java.compact1"),
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    35
    COMPACT2("compact2", 2, "java.compact2"),
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
    36
    COMPACT3("compact3", 3, "java.compact3", "java.smartcardio", "jdk.sctp",
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
    37
                            "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
    38
                            "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
    39
                            "jdk.management"),
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
    40
    FULL_JRE("Full JRE", 4, "java.se", "jdk.deploy.osx", "jdk.charsets",
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
    41
                            "jdk.crypto.ec", "jdk.crypto.pkcs11",
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
    42
                            "jdk.crypto.mscapi", "jdk.crypto.ucrypto", "jdk.jvmstat",
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
    43
                            "jdk.localedata", "jdk.scripting.nashorn", "jdk.zipfs");
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    44
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    45
    final String name;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    46
    final int profile;
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
    47
    final String[] mnames;
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    48
    final Set<Module> modules = new HashSet<>();
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    49
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
    50
    Profile(String name, int profile, String... mnames) {
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    51
        this.name = name;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    52
        this.profile = profile;
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
    53
        this.mnames = mnames;
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    54
    }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    55
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 21503
diff changeset
    56
    public String profileName() {
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    57
        return name;
16550
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    58
    }
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    59
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    60
    @Override
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    61
    public String toString() {
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
    62
        return mnames[0];
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    63
    }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    64
16550
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    65
    public static int getProfileCount() {
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    66
        return JDK.isEmpty() ? 0 : Profile.values().length;
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    67
    }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    68
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    69
    /**
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    70
     * 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
    71
     */
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    72
    public static Profile getProfile(String pn) {
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    73
        for (Profile p : Profile.values()) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    74
            for (Module m : p.modules) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    75
                if (m.packages().contains(pn)) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    76
                    return p;
21046
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
            }
16550
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
        return null;
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    81
    }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    82
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    83
    /*
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    84
     * Returns the Profile for a given Module; null if not found.
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    85
     */
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    86
    public static Profile getProfile(Module m) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    87
        for (Profile p : Profile.values()) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    88
            if (p.modules.contains(m)) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    89
                return p;
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
        return null;
16550
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    93
    }
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    94
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
    95
    private final static Set<Module> JDK = new HashSet<>();
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
    96
    static void initProfiles(List<Archive> modules) {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
    97
        // add all modules into  JDK
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
    98
        modules.forEach(m -> JDK.add((Module)m));
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
    99
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   100
        for (Profile p : Profile.values()) {
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
   101
            for (String mn : p.mnames) {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
   102
                // this includes platform-dependent module that may not exist
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
   103
                Module m = PlatformClassPath.findModule(mn);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
   104
                if (m != null) {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
   105
                    p.addModule(m);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
   106
                }
16550
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
   107
            }
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   108
        }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   109
    }
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
   110
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
   111
    private void addModule(Module m) {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
   112
        modules.add(m);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
   113
        for (String n : m.requires().keySet()) {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
   114
            Module d = PlatformClassPath.findModule(n);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
   115
            if (d == null) {
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
   116
                throw new InternalError("module " + n + " required by " +
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
   117
                        m.name() + " doesn't exist");
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
   118
            }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
   119
            modules.add(d);
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
   120
        }
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
   121
    }
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   122
    // for debugging
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   123
    public static void main(String[] args) throws IOException {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   124
        // find platform modules
27579
d1a63c99cdd5 8049367: Modular Run-Time Images
chegar
parents: 25874
diff changeset
   125
        PlatformClassPath.getModules(null);
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   126
        if (Profile.getProfileCount() == 0) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   127
            System.err.println("No profile is present in this JDK");
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   128
        }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   129
        for (Profile p : Profile.values()) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   130
            String profileName = p.name;
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   131
            System.out.format("%2d: %-10s  %s%n", p.profile, profileName, p.modules);
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   132
            for (Module m: p.modules) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   133
                System.out.format("module %s%n", m.name());
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   134
                System.out.format("   requires %s%n", m.requires());
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   135
                for (Map.Entry<String,Set<String>> e: m.exports().entrySet()) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   136
                    System.out.format("   exports %s %s%n", e.getKey(),
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   137
                        e.getValue().isEmpty() ? "" : "to " + e.getValue());
16550
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
   138
                }
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
   139
            }
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
   140
        }
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   141
        System.out.println("All JDK modules:-");
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   142
        JDK.stream().sorted(Comparator.comparing(Module::name))
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   143
           .forEach(m -> System.out.println(m));
16550
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
   144
    }
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
   145
}