Use underscore in native library names for consistency.

Motivation:

At the moment we try to load the library using multiple names which includes names using - but also _ . We should just use _ all the time.

Modifications:

Replace - with _

Result:

Fixes [#7069]
This commit is contained in:
Norman Maurer 2017-08-14 09:11:07 +02:00
parent e249b453a0
commit 19dcb15062
8 changed files with 14 additions and 18 deletions

View File

@ -111,7 +111,7 @@ public final class NativeLibraryLoader {
*/
public static void load(String originalName, ClassLoader loader) {
// Adjust expected name to support shading of native libraries.
String name = calculatePackagePrefix().replace('.', '-') + originalName;
String name = calculatePackagePrefix().replace('.', '_') + originalName;
String libname = System.mapLibraryName(name);
String path = NATIVE_RESOURCE_HOME + libname;

View File

@ -144,6 +144,7 @@
<execution>
<id>build-native-lib</id>
<configuration>
<name>netty_transport_native_epoll</name>
<nativeSourceDirectory>${project.basedir}/src/main/c</nativeSourceDirectory>
<libDirectory>${project.build.outputDirectory}</libDirectory>
<!-- We use Maven's artifact classifier instead.
@ -178,7 +179,7 @@
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<Bundle-NativeCode>META-INF/native/libnetty-transport-native-epoll.so; osname=linux; processor=x86_64,*</Bundle-NativeCode>
<Bundle-NativeCode>META-INF/native/libnetty_transport_native_epoll.so; osname=linux; processor=x86_64,*</Bundle-NativeCode>
</manifestEntries>
<index>true</index>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>

View File

@ -604,7 +604,7 @@ jint JNI_OnLoad_netty_transport_native_epoll(JavaVM* vm, void* reserved) {
fprintf(stderr, "FATAL: transport-native-epoll JNI call to dladdr failed!\n");
return JNI_ERR;
}
packagePrefix = netty_unix_util_parse_package_prefix(dlinfo.dli_fname, "netty-transport-native-epoll", &status);
packagePrefix = netty_unix_util_parse_package_prefix(dlinfo.dli_fname, "netty_transport_native_epoll", &status);
if (status == JNI_ERR) {
fprintf(stderr, "FATAL: transport-native-epoll JNI encountered unexpected dlinfo.dli_fname: %s\n", dlinfo.dli_fname);
return JNI_ERR;

View File

@ -188,11 +188,7 @@ public final class Native {
if (!name.startsWith("linux")) {
throw new IllegalStateException("Only supported on Linux");
}
String []libraryNames = new String[] {
"netty-transport-native-epoll",
"netty_transport_native_epoll"
};
NativeLibraryLoader.loadFirstAvailable(PlatformDependent.getClassLoader(Native.class), libraryNames);
NativeLibraryLoader.load("netty_transport_native_epoll", PlatformDependent.getClassLoader(Native.class));
}
private Native() {

View File

@ -70,6 +70,7 @@
<execution>
<id>build-native-lib</id>
<configuration>
<name>netty_transport_native_kqueue</name>
<nativeSourceDirectory>${project.basedir}/src/main/c</nativeSourceDirectory>
<libDirectory>${project.build.outputDirectory}</libDirectory>
<!-- We use Maven's artifact classifier instead.
@ -109,7 +110,7 @@
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<Bundle-NativeCode>META-INF/native/libnetty-transport-native-kqueue.jnilib; osname=darwin, processor=x86_64"</Bundle-NativeCode>
<Bundle-NativeCode>META-INF/native/libnetty_transport_native_kqueue.jnilib; osname=darwin, processor=x86_64"</Bundle-NativeCode>
</manifestEntries>
<index>true</index>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
@ -178,6 +179,7 @@
<execution>
<id>build-native-lib</id>
<configuration>
<name>netty_transport_native_kqueue</name>
<nativeSourceDirectory>${project.basedir}/src/main/c</nativeSourceDirectory>
<libDirectory>${project.build.outputDirectory}</libDirectory>
<!-- We use Maven's artifact classifier instead.
@ -215,7 +217,7 @@
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<Bundle-NativeCode>META-INF/native/libnetty-transport-native-kqueue.jnilib; osname=darwin, processor=x86_64"</Bundle-NativeCode>
<Bundle-NativeCode>META-INF/native/libnetty_transport_native_kqueue.jnilib; osname=darwin, processor=x86_64"</Bundle-NativeCode>
</manifestEntries>
<index>true</index>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
@ -284,6 +286,7 @@
<execution>
<id>build-native-lib</id>
<configuration>
<name>netty_transport_native_kqueue</name>
<nativeSourceDirectory>${project.basedir}/src/main/c</nativeSourceDirectory>
<libDirectory>${project.build.outputDirectory}</libDirectory>
<!-- We use Maven's artifact classifier instead.
@ -321,7 +324,7 @@
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<Bundle-NativeCode>META-INF/native/libnetty-transport-native-kqueue.jnilib; osname=darwin, processor=x86_64"</Bundle-NativeCode>
<Bundle-NativeCode>META-INF/native/libnetty_transport_native_kqueue.jnilib; osname=darwin, processor=x86_64"</Bundle-NativeCode>
</manifestEntries>
<index>true</index>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>

View File

@ -287,7 +287,7 @@ jint JNI_OnLoad_netty_transport_native_kqueue(JavaVM* vm, void* reserved) {
fprintf(stderr, "FATAL: transport-native-kqueue JNI call to dladdr failed!\n");
return JNI_ERR;
}
packagePrefix = netty_unix_util_parse_package_prefix(dlinfo.dli_fname, "netty-transport-native-kqueue", &status);
packagePrefix = netty_unix_util_parse_package_prefix(dlinfo.dli_fname, "netty_transport_native_kqueue", &status);
if (status == JNI_ERR) {
fprintf(stderr, "FATAL: transport-native-kqueue JNI encountered unexpected dlinfo.dli_fname: %s\n", dlinfo.dli_fname);
return JNI_ERR;

View File

@ -100,11 +100,7 @@ final class Native {
if (!name.startsWith("mac") && !name.contains("bsd") && !name.startsWith("darwin")) {
throw new IllegalStateException("Only supported on BSD");
}
String []libraryNames = new String[] {
"netty-transport-native-kqueue",
"netty_transport_native_kqueue"
};
NativeLibraryLoader.loadFirstAvailable(PlatformDependent.getClassLoader(Native.class), libraryNames);
NativeLibraryLoader.load("netty_transport_native_kqueue", PlatformDependent.getClassLoader(Native.class));
}
private Native() {

View File

@ -87,7 +87,7 @@ char* netty_unix_util_parse_package_prefix(const char* libraryPathName, const ch
packageNameEnd = packagePrefix + packagePrefixLen;
// Package names must be sanitized, in JNI packages names are separated by '/' characters.
for (; temp != packageNameEnd; ++temp) {
if (*temp == '-') {
if (*temp == '_') {
*temp = '/';
}
}