Skip to content

Commit

Permalink
#36 added info on loaded native library
Browse files Browse the repository at this point in the history
  • Loading branch information
hboutemy committed Dec 4, 2017
1 parent 16c5d82 commit 4a42ee6
Showing 1 changed file with 29 additions and 5 deletions.
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

0 comments on commit 4a42ee6

Please sign in to comment.