Skip to content

Commit

Permalink
Share code that is needed to support shaded native libraries.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
normanmaurer committed May 19, 2017
1 parent 915bf5f commit 201d9b6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ public static void loadFirstAvailable(ClassLoader loader, String... names) {
/**
* 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 path = NATIVE_RESOURCE_HOME + libname;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,7 @@ private static void loadNativeLibrary() {
if (!name.startsWith("linux")) {
throw new IllegalStateException("Only supported on Linux");
}
NativeLibraryLoader.load(SystemPropertyUtil.get("io.netty.packagePrefix", "").replace('.', '-') +
"netty-transport-native-epoll", PlatformDependent.getClassLoader(Native.class));
NativeLibraryLoader.load("netty-transport-native-epoll", PlatformDependent.getClassLoader(Native.class));
}

private Native() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ private static void loadNativeLibrary() {
if (!name.startsWith("mac") && !name.contains("bsd") && !name.startsWith("darwin")) {
throw new IllegalStateException("Only supported on BSD");
}
NativeLibraryLoader.load(SystemPropertyUtil.get("io.netty.packagePrefix", "").replace('.', '-') +
"netty-transport-native-kqueue", PlatformDependent.getClassLoader(Native.class));
NativeLibraryLoader.load("netty-transport-native-kqueue", PlatformDependent.getClassLoader(Native.class));
}

private Native() {
Expand Down

0 comments on commit 201d9b6

Please sign in to comment.