author | attila |
Wed, 01 Oct 2014 10:26:25 +0200 | |
changeset 26888 | 2722a9c501a5 |
parent 25874 | 83c19f00452c |
child 27579 | d1a63c99cdd5 |
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 |
/** |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
31 |
* Build the profile information from ct.sym if exists. |
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"), |
|
36 |
COMPACT3("compact3", 3, "java.compact3"), |
|
37 |
FULL_JRE("Full JRE", 4, "java.se"); |
|
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
38 |
|
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
39 |
final String name; |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
40 |
final int profile; |
25874 | 41 |
final String moduleName; |
42 |
final Set<Module> modules = new HashSet<>(); |
|
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
43 |
|
25874 | 44 |
Profile(String name, int profile, String moduleName) { |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
45 |
this.name = name; |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
46 |
this.profile = profile; |
25874 | 47 |
this.moduleName = moduleName; |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
48 |
} |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
49 |
|
25442
755ff386d1ac
8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents:
21503
diff
changeset
|
50 |
public String profileName() { |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
51 |
return name; |
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
52 |
} |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
53 |
|
25874 | 54 |
@Override |
55 |
public String toString() { |
|
56 |
return moduleName; |
|
57 |
} |
|
58 |
||
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
59 |
public static int getProfileCount() { |
25874 | 60 |
return JDK.isEmpty() ? 0 : Profile.values().length; |
21046
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
61 |
} |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
62 |
|
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
63 |
/** |
25874 | 64 |
* 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
|
65 |
*/ |
ebf16a1a6328
8015912: jdeps support to output in dot file format
mchung
parents:
16550
diff
changeset
|
66 |
public static Profile getProfile(String pn) { |
25874 | 67 |
for (Profile p : Profile.values()) { |
68 |
for (Module m : p.modules) { |
|
69 |
if (m.packages().contains(pn)) { |
|
70 |
return p; |
|
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 |
} |
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
73 |
} |
25874 | 74 |
return null; |
75 |
} |
|
76 |
||
77 |
/* |
|
78 |
* Returns the Profile for a given Module; null if not found. |
|
79 |
*/ |
|
80 |
public static Profile getProfile(Module m) { |
|
81 |
for (Profile p : Profile.values()) { |
|
82 |
if (p.modules.contains(m)) { |
|
83 |
return p; |
|
84 |
} |
|
85 |
} |
|
86 |
return null; |
|
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
87 |
} |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
88 |
|
25874 | 89 |
final static Set<Module> JDK = new HashSet<>(); |
90 |
static void initProfiles() { |
|
91 |
for (Profile p : Profile.values()) { |
|
92 |
Module m = PlatformClassPath.findModule(p.moduleName); |
|
93 |
if (m == null) |
|
94 |
throw new Error(p.moduleName + " doesn't exist"); |
|
95 |
p.modules.add(m); |
|
96 |
JDK.add(m); |
|
97 |
for (String n : m.requires().keySet()) { |
|
98 |
Module d = PlatformClassPath.findModule(n); |
|
99 |
if (d == null) |
|
100 |
throw new Error(n + " doesn't exist"); |
|
101 |
p.modules.add(d); |
|
102 |
JDK.add(d); |
|
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
103 |
} |
25874 | 104 |
} |
105 |
} |
|
106 |
// for debugging |
|
107 |
public static void main(String[] args) throws IOException { |
|
108 |
// find platform modules |
|
109 |
PlatformClassPath.getArchives(null); |
|
110 |
if (Profile.getProfileCount() == 0) { |
|
111 |
System.err.println("No profile is present in this JDK"); |
|
112 |
} |
|
113 |
for (Profile p : Profile.values()) { |
|
114 |
String profileName = p.name; |
|
115 |
System.out.format("%2d: %-10s %s%n", p.profile, profileName, p.modules); |
|
116 |
for (Module m: p.modules) { |
|
117 |
System.out.format("module %s%n", m.name()); |
|
118 |
System.out.format(" requires %s%n", m.requires()); |
|
119 |
for (Map.Entry<String,Set<String>> e: m.exports().entrySet()) { |
|
120 |
System.out.format(" exports %s %s%n", e.getKey(), |
|
121 |
e.getValue().isEmpty() ? "" : "to " + e.getValue()); |
|
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
122 |
} |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
123 |
} |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
124 |
} |
25874 | 125 |
System.out.println("All JDK modules:-"); |
126 |
JDK.stream().sorted(Comparator.comparing(Module::name)) |
|
127 |
.forEach(m -> System.out.println(m)); |
|
16550
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
128 |
} |
f20e2521f3df
8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff
changeset
|
129 |
} |