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

Method loadLibrary

src/com/sun/jna/NativeLibrary.java:175–335  ·  view source on GitHub ↗
(final String libraryName, final Map<String, ?> options)

Source from the content-addressed store, hash-verified

173 }
174
175 private static NativeLibrary loadLibrary(final String libraryName, final Map<String, ?> options) {
176 LOG.log(DEBUG_LOAD_LEVEL, "Looking for library '" + libraryName + "'");
177
178 List<Throwable> exceptions = new ArrayList<>();
179 boolean isAbsolutePath = new File(libraryName).isAbsolute();
180 LinkedHashSet<String> searchPath = new LinkedHashSet<>();
181 int openFlags = openFlags(options);
182
183 //
184 // Prepend any custom search paths specifically for this library
185 //
186 List<String> customPaths = searchPaths.get(libraryName);
187 if (customPaths != null) {
188 synchronized (customPaths) {
189 searchPath.addAll(customPaths);
190 }
191 }
192
193 // Append web start path, if available. Note that this does not
194 // attempt any library name variations
195 String webstartPath = Native.getWebStartLibraryPath(libraryName);
196 if (webstartPath != null) {
197 LOG.log(DEBUG_LOAD_LEVEL, "Adding web start path " + webstartPath);
198 searchPath.add(webstartPath);
199 }
200
201 LOG.log(DEBUG_LOAD_LEVEL, "Adding paths from jna.library.path: " + System.getProperty("jna.library.path"));
202
203 searchPath.addAll(initPaths("jna.library.path"));
204 String libraryPath = findLibraryPath(libraryName, searchPath);
205 long handle = 0;
206 //
207 // Only search user specified paths first. This will also fall back
208 // to dlopen/LoadLibrary() since findLibraryPath returns the mapped
209 // name if it cannot find the library.
210 //
211 try {
212 LOG.log(DEBUG_LOAD_LEVEL, "Trying " + libraryPath);
213 handle = Native.open(libraryPath, openFlags);
214 } catch(UnsatisfiedLinkError e) {
215 // Add the system paths back for all fallback searching
216 LOG.log(DEBUG_LOAD_LEVEL, "Loading failed with message: " + e.getMessage());
217 LOG.log(DEBUG_LOAD_LEVEL, "Adding system paths: " + librarySearchPath);
218 exceptions.add(e);
219 searchPath.addAll(librarySearchPath);
220 }
221
222 try {
223 if (handle == 0) {
224 libraryPath = findLibraryPath(libraryName, searchPath);
225 LOG.log(DEBUG_LOAD_LEVEL, "Trying " + libraryPath);
226 handle = Native.open(libraryPath, openFlags);
227 if (handle == 0) {
228 throw new UnsatisfiedLinkError("Failed to load library '" + libraryName + "'");
229 }
230 }
231 } catch(UnsatisfiedLinkError ule) {
232 LOG.log(DEBUG_LOAD_LEVEL, "Loading failed with message: " + ule.getMessage());

Callers 1

getInstanceMethod · 0.95

Calls 15

openFlagsMethod · 0.95
initPathsMethod · 0.95
findLibraryPathMethod · 0.95
openMethod · 0.95
isAndroidMethod · 0.95
isLinuxMethod · 0.95
isFreeBSDMethod · 0.95
isDragonFlyBSDMethod · 0.95
matchLibraryMethod · 0.95
isMacMethod · 0.95
matchFrameworkMethod · 0.95

Tested by

no test coverage detected