Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added info on loaded native library #36

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public class Library {
final private String version;
final private ClassLoader classLoader;
private boolean loaded;
private String nativeLibraryPath;
private URL nativeLibrarySourceUrl;

public Library(String name) {
this(name, null, null);
Expand Down Expand Up @@ -116,6 +118,24 @@ private static String version(Class<?> clazz) {
return null;
}

/**
* Get the path to the native library loaded.
* @return the path (should not be null once the library is loaded)
* @since 1.16
*/
public String getNativeLibraryPath() {
return nativeLibraryPath;
}

/**
* Get the URL to the native library source that has been extracted (if it was extracted).
* @return the url to the source (in classpath)
* @since 1.16
*/
public URL getNativeLibrarySourceUrl() {
return nativeLibrarySourceUrl;
}

public static String getOperatingSystem() {
String name = System.getProperty("os.name").toLowerCase().trim();
if( name.startsWith("linux") ) {
Expand Down Expand Up @@ -147,7 +167,7 @@ public static int getBitModel() {
}

/**
*
* Load the native library.
*/
synchronized public void load() {
if( loaded ) {
Expand Down Expand Up @@ -181,11 +201,11 @@ private void doLoad() {
}

/* Try loading library from java library path */
if( version!=null && load(errors, name + getBitModel() + "-" + version) )
if( version!=null && loadLibrary(errors, name + getBitModel() + "-" + version) )
return;
if( version!=null && load(errors, name + "-" + version) )
if( version!=null && loadLibrary(errors, name + "-" + version) )
return;
if( load(errors, name ) )
if( loadLibrary(errors, name) )
return;


Expand Down Expand Up @@ -262,6 +282,7 @@ final public String getLibraryFileName() {
* <li>no directory</li>
* </ul>
* @return the list
* @since 1.15
*/
final public String[] getSpecificSearchDirs() {
return new String[] {
Expand Down Expand Up @@ -292,6 +313,7 @@ private boolean extractAndLoad(ArrayList<Throwable> errors, String customPath, S
File target = extract(errors, resource, prefix, suffix, path);
if( target!=null ) {
if( load(errors, target) ) {
nativeLibrarySourceUrl = resource;
return true;
}
}
Expand Down Expand Up @@ -409,6 +431,7 @@ private void chmod755(File file) {
private boolean load(ArrayList<Throwable> errors, File lib) {
try {
System.load(lib.getPath());
nativeLibraryPath = lib.getPath();
return true;
} catch (UnsatisfiedLinkError e) {
LinkageError le = new LinkageError("Unable to load library from " + lib);
Expand All @@ -418,9 +441,10 @@ private boolean load(ArrayList<Throwable> errors, File lib) {
return false;
}

private boolean load(ArrayList<Throwable> errors, String lib) {
private boolean loadLibrary(ArrayList<Throwable> errors, String lib) {
try {
System.loadLibrary(lib);
nativeLibraryPath = "java.library.path,sun.boot.library.pathlib:" + lib;
return true;
} catch (UnsatisfiedLinkError e) {
LinkageError le = new LinkageError("Unable to load library " + lib);
Expand Down