author | serb |
Sat, 09 Jun 2018 13:33:35 -0700 | |
changeset 50647 | a98ff7c2103d |
parent 48253 | 82767203606e |
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; |
|
35 |
import java.util.Set; |
|
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
36 |
|
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
37 |
/** |
27579 | 38 |
* Build the profile information. |
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
39 |
*/ |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
40 |
enum Profile { |
42817 | 41 |
COMPACT1("compact1", 1, "java.logging", |
42 |
"java.scripting"), |
|
43 |
COMPACT2("compact2", 2, "java.rmi", |
|
44 |
"java.sql", |
|
45 |
"java.xml", |
|
46 |
"jdk.xml.dom", |
|
47 |
"jdk.httpserver"), |
|
48 |
COMPACT3("compact3", 3, "java.smartcardio", |
|
49 |
"java.compiler", |
|
50 |
"java.instrument", |
|
51 |
"java.management", |
|
52 |
"java.naming", |
|
53 |
"java.prefs", |
|
54 |
"java.security.jgss", |
|
55 |
"java.security.sasl", |
|
56 |
"java.sql.rowset", |
|
57 |
"java.xml.crypto", |
|
58 |
"jdk.management", |
|
59 |
"jdk.naming.dns", |
|
60 |
"jdk.naming.rmi", |
|
61 |
"jdk.sctp", |
|
62 |
"jdk.security.auth"); |
|
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 |
final String name; |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
65 |
final int profile; |
27579 | 66 |
final String[] mnames; |
38524 | 67 |
final Map<String, Module> modules = new HashMap<>(); |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
68 |
|
27579 | 69 |
Profile(String name, int profile, String... mnames) { |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
70 |
this.name = name; |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
71 |
this.profile = profile; |
27579 | 72 |
this.mnames = mnames; |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
73 |
} |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
74 |
|
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
21503
diff
changeset
|
75 |
public String profileName() { |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
76 |
return name; |
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
77 |
} |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
78 |
|
25874 | 79 |
@Override |
80 |
public String toString() { |
|
27579 | 81 |
return mnames[0]; |
25874 | 82 |
} |
83 |
||
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
84 |
public static int getProfileCount() { |
25874 | 85 |
return JDK.isEmpty() ? 0 : Profile.values().length; |
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 |
|
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
88 |
/** |
25874 | 89 |
* 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
|
90 |
*/ |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
91 |
public static Profile getProfile(String pn) { |
25874 | 92 |
for (Profile p : Profile.values()) { |
38524 | 93 |
for (Module m : p.modules.values()) { |
25874 | 94 |
if (m.packages().contains(pn)) { |
95 |
return p; |
|
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
96 |
} |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
97 |
} |
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
98 |
} |
25874 | 99 |
return null; |
100 |
} |
|
101 |
||
102 |
/* |
|
103 |
* Returns the Profile for a given Module; null if not found. |
|
104 |
*/ |
|
105 |
public static Profile getProfile(Module m) { |
|
106 |
for (Profile p : Profile.values()) { |
|
38524 | 107 |
if (p.modules.containsValue(m)) { |
25874 | 108 |
return p; |
109 |
} |
|
110 |
} |
|
111 |
return null; |
|
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
112 |
} |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
113 |
|
27579 | 114 |
private final static Set<Module> JDK = new HashSet<>(); |
38524 | 115 |
static synchronized void init(Map<String, Module> systemModules) { |
116 |
Arrays.stream(Profile.values()).forEach(p -> |
|
117 |
// this includes platform-dependent module that may not exist |
|
118 |
Arrays.stream(p.mnames) |
|
119 |
.filter(systemModules::containsKey) |
|
120 |
.map(systemModules::get) |
|
121 |
.forEach(m -> p.addModule(systemModules, m))); |
|
36526 | 122 |
|
123 |
// JDK modules should include full JRE plus other jdk.* modules |
|
124 |
// Just include all installed modules. Assume jdeps is running |
|
125 |
// in JDK image |
|
38524 | 126 |
JDK.addAll(systemModules.values()); |
25874 | 127 |
} |
27579 | 128 |
|
38524 | 129 |
private void addModule(Map<String, Module> systemModules, Module module) { |
130 |
modules.put(module.name(), module); |
|
131 |
module.descriptor().requires().stream() |
|
132 |
.map(ModuleDescriptor.Requires::name) |
|
133 |
.map(systemModules::get) |
|
134 |
.forEach(m -> modules.put(m.name(), m)); |
|
27579 | 135 |
} |
38524 | 136 |
|
25874 | 137 |
// for debugging |
138 |
public static void main(String[] args) throws IOException { |
|
42817 | 139 |
// initialize Profiles |
48253
82767203606e
8193192: jdeps --generate-module-info does not look at module path
mchung
parents:
47216
diff
changeset
|
140 |
new JdepsConfiguration.Builder().addmods(Set.of("ALL-SYSTEM")).build(); |
42817 | 141 |
|
25874 | 142 |
// find platform modules |
143 |
if (Profile.getProfileCount() == 0) { |
|
144 |
System.err.println("No profile is present in this JDK"); |
|
145 |
} |
|
146 |
for (Profile p : Profile.values()) { |
|
147 |
String profileName = p.name; |
|
148 |
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
|
149 |
} |
25874 | 150 |
System.out.println("All JDK modules:-"); |
151 |
JDK.stream().sorted(Comparator.comparing(Module::name)) |
|
42827
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
42817
diff
changeset
|
152 |
.forEach(System.out::println); |
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
153 |
} |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
154 |
} |