author | alanb |
Thu, 17 Mar 2016 19:04:28 +0000 | |
changeset 36526 | 3b41f1c69604 |
parent 36493 | 1e87cd35c980 |
child 38524 | badd925c1d2f |
permissions | -rw-r--r-- |
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
1 |
/* |
36526 | 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 | 29 |
import java.util.Comparator; |
30 |
import java.util.HashSet; |
|
31 |
import java.util.Map; |
|
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 | 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 | 38 |
COMPACT1("compact1", 1, "java.compact1"), |
39 |
COMPACT2("compact2", 2, "java.compact2"), |
|
27579 | 40 |
COMPACT3("compact3", 3, "java.compact3", "java.smartcardio", "jdk.sctp", |
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 | 44 |
// need a way to determine JRE modules |
45 |
SE_JRE("Java SE JRE", 4, "java.se", "jdk.charsets", |
|
46 |
"jdk.crypto.ec", "jdk.crypto.pkcs11", |
|
47 |
"jdk.crypto.mscapi", "jdk.crypto.ucrypto", "jdk.jvmstat", |
|
48 |
"jdk.localedata", "jdk.scripting.nashorn", "jdk.zipfs"), |
|
49 |
FULL_JRE("Full JRE", 5, "java.se.ee", "jdk.charsets", |
|
27579 | 50 |
"jdk.crypto.ec", "jdk.crypto.pkcs11", |
51 |
"jdk.crypto.mscapi", "jdk.crypto.ucrypto", "jdk.jvmstat", |
|
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 | 56 |
final String[] mnames; |
25874 | 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 | 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 | 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 | 69 |
@Override |
70 |
public String toString() { |
|
27579 | 71 |
return mnames[0]; |
25874 | 72 |
} |
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 | 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 | 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 | 82 |
for (Profile p : Profile.values()) { |
83 |
for (Module m : p.modules) { |
|
84 |
if (m.packages().contains(pn)) { |
|
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 | 89 |
return null; |
90 |
} |
|
91 |
||
92 |
/* |
|
93 |
* Returns the Profile for a given Module; null if not found. |
|
94 |
*/ |
|
95 |
public static Profile getProfile(Module m) { |
|
96 |
for (Profile p : Profile.values()) { |
|
97 |
if (p.modules.contains(m)) { |
|
98 |
return p; |
|
99 |
} |
|
100 |
} |
|
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 | 104 |
private final static Set<Module> JDK = new HashSet<>(); |
36526 | 105 |
static synchronized void init(Map<String, Module> installed) { |
25874 | 106 |
for (Profile p : Profile.values()) { |
27579 | 107 |
for (String mn : p.mnames) { |
108 |
// this includes platform-dependent module that may not exist |
|
36526 | 109 |
Module m = installed.get(mn); |
27579 | 110 |
if (m != null) { |
36526 | 111 |
p.addModule(installed, m); |
27579 | 112 |
} |
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
113 |
} |
25874 | 114 |
} |
36526 | 115 |
|
116 |
// JDK modules should include full JRE plus other jdk.* modules |
|
117 |
// Just include all installed modules. Assume jdeps is running |
|
118 |
// in JDK image |
|
119 |
JDK.addAll(installed.values()); |
|
25874 | 120 |
} |
27579 | 121 |
|
36526 | 122 |
private void addModule(Map<String, Module> installed, Module m) { |
27579 | 123 |
modules.add(m); |
124 |
for (String n : m.requires().keySet()) { |
|
36526 | 125 |
Module d = installed.get(n); |
27579 | 126 |
if (d == null) { |
127 |
throw new InternalError("module " + n + " required by " + |
|
128 |
m.name() + " doesn't exist"); |
|
129 |
} |
|
130 |
modules.add(d); |
|
131 |
} |
|
132 |
} |
|
25874 | 133 |
// for debugging |
134 |
public static void main(String[] args) throws IOException { |
|
135 |
// find platform modules |
|
136 |
if (Profile.getProfileCount() == 0) { |
|
137 |
System.err.println("No profile is present in this JDK"); |
|
138 |
} |
|
139 |
for (Profile p : Profile.values()) { |
|
140 |
String profileName = p.name; |
|
141 |
System.out.format("%2d: %-10s %s%n", p.profile, profileName, p.modules); |
|
142 |
for (Module m: p.modules) { |
|
143 |
System.out.format("module %s%n", m.name()); |
|
144 |
System.out.format(" requires %s%n", m.requires()); |
|
145 |
for (Map.Entry<String,Set<String>> e: m.exports().entrySet()) { |
|
146 |
System.out.format(" exports %s %s%n", e.getKey(), |
|
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 | 151 |
System.out.println("All JDK modules:-"); |
152 |
JDK.stream().sorted(Comparator.comparing(Module::name)) |
|
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 |
} |