Skip to content

Commit f7cb347

Browse files
authored
Merge pull request #30 from Electrostat-Lab/1.0.0-stable-branch
1.0.0 stable branch
2 parents bb00290 + 9da8878 commit f7cb347

File tree

18 files changed

+448
-253
lines changed

18 files changed

+448
-253
lines changed

snaploader-examples/src/main/java/electrostatic4j/snaploader/examples/TestBasicFeatures.java

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

3333
package electrostatic4j.snaploader.examples;
3434

35-
import java.io.IOException;
36-
3735
import electrostatic4j.snaploader.LibraryInfo;
3836
import electrostatic4j.snaploader.NativeBinaryLoader;
37+
import electrostatic4j.snaploader.filesystem.DirectoryPath;
3938
import electrostatic4j.snaploader.platform.util.DefaultDynamicLibraries;
4039
import electrostatic4j.snaploader.platform.NativeDynamicLibrary;
4140
import electrostatic4j.snaploader.platform.util.NativeVariant;
@@ -51,7 +50,7 @@
5150
public final class TestBasicFeatures {
5251

5352
protected static final LibraryInfo libraryInfo = new LibraryInfo(getJarFilePath(),
54-
"lib/placeholder",
53+
new DirectoryPath(DefaultDynamicLibraries.LINUX_X86.getPlatformDirectory()),
5554
getLibraryBaseName(),
5655
getLibrariesAbsolutePath());
5756

@@ -92,18 +91,16 @@ protected static void printDetails(NativeBinaryLoader loader) {
9291
System.out.println("--------------------------------------------------------------");
9392
}
9493

95-
protected static String getLibrariesAbsolutePath() {
96-
return PropertiesProvider.USER_DIR.getSystemProperty() +
97-
PropertiesProvider.FILE_SEPARATOR.getSystemProperty() + "libs";
94+
protected static DirectoryPath getLibrariesAbsolutePath() {
95+
return new DirectoryPath(PropertiesProvider.USER_DIR.getSystemProperty(), "libs");
9896
}
9997

100-
protected static String getJarFilePath() {
101-
return getLibrariesAbsolutePath() +
102-
PropertiesProvider.FILE_SEPARATOR.getSystemProperty() + getJarFile();
98+
protected static DirectoryPath getJarFilePath() {
99+
return new DirectoryPath(getLibrariesAbsolutePath().getPath(), getJarFile());
103100
}
104101

105102
protected static String getNativeDynamicLibraryPath() {
106-
return getLibrariesAbsolutePath() +
103+
return getLibrariesAbsolutePath().getPath() +
107104
PropertiesProvider.FILE_SEPARATOR.getSystemProperty() +
108105
"lib" + getLibraryBaseName() + ".so";
109106
}

snaploader-examples/src/main/java/electrostatic4j/snaploader/examples/TestBasicFeatures2.java

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

3333
package electrostatic4j.snaploader.examples;
3434

35-
import java.io.IOException;
3635
import java.nio.file.Path;
3736
import java.nio.file.Paths;
3837
import java.nio.file.Files;
3938
import electrostatic4j.snaploader.LibraryInfo;
4039
import electrostatic4j.snaploader.NativeBinaryLoader;
40+
import electrostatic4j.snaploader.filesystem.DirectoryPath;
4141
import electrostatic4j.snaploader.platform.util.DefaultDynamicLibraries;
4242
import electrostatic4j.snaploader.platform.NativeDynamicLibrary;
4343
import electrostatic4j.snaploader.platform.util.NativeVariant;
@@ -59,8 +59,8 @@ public static void main(String[] args) throws Exception {
5959
final Path extractionPath = Files.createDirectories(Paths.get(PropertiesProvider.USER_DIR.getSystemProperty(), "libs",
6060
NativeVariant.OS_NAME.getProperty(), NativeVariant.OS_ARCH.getProperty()));
6161

62-
final LibraryInfo libraryInfo = new LibraryInfo(compressionPath.toString(), "lib/placeholder",
63-
"jmealloc", extractionPath.toString());
62+
final LibraryInfo libraryInfo = new LibraryInfo(new DirectoryPath(compressionPath.toString()), new DirectoryPath("lib/placeholder"),
63+
"jmealloc", new DirectoryPath(extractionPath.toString()));
6464

6565
final NativeDynamicLibrary[] libraries = new NativeDynamicLibrary[] {
6666
DefaultDynamicLibraries.LINUX_X86,

snaploader-examples/src/main/java/electrostatic4j/snaploader/examples/TestFilesystemException.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import electrostatic4j.snaploader.LibraryInfo;
44
import electrostatic4j.snaploader.LoadingCriterion;
55
import electrostatic4j.snaploader.NativeBinaryLoader;
6+
import electrostatic4j.snaploader.filesystem.DirectoryPath;
67
import electrostatic4j.snaploader.platform.NativeDynamicLibrary;
78
import electrostatic4j.snaploader.platform.util.DefaultDynamicLibraries;
89
import electrostatic4j.snaploader.platform.util.NativeVariant;
@@ -20,8 +21,8 @@ public static void main(String[] args) throws Exception {
2021
final Path extractionPath = Files.createDirectories(Paths.get(PropertiesProvider.USER_DIR.getSystemProperty(), "libs",
2122
NativeVariant.OS_NAME.getProperty(), NativeVariant.OS_ARCH.getProperty()));
2223

23-
final LibraryInfo libraryInfo = new LibraryInfo(compressionPath.toString(), "lib/placeholder",
24-
"jme3alloc", extractionPath.toString());
24+
final LibraryInfo libraryInfo = new LibraryInfo(new DirectoryPath(compressionPath.toString()), new DirectoryPath("lib/placeholder"),
25+
"jme3alloc", new DirectoryPath(extractionPath.toString()));
2526

2627
final NativeDynamicLibrary[] libraries = new NativeDynamicLibrary[] {
2728
DefaultDynamicLibraries.LINUX_X86,

snaploader-examples/src/main/java/electrostatic4j/snaploader/examples/TestFilesystemMemoryLeak.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,11 @@
3535
import electrostatic4j.snaploader.filesystem.FileExtractionListener;
3636
import electrostatic4j.snaploader.filesystem.FileExtractor;
3737
import electrostatic4j.snaploader.filesystem.FileLocator;
38-
import electrostatic4j.snaploader.filesystem.ZipCompressionType;
3938
import electrostatic4j.snaploader.platform.util.PropertiesProvider;
4039
import electrostatic4j.snaploader.util.SnapLoaderLogger;
41-
42-
import java.io.IOException;
4340
import java.util.logging.Level;
4441
import java.util.logging.Logger;
42+
import java.util.zip.ZipFile;
4543

4644
/**
4745
* Testing impacts of memory leaks, test this using jconsole.
@@ -52,7 +50,7 @@ public class TestFilesystemMemoryLeak {
5250
public static void main(String[] args) throws Exception {
5351
/* Locates the image inside the Zip Compression */
5452
SnapLoaderLogger.setLoggingEnabled(true);
55-
final FileLocator fileLocator = new FileLocator(getZipAbsolutePath(), getFilePath(), ZipCompressionType.ZIP);
53+
final FileLocator fileLocator = new FileLocator(new ZipFile(getZipAbsolutePath()), getFilePath());
5654
/* Extracts the image filesystem from the Zip Compression */
5755
final FileExtractor fileExtractor = new FileExtractor(fileLocator, getExtractionPath());
5856
fileLocator.initialize(0);
@@ -79,12 +77,12 @@ public void onExtractionFinalization(FileExtractor fileExtractor, FileLocator fi
7977
}
8078

8179
protected static String getZipAbsolutePath() {
82-
return TestBasicFeatures.getLibrariesAbsolutePath() +
80+
return TestBasicFeatures.getLibrariesAbsolutePath().getPath() +
8381
PropertiesProvider.FILE_SEPARATOR.getSystemProperty() + "jmelogo700.zip";
8482
}
8583

8684
protected static String getExtractionPath() {
87-
return TestBasicFeatures.getLibrariesAbsolutePath() +
85+
return TestBasicFeatures.getLibrariesAbsolutePath().getPath() +
8886
PropertiesProvider.FILE_SEPARATOR.getSystemProperty() + getFilePath();
8987
}
9088

snaploader-examples/src/main/java/electrostatic4j/snaploader/examples/TestZipExtractor.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,14 @@
3232

3333
package electrostatic4j.snaploader.examples;
3434

35-
import java.io.IOException;
36-
3735
import electrostatic4j.snaploader.filesystem.FileExtractionListener;
3836
import electrostatic4j.snaploader.filesystem.FileExtractor;
3937
import electrostatic4j.snaploader.filesystem.FileLocator;
40-
import electrostatic4j.snaploader.filesystem.ZipCompressionType;
4138
import electrostatic4j.snaploader.platform.util.PropertiesProvider;
4239
import electrostatic4j.snaploader.throwable.FilesystemResourceScavengingException;
4340

41+
import java.util.zip.ZipFile;
42+
4443
/**
4544
* Tests extracting an image compression from a Zip compression type filesystem using {@link FileExtractor} API.
4645
*
@@ -50,7 +49,7 @@ public class TestZipExtractor {
5049

5150
public static void main(String[] args) throws Exception {
5251
/* Locates the image inside the Zip Compression */
53-
final FileLocator fileLocator = new FileLocator(getZipAbsolutePath(), getFilePath(), ZipCompressionType.ZIP);
52+
final FileLocator fileLocator = new FileLocator(new ZipFile(getZipAbsolutePath()), getFilePath());
5453
/* Extracts the image filesystem from the Zip Compression */
5554
final FileExtractor fileExtractor = new FileExtractor(fileLocator, getExtractionPath());
5655
fileLocator.initialize(0);
@@ -80,12 +79,12 @@ public void onExtractionFinalization(FileExtractor fileExtractor, FileLocator fi
8079
}
8180

8281
protected static String getZipAbsolutePath() {
83-
return TestBasicFeatures.getLibrariesAbsolutePath() +
82+
return TestBasicFeatures.getLibrariesAbsolutePath().getPath() +
8483
PropertiesProvider.FILE_SEPARATOR.getSystemProperty() + "jmelogo700.zip";
8584
}
8685

8786
protected static String getExtractionPath() {
88-
return TestBasicFeatures.getLibrariesAbsolutePath() +
87+
return TestBasicFeatures.getLibrariesAbsolutePath().getPath() +
8988
PropertiesProvider.FILE_SEPARATOR.getSystemProperty() + getFilePath();
9089
}
9190

snaploader/src/main/java/electrostatic4j/snaploader/LibraryInfo.java

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

3333
package electrostatic4j.snaploader;
3434

35+
import electrostatic4j.snaploader.filesystem.DirectoryPath;
3536
import electrostatic4j.snaploader.platform.NativeDynamicLibrary;
3637

3738
/**
@@ -59,41 +60,44 @@
5960
*/
6061
public final class LibraryInfo {
6162

62-
private String jarPath;
63-
private String directory;
63+
private DirectoryPath jarPath;
64+
private DirectoryPath directory;
6465
private String baseName;
65-
private String extractionDir;
66+
private DirectoryPath directoryPath;
6667

6768
/**
6869
* Instantiates a library info data structure pointing to a library in the classpath.
6970
*
7071
* @param directory the platform-independent directory inside the compression used for locating the native dynamic library,
7172
* this is used as a backup directory path
7273
* in case the {@link NativeDynamicLibrary#getPlatformDirectory()} is not valid.
73-
* @param baseName the library basename, for example, 'lib-basename.so'.
74-
* @param extractionDir the extraction destination in absolute string format, "null" if the current [user.dir] is
75-
* specified as the extraction directory
74+
* @param baseName the library basename, for example, 'lib-basename.so' (not null).
75+
* @param directoryPath the extraction destination path, {@link DirectoryPath#USER_DIR} for
76+
* a user working directory extraction path,
77+
* and {@link DirectoryPath#USER_HOME} for the user home (not null).
7678
*/
77-
public LibraryInfo(String directory, String baseName, String extractionDir) {
78-
this(null, directory, baseName, extractionDir);
79+
public LibraryInfo(DirectoryPath directory, String baseName, DirectoryPath directoryPath) {
80+
this(DirectoryPath.CLASS_PATH, directory, baseName, directoryPath);
7981
}
8082

8183
/**
8284
* Instantiates a library info data structure pointing to a library in an external jar with jarPath.
8385
*
84-
* @param jarPath a path to an external jar to locate the library inside, "null" to use the project jar (classpath).
86+
* @param jarPath a path to an external jar to locate the library inside, {@link DirectoryPath#CLASS_PATH} to assign the classpath routine
87+
* to the {@link electrostatic4j.snaploader.filesystem.FileLocator} API (not null).
8588
* @param directory the platform-independent directory inside the compression used for locating the native dynamic library,
8689
* this is used as a backup directory path
8790
* in case the {@link NativeDynamicLibrary#getPlatformDirectory()} is not valid.
88-
* @param baseName the library basename, for example, 'lib-basename.so'.
89-
* @param extractionDir the extraction destination in absolute string format, "null" if the current [user.dir] is
90-
* specified as the extraction directory
91+
* @param baseName the library basename, for example, 'lib-basename.so' (not null).
92+
* @param directoryPath the extraction destination path, {@link DirectoryPath#USER_DIR} for
93+
* a user working directory extraction path,
94+
* and {@link DirectoryPath#USER_HOME} for the user home (not null).
9195
*/
92-
public LibraryInfo(String jarPath, String directory, String baseName, String extractionDir) {
96+
public LibraryInfo(DirectoryPath jarPath, DirectoryPath directory, String baseName, DirectoryPath directoryPath) {
9397
this.jarPath = jarPath;
9498
this.directory = directory;
9599
this.baseName = baseName;
96-
this.extractionDir = extractionDir;
100+
this.directoryPath = directoryPath;
97101
}
98102

99103
/**
@@ -109,52 +113,48 @@ public String getBaseName() {
109113
* Retrieves the jar filesystem path, the jar is the compression used to locate the native dynamic library to
110114
* be extracted and loaded by {@link NativeBinaryLoader}.
111115
*
112-
* @return the jar absolute filesystem path in a string format, "null" if the classpath is specified instead of
113-
* an external jar compression
116+
* @return the jar absolute filesystem path object.
114117
*/
115-
public String getJarPath() {
118+
public DirectoryPath getJarPath() {
116119
return jarPath;
117120
}
118121

119122
/**
120123
* Retrieves the directory inside the compression used for locating the native dynamic library.
121124
*
122-
* @return the path to the dynamic library filesystem inside the compression, "null" if the
123-
* default variant-based directories are set to be used
125+
* @return the path to the dynamic library filesystem inside the compression.
124126
*/
125-
public String getDirectory() {
127+
public DirectoryPath getDirectory() {
126128
return directory;
127129
}
128130

129131
/**
130132
* Retrieves the extraction absolute directory.
131133
*
132-
* @return the extraction destination in absolute string format, "null" if the current [user.dir] is
133-
* specified as the extraction directory
134+
* @return the extraction destination path object.
134135
*/
135-
public String getExtractionDir() {
136-
return extractionDir;
136+
public DirectoryPath getExtractionDirectory() {
137+
return directoryPath;
137138
}
138139

139140
/**
140141
* Sets the absolute path to the jar filesystem to locate the native dynamic library to be
141142
* extracted and loaded, "null" to use the "classpath (the stock jar)"" to load the library filesystem.
142143
*
143-
* @param jarPath the absolute path to the jar filesystem to locate the library to be extracted, "null" to
144-
* use the "classpath" (aka. the stock jar)
144+
* @param jarPath the external jar path object to localize the compression, use {@link DirectoryPath#CLASS_PATH}
145+
* to switch the file locator to the classpath routine.
145146
*/
146-
public void setJarPath(String jarPath) {
147+
public void setJarPath(DirectoryPath jarPath) {
147148
this.jarPath = jarPath;
148149
}
149150

150151
/**
151152
* Sets the directory to the native dynamic library inside the jar compression, "null" to use
152153
* the default directories specified for each variant by {@link NativeBinaryLoader}.
153154
*
154-
* @param directory the location to the native dynamic library inside the jar compression, "null"
155-
* to use the default variant-based directories
155+
* @param directory the location to the native dynamic library inside the jar compression.
156156
*/
157-
public void setDirectory(String directory) {
157+
public void setDirectory(DirectoryPath directory) {
158158
this.directory = directory;
159159
}
160160

@@ -168,13 +168,12 @@ public void setBaseName(final String baseName) {
168168
}
169169

170170
/**
171-
* Sets the extraction directory used for extracting the native dynamic library in the
172-
* form of an absolute directory, "null" to use the current [user.dir].
171+
* Sets the extraction directory used for extracting the native dynamic library.
173172
*
174-
* @param extractionDir the absolute extraction directory to which the located library
175-
* will be extracted to, "null" to set the extraction to the current [user.dir]
173+
* @param directoryPath the extraction directory path to which the native-located library
174+
* will be extracted to.
176175
*/
177-
public void setExtractionDir(String extractionDir) {
178-
this.extractionDir = extractionDir;
176+
public void setExtractionDirectory(DirectoryPath directoryPath) {
177+
this.directoryPath = directoryPath;
179178
}
180179
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.io.IOException;
3636
import java.util.Arrays;
3737
import java.util.List;
38+
import java.util.jar.JarFile;
3839
import java.util.logging.Level;
3940
import java.lang.UnsatisfiedLinkError;
4041
import electrostatic4j.snaploader.filesystem.FileExtractionListener;
@@ -349,8 +350,10 @@ public void onExtractionFinalization(FileExtractor fileExtractor, FileLocator fi
349350
protected FileExtractor initializeLibraryExtractor(NativeDynamicLibrary library) throws Exception {
350351
FileExtractor extractor;
351352
if (library.getJarPath() != null) {
352-
extractor = new LibraryExtractor(library.getJarPath(), library.getCompressedLibrary(), library.getExtractedLibrary());
353+
// use an extractor with the external jar routine
354+
extractor = new LibraryExtractor(new JarFile(library.getJarPath()), library.getCompressedLibrary(), library.getExtractedLibrary());
353355
} else {
356+
// use an extractor with the classpath routine
354357
extractor = new LibraryExtractor(library.getCompressedLibrary(), library.getExtractedLibrary());
355358
}
356359
extractor.initialize(0);
@@ -363,7 +366,7 @@ protected LibraryLocator preInitLibraryLocator(FileExtractor extractor) {
363366
extractor.getFileLocator().setFileLocalizingListener(new FileLocalizingListener() {
364367
@Override
365368
public void onFileLocalizationSuccess(FileLocator locator) {
366-
SnapLoaderLogger.log(Level.INFO, getClass().getName(), "initializeLibraryExtractor",
369+
SnapLoaderLogger.log(Level.INFO, getClass().getName(), "preInitLibraryLocator",
367370
"Locating native libraries has succeeded!");
368371

369372
// bind the library locator lifecycle to the user application
@@ -374,7 +377,7 @@ public void onFileLocalizationSuccess(FileLocator locator) {
374377

375378
@Override
376379
public void onFileLocalizationFailure(FileLocator locator, Throwable throwable) {
377-
SnapLoaderLogger.log(Level.SEVERE, getClass().getName(), "initializeLibraryExtractor",
380+
SnapLoaderLogger.log(Level.SEVERE, getClass().getName(), "preInitLibraryLocator",
378381
"Locating native libraries has failed!", throwable);
379382
try {
380383
extractor.close();

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232

3333
package electrostatic4j.snaploader.filesystem;
3434

35-
import java.io.FileNotFoundException;
3635
import java.io.IOException;
3736
import java.util.concurrent.locks.ReentrantLock;
3837

@@ -53,9 +52,8 @@ public class ConcurrentFileExtractor extends FileExtractor {
5352
*
5453
* @param fileLocator locates a filesystem inside a zip compression
5554
* @param destination an absolute filesystem path representing the extraction destination filesystem
56-
* @throws FileNotFoundException if the destination filesystem path is not found
5755
*/
58-
public ConcurrentFileExtractor(FileLocator fileLocator, String destination) throws FileNotFoundException {
56+
public ConcurrentFileExtractor(FileLocator fileLocator, String destination) {
5957
super(fileLocator, destination);
6058
}
6159

0 commit comments

Comments
 (0)