MCPcopy Create free account
hub / github.com/HumbleUI/Skija / load

Method load

shared/java/impl/Library.java:37–124  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

35 }
36
37 @SneakyThrows
38 public static synchronized void load() {
39 if (_loaded) return;
40
41 // If `skija.loadFromLibraryPath` is set to true, use System.loadLibrary to load the native library
42 String loadFromLibraryPath = System.getProperty("skija.loadFromLibraryPath");
43 if ("true".equals(loadFromLibraryPath)) {
44 _loadFromLibraryPath();
45 return;
46 }
47
48 // If `skija.library.path` is set, load the native library from this path
49 String libraryPath = System.getProperty("skija.library.path");
50 if (libraryPath != null) {
51 _loadFromDir(new File(libraryPath));
52 return;
53 }
54
55 boolean failedLoadFromLibraryPath = false;
56
57 // If skija is bundled in JRE, try to load the bundled native library
58 // User can disable this behavior by set `skija.loadFromLibraryPath` to false
59 if (loadFromLibraryPath == null) {
60 URL theClassFile = Library.class.getResource("Library.class");
61 if (theClassFile != null && "jrt".equals(theClassFile.getProtocol())) {
62 try {
63 _loadFromLibraryPath();
64 return;
65 } catch (UnsatisfiedLinkError e) {
66 failedLoadFromLibraryPath = true;
67 Log.warn("Please use skija platform jmod when using jlink");
68 }
69 }
70 }
71
72 String osName = OperatingSystem.CURRENT.name().toLowerCase(Locale.ROOT);
73 String archName = Architecture.CURRENT.name().toLowerCase(Locale.ROOT);
74 String moduleName = "io.github.humbleui.skija." + osName + "." + archName;
75 String basePath = moduleName.replace('.', '/') + "/";
76
77 try (ResourceFinder finder = new ResourceFinder(moduleName)) {
78 URL versionFile = finder.findResource(basePath + "skija.version");
79
80 // The platform library is bundled in the JRE, but the skija shared is not bundled.
81 // Platforms without official support can provide native libraries in this way.
82 if (loadFromLibraryPath == null
83 && !failedLoadFromLibraryPath
84 && versionFile != null
85 && "jrt".equals(versionFile.getProtocol())) {
86 try {
87 _loadFromLibraryPath();
88 return;
89 } catch (UnsatisfiedLinkError e) {
90 failedLoadFromLibraryPath = true;
91 Log.warn("Please use skija platform jmod when using jlink");
92 }
93 }
94

Callers 7

staticLoadMethod · 0.95
loopMethod · 0.95
_loadFromDirMethod · 0.80
_loadFromFileMethod · 0.80
mainMethod · 0.80
MainMethod · 0.80

Calls 11

_loadFromLibraryPathMethod · 0.95
_loadFromDirMethod · 0.95
warnMethod · 0.95
readResourceMethod · 0.95
_extractMethod · 0.95
debugMethod · 0.95
_loadFromFileMethod · 0.95
getPropertyMethod · 0.80
equalsMethod · 0.45
findResourceMethod · 0.45
valueOfMethod · 0.45

Tested by

no test coverage detected