feat(jdk8): move files to new folder to avoid resources compiled.

This commit is contained in:
2025-09-07 15:25:52 +08:00
parent 3f0047bf6f
commit 8c35cfb1c0
17415 changed files with 217 additions and 213 deletions

View File

@@ -0,0 +1,520 @@
/*
* Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.javac.sym;
import com.sun.tools.javac.api.JavacTaskImpl;
import com.sun.tools.javac.code.Kinds;
import com.sun.tools.javac.code.Scope;
import com.sun.tools.javac.code.Symbol.*;
import com.sun.tools.javac.code.Symbol;
import com.sun.tools.javac.code.Attribute;
import com.sun.tools.javac.code.Symtab;
import com.sun.tools.javac.code.Type;
import com.sun.tools.javac.code.Types;
import com.sun.tools.javac.jvm.ClassWriter;
import com.sun.tools.javac.jvm.Pool;
import com.sun.tools.javac.processing.JavacProcessingEnvironment;
import com.sun.tools.javac.util.List;
import com.sun.tools.javac.util.Names;
import com.sun.tools.javac.util.Pair;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.Set;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedOptions;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.TypeElement;
import javax.tools.Diagnostic;
import javax.tools.JavaCompiler;
import javax.tools.JavaFileManager.Location;
import javax.tools.JavaFileObject;
import static javax.tools.JavaFileObject.Kind.CLASS;
import javax.tools.StandardJavaFileManager;
import javax.tools.StandardLocation;
import javax.tools.ToolProvider;
/**
* Used to generate a "symbol file" representing rt.jar that only
* includes supported or legacy proprietary API. Valid annotation
* processor options:
*
* <dl>
* <dt>com.sun.tools.javac.sym.Jar</dt>
* <dd>Specifies the location of rt.jar.</dd>
* <dt>com.sun.tools.javac.sym.Dest</dt>
* <dd>Specifies the destination directory.</dd>
* </dl>
*
* <p><b>This is NOT part of any supported API.
* If you write code that depends on this, you do so at your own
* risk. This code and its internal interfaces are subject to change
* or deletion without notice.</b></p>
*
* @author Peter von der Ah\u00e9
*/
@SupportedOptions({
"com.sun.tools.javac.sym.Jar",
"com.sun.tools.javac.sym.Dest",
"com.sun.tools.javac.sym.Profiles"})
@SupportedAnnotationTypes("*")
public class CreateSymbols extends AbstractProcessor {
static Set<String> getLegacyPackages() {
ResourceBundle legacyBundle
= ResourceBundle.getBundle("com.sun.tools.javac.resources.legacy");
Set<String> keys = new HashSet<String>();
for (Enumeration<String> e = legacyBundle.getKeys(); e.hasMoreElements(); )
keys.add(e.nextElement());
return keys;
}
public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv) {
try {
if (renv.processingOver())
createSymbols();
} catch (IOException e) {
CharSequence msg = e.getLocalizedMessage();
if (msg == null)
msg = e.toString();
processingEnv.getMessager()
.printMessage(Diagnostic.Kind.ERROR, msg);
} catch (Throwable t) {
t.printStackTrace();
Throwable cause = t.getCause();
if (cause == null)
cause = t;
CharSequence msg = cause.getLocalizedMessage();
if (msg == null)
msg = cause.toString();
processingEnv.getMessager()
.printMessage(Diagnostic.Kind.ERROR, msg);
}
return true;
}
void createSymbols() throws IOException {
Set<String> legacy = getLegacyPackages();
Set<String> legacyProprietary = getLegacyPackages();
Set<String> documented = new HashSet<String>();
Set<PackageSymbol> packages =
((JavacProcessingEnvironment)processingEnv).getSpecifiedPackages();
Map<String,String> pOptions = processingEnv.getOptions();
String jarName = pOptions.get("com.sun.tools.javac.sym.Jar");
if (jarName == null)
throw new RuntimeException("Must use -Acom.sun.tools.javac.sym.Jar=LOCATION_OF_JAR");
String destName = pOptions.get("com.sun.tools.javac.sym.Dest");
if (destName == null)
throw new RuntimeException("Must use -Acom.sun.tools.javac.sym.Dest=LOCATION_OF_JAR");
String profileSpec=pOptions.get("com.sun.tools.javac.sym.Profiles");
if (profileSpec == null)
throw new RuntimeException("Must use -Acom.sun.tools.javac.sym.Profiles=PROFILES_SPEC");
Profiles profiles = Profiles.read(new File(profileSpec));
for (PackageSymbol psym : packages) {
String name = psym.getQualifiedName().toString();
legacyProprietary.remove(name);
documented.add(name);
}
JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
Location jarLocation = StandardLocation.locationFor(jarName);
File jarFile = new File(jarName);
fm.setLocation(jarLocation, List.of(jarFile));
fm.setLocation(StandardLocation.CLASS_PATH, List.<File>nil());
fm.setLocation(StandardLocation.SOURCE_PATH, List.<File>nil());
{
ArrayList<File> bootClassPath = new ArrayList<File>();
bootClassPath.add(jarFile);
for (File path : fm.getLocation(StandardLocation.PLATFORM_CLASS_PATH)) {
if (!new File(path.getName()).equals(new File("rt.jar")))
bootClassPath.add(path);
}
System.err.println("Using boot class path = " + bootClassPath);
fm.setLocation(StandardLocation.PLATFORM_CLASS_PATH, bootClassPath);
}
// System.out.println(fm.getLocation(StandardLocation.PLATFORM_CLASS_PATH));
File destDir = new File(destName);
if (!destDir.exists())
if (!destDir.mkdirs())
throw new RuntimeException("Could not create " + destDir);
fm.setLocation(StandardLocation.CLASS_OUTPUT, List.of(destDir));
Set<String> hiddenPackages = new HashSet<String>();
Set<String> crisp = new HashSet<String>();
List<String> options = List.of("-XDdev");
// options = options.prepend("-doe");
// options = options.prepend("-verbose");
JavacTaskImpl task = (JavacTaskImpl)
tool.getTask(null, fm, null, options, null, null);
com.sun.tools.javac.main.JavaCompiler compiler =
com.sun.tools.javac.main.JavaCompiler.instance(task.getContext());
ClassWriter writer = ClassWriter.instance(task.getContext());
Symtab syms = Symtab.instance(task.getContext());
Names names = Names.instance(task.getContext());
Attribute.Compound proprietaryAnno =
new Attribute.Compound(syms.proprietaryType,
List.<Pair<Symbol.MethodSymbol,Attribute>>nil());
Attribute.Compound[] profileAnnos = new Attribute.Compound[profiles.getProfileCount() + 1];
Symbol.MethodSymbol profileValue = (MethodSymbol) syms.profileType.tsym.members().lookup(names.value).sym;
for (int i = 1; i < profileAnnos.length; i++) {
profileAnnos[i] = new Attribute.Compound(syms.profileType,
List.<Pair<Symbol.MethodSymbol, Attribute>>of(
new Pair<Symbol.MethodSymbol, Attribute>(profileValue, new Attribute.Constant(syms.intType, i))));
}
Type.moreInfo = true;
Types types = Types.instance(task.getContext());
Pool pool = new Pool(types);
for (JavaFileObject file : fm.list(jarLocation, "", EnumSet.of(CLASS), true)) {
String className = fm.inferBinaryName(jarLocation, file);
int index = className.lastIndexOf('.');
String pckName = index == -1 ? "" : className.substring(0, index);
boolean addLegacyAnnotation = false;
if (documented.contains(pckName)) {
if (!legacy.contains(pckName))
crisp.add(pckName);
// System.out.println("Documented: " + className);
} else if (legacyProprietary.contains(pckName)) {
addLegacyAnnotation = true;
// System.out.println("Legacy proprietary: " + className);
} else {
// System.out.println("Hidden " + className);
hiddenPackages.add(pckName);
continue;
}
TypeSymbol sym = (TypeSymbol)compiler.resolveIdent(className);
if (sym.kind != Kinds.TYP) {
if (className.indexOf('$') < 0) {
System.err.println("Ignoring (other) " + className + " : " + sym);
System.err.println(" " + sym.getClass().getSimpleName() + " " + sym.type);
}
continue;
}
sym.complete();
if (sym.getEnclosingElement().getKind() != ElementKind.PACKAGE) {
System.err.println("Ignoring (bad) " + sym.getQualifiedName());
continue;
}
ClassSymbol cs = (ClassSymbol) sym;
if (addLegacyAnnotation) {
cs.prependAttributes(List.of(proprietaryAnno));
}
int p = profiles.getProfile(cs.fullname.toString().replace(".", "/"));
if (0 < p && p < profileAnnos.length)
cs.prependAttributes(List.of(profileAnnos[p]));
writeClass(pool, cs, writer);
}
if (false) {
for (String pckName : crisp)
System.out.println("Crisp: " + pckName);
for (String pckName : hiddenPackages)
System.out.println("Hidden: " + pckName);
for (String pckName : legacyProprietary)
System.out.println("Legacy proprietary: " + pckName);
for (String pckName : documented)
System.out.println("Documented: " + pckName);
}
}
void writeClass(final Pool pool, final ClassSymbol cs, final ClassWriter writer)
throws IOException
{
try {
pool.reset();
cs.pool = pool;
writer.writeClass(cs);
for (Scope.Entry e = cs.members().elems; e != null; e = e.sibling) {
if (e.sym.kind == Kinds.TYP) {
ClassSymbol nestedClass = (ClassSymbol)e.sym;
nestedClass.complete();
writeClass(pool, nestedClass, writer);
}
}
} catch (ClassWriter.StringOverflow ex) {
throw new RuntimeException(ex);
} catch (ClassWriter.PoolOverflow ex) {
throw new RuntimeException(ex);
}
}
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
// used for debugging
public static void main(String... args) {
String rt_jar = args[0];
String dest = args[1];
args = new String[] {
"-Xbootclasspath:" + rt_jar,
"-XDprocess.packages",
"-proc:only",
"-processor",
"com.sun.tools.javac.sym.CreateSymbols",
"-Acom.sun.tools.javac.sym.Jar=" + rt_jar,
"-Acom.sun.tools.javac.sym.Dest=" + dest,
// <editor-fold defaultstate="collapsed">
"java.applet",
"java.awt",
"java.awt.color",
"java.awt.datatransfer",
"java.awt.dnd",
"java.awt.event",
"java.awt.font",
"java.awt.geom",
"java.awt.im",
"java.awt.im.spi",
"java.awt.image",
"java.awt.image.renderable",
"java.awt.print",
"java.beans",
"java.beans.beancontext",
"java.io",
"java.lang",
"java.lang.annotation",
"java.lang.instrument",
"java.lang.management",
"java.lang.ref",
"java.lang.reflect",
"java.math",
"java.net",
"java.nio",
"java.nio.channels",
"java.nio.channels.spi",
"java.nio.charset",
"java.nio.charset.spi",
"java.rmi",
"java.rmi.activation",
"java.rmi.dgc",
"java.rmi.registry",
"java.rmi.server",
"java.security",
"java.security.acl",
"java.security.cert",
"java.security.interfaces",
"java.security.spec",
"java.sql",
"java.text",
"java.text.spi",
"java.util",
"java.util.concurrent",
"java.util.concurrent.atomic",
"java.util.concurrent.locks",
"java.util.jar",
"java.util.logging",
"java.util.prefs",
"java.util.regex",
"java.util.spi",
"java.util.zip",
"javax.accessibility",
"javax.activation",
"javax.activity",
"javax.annotation",
"javax.annotation.processing",
"javax.crypto",
"javax.crypto.interfaces",
"javax.crypto.spec",
"javax.imageio",
"javax.imageio.event",
"javax.imageio.metadata",
"javax.imageio.plugins.jpeg",
"javax.imageio.plugins.bmp",
"javax.imageio.spi",
"javax.imageio.stream",
"javax.jws",
"javax.jws.soap",
"javax.lang.model",
"javax.lang.model.element",
"javax.lang.model.type",
"javax.lang.model.util",
"javax.management",
"javax.management.loading",
"javax.management.monitor",
"javax.management.relation",
"javax.management.openmbean",
"javax.management.timer",
"javax.management.modelmbean",
"javax.management.remote",
"javax.management.remote.rmi",
"javax.naming",
"javax.naming.directory",
"javax.naming.event",
"javax.naming.ldap",
"javax.naming.spi",
"javax.net",
"javax.net.ssl",
"javax.print",
"javax.print.attribute",
"javax.print.attribute.standard",
"javax.print.event",
"javax.rmi",
"javax.rmi.CORBA",
"javax.rmi.ssl",
"javax.script",
"javax.security.auth",
"javax.security.auth.callback",
"javax.security.auth.kerberos",
"javax.security.auth.login",
"javax.security.auth.spi",
"javax.security.auth.x500",
"javax.security.cert",
"javax.security.sasl",
"javax.sound.sampled",
"javax.sound.sampled.spi",
"javax.sound.midi",
"javax.sound.midi.spi",
"javax.sql",
"javax.sql.rowset",
"javax.sql.rowset.serial",
"javax.sql.rowset.spi",
"javax.swing",
"javax.swing.border",
"javax.swing.colorchooser",
"javax.swing.filechooser",
"javax.swing.event",
"javax.swing.table",
"javax.swing.text",
"javax.swing.text.html",
"javax.swing.text.html.parser",
"javax.swing.text.rtf",
"javax.swing.tree",
"javax.swing.undo",
"javax.swing.plaf",
"javax.swing.plaf.basic",
"javax.swing.plaf.metal",
"javax.swing.plaf.multi",
"javax.swing.plaf.synth",
"javax.tools",
"javax.transaction",
"javax.transaction.xa",
"javax.xml.parsers",
"javax.xml.bind",
"javax.xml.bind.annotation",
"javax.xml.bind.annotation.adapters",
"javax.xml.bind.attachment",
"javax.xml.bind.helpers",
"javax.xml.bind.util",
"javax.xml.soap",
"javax.xml.ws",
"javax.xml.ws.handler",
"javax.xml.ws.handler.soap",
"javax.xml.ws.http",
"javax.xml.ws.soap",
"javax.xml.ws.spi",
"javax.xml.transform",
"javax.xml.transform.sax",
"javax.xml.transform.dom",
"javax.xml.transform.stax",
"javax.xml.transform.stream",
"javax.xml",
"javax.xml.crypto",
"javax.xml.crypto.dom",
"javax.xml.crypto.dsig",
"javax.xml.crypto.dsig.dom",
"javax.xml.crypto.dsig.keyinfo",
"javax.xml.crypto.dsig.spec",
"javax.xml.datatype",
"javax.xml.validation",
"javax.xml.namespace",
"javax.xml.xpath",
"javax.xml.stream",
"javax.xml.stream.events",
"javax.xml.stream.util",
"org.ietf.jgss",
"org.omg.CORBA",
"org.omg.CORBA.DynAnyPackage",
"org.omg.CORBA.ORBPackage",
"org.omg.CORBA.TypeCodePackage",
"org.omg.stub.java.rmi",
"org.omg.CORBA.portable",
"org.omg.CORBA_2_3",
"org.omg.CORBA_2_3.portable",
"org.omg.CosNaming",
"org.omg.CosNaming.NamingContextExtPackage",
"org.omg.CosNaming.NamingContextPackage",
"org.omg.SendingContext",
"org.omg.PortableServer",
"org.omg.PortableServer.CurrentPackage",
"org.omg.PortableServer.POAPackage",
"org.omg.PortableServer.POAManagerPackage",
"org.omg.PortableServer.ServantLocatorPackage",
"org.omg.PortableServer.portable",
"org.omg.PortableInterceptor",
"org.omg.PortableInterceptor.ORBInitInfoPackage",
"org.omg.Messaging",
"org.omg.IOP",
"org.omg.IOP.CodecFactoryPackage",
"org.omg.IOP.CodecPackage",
"org.omg.Dynamic",
"org.omg.DynamicAny",
"org.omg.DynamicAny.DynAnyPackage",
"org.omg.DynamicAny.DynAnyFactoryPackage",
"org.w3c.dom",
"org.w3c.dom.events",
"org.w3c.dom.bootstrap",
"org.w3c.dom.ls",
"org.xml.sax",
"org.xml.sax.ext",
"org.xml.sax.helpers",
"com.sun.java.browser.dom",
"org.w3c.dom",
"org.w3c.dom.bootstrap",
"org.w3c.dom.ls",
"org.w3c.dom.ranges",
"org.w3c.dom.traversal",
"org.w3c.dom.html",
"org.w3c.dom.stylesheets",
"org.w3c.dom.css",
"org.w3c.dom.events",
"org.w3c.dom.views",
"com.sun.jndi.ldap.spi",
"com.sun.management",
"com.sun.security.auth",
"com.sun.security.auth.callback",
"com.sun.security.auth.login",
"com.sun.security.auth.module",
"com.sun.security.jgss",
"com.sun.net.httpserver",
"com.sun.net.httpserver.spi",
"javax.smartcardio"
// </editor-fold>
};
com.sun.tools.javac.Main.compile(args);
}
}

View File

@@ -0,0 +1,310 @@
/*
* Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.javac.sym;
import java.io.BufferedInputStream;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import com.sun.tools.javac.util.Assert;
/**
* Provide details about profile contents.
*
* <p><b>This is NOT part of any supported API.
* If you write code that depends on this, you do so at your own
* risk. This code and its internal interfaces are subject to change
* or deletion without notice.</b></p>
*/
public abstract class Profiles {
// for debugging
public static void main(String[] args) throws IOException {
Profiles p = Profiles.read(new File(args[0]));
if (args.length >= 2) {
Map<Integer,Set<String>> lists = new TreeMap<Integer,Set<String>>();
for (int i = 1; i <= 4; i++)
lists.put(i, new TreeSet<String>());
File rt_jar_lst = new File(args[1]);
for (String line: Files.readAllLines(rt_jar_lst.toPath(), Charset.defaultCharset())) {
if (line.endsWith(".class")) {
String type = line.substring(0, line.length() - 6);
int profile = p.getProfile(type);
for (int i = profile; i <= 4; i++)
lists.get(i).add(type);
}
}
for (int i = 1; i <= 4; i++) {
BufferedWriter out = new BufferedWriter(new FileWriter(i + ".txt"));
try {
for (String type: lists.get(i)) {
out.write(type);
out.newLine();
}
} finally {
out.close();
}
}
}
}
public static Profiles read(File file) throws IOException {
BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));
try {
Properties p = new Properties();
p.load(in);
if (p.containsKey("java/lang/Object"))
return new SimpleProfiles(p);
else
return new MakefileProfiles(p);
} finally {
in.close();
}
}
public abstract int getProfileCount();
public abstract int getProfile(String typeName);
public abstract Set<String> getPackages(int profile);
private static class MakefileProfiles extends Profiles {
static class Package {
final Package parent;
final String name;
Map<String, Package> subpackages = new TreeMap<String, Package>();
int profile;
Map<String, Integer> includedTypes = new TreeMap<String,Integer>();
Map<String, Integer> excludedTypes = new TreeMap<String,Integer>();
Package(Package parent, String name) {
this.parent = parent;
this.name = name;
}
int getProfile() {
return (parent == null) ? profile : Math.max(parent.getProfile(), profile);
}
int getProfile(String simpleTypeName) {
Integer i;
if ((i = includedTypes.get(simpleTypeName)) != null)
return i;
if ((i = includedTypes.get("*")) != null)
return i;
if ((i = excludedTypes.get(simpleTypeName)) != null)
return i + 1;
if ((i = excludedTypes.get("*")) != null)
return i + 1;
return getProfile();
}
String getName() {
return (parent == null) ? name : (parent.getName() + "/" + name);
}
void getPackages(int profile, Set<String> results) {
int prf = getProfile();
if (prf != 0 && profile >= prf)
results.add(getName());
for (Package pkg: subpackages.values())
pkg.getPackages(profile, results);
}
}
final Map<String, Package> packages = new TreeMap<String, Package>();
final int maxProfile = 4; // Three compact profiles plus full JRE
MakefileProfiles(Properties p) {
// consider crypto, only if java/lang package exists
boolean foundJavaLang = false;
for (int profile = 1; profile <= maxProfile; profile++) {
String prefix = (profile < maxProfile ? "PROFILE_" + profile : "FULL_JRE");
String inclPackages = p.getProperty(prefix + "_RTJAR_INCLUDE_PACKAGES");
if (inclPackages == null)
break;
for (String pkg: inclPackages.substring(1).trim().split("\\s+")) {
if (pkg.endsWith("/"))
pkg = pkg.substring(0, pkg.length() - 1);
if (foundJavaLang == false && pkg.equals("java/lang"))
foundJavaLang = true;
includePackage(profile, pkg);
}
String inclTypes = p.getProperty(prefix + "_RTJAR_INCLUDE_TYPES");
if (inclTypes != null) {
for (String type: inclTypes.replace("$$", "$").split("\\s+")) {
if (type.endsWith(".class"))
includeType(profile, type.substring(0, type.length() - 6));
}
}
String exclTypes = p.getProperty(prefix + "_RTJAR_EXCLUDE_TYPES");
if (exclTypes != null) {
for (String type: exclTypes.replace("$$", "$").split("\\s+")) {
if (type.endsWith(".class"))
excludeType(profile, type.substring(0, type.length() - 6));
}
}
}
/*
* A hack to force javax/crypto package into the compact1 profile,
* because this package exists in jce.jar, and therefore not in
* ct.sym. Note javax/crypto should exist in a profile along with
* javax/net/ssl package. Thus, this package is added to compact1,
* implying that it should exist in all three profiles.
*/
if (foundJavaLang)
includePackage(1, "javax/crypto");
}
@Override
public int getProfileCount() {
return maxProfile;
}
@Override
public int getProfile(String typeName) {
int sep = typeName.lastIndexOf("/");
String packageName = typeName.substring(0, sep);
String simpleName = typeName.substring(sep + 1);
Package p = getPackage(packageName);
return p.getProfile(simpleName);
}
@Override
public Set<String> getPackages(int profile) {
Set<String> results = new TreeSet<String>();
for (Package p: packages.values())
p.getPackages(profile, results);
return results;
}
private void includePackage(int profile, String packageName) {
// System.err.println("include package " + packageName);
Package p = getPackage(packageName);
Assert.check(p.profile == 0);
p.profile = profile;
}
private void includeType(int profile, String typeName) {
// System.err.println("include type " + typeName);
int sep = typeName.lastIndexOf("/");
String packageName = typeName.substring(0, sep);
String simpleName = typeName.substring(sep + 1);
Package p = getPackage(packageName);
Assert.check(!p.includedTypes.containsKey(simpleName));
p.includedTypes.put(simpleName, profile);
}
private void excludeType(int profile, String typeName) {
// System.err.println("exclude type " + typeName);
int sep = typeName.lastIndexOf("/");
String packageName = typeName.substring(0, sep);
String simpleName = typeName.substring(sep + 1);
Package p = getPackage(packageName);
Assert.check(!p.excludedTypes.containsKey(simpleName));
p.excludedTypes.put(simpleName, profile);
}
private Package getPackage(String packageName) {
int sep = packageName.lastIndexOf("/");
Package parent;
Map<String, Package> parentSubpackages;
String simpleName;
if (sep == -1) {
parent = null;
parentSubpackages = packages;
simpleName = packageName;
} else {
parent = getPackage(packageName.substring(0, sep));
parentSubpackages = parent.subpackages;
simpleName = packageName.substring(sep + 1);
}
Package p = parentSubpackages.get(simpleName);
if (p == null) {
parentSubpackages.put(simpleName, p = new Package(parent, simpleName));
}
return p;
}
}
private static class SimpleProfiles extends Profiles {
private final Map<String, Integer> map;
private final int profileCount;
SimpleProfiles(Properties p) {
int max = 0;
map = new HashMap<String, Integer>();
for (Map.Entry<Object,Object> e: p.entrySet()) {
String typeName = (String) e.getKey();
int profile = Integer.valueOf((String) e.getValue());
map.put(typeName, profile);
max = Math.max(max, profile);
}
profileCount = max;
}
@Override
public int getProfileCount() {
return profileCount;
}
@Override
public int getProfile(String typeName) {
return map.get(typeName);
}
@Override
public Set<String> getPackages(int profile) {
Set<String> results = new TreeSet<String>();
for (Map.Entry<String,Integer> e: map.entrySet()) {
String tn = e.getKey();
int prf = e.getValue();
int sep = tn.lastIndexOf("/");
if (sep > 0 && profile >= prf)
results.add(tn);
}
return results;
}
}
}