Skip to content

Commit fa68578

Browse files
committed
improve native library loading logging a bit
1 parent b90c192 commit fa68578

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

core/src/main/java/tel/schich/javacan/platform/Platform.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public static OS getOS() {
6464
public static void loadNativeLibrary(String name, Class<?> base) {
6565
try {
6666
System.loadLibrary(name);
67+
LOGGER.trace("Loaded native library {} from library path", name);
6768
} catch (LinkageError e) {
6869
loadExplicitLibrary(name, base);
6970
}
@@ -72,40 +73,40 @@ public static void loadNativeLibrary(String name, Class<?> base) {
7273
private static void loadExplicitLibrary(String name, Class<?> base) {
7374
String explicitLibraryPath = System.getProperty(PATH_PROP_PREFIX + name.toLowerCase() + PATH_PROP_FS_PATH);
7475
if (explicitLibraryPath != null) {
75-
LOGGER.trace("Loading native library from {}", explicitLibraryPath);
76+
LOGGER.trace("Loading native library {} from {}", name, explicitLibraryPath);
7677
System.load(explicitLibraryPath);
7778
return;
7879
}
7980

8081
String explicitLibraryClassPath = System.getProperty(PATH_PROP_PREFIX + name.toLowerCase() + PATH_PROP_CLASS_PATH);
8182
if (explicitLibraryClassPath != null) {
82-
LOGGER.trace("Loading native library from explicit classpath at {}", explicitLibraryClassPath);
83+
LOGGER.trace("Loading native library {} from explicit classpath at {}", name, explicitLibraryClassPath);
8384
try {
8485
final Path tempDirectory = Files.createTempDirectory(name + "-");
8586
final Path libPath = tempDirectory.resolve("lib" + name + ".so");
86-
loadFromClassPath(base, explicitLibraryClassPath, libPath);
87+
loadFromClassPath(name, base, explicitLibraryClassPath, libPath);
8788
return;
8889
} catch (IOException e) {
89-
throw new LinkageError("Unable to load native library '" + name + "'!", e);
90+
throw new LinkageError("Unable to load native library " + name + "!", e);
9091
}
9192
}
9293

9394
final String sourceLibPath = LIB_PREFIX + "/lib" + name + ".so";
94-
LOGGER.trace("Loading native library from {}", sourceLibPath);
95+
LOGGER.trace("Loading native library {} from {}", name, sourceLibPath);
9596

9697
try {
9798
final Path tempDirectory = Files.createTempDirectory(name + "-");
9899
final Path libPath = tempDirectory.resolve("lib" + name + ".so");
99-
loadFromClassPath(base, sourceLibPath, libPath);
100+
loadFromClassPath(name, base, sourceLibPath, libPath);
100101
} catch (IOException e) {
101-
throw new LinkageError("Unable to load native library '" + name + "'!", e);
102+
throw new LinkageError("Unable to load native library " + name + "!", e);
102103
}
103104
}
104105

105-
private static void loadFromClassPath(Class<?> base, String classPath, Path fsPath) throws IOException {
106+
private static void loadFromClassPath(String name, Class<?> base, String classPath, Path fsPath) throws IOException {
106107
try (InputStream libStream = base.getResourceAsStream(classPath)) {
107108
if (libStream == null) {
108-
throw new LinkageError("Failed to load the native library: " + classPath + " not found.");
109+
throw new LinkageError("Failed to load the native library " + name + ": " + classPath + " not found.");
109110
}
110111

111112
Files.copy(libStream, fsPath, REPLACE_EXISTING);

0 commit comments

Comments
 (0)