Skip to content

Commit bbb3564

Browse files
committed
Applied API changes
1 parent 253728a commit bbb3564

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

snaploader/src/main/java/electrostatic4j/snaploader/NativeBinaryLoader.java

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232

3333
package electrostatic4j.snaploader;
3434

35+
import java.io.File;
3536
import java.io.IOException;
37+
import java.nio.file.FileSystems;
3638
import java.util.Arrays;
3739
import java.util.List;
3840
import java.util.jar.JarFile;
@@ -45,6 +47,8 @@
4547
import electrostatic4j.snaploader.library.LibraryLocator;
4648
import electrostatic4j.snaploader.platform.NativeDynamicLibrary;
4749
import electrostatic4j.snaploader.platform.util.NativeVariant;
50+
import electrostatic4j.snaploader.platform.util.PropertiesControllerNamespace;
51+
import electrostatic4j.snaploader.platform.util.PropertiesController;
4852
import electrostatic4j.snaploader.throwable.LoadingRetryExhaustionException;
4953
import electrostatic4j.snaploader.throwable.UnSupportedSystemError;
5054
import electrostatic4j.snaploader.util.CallingStackMetaData;
@@ -89,11 +93,15 @@ public class NativeBinaryLoader {
8993

9094
protected int numberOfLoadingFailure = 0;
9195

96+
private LoadingCriterion loadingCriterion; // cache the loading criterion for system controller use
97+
9298
/**
9399
* Instantiates a native dynamic library loader to extract and load a system-specific native dynamic library.
94100
*/
95101
public NativeBinaryLoader(final LibraryInfo libraryInfo) {
96102
this.libraryInfo = libraryInfo;
103+
// initialize the system controller object
104+
PropertiesControllerNamespace.systemDirectoryController.initialize();
97105
}
98106

99107
/**
@@ -176,14 +184,17 @@ public NativeBinaryLoader loadLibrary(LoadingCriterion criterion) throws Excepti
176184
}
177185
// commands and loads the library from the system directories
178186
if (NativeVariant.Os.isAndroid() || criterion == LoadingCriterion.SYSTEM_LOAD) {
179-
loadSystemBinary();
187+
loadSystemBinary(nativeDynamicLibrary);
188+
loadingCriterion = LoadingCriterion.SYSTEM_LOAD;
180189
return this;
181190
}
182191
if (criterion == LoadingCriterion.INCREMENTAL_LOADING && nativeDynamicLibrary.isExtracted()) {
183192
loadBinary(nativeDynamicLibrary, criterion);
193+
loadingCriterion = LoadingCriterion.INCREMENTAL_LOADING;
184194
return this;
185195
}
186196
cleanExtractBinary(nativeDynamicLibrary);
197+
loadingCriterion = LoadingCriterion.CLEAN_EXTRACTION;
187198
return this;
188199
}
189200

@@ -196,6 +207,10 @@ public NativeDynamicLibrary getNativeDynamicLibrary() {
196207
return nativeDynamicLibrary;
197208
}
198209

210+
public PropertiesController getSystemDirectoryController() {
211+
return PropertiesControllerNamespace.systemDirectoryController;
212+
}
213+
199214
/**
200215
* Enables the logging for this object, default value is false.
201216
*
@@ -271,12 +286,27 @@ public NativeBinaryLoader setMaxNumberOfLoadingFailure(int maxNumberOfLoadingFai
271286
}
272287

273288
/**
274-
* Loads a native binary from the system directories into the process virtual
289+
* Loads a native binary from the customized system directories into the process virtual
275290
* address space using the library basename in a platform-dependent way.
276291
*/
277-
protected void loadSystemBinary() {
292+
protected void loadSystemBinary(NativeDynamicLibrary dynamicLibrary) {
293+
SnapLoaderLogger.log(Level.INFO, getClass().getName(), "loadSystemBinary", "Loading library from the system: "
294+
+ Arrays.toString(PropertiesControllerNamespace.systemDirectoryController.toList()));
278295
try {
279-
System.loadLibrary(libraryInfo.getBaseName());
296+
// use custom system directories for desktop ONLY!
297+
if (NativeVariant.Os.isDesktop()) {
298+
PropertiesControllerNamespace.systemDirectoryController.iterate(path -> {
299+
final File lib = new File(FileSystems.getDefault()
300+
.getPath(path.toString(),
301+
dynamicLibrary.getLibraryFile()).toString());
302+
if (lib.exists()) {
303+
System.load(lib.getAbsolutePath());
304+
}
305+
return "";
306+
});
307+
} else {
308+
System.loadLibrary(libraryInfo.getBaseName());
309+
}
280310
SnapLoaderLogger.log(Level.INFO, getClass().getName(), "loadSystemBinary", "Successfully loaded library from the system: "
281311
+ libraryInfo.getBaseName());
282312
if (nativeBinaryLoadingListener != null) {

snaploader/src/main/java/electrostatic4j/snaploader/filesystem/DirectoryPath.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
package electrostatic4j.snaploader.filesystem;
3434

35-
import electrostatic4j.snaploader.platform.util.PropertiesProvider;
35+
import electrostatic4j.snaploader.platform.util.DefaultPropertiesProvider;
3636

3737
/**
3838
* A class denotes and provides a directory absolute path.
@@ -45,13 +45,13 @@ public final class DirectoryPath {
4545
* An alias object for the current working directory absolute path.
4646
*/
4747
public static final DirectoryPath USER_DIR =
48-
new DirectoryPath(PropertiesProvider.USER_DIR.getSystemProperty());
48+
new DirectoryPath(DefaultPropertiesProvider.USER_DIR.getSystemProperty());
4949

5050
/**
5151
* An alias object for the root user home directory absolute path.
5252
*/
5353
public static final DirectoryPath USER_HOME =
54-
new DirectoryPath(PropertiesProvider.USER_HOME.getSystemProperty());
54+
new DirectoryPath(DefaultPropertiesProvider.USER_HOME.getSystemProperty());
5555

5656
/**
5757
* When combined with the
@@ -85,7 +85,7 @@ public DirectoryPath(final String root, final String... entries) {
8585
if (entry == null) {
8686
continue;
8787
}
88-
path = getPath() + PropertiesProvider.FILE_SEPARATOR.getSystemProperty() + entry;
88+
path = getPath() + DefaultPropertiesProvider.FILE_SEPARATOR.getSystemProperty() + entry;
8989
}
9090
}
9191

0 commit comments

Comments
 (0)