blob: 0786272bc702359a272171fc8b17443209f9b1b1 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
package com.yahoo.container.plugin.util;
import java.net.URL;
/**
* @author gjoranv
*/
public class JdkPackages {
/**
* Returns a boolean indicating (via best effort) if the given package is part of the JDK.
*/
public static boolean isJdkPackage(String pkg) {
return hasJdkExclusivePrefix(pkg)
|| isResourceInPlatformClassLoader(pkg); // TODO: must be a class, not a package, due to module encapsulation
}
private static boolean isResourceInPlatformClassLoader(String klass) {
String klassAsPath = klass.replaceAll("\\.", "/") + ".class";
URL resource = getPlatformClassLoader().getResource(klassAsPath);
return !(resource == null);
}
private static ClassLoader getPlatformClassLoader() {
ClassLoader platform = JdkPackages.class.getClassLoader().getParent();
// Will fail upon changes in classloader hierarchy between JDK versions
assert (platform.getName().equals("platform"));
return platform;
}
private static boolean hasJdkExclusivePrefix(String pkg) {
return pkg.startsWith("java.")
|| pkg.startsWith("sun.");
}
}
|