Skip to content

Commit c88c252

Browse files
author
pavl-x86-machine
committed
snaploader-examples: TestCrossPlatformClassPathLoading test case for loading from classpath
1 parent 8c99611 commit c88c252

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright (c) 2023-2025, The Electrostatic-Sandbox Distributed Simulation Framework, jSnapLoader
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are
7+
* met:
8+
*
9+
* * Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
*
12+
* * Redistributions in binary form must reproduce the above copyright
13+
* notice, this list of conditions and the following disclaimer in the
14+
* documentation and/or other materials provided with the distribution.
15+
*
16+
* * Neither the name of 'Electrostatic-Sandbox' nor the names of its contributors
17+
* may be used to endorse or promote products derived from this software
18+
* without specific prior written permission.
19+
*
20+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22+
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
*/
32+
33+
package electrostatic4j.snaploader.examples;
34+
35+
import electrostatic4j.snaploader.LibraryInfo;
36+
import electrostatic4j.snaploader.LoadingCriterion;
37+
import electrostatic4j.snaploader.NativeBinaryLoader;
38+
import electrostatic4j.snaploader.filesystem.DirectoryPath;
39+
import electrostatic4j.snaploader.platform.NativeDynamicLibrary;
40+
import electrostatic4j.snaploader.platform.util.DefaultDynamicLibraries;
41+
import electrostatic4j.snaploader.platform.util.NativeVariant;
42+
import electrostatic4j.snaploader.platform.util.PlatformPredicate;
43+
44+
/**
45+
* Examines the cross-platform capabilities of jSnapLoader.
46+
*
47+
* @author pavl_g.
48+
*/
49+
public class TestCrossPlatformClassPathLoading {
50+
public static void main(String[] args) throws Exception {
51+
52+
final LibraryInfo libraryInfo = new LibraryInfo(new DirectoryPath("lib/independent"), "jmealloc", DirectoryPath.USER_DIR);
53+
54+
final NativeDynamicLibrary[] libraries = new NativeDynamicLibrary[] {
55+
DefaultDynamicLibraries.ANDROID_ALL,
56+
DefaultDynamicLibraries.LINUX_X86,
57+
DefaultDynamicLibraries.LINUX_X86_64,
58+
new NativeDynamicLibrary("lib/windows/x86", "libjmealloc.dll", PlatformPredicate.WIN_X86),
59+
new NativeDynamicLibrary("lib/windows/x86-64", "libjmealloc.dll", PlatformPredicate.WIN_X86_64),
60+
DefaultDynamicLibraries.MAC_X86,
61+
DefaultDynamicLibraries.MAC_X86_64,
62+
};
63+
64+
final NativeBinaryLoader loader = new NativeBinaryLoader(libraryInfo);
65+
66+
loader.registerNativeLibraries(libraries).initPlatformLibrary();
67+
loader.setLoggingEnabled(true);
68+
loader.setRetryWithCleanExtraction(true);
69+
/* Native dynamic library properties */
70+
printDetails(loader);
71+
loader.loadLibrary(LoadingCriterion.INCREMENTAL_LOADING);
72+
}
73+
74+
public static void printDetails(NativeBinaryLoader loader) {
75+
System.out.println("--------------------------------------------------------------");
76+
System.out.println("OS: " + NativeVariant.OS_NAME.getProperty());
77+
System.out.println("ARCH: " + NativeVariant.OS_ARCH.getProperty());
78+
System.out.println("VM: " + NativeVariant.JVM.getProperty());
79+
System.out.println("--------------------------------------------------------------");
80+
System.out.println("Jar Path: " + loader.getNativeDynamicLibrary().getJarPath());
81+
System.out.println("Library Directory: " + loader.getNativeDynamicLibrary().getPlatformDirectory());
82+
System.out.println("Compressed library path: " + loader.getNativeDynamicLibrary().getCompressedLibrary());
83+
System.out.println("Extracted library absolute path: " + loader.getNativeDynamicLibrary().getExtractedLibrary());
84+
System.out.println("Is Extracted: " + loader.getNativeDynamicLibrary().isExtracted());
85+
System.out.println("--------------------------------------------------------------");
86+
}
87+
}

0 commit comments

Comments
 (0)