author | martin |
Thu, 30 Oct 2014 07:31:41 -0700 | |
changeset 28059 | e576535359cc |
parent 27579 | d1a63c99cdd5 |
child 30407 | 74a552051c9f |
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", |
|
38 |
"jdk.naming.dns", "jdk.naming.rmi"), |
|
39 |
FULL_JRE("Full JRE", 4, "java.se", "jdk.deploy.osx", "jdk.charsets", |
|
40 |
"jdk.crypto.ec", "jdk.crypto.pkcs11", |
|
41 |
"jdk.crypto.mscapi", "jdk.crypto.ucrypto", "jdk.jvmstat", |
|
42 |
"jdk.localedata", "jdk.scripting.nashorn", "jdk.zipfs"); |
|
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
43 |
|
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
44 |
final String name; |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
45 |
final int profile; |
27579 | 46 |
final String[] mnames; |
25874 | 47 |
final Set<Module> modules = new HashSet<>(); |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
48 |
|
27579 | 49 |
Profile(String name, int profile, String... mnames) { |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
50 |
this.name = name; |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
51 |
this.profile = profile; |
27579 | 52 |
this.mnames = mnames; |
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 |
|
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
21503
diff
changeset
|
55 |
public String profileName() { |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
56 |
return name; |
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
57 |
} |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
58 |
|
25874 | 59 |
@Override |
60 |
public String toString() { |
|
27579 | 61 |
return mnames[0]; |
25874 | 62 |
} |
63 |
||
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
64 |
public static int getProfileCount() { |
25874 | 65 |
return JDK.isEmpty() ? 0 : Profile.values().length; |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
66 |
} |
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 |
/** |
25874 | 69 |
* 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
|
70 |
*/ |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
71 |
public static Profile getProfile(String pn) { |
25874 | 72 |
for (Profile p : Profile.values()) { |
73 |
for (Module m : p.modules) { |
|
74 |
if (m.packages().contains(pn)) { |
|
75 |
return p; |
|
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 |
} |
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
78 |
} |
25874 | 79 |
return null; |
80 |
} |
|
81 |
||
82 |
/* |
|
83 |
* Returns the Profile for a given Module; null if not found. |
|
84 |
*/ |
|
85 |
public static Profile getProfile(Module m) { |
|
86 |
for (Profile p : Profile.values()) { |
|
87 |
if (p.modules.contains(m)) { |
|
88 |
return p; |
|
89 |
} |
|
90 |
} |
|
91 |
return null; |
|
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
92 |
} |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
93 |
|
27579 | 94 |
private final static Set<Module> JDK = new HashSet<>(); |
95 |
static void initProfiles(List<Archive> modules) { |
|
96 |
// add all modules into JDK |
|
97 |
modules.forEach(m -> JDK.add((Module)m)); |
|
98 |
||
25874 | 99 |
for (Profile p : Profile.values()) { |
27579 | 100 |
for (String mn : p.mnames) { |
101 |
// this includes platform-dependent module that may not exist |
|
102 |
Module m = PlatformClassPath.findModule(mn); |
|
103 |
if (m != null) { |
|
104 |
p.addModule(m); |
|
105 |
} |
|
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
106 |
} |
25874 | 107 |
} |
108 |
} |
|
27579 | 109 |
|
110 |
private void addModule(Module m) { |
|
111 |
modules.add(m); |
|
112 |
for (String n : m.requires().keySet()) { |
|
113 |
Module d = PlatformClassPath.findModule(n); |
|
114 |
if (d == null) { |
|
115 |
throw new InternalError("module " + n + " required by " + |
|
116 |
m.name() + " doesn't exist"); |
|
117 |
} |
|
118 |
modules.add(d); |
|
119 |
} |
|
120 |
} |
|
25874 | 121 |
// for debugging |
122 |
public static void main(String[] args) throws IOException { |
|
123 |
// find platform modules |
|
27579 | 124 |
PlatformClassPath.getModules(null); |
25874 | 125 |
if (Profile.getProfileCount() == 0) { |
126 |
System.err.println("No profile is present in this JDK"); |
|
127 |
} |
|
128 |
for (Profile p : Profile.values()) { |
|
129 |
String profileName = p.name; |
|
130 |
System.out.format("%2d: %-10s %s%n", p.profile, profileName, p.modules); |
|
131 |
for (Module m: p.modules) { |
|
132 |
System.out.format("module %s%n", m.name()); |
|
133 |
System.out.format(" requires %s%n", m.requires()); |
|
134 |
for (Map.Entry<String,Set<String>> e: m.exports().entrySet()) { |
|
135 |
System.out.format(" exports %s %s%n", e.getKey(), |
|
136 |
e.getValue().isEmpty() ? "" : "to " + e.getValue()); |
|
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
137 |
} |
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 |
} |
25874 | 140 |
System.out.println("All JDK modules:-"); |
141 |
JDK.stream().sorted(Comparator.comparing(Module::name)) |
|
142 |
.forEach(m -> System.out.println(m)); |
|
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
143 |
} |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
144 |
} |