src/share/classes/com/sun/tools/jdeps/PlatformClassPath.java

changeset 1638
fd3fdaff0257
parent 1472
0c244701188e
child 1648
a03c4a86ea2b
equal deleted inserted replaced
1637:2e21ecd7a5ad 1638:fd3fdaff0257
35 35
36 /** 36 /**
37 * ClassPath for Java SE and JDK 37 * ClassPath for Java SE and JDK
38 */ 38 */
39 class PlatformClassPath { 39 class PlatformClassPath {
40 /*
41 * Profiles for Java SE
42 *
43 * This is a temporary workaround until a common API is defined for langtools
44 * to determine which profile a given classname belongs to. The list of
45 * packages and profile names are hardcoded in jdk.properties and
46 * split packages are not supported.
47 */
48 static class Profile {
49 final String name;
50 final Set<String> packages;
51
52 Profile(String name) {
53 this.name = name;
54 this.packages = new HashSet<String>();
55 }
56 }
57
58 private final static String JAVAFX = "javafx";
59 private final static Map<String,Profile> map = getProfilePackages();
60 static String getProfileName(String packageName) {
61 Profile profile = map.get(packageName);
62 if (packageName.startsWith(JAVAFX + ".")) {
63 profile = map.get(JAVAFX);
64 }
65 return profile != null ? profile.name : "";
66 }
67
68 private final static List<Archive> javaHomeArchives = init(); 40 private final static List<Archive> javaHomeArchives = init();
69 static List<Archive> getArchives() { 41 static List<Archive> getArchives() {
70 return javaHomeArchives; 42 return javaHomeArchives;
71 } 43 }
72 44
98 throw new RuntimeException("\"" + javaHome + "\" not a JDK home"); 70 throw new RuntimeException("\"" + javaHome + "\" not a JDK home");
99 } 71 }
100 } catch (IOException e) { 72 } catch (IOException e) {
101 throw new RuntimeException(e); 73 throw new RuntimeException(e);
102 } 74 }
103
104 // add a JavaFX profile if there is jfxrt.jar
105 for (Archive archive : result) {
106 if (archive.getFileName().equals("jfxrt.jar")) {
107 map.put(JAVAFX, new Profile("jfxrt.jar"));
108 }
109 }
110 return result; 75 return result;
111 } 76 }
112 77
113 private static List<Archive> addJarFiles(File f) throws IOException { 78 private static List<Archive> addJarFiles(File f) throws IOException {
114 final List<Archive> result = new ArrayList<Archive>(); 79 final List<Archive> result = new ArrayList<Archive>();
138 return FileVisitResult.CONTINUE; 103 return FileVisitResult.CONTINUE;
139 } 104 }
140 }); 105 });
141 return result; 106 return result;
142 } 107 }
143
144 private static Map<String,Profile> getProfilePackages() {
145 Map<String,Profile> map = new HashMap<String,Profile>();
146
147 // read the properties as a ResourceBundle as the build compiles
148 // the properties file into Java class. Another alternative is
149 // to load it as Properties and fix the build to exclude this file.
150 ResourceBundle profileBundle =
151 ResourceBundle.getBundle("com.sun.tools.jdeps.resources.jdk");
152
153 int i=1;
154 String key;
155 while (profileBundle.containsKey((key = "profile." + i + ".name"))) {
156 Profile profile = new Profile(profileBundle.getString(key));
157 String n = profileBundle.getString("profile." + i + ".packages");
158 String[] pkgs = n.split("\\s+");
159 for (String p : pkgs) {
160 if (p.isEmpty()) continue;
161 assert(map.containsKey(p) == false);
162 profile.packages.add(p);
163 map.put(p, profile);
164 }
165 i++;
166 }
167 return map;
168 }
169 } 108 }

mercurial