Skip to content

Commit 4502aff

Browse files
committed
Added support for loading alpine shared library
Added Azure pipelines CI file
1 parent aff67cf commit 4502aff

File tree

3 files changed

+57
-3
lines changed

3 files changed

+57
-3
lines changed

azure-pipelines.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
trigger:
2+
branches:
3+
include:
4+
- master
5+
- refs/tags/*
6+
7+
jobs:
8+
- job:
9+
displayName: 'Snapshot build'
10+
condition: eq(variables['build.sourceBranch'], 'refs/heads/master')
11+
pool:
12+
vmImage: 'macOS-10.15'
13+
14+
steps:
15+
- checkout: self
16+
17+
- task: Maven@3
18+
inputs:
19+
mavenPomFile: 'pom.xml'
20+
goals: 'clean install'
21+
options: '-Drevision=$(Build.BuildNumber)'
22+
publishJUnitResults: false
23+
testResultsFiles: '**/surefire-reports/TEST-*.xml'
24+
javaHomeOption: 'JDKVersion'
25+
jdkVersionOption: '1.11'
26+
mavenVersionOption: 'Default'
27+
mavenAuthenticateFeed: false
28+
effectivePomSkip: false
29+
sonarQubeRunAnalysis: false

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
<artifactId>acegi-standard-project</artifactId>
77
<version>0.2.3</version>
88
</parent>
9-
<groupId>org.lmdbjava</groupId>
9+
<groupId>org.lmdbjava.alt</groupId>
1010
<artifactId>lmdbjava</artifactId>
11-
<version>0.7.1-SNAPSHOT</version>
11+
<version>0.7.1-${revision}-SNAPSHOT</version>
1212
<packaging>jar</packaging>
1313
<name>LmdbJava</name>
1414
<description>Low latency Java API for the ultra-fast, embedded Symas Lightning Database (LMDB)</description>

src/main/java/org/lmdbjava/Library.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
2424
import java.io.File;
2525
import static java.io.File.createTempFile;
26+
import java.io.FileInputStream;
2627
import java.io.IOException;
2728
import java.io.InputStream;
2829
import java.io.OutputStream;
@@ -33,6 +34,7 @@
3334
import static java.util.Locale.ENGLISH;
3435
import static java.util.Objects.nonNull;
3536
import static java.util.Objects.requireNonNull;
37+
import java.util.Properties;
3638
import static jnr.ffi.LibraryLoader.create;
3739
import jnr.ffi.Pointer;
3840
import static jnr.ffi.Runtime.getRuntime;
@@ -97,7 +99,8 @@ final class Library {
9799
if (SHOULD_USE_LIB) {
98100
libToLoad = getProperty(LMDB_NATIVE_LIB_PROP);
99101
} else if (SHOULD_EXTRACT && arch64 && linux) {
100-
libToLoad = extract("org/lmdbjava/lmdbjava-native-linux-x86_64.so");
102+
final String flavor = refineLinux();
103+
libToLoad = extract(String.format("org/lmdbjava/lmdbjava-native-%s-x86_64.so", flavor));
101104
} else if (SHOULD_EXTRACT && arch64 && osx) {
102105
libToLoad = extract("org/lmdbjava/lmdbjava-native-osx-x86_64.dylib");
103106
} else if (SHOULD_EXTRACT && arch64 && windows) {
@@ -137,6 +140,28 @@ private static String extract(final String name) {
137140
}
138141
}
139142

143+
@SuppressWarnings({"checkstyle:returncount", "PMD.AvoidFileStream"})
144+
private static String refineLinux() {
145+
// /etc/os-release is a very cross-platform way to determine the linux distribution
146+
// and just happens to be specified in properties format
147+
try (InputStream inputStream = new FileInputStream("/etc/os-release")) {
148+
final Properties properties = new Properties();
149+
properties.load(inputStream);
150+
151+
final String flavor = String.valueOf(properties.get("ID")).trim();
152+
153+
// We only care if it's Alpine for now as it uses MUSL instead of GLIBC
154+
if ("alpine".equals(flavor)) {
155+
return "linux-alpine";
156+
} else {
157+
return "linux";
158+
}
159+
} catch (final IOException e) {
160+
// Default to plain 'linux' if anything fails
161+
return "linux";
162+
}
163+
}
164+
140165
/**
141166
* Structure to wrap a native <code>MDB_envinfo</code>. Not for external use.
142167
*/

0 commit comments

Comments
 (0)