author | mcimadamore |
Fri, 16 Dec 2016 15:27:34 +0000 | |
changeset 42827 | 36468b5fa7f4 |
parent 42817 | 6545638adc59 |
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; |
38524 | 29 |
import java.lang.module.ModuleDescriptor; |
30 |
import java.util.Arrays; |
|
36526 | 31 |
import java.util.Comparator; |
38524 | 32 |
import java.util.HashMap; |
36526 | 33 |
import java.util.HashSet; |
34 |
import java.util.Map; |
|
38524 | 35 |
import java.util.Optional; |
36526 | 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 | 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 | 42 |
COMPACT1("compact1", 1, "java.logging", |
43 |
"java.scripting"), |
|
44 |
COMPACT2("compact2", 2, "java.rmi", |
|
45 |
"java.sql", |
|
46 |
"java.xml", |
|
47 |
"jdk.xml.dom", |
|
48 |
"jdk.httpserver"), |
|
49 |
COMPACT3("compact3", 3, "java.smartcardio", |
|
50 |
"java.compiler", |
|
51 |
"java.instrument", |
|
52 |
"java.management", |
|
53 |
"java.naming", |
|
54 |
"java.prefs", |
|
55 |
"java.security.jgss", |
|
56 |
"java.security.sasl", |
|
57 |
"java.sql.rowset", |
|
58 |
"java.xml.crypto", |
|
59 |
"jdk.management", |
|
60 |
"jdk.naming.dns", |
|
61 |
"jdk.naming.rmi", |
|
62 |
"jdk.sctp", |
|
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 | 67 |
final String[] mnames; |
38524 | 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 | 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 | 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 | 80 |
@Override |
81 |
public String toString() { |
|
27579 | 82 |
return mnames[0]; |
25874 | 83 |
} |
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 | 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 | 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 | 93 |
for (Profile p : Profile.values()) { |
38524 | 94 |
for (Module m : p.modules.values()) { |
25874 | 95 |
if (m.packages().contains(pn)) { |
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 | 100 |
return null; |
101 |
} |
|
102 |
||
103 |
/* |
|
104 |
* Returns the Profile for a given Module; null if not found. |
|
105 |
*/ |
|
106 |
public static Profile getProfile(Module m) { |
|
107 |
for (Profile p : Profile.values()) { |
|
38524 | 108 |
if (p.modules.containsValue(m)) { |
25874 | 109 |
return p; |
110 |
} |
|
111 |
} |
|
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 | 115 |
private final static Set<Module> JDK = new HashSet<>(); |
38524 | 116 |
static synchronized void init(Map<String, Module> systemModules) { |
117 |
Arrays.stream(Profile.values()).forEach(p -> |
|
118 |
// this includes platform-dependent module that may not exist |
|
119 |
Arrays.stream(p.mnames) |
|
120 |
.filter(systemModules::containsKey) |
|
121 |
.map(systemModules::get) |
|
122 |
.forEach(m -> p.addModule(systemModules, m))); |
|
36526 | 123 |
|
124 |
// JDK modules should include full JRE plus other jdk.* modules |
|
125 |
// Just include all installed modules. Assume jdeps is running |
|
126 |
// in JDK image |
|
38524 | 127 |
JDK.addAll(systemModules.values()); |
25874 | 128 |
} |
27579 | 129 |
|
38524 | 130 |
private void addModule(Map<String, Module> systemModules, Module module) { |
131 |
modules.put(module.name(), module); |
|
132 |
module.descriptor().requires().stream() |
|
133 |
.map(ModuleDescriptor.Requires::name) |
|
134 |
.map(systemModules::get) |
|
135 |
.forEach(m -> modules.put(m.name(), m)); |
|
27579 | 136 |
} |
38524 | 137 |
|
25874 | 138 |
// for debugging |
139 |
public static void main(String[] args) throws IOException { |
|
42817 | 140 |
// initialize Profiles |
141 |
new JdepsConfiguration.Builder().allModules().build(); |
|
142 |
||
25874 | 143 |
// find platform modules |
144 |
if (Profile.getProfileCount() == 0) { |
|
145 |
System.err.println("No profile is present in this JDK"); |
|
146 |
} |
|
147 |
for (Profile p : Profile.values()) { |
|
148 |
String profileName = p.name; |
|
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 | 151 |
System.out.println("All JDK modules:-"); |
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 |
} |