Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import electrostatic4j.snaploader.platform.NativeDynamicLibrary;
import electrostatic4j.snaploader.platform.util.NativeVariant;
import electrostatic4j.snaploader.platform.util.PlatformPredicate;
import electrostatic4j.snaploader.platform.util.PropertiesProvider;
import electrostatic4j.snaploader.platform.util.DefaultPropertiesProvider;
import electrostatic4j.snaploader.LoadingCriterion;

/**
Expand Down Expand Up @@ -92,7 +92,7 @@ protected static void printDetails(NativeBinaryLoader loader) {
}

protected static DirectoryPath getLibrariesAbsolutePath() {
return new DirectoryPath(PropertiesProvider.USER_DIR.getSystemProperty(), "libs");
return new DirectoryPath(DefaultPropertiesProvider.USER_DIR.getSystemProperty(), "libs");
}

protected static DirectoryPath getJarFilePath() {
Expand All @@ -101,7 +101,7 @@ protected static DirectoryPath getJarFilePath() {

protected static String getNativeDynamicLibraryPath() {
return getLibrariesAbsolutePath().getPath() +
PropertiesProvider.FILE_SEPARATOR.getSystemProperty() +
DefaultPropertiesProvider.FILE_SEPARATOR.getSystemProperty() +
"lib" + getLibraryBaseName() + ".so";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import electrostatic4j.snaploader.platform.NativeDynamicLibrary;
import electrostatic4j.snaploader.platform.util.NativeVariant;
import electrostatic4j.snaploader.platform.util.PlatformPredicate;
import electrostatic4j.snaploader.platform.util.PropertiesProvider;
import electrostatic4j.snaploader.platform.util.DefaultPropertiesProvider;
import electrostatic4j.snaploader.LoadingCriterion;

/**
Expand All @@ -55,8 +55,8 @@ public final class TestBasicFeatures2 {

public static void main(String[] args) throws Exception {

final Path compressionPath = Paths.get(PropertiesProvider.USER_DIR.getSystemProperty(), "libs", TestBasicFeatures.getJarFile());
final Path extractionPath = Files.createDirectories(Paths.get(PropertiesProvider.USER_DIR.getSystemProperty(), "libs",
final Path compressionPath = Paths.get(DefaultPropertiesProvider.USER_DIR.getSystemProperty(), "libs", TestBasicFeatures.getJarFile());
final Path extractionPath = Files.createDirectories(Paths.get(DefaultPropertiesProvider.USER_DIR.getSystemProperty(), "libs",
NativeVariant.OS_NAME.getProperty(), NativeVariant.OS_ARCH.getProperty()));

final LibraryInfo libraryInfo = new LibraryInfo(new DirectoryPath(compressionPath.toString()), new DirectoryPath("lib/placeholder"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@
import electrostatic4j.snaploader.platform.util.DefaultDynamicLibraries;
import electrostatic4j.snaploader.platform.util.NativeVariant;
import electrostatic4j.snaploader.platform.util.PlatformPredicate;
import electrostatic4j.snaploader.platform.util.PropertiesProvider;
import electrostatic4j.snaploader.platform.util.DefaultPropertiesProvider;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public final class TestFilesystemException {
public static void main(String[] args) throws Exception {
final Path compressionPath = Paths.get(PropertiesProvider.USER_DIR.getSystemProperty(), "libs", TestBasicFeatures.getJarFile());
final Path extractionPath = Files.createDirectories(Paths.get(PropertiesProvider.USER_DIR.getSystemProperty(), "libs",
final Path compressionPath = Paths.get(DefaultPropertiesProvider.USER_DIR.getSystemProperty(), "libs", TestBasicFeatures.getJarFile());
final Path extractionPath = Files.createDirectories(Paths.get(DefaultPropertiesProvider.USER_DIR.getSystemProperty(), "libs",
NativeVariant.OS_NAME.getProperty(), NativeVariant.OS_ARCH.getProperty()));

final LibraryInfo libraryInfo = new LibraryInfo(new DirectoryPath(compressionPath.toString()), new DirectoryPath("lib/placeholder"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import electrostatic4j.snaploader.filesystem.FileExtractionListener;
import electrostatic4j.snaploader.filesystem.FileExtractor;
import electrostatic4j.snaploader.filesystem.FileLocator;
import electrostatic4j.snaploader.platform.util.PropertiesProvider;
import electrostatic4j.snaploader.platform.util.DefaultPropertiesProvider;
import electrostatic4j.snaploader.util.SnapLoaderLogger;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -78,12 +78,12 @@ public void onExtractionFinalization(FileExtractor fileExtractor, FileLocator fi

protected static String getZipAbsolutePath() {
return TestBasicFeatures.getLibrariesAbsolutePath().getPath() +
PropertiesProvider.FILE_SEPARATOR.getSystemProperty() + "jmelogo700.zip";
DefaultPropertiesProvider.FILE_SEPARATOR.getSystemProperty() + "jmelogo700.zip";
}

protected static String getExtractionPath() {
return TestBasicFeatures.getLibrariesAbsolutePath().getPath() +
PropertiesProvider.FILE_SEPARATOR.getSystemProperty() + getFilePath();
DefaultPropertiesProvider.FILE_SEPARATOR.getSystemProperty() + getFilePath();
}

protected static String getFilePath() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public final class TestNativeDllLoader {
public static void main(String[] args) throws Exception {
final NativeDynamicLibrary[] baseLibs = new NativeDynamicLibrary[] {
DefaultDynamicLibraries.ANDROID_ALL,
new NativeDynamicLibrary("linux/x86-64/com/github/stephengoldd", PlatformPredicate.LINUX_X86_64),
new NativeDynamicLibrary("windows/x86-64/com/github/stephengoldd", PlatformPredicate.WIN_X86_64),
new NativeDynamicLibrary("linux/x86-64/com/github/stephengold", PlatformPredicate.LINUX_X86_64),
new NativeDynamicLibrary("windows/x86-64/com/github/stephengold", PlatformPredicate.WIN_X86_64),
};

final NativeDynamicLibrary[] cpuEnhancedLibs = new NativeDynamicLibrary[]{
Expand All @@ -24,7 +24,7 @@ public static void main(String[] args) throws Exception {
"avx", "avx2", "sse4_1", "sse4_2")),
};
final LibraryInfo info = new LibraryInfo(new DirectoryPath("linux/x86-64/com/github/stephengold"),
"joltjnid", DirectoryPath.USER_DIR);
"joltjni", DirectoryPath.USER_DIR);
final NativeDllLoader nativeDllLoader = new NativeDllLoader(baseLibs, cpuEnhancedLibs, info, true, true);
nativeDllLoader.loadCpuEnhancedLibs(LoadingCriterion.INCREMENTAL_LOADING);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import electrostatic4j.snaploader.platform.util.DefaultDynamicLibraries;
import electrostatic4j.snaploader.platform.util.NativeVariant;
import electrostatic4j.snaploader.platform.util.PlatformPredicate;
import electrostatic4j.snaploader.platform.util.PropertiesProvider;
import electrostatic4j.snaploader.platform.util.DefaultPropertiesProvider;

/**
* Tests retry exhaustion on a broken library.
Expand All @@ -53,8 +53,8 @@
public class TestRetryExhaustionException {
public static void main(String[] args) throws Exception {

final Path compressionPath = Paths.get(PropertiesProvider.USER_DIR.getSystemProperty(), "libs", "corrupted-lib.jar");
final Path extractionPath = Files.createDirectories(Paths.get(PropertiesProvider.USER_DIR.getSystemProperty(), "libs",
final Path compressionPath = Paths.get(DefaultPropertiesProvider.USER_DIR.getSystemProperty(), "libs", "corrupted-lib.jar");
final Path extractionPath = Files.createDirectories(Paths.get(DefaultPropertiesProvider.USER_DIR.getSystemProperty(), "libs",
NativeVariant.OS_NAME.getProperty(), NativeVariant.OS_ARCH.getProperty()));

final LibraryInfo libraryInfo = new LibraryInfo(new DirectoryPath(compressionPath.toString()), new DirectoryPath("lib/placeholder"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import electrostatic4j.snaploader.filesystem.FileExtractionListener;
import electrostatic4j.snaploader.filesystem.FileExtractor;
import electrostatic4j.snaploader.filesystem.FileLocator;
import electrostatic4j.snaploader.platform.util.PropertiesProvider;
import electrostatic4j.snaploader.platform.util.DefaultPropertiesProvider;
import electrostatic4j.snaploader.throwable.FilesystemResourceScavengingException;

import java.util.zip.ZipFile;
Expand Down Expand Up @@ -80,12 +80,12 @@ public void onExtractionFinalization(FileExtractor fileExtractor, FileLocator fi

protected static String getZipAbsolutePath() {
return TestBasicFeatures.getLibrariesAbsolutePath().getPath() +
PropertiesProvider.FILE_SEPARATOR.getSystemProperty() + "jmelogo700.zip";
DefaultPropertiesProvider.FILE_SEPARATOR.getSystemProperty() + "jmelogo700.zip";
}

protected static String getExtractionPath() {
return TestBasicFeatures.getLibrariesAbsolutePath().getPath() +
PropertiesProvider.FILE_SEPARATOR.getSystemProperty() + getFilePath();
DefaultPropertiesProvider.FILE_SEPARATOR.getSystemProperty() + getFilePath();
}

protected static String getFilePath() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,4 +348,13 @@ protected void signalImminentFailure(CallingStackMetaData callingStackMetaData)
// signal an imminent failure and crash the application
Runtime.getRuntime().exit(-callingStackMetaData.getErrorCause().hashCode());
}

/**
* Retrieves the associated native binary loader object.
*
* @return a native binary loader object that is associated wtih this object.
*/
public NativeBinaryLoader getLoader() {
return loader;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@

package electrostatic4j.snaploader;

import java.io.File;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.util.Arrays;
import java.util.List;
import java.util.jar.JarFile;
Expand All @@ -45,6 +47,8 @@
import electrostatic4j.snaploader.library.LibraryLocator;
import electrostatic4j.snaploader.platform.NativeDynamicLibrary;
import electrostatic4j.snaploader.platform.util.NativeVariant;
import electrostatic4j.snaploader.platform.util.PropertiesControllerNamespace;
import electrostatic4j.snaploader.platform.util.PropertiesController;
import electrostatic4j.snaploader.throwable.LoadingRetryExhaustionException;
import electrostatic4j.snaploader.throwable.UnSupportedSystemError;
import electrostatic4j.snaploader.util.CallingStackMetaData;
Expand Down Expand Up @@ -89,11 +93,15 @@

protected int numberOfLoadingFailure = 0;

private LoadingCriterion loadingCriterion; // cache the loading criterion for system controller use

Check warning on line 96 in snaploader/src/main/java/electrostatic4j/snaploader/NativeBinaryLoader.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

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

Avoid unused private fields such as 'loadingCriterion'.

/**
* Instantiates a native dynamic library loader to extract and load a system-specific native dynamic library.
*/
public NativeBinaryLoader(final LibraryInfo libraryInfo) {
this.libraryInfo = libraryInfo;
// initialize the system controller object
PropertiesControllerNamespace.systemDirectoryController.initialize();
}

/**
Expand Down Expand Up @@ -176,14 +184,17 @@
}
// commands and loads the library from the system directories
if (NativeVariant.Os.isAndroid() || criterion == LoadingCriterion.SYSTEM_LOAD) {
loadSystemBinary();
loadSystemBinary(nativeDynamicLibrary);
loadingCriterion = LoadingCriterion.SYSTEM_LOAD;
return this;
}
if (criterion == LoadingCriterion.INCREMENTAL_LOADING && nativeDynamicLibrary.isExtracted()) {
loadBinary(nativeDynamicLibrary, criterion);
loadingCriterion = LoadingCriterion.INCREMENTAL_LOADING;
return this;
}
cleanExtractBinary(nativeDynamicLibrary);
loadingCriterion = LoadingCriterion.CLEAN_EXTRACTION;
return this;
}

Expand All @@ -196,6 +207,10 @@
return nativeDynamicLibrary;
}

public PropertiesController getSystemDirectoryController() {
return PropertiesControllerNamespace.systemDirectoryController;
}

/**
* Enables the logging for this object, default value is false.
*
Expand Down Expand Up @@ -271,12 +286,27 @@
}

/**
* Loads a native binary from the system directories into the process virtual
* Loads a native binary from the customized system directories into the process virtual
* address space using the library basename in a platform-dependent way.
*/
protected void loadSystemBinary() {
protected void loadSystemBinary(NativeDynamicLibrary dynamicLibrary) {
SnapLoaderLogger.log(Level.INFO, getClass().getName(), "loadSystemBinary", "Loading library from the system: "
+ Arrays.toString(PropertiesControllerNamespace.systemDirectoryController.toList()));
try {
System.loadLibrary(libraryInfo.getBaseName());
// use custom system directories for desktop ONLY!
if (NativeVariant.Os.isDesktop()) {
PropertiesControllerNamespace.systemDirectoryController.iterate(path -> {
final File lib = new File(FileSystems.getDefault()
.getPath(path.toString(),
dynamicLibrary.getLibraryFile()).toString());
if (lib.exists()) {
System.load(lib.getAbsolutePath());
}
return "";
});
} else {
System.loadLibrary(libraryInfo.getBaseName());
}
SnapLoaderLogger.log(Level.INFO, getClass().getName(), "loadSystemBinary", "Successfully loaded library from the system: "
+ libraryInfo.getBaseName());
if (nativeBinaryLoadingListener != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

package electrostatic4j.snaploader.filesystem;

import electrostatic4j.snaploader.platform.util.PropertiesProvider;
import electrostatic4j.snaploader.platform.util.DefaultPropertiesProvider;

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

/**
* An alias object for the root user home directory absolute path.
*/
public static final DirectoryPath USER_HOME =
new DirectoryPath(PropertiesProvider.USER_HOME.getSystemProperty());
new DirectoryPath(DefaultPropertiesProvider.USER_HOME.getSystemProperty());

/**
* When combined with the
Expand Down Expand Up @@ -85,7 +85,7 @@ public DirectoryPath(final String root, final String... entries) {
if (entry == null) {
continue;
}
path = getPath() + PropertiesProvider.FILE_SEPARATOR.getSystemProperty() + entry;
path = getPath() + DefaultPropertiesProvider.FILE_SEPARATOR.getSystemProperty() + entry;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import electrostatic4j.snaploader.filesystem.DirectoryPath;
import electrostatic4j.snaploader.platform.util.NativeVariant;
import electrostatic4j.snaploader.platform.util.PlatformPredicate;
import electrostatic4j.snaploader.platform.util.PropertiesProvider;
import electrostatic4j.snaploader.platform.util.DefaultPropertiesProvider;

/**
* Represents a filesystem to a platform-specific binary inside
Expand Down Expand Up @@ -170,7 +170,7 @@ public String getPlatformDirectory() {
* @return a string representing the library path within the jar compression
*/
public String getCompressedLibrary() {
return platformDirectory + PropertiesProvider.ZIP_FILE_SEPARATOR.getSystemProperty() + libraryFile;
return platformDirectory + DefaultPropertiesProvider.ZIP_FILE_SEPARATOR.getSystemProperty() + libraryFile;
}

/**
Expand All @@ -180,7 +180,11 @@ public String getCompressedLibrary() {
*/
public String getExtractedLibrary() {
return directoryPath.getPath()
+ PropertiesProvider.FILE_SEPARATOR.getSystemProperty() + libraryFile;
+ DefaultPropertiesProvider.FILE_SEPARATOR.getSystemProperty() + libraryFile;
}

public String getLibraryFile() {
return libraryFile;
}

/**
Expand Down
Loading