Path: blob/master/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/Profile.java
41161 views
/*1* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.sun.tools.jdeps;2627import java.io.IOException;28import java.lang.module.ModuleDescriptor;29import java.util.Arrays;30import java.util.Comparator;31import java.util.HashMap;32import java.util.HashSet;33import java.util.Map;34import java.util.Set;3536/**37* Build the profile information.38*/39enum Profile {40COMPACT1("compact1", 1, "java.logging",41"java.scripting"),42COMPACT2("compact2", 2, "java.rmi",43"java.sql",44"java.xml",45"jdk.xml.dom",46"jdk.httpserver"),47COMPACT3("compact3", 3, "java.smartcardio",48"java.compiler",49"java.instrument",50"java.management",51"java.naming",52"java.prefs",53"java.security.jgss",54"java.security.sasl",55"java.sql.rowset",56"java.xml.crypto",57"jdk.management",58"jdk.naming.dns",59"jdk.naming.rmi",60"jdk.sctp",61"jdk.security.auth");6263final String name;64final int profile;65final String[] mnames;66final Map<String, Module> modules = new HashMap<>();6768Profile(String name, int profile, String... mnames) {69this.name = name;70this.profile = profile;71this.mnames = mnames;72}7374public String profileName() {75return name;76}7778@Override79public String toString() {80return mnames[0];81}8283public static int getProfileCount() {84return JDK.isEmpty() ? 0 : Profile.values().length;85}8687/**88* Returns the Profile for the given package name; null if not found.89*/90public static Profile getProfile(String pn) {91for (Profile p : Profile.values()) {92for (Module m : p.modules.values()) {93if (m.packages().contains(pn)) {94return p;95}96}97}98return null;99}100101/*102* Returns the Profile for a given Module; null if not found.103*/104public static Profile getProfile(Module m) {105for (Profile p : Profile.values()) {106if (p.modules.containsValue(m)) {107return p;108}109}110return null;111}112113private final static Set<Module> JDK = new HashSet<>();114static synchronized void init(Map<String, Module> systemModules) {115Arrays.stream(Profile.values()).forEach(p ->116// this includes platform-dependent module that may not exist117Arrays.stream(p.mnames)118.filter(systemModules::containsKey)119.map(systemModules::get)120.forEach(m -> p.addModule(systemModules, m)));121122// JDK modules should include full JRE plus other jdk.* modules123// Just include all installed modules. Assume jdeps is running124// in JDK image125JDK.addAll(systemModules.values());126}127128private void addModule(Map<String, Module> systemModules, Module module) {129modules.put(module.name(), module);130module.descriptor().requires().stream()131.map(ModuleDescriptor.Requires::name)132.map(systemModules::get)133.forEach(m -> modules.put(m.name(), m));134}135136// for debugging137public static void main(String[] args) throws IOException {138// initialize Profiles139new JdepsConfiguration.Builder().addmods(Set.of("ALL-SYSTEM")).build();140141// find platform modules142if (Profile.getProfileCount() == 0) {143System.err.println("No profile is present in this JDK");144}145for (Profile p : Profile.values()) {146String profileName = p.name;147System.out.format("%2d: %-10s %s%n", p.profile, profileName, p.modules);148}149System.out.println("All JDK modules:-");150JDK.stream().sorted(Comparator.comparing(Module::name))151.forEach(System.out::println);152}153}154155156