-
Notifications
You must be signed in to change notification settings - Fork 339
Expand file tree
/
Copy pathFlatDirLibraryResolver.java
More file actions
55 lines (41 loc) · 1.74 KB
/
Copy pathFlatDirLibraryResolver.java
File metadata and controls
55 lines (41 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package datadog.nativeloader;
import java.net.URL;
/**
* FlatDirLibraryResolver - uses flat directories to provide more specific libraries to load <code>
* {os}-{arch}-{libc/musl}</code>
*/
public final class FlatDirLibraryResolver implements LibraryResolver {
public static final FlatDirLibraryResolver INSTANCE = new FlatDirLibraryResolver();
private FlatDirLibraryResolver() {}
@Override
public final URL resolve(
PathLocator pathLocator, String component, PlatformSpec platformSpec, String libName)
throws Exception {
PathLocatorHelper pathLocatorHelper = new PathLocatorHelper(libName, pathLocator);
String libFileName = PathUtils.libFileName(platformSpec, libName);
String osPath = PathUtils.osPartOf(platformSpec);
String archPath = PathUtils.archPartOf(platformSpec);
String libcPath = PathUtils.libcPartOf(platformSpec);
URL url;
String regularPath = osPath + "-" + archPath;
if (libcPath != null) {
String specializedPath = regularPath + "-" + libcPath;
url = pathLocatorHelper.locate(component, specializedPath + "/" + libFileName);
if (url != null) return url;
}
url = pathLocatorHelper.locate(component, regularPath + "/" + libFileName);
if (url != null) return url;
url = pathLocatorHelper.locate(component, osPath + "/" + libFileName);
if (url != null) return url;
// fallback to searching at top-level, mostly concession to good out-of-box behavior
// with java.library.path
url = pathLocatorHelper.locate(component, libFileName);
if (url != null) return url;
if (component != null) {
url = pathLocatorHelper.locate(null, libFileName);
if (url != null) return url;
}
pathLocatorHelper.tryThrow();
return null;
}
}