Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/Profile.java
41161 views
1
/*
2
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
package com.sun.tools.jdeps;
27
28
import java.io.IOException;
29
import java.lang.module.ModuleDescriptor;
30
import java.util.Arrays;
31
import java.util.Comparator;
32
import java.util.HashMap;
33
import java.util.HashSet;
34
import java.util.Map;
35
import java.util.Set;
36
37
/**
38
* Build the profile information.
39
*/
40
enum Profile {
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");
63
64
final String name;
65
final int profile;
66
final String[] mnames;
67
final Map<String, Module> modules = new HashMap<>();
68
69
Profile(String name, int profile, String... mnames) {
70
this.name = name;
71
this.profile = profile;
72
this.mnames = mnames;
73
}
74
75
public String profileName() {
76
return name;
77
}
78
79
@Override
80
public String toString() {
81
return mnames[0];
82
}
83
84
public static int getProfileCount() {
85
return JDK.isEmpty() ? 0 : Profile.values().length;
86
}
87
88
/**
89
* Returns the Profile for the given package name; null if not found.
90
*/
91
public static Profile getProfile(String pn) {
92
for (Profile p : Profile.values()) {
93
for (Module m : p.modules.values()) {
94
if (m.packages().contains(pn)) {
95
return p;
96
}
97
}
98
}
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()) {
107
if (p.modules.containsValue(m)) {
108
return p;
109
}
110
}
111
return null;
112
}
113
114
private final static Set<Module> JDK = new HashSet<>();
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)));
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
126
JDK.addAll(systemModules.values());
127
}
128
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));
135
}
136
137
// for debugging
138
public static void main(String[] args) throws IOException {
139
// initialize Profiles
140
new JdepsConfiguration.Builder().addmods(Set.of("ALL-SYSTEM")).build();
141
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);
149
}
150
System.out.println("All JDK modules:-");
151
JDK.stream().sorted(Comparator.comparing(Module::name))
152
.forEach(System.out::println);
153
}
154
}
155
156