forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move snappy native library resource registration to a feature
Always registers the correct native library as the logic runs on the same architecture we are targeting (even when using containers). Closes quarkusio#43801
- Loading branch information
Showing
3 changed files
with
68 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 0 additions & 17 deletions
17
...kafka-client/deployment/src/main/java/io/quarkus/kafka/client/deployment/SnappyUtils.java
This file was deleted.
Oops, something went wrong.
63 changes: 63 additions & 0 deletions
63
...fka-client/runtime/src/main/java/io/quarkus/kafka/client/runtime/graal/SnappyFeature.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package io.quarkus.kafka.client.runtime.graal; | ||
|
||
import java.io.File; | ||
|
||
import org.graalvm.nativeimage.hosted.Feature; | ||
import org.graalvm.nativeimage.hosted.RuntimeResourceAccess; | ||
import org.xerial.snappy.OSInfo; | ||
|
||
public class SnappyFeature implements Feature { | ||
|
||
/** | ||
* This method uses code from org.xerial.snappy.SnappyLoader#findNativeLibrary | ||
* to load the Snappy native library. The original code is licensed under the | ||
* Apache License, Version 2.0 and includes the following notice: | ||
* | ||
* <pre> | ||
*-------------------------------------------------------------------------- | ||
* Copyright 2011 Taro L. Saito | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*-------------------------------------------------------------------------- | ||
* </pre> | ||
*/ | ||
@Override | ||
public void beforeAnalysis(BeforeAnalysisAccess access) { | ||
final String KEY_SNAPPY_LIB_PATH = "org.xerial.snappy.lib.path"; | ||
final String KEY_SNAPPY_LIB_NAME = "org.xerial.snappy.lib.name"; | ||
|
||
// Try to load the library in org.xerial.snappy.lib.path */ | ||
String snappyNativeLibraryPath = System.getProperty(KEY_SNAPPY_LIB_PATH); | ||
String snappyNativeLibraryName = System.getProperty(KEY_SNAPPY_LIB_NAME); | ||
|
||
// Resolve the library file name with a suffix (e.g., dll, .so, etc.) | ||
if (snappyNativeLibraryName == null) { | ||
snappyNativeLibraryName = System.mapLibraryName("snappyjava"); | ||
} | ||
|
||
if (snappyNativeLibraryPath != null) { | ||
File nativeLib = new File(snappyNativeLibraryPath, snappyNativeLibraryName); | ||
if (nativeLib.exists()) { | ||
RuntimeResourceAccess.addResource(OSInfo.class.getModule(), | ||
snappyNativeLibraryPath + "/" + snappyNativeLibraryName); | ||
return; | ||
} | ||
} | ||
|
||
// Load an OS-dependent native library inside a jar file | ||
snappyNativeLibraryPath = "org/xerial/snappy/native/" + OSInfo.getNativeLibFolderPathForCurrentOS(); | ||
String path = snappyNativeLibraryPath + "/" + snappyNativeLibraryName; | ||
RuntimeResourceAccess.addResource(OSInfo.class.getModule(), path); | ||
} | ||
|
||
} |