MCPcopy Index your code
hub / github.com/java-native-access/jna / loadNativeDispatchLibrary

Method loadNativeDispatchLibrary

src/com/sun/jna/Native.java:1010–1087  ·  view source on GitHub ↗

Loads the JNA stub library. First tries jna.boot.library.path, then the system path, then from the jar file.

()

Source from the content-addressed store, hash-verified

1008 * jar file.
1009 */
1010 private static void loadNativeDispatchLibrary() {
1011 if (!Boolean.getBoolean("jna.nounpack")) {
1012 try {
1013 removeTemporaryFiles();
1014 }
1015 catch(IOException e) {
1016 LOG.log(Level.WARNING, "JNA Warning: IOException removing temporary files", e);
1017 }
1018 }
1019
1020 String libName = System.getProperty("jna.boot.library.name", "jnidispatch");
1021 String bootPath = System.getProperty("jna.boot.library.path");
1022 if (bootPath != null) {
1023 // String.split not available in 1.4
1024 StringTokenizer dirs = new StringTokenizer(bootPath, File.pathSeparator);
1025 while (dirs.hasMoreTokens()) {
1026 String dir = dirs.nextToken();
1027 File file = new File(new File(dir), System.mapLibraryName(libName).replace(".dylib", ".jnilib"));
1028 String path = file.getAbsolutePath();
1029 LOG.log(DEBUG_JNA_LOAD_LEVEL, "Looking in {0}", path);
1030 if (file.exists()) {
1031 try {
1032 LOG.log(DEBUG_JNA_LOAD_LEVEL, "Trying {0}", path);
1033 System.setProperty("jnidispatch.path", path);
1034 System.load(path);
1035 jnidispatchPath = path;
1036 LOG.log(DEBUG_JNA_LOAD_LEVEL, "Found jnidispatch at {0}", path);
1037 return;
1038 } catch (UnsatisfiedLinkError ex) {
1039 // Not a problem if already loaded in anoteher class loader
1040 // Unfortunately we can't distinguish the difference...
1041 //System.out.println("File found at " + file + " but not loadable: " + ex.getMessage());
1042 }
1043 }
1044 if (Platform.isMac()) {
1045 String orig, ext;
1046 if (path.endsWith("dylib")) {
1047 orig = "dylib";
1048 ext = "jnilib";
1049 } else {
1050 orig = "jnilib";
1051 ext = "dylib";
1052 }
1053 path = path.substring(0, path.lastIndexOf(orig)) + ext;
1054 LOG.log(DEBUG_JNA_LOAD_LEVEL, "Looking in {0}", path);
1055 if (new File(path).exists()) {
1056 try {
1057 LOG.log(DEBUG_JNA_LOAD_LEVEL, "Trying {0}", path);
1058 System.setProperty("jnidispatch.path", path);
1059 System.load(path);
1060 jnidispatchPath = path;
1061 LOG.log(DEBUG_JNA_LOAD_LEVEL, "Found jnidispatch at {0}", path);
1062 return;
1063 } catch (UnsatisfiedLinkError ex) {
1064 LOG.log(Level.WARNING, "File found at " + path + " but not loadable: " + ex.getMessage(), ex);
1065 }
1066 }
1067 }

Callers 1

NativeClass · 0.95

Calls 10

removeTemporaryFilesMethod · 0.95
isMacMethod · 0.95
isAndroidMethod · 0.95
replaceMethod · 0.80
getPropertyMethod · 0.65
setPropertyMethod · 0.65
logMethod · 0.45
loadMethod · 0.45
loadLibraryMethod · 0.45

Tested by

no test coverage detected