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-- |
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 | 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 | 34 |
COMPACT1("compact1", 1, "java.compact1"), |
35 |
COMPACT2("compact2", 2, "java.compact2"), |
|
27579 | 36 |
COMPACT3("compact3", 3, "java.compact3", "java.smartcardio", "jdk.sctp", |
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 | 40 |
FULL_JRE("Full JRE", 4, "java.se", "jdk.deploy.osx", "jdk.charsets", |
41 |
"jdk.crypto.ec", "jdk.crypto.pkcs11", |
|
42 |
"jdk.crypto.mscapi", "jdk.crypto.ucrypto", "jdk.jvmstat", |
|
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 | 47 |
final String[] mnames; |
25874 | 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 | 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 | 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 | 60 |
@Override |
61 |
public String toString() { |
|
27579 | 62 |
return mnames[0]; |
25874 | 63 |
} |
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 | 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 | 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 | 73 |
for (Profile p : Profile.values()) { |
74 |
for (Module m : p.modules) { |
|
75 |
if (m.packages().contains(pn)) { |
|
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 | 80 |
return null; |
81 |
} |
|
82 |
||
83 |
/* |
|
84 |
* Returns the Profile for a given Module; null if not found. |
|
85 |
*/ |
|
86 |
public static Profile getProfile(Module m) { |
|
87 |
for (Profile p : Profile.values()) { |
|
88 |
if (p.modules.contains(m)) { |
|
89 |
return p; |
|
90 |
} |
|
91 |
} |
|
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 | 95 |
private final static Set<Module> JDK = new HashSet<>(); |
96 |
static void initProfiles(List<Archive> modules) { |
|
97 |
// add all modules into JDK |
|
98 |
modules.forEach(m -> JDK.add((Module)m)); |
|
99 |
||
25874 | 100 |
for (Profile p : Profile.values()) { |
27579 | 101 |
for (String mn : p.mnames) { |
102 |
// this includes platform-dependent module that may not exist |
|
103 |
Module m = PlatformClassPath.findModule(mn); |
|
104 |
if (m != null) { |
|
105 |
p.addModule(m); |
|
106 |
} |
|
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
107 |
} |
25874 | 108 |
} |
109 |
} |
|
27579 | 110 |
|
111 |
private void addModule(Module m) { |
|
112 |
modules.add(m); |
|
113 |
for (String n : m.requires().keySet()) { |
|
114 |
Module d = PlatformClassPath.findModule(n); |
|
115 |
if (d == null) { |
|
116 |
throw new InternalError("module " + n + " required by " + |
|
117 |
m.name() + " doesn't exist"); |
|
118 |
} |
|
119 |
modules.add(d); |
|
120 |
} |
|
121 |
} |
|
25874 | 122 |
// for debugging |
123 |
public static void main(String[] args) throws IOException { |
|
124 |
// find platform modules |
|
27579 | 125 |
PlatformClassPath.getModules(null); |
25874 | 126 |
if (Profile.getProfileCount() == 0) { |
127 |
System.err.println("No profile is present in this JDK"); |
|
128 |
} |
|
129 |
for (Profile p : Profile.values()) { |
|
130 |
String profileName = p.name; |
|
131 |
System.out.format("%2d: %-10s %s%n", p.profile, profileName, p.modules); |
|
132 |
for (Module m: p.modules) { |
|
133 |
System.out.format("module %s%n", m.name()); |
|
134 |
System.out.format(" requires %s%n", m.requires()); |
|
135 |
for (Map.Entry<String,Set<String>> e: m.exports().entrySet()) { |
|
136 |
System.out.format(" exports %s %s%n", e.getKey(), |
|
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 | 141 |
System.out.println("All JDK modules:-"); |
142 |
JDK.stream().sorted(Comparator.comparing(Module::name)) |
|
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 |
} |