Share code that is needed to support shaded native libraries.
Motivation: For our native libraries in netty we support shading, to have this work on runtime the user needs to set a system property. This code should shared. Modifications: Move logic to NativeLbiraryLoader and so share for all native libs. Result: Less code duplication and also will work for netty-tcnative out of the box once it support shading
This commit is contained in:
parent
915bf5f5b7
commit
201d9b6536
@ -181,7 +181,10 @@ public final class NativeLibraryLoader {
|
|||||||
/**
|
/**
|
||||||
* Load the given library with the specified {@link ClassLoader}
|
* Load the given library with the specified {@link ClassLoader}
|
||||||
*/
|
*/
|
||||||
public static void load(String name, ClassLoader loader) {
|
public static void load(String originalName, ClassLoader loader) {
|
||||||
|
// Adjust expected name to support shading of native libraries.
|
||||||
|
String name = SystemPropertyUtil.get("io.netty.packagePrefix", "").replace('.', '-') + originalName;
|
||||||
|
|
||||||
String libname = System.mapLibraryName(name);
|
String libname = System.mapLibraryName(name);
|
||||||
String path = NATIVE_RESOURCE_HOME + libname;
|
String path = NATIVE_RESOURCE_HOME + libname;
|
||||||
|
|
||||||
|
@ -188,8 +188,7 @@ public final class Native {
|
|||||||
if (!name.startsWith("linux")) {
|
if (!name.startsWith("linux")) {
|
||||||
throw new IllegalStateException("Only supported on Linux");
|
throw new IllegalStateException("Only supported on Linux");
|
||||||
}
|
}
|
||||||
NativeLibraryLoader.load(SystemPropertyUtil.get("io.netty.packagePrefix", "").replace('.', '-') +
|
NativeLibraryLoader.load("netty-transport-native-epoll", PlatformDependent.getClassLoader(Native.class));
|
||||||
"netty-transport-native-epoll", PlatformDependent.getClassLoader(Native.class));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Native() {
|
private Native() {
|
||||||
|
@ -100,8 +100,7 @@ final class Native {
|
|||||||
if (!name.startsWith("mac") && !name.contains("bsd") && !name.startsWith("darwin")) {
|
if (!name.startsWith("mac") && !name.contains("bsd") && !name.startsWith("darwin")) {
|
||||||
throw new IllegalStateException("Only supported on BSD");
|
throw new IllegalStateException("Only supported on BSD");
|
||||||
}
|
}
|
||||||
NativeLibraryLoader.load(SystemPropertyUtil.get("io.netty.packagePrefix", "").replace('.', '-') +
|
NativeLibraryLoader.load("netty-transport-native-kqueue", PlatformDependent.getClassLoader(Native.class));
|
||||||
"netty-transport-native-kqueue", PlatformDependent.getClassLoader(Native.class));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Native() {
|
private Native() {
|
||||||
|
Loading…
Reference in New Issue
Block a user