X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/f3b7e5f4b4d7c87ee3e8827313ec966ea8fc8387..73e97710413bba3ee2ae8baab0537fbd78811016:/src/bindings/java/org/simgrid/NativeLib.java diff --git a/src/bindings/java/org/simgrid/NativeLib.java b/src/bindings/java/org/simgrid/NativeLib.java index 3e2322d47a..eb938c019e 100644 --- a/src/bindings/java/org/simgrid/NativeLib.java +++ b/src/bindings/java/org/simgrid/NativeLib.java @@ -1,4 +1,4 @@ -/* Copyright (c) 2014-2020. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2014-2021. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -36,7 +36,7 @@ public final class NativeLib { public static void main(String[] args) { System.out.println("This jarfile searches the native code under: " +getPath()); } - + /** Main function loading all the native classes that we need */ public static void nativeInit() { if (isNativeInited) @@ -60,13 +60,13 @@ public final class NativeLib { } catch (UnsatisfiedLinkError|SecurityException|IOException e) { cause = e; } - + /* If not found, try to see if we can find a version on disk */ try { System.loadLibrary(name); return; } catch (UnsatisfiedLinkError systemException) { /* don't care */ } - + System.err.println("\nCannot load the bindings to the "+name+" library in path "+getPath()+" and no usable SimGrid installation found on disk."); if (cause != null) { if (cause.getMessage().contains("libcgraph.so")) @@ -87,7 +87,7 @@ public final class NativeLib { /** Try to extract the library from the jarfile before loading it */ private static boolean loadLibAsStream (String name) throws IOException, UnsatisfiedLinkError { String path = NativeLib.getPath(); - + // We must write the lib onto the disk before loading it -- stupid operating systems if (tempDir == null) { final String tempPrefix = "simgrid-java-"; @@ -111,14 +111,14 @@ public final class NativeLib { // don't leak the files on disk, but remove it on JVM shutdown Runtime.getRuntime().addShutdownHook(new Thread(new FileCleaner(tempDir.toFile()))); } - + /* For each possible filename of the given library on all possible OSes, try it */ for (String filename : new String[] { name, "lib"+name+".so", /* linux */ name+".dll", "lib"+name+".dll", /* windows (pure and mingw) */ "lib"+name+".dylib" /* macOS */}) { - + File fileOut = new File(tempDir.toFile(), filename); try ( // Try-with-resources. These stream will be autoclosed when needed. InputStream in = NativeLib.class.getClassLoader().getResourceAsStream(path+filename); @@ -135,7 +135,7 @@ public final class NativeLib { } } } - + /* No suitable name found */ return false; } @@ -162,7 +162,7 @@ public final class NativeLib { return prefix + "/" + os + "/" + arch + "/"; } - + /** A hackish mechanism used to remove the file containing our library when the JVM shuts down */ private static class FileCleaner implements Runnable { private File dir;