27package jau.test.pkg.cache;
30import java.io.IOException;
31import java.lang.reflect.Method;
32import java.net.URISyntaxException;
34import java.net.URLClassLoader;
35import java.util.jar.JarFile;
37import org.jau.io.IOUtil;
38import org.jau.lang.ReflectionUtil;
39import org.jau.net.Uri;
40import org.jau.pkg.JarUtil;
41import org.jau.pkg.cache.TempCacheReg;
42import org.jau.pkg.cache.TempFileCache;
43import org.jau.pkg.cache.TempJarCache;
44import org.jau.sys.AndroidVersion;
45import org.jau.sys.JNILibrary;
46import org.jau.sys.RuntimeProps;
47import org.junit.Assert;
48import org.junit.BeforeClass;
49import org.junit.FixMethodOrder;
51import org.junit.runners.MethodSorters;
53import jau.test.junit.util.JunitTracer;
54import jau.test.net.URIDumpUtil;
56@FixMethodOrder(MethodSorters.NAME_ASCENDING)
60 static class TestClassLoader
extends URLClassLoader {
61 public TestClassLoader(
final URL[] urls) {
64 public TestClassLoader(
final URL[] urls,
final ClassLoader parent) {
69 static void assertTempFileCachesIndividualInstances(
final boolean shallBeSame,
final TempFileCache fileCache2,
final TempFileCache fileCache3) {
70 Assert.assertTrue(fileCache2.
getTempDir().exists());
71 Assert.assertTrue(fileCache2.
getTempDir().isDirectory());
72 Assert.assertTrue(fileCache3.
getTempDir().exists());
73 Assert.assertTrue(fileCache3.
getTempDir().isDirectory());
79 Assert.assertTrue(
"file caches are not equal", fileCache2.
getTempDir().equals(fileCache3.
getTempDir()));
81 Assert.assertFalse(
"file caches are equal", fileCache2.
getTempDir().equals(fileCache3.
getTempDir()));
85 final ClassLoader cl = fileCache2.getClass().getClassLoader();
86 assertTempFileCachesIndividualInstances(shallBeSame, fileCache2, cl, fileCache3, cl);
89 static void assertTempFileCachesIndividualInstances(
final boolean shallBeSame,
final Object fileCache2,
final ClassLoader cl2,
final Object fileCache3,
final ClassLoader cl3) {
97 Assert.assertEquals(baseDir2, baseDir3);
103 Assert.assertEquals(rootDir2, rootDir3);
111 Assert.assertTrue(
"file caches are not equal", tempDir2.equals(tempDir3));
113 Assert.assertFalse(
"file caches are equal", tempDir2.equals(tempDir3));
125 Assert.assertTrue(fileCache.
isValid(
false));
126 System.err.println(
"tmp dir: "+fileCache.
getTempDir());
131 Assert.assertTrue(fileCache.
getTempDir().exists());
132 Assert.assertTrue(fileCache.
getTempDir().isDirectory());
140 assertTempFileCachesIndividualInstances(
false, fileCache2, fileCache3);
144 public void testJarUtil01a() throws IOException, IllegalArgumentException, URISyntaxException {
147 Assert.assertNotNull(jarFile);
149 File f =
new File(fileCache.
getTempDir(),
"META-INF/MANIFEST.MF");
150 Assert.assertTrue(f.exists());
152 Assert.assertTrue(f.exists());
158 File f =
new File(fileCache.
getTempDir(),
"META-INF/MANIFEST.MF");
159 Assert.assertTrue(f.exists());
161 Assert.assertTrue(f.exists());
178 final ClassLoader cl = getClass().getClassLoader();
182 Assert.assertTrue(f0.exists());
185 Assert.assertTrue(f1.exists());
186 Assert.assertEquals(f0, f1);
189 Assert.assertTrue(f0.exists());
192 Assert.assertTrue(f1.exists());
193 Assert.assertEquals(f0, f1);
200 final Uri.Encoded nativeJarName =
Uri.
Encoded.
cast(
"jaulib-fat.jar");
201 final String libBaseName =
"jaulib_jni_jni";
202 final ClassLoader cl = getClass().getClassLoader();
205 Assert.assertNotNull(jarUri);
206 System.err.println(
"1 - jarUri:");
210 Assert.assertNotNull(jarFileUri);
211 System.err.println(
"2 - jarFileUri:");
215 Assert.assertNotNull(jarFileDir);
216 System.err.println(
"3 - jarFileDir:");
220 System.err.println(
"4 - nativeJarURI:");
225 Assert.assertNotNull(libFullPath);
227 final File f =
new File(libFullPath);
228 Assert.assertTrue(f.exists());
235 final ClassLoader cl = getClass().getClassLoader();
238 assertTempFileCachesIndividualInstances(
true, fileCache2, fileCache3);
245 System.err.println(
"url: "+urls[0]);
246 final ClassLoader cl2 =
new TestClassLoader(urls,
null);
247 final ClassLoader cl3 =
new TestClassLoader(urls,
null);
265 assertTempFileCachesIndividualInstances(
false, fileCache2, cl2, fileCache3, cl3);
268 public static void main(
final String args[])
throws IOException {
270 org.junit.runner.JUnitCore.
main(tstname);
static void showUri(final Uri uri)
void testTempJarCache00Init()
void testTempJarCache04bDiffClassLoader()
void testTempFileCache01FileExist()
void testTempJarCache01LoadAllTestManifestAndClass()
void testTempJarCache04aSameClassLoader()
static void main(final String args[])
void testTempFileCache02Instances()
void testTempJarCache02AddNativeLibs()
static String getClassFileName(final String clazzBinName)
Utility methods to simplify reflection access.
static final< R > R callStaticMethod(final Method method, final Object ... args)
static final Class<?> getClass(final String clazzName, final boolean initializeClazz, final ClassLoader cl)
Loads and returns the class or null.
static final< R > R callMethod(final Object instance, final Method method, final Object ... args)
static final Method getMethod(final Class<?> clazz, final String methodName, final Class<?> ... argTypes)
Immutable RFC3986 encoded string.
static Encoded cast(final String encoded)
Casts the given encoded String by creating a new Encoded instance.
This class implements an immutable Uri as defined by RFC 2396.
final Uri getParent()
Returns this Uri's parent directory Uri.
final java.net.URL toURL()
Returns a new URL instance using the encoded input string, new URL(uri.input), i.e.
final Uri getContainedUri()
If this instance's schemeSpecificPart contains a Uri itself, a sub-Uri, return schemeSpecificPart + #...
static Uri getJarFileUri(final String clazzBinName, final ClassLoader cl)
The Class's "com.jogamp.common.GlueGenVersion" Uri jar:sub_protocol:/some/path/gluegen-rt....
static Uri getJarUri(final String clazzBinName, final ClassLoader cl)
The Class's "com.jogamp.common.GlueGenVersion" Uri jar:sub_protocol:/some/path/gluegen-rt....
static JarFile getJarFile(final String clazzBinName, final ClassLoader cl)
static final int extract(final File dest, final Map< String, String > nativeLibMap, final JarFile jarFile, final String nativeLibraryPath, final boolean extractNativeLibraries, final boolean extractClassFiles, final boolean extractOtherFiles)
Extract the files of the given jar file.
static boolean isTempJarCacheUsed(final boolean forExecutables)
static boolean isTempFileCacheUsed()
File getTempDir()
Temporary directory for individual files (eg.
static File getRootDir()
Root temp directory for this JVM instance.
boolean isValid(final boolean forExecutables)
static File getBaseDir()
Base temp directory used by TempFileCache.
static boolean initSingleton()
Documented way to kick off static initialization.
Static Jar file cache handler using an underlying instance of TempFileCache, see getTempFileCache().
static boolean isInitialized(final boolean forExecutables)
static synchronized final void addAll(final Class<?> certClass, final Uri jarUri)
Adds all types, native libraries, class files and other files (resources) if not yet added.
static synchronized final String findResource(final String name)
TODO class access pending needs Classloader.defineClass(..) access, ie.
static synchronized final boolean addNativeLibs(final Class<?> certClass, final Uri jarUri, final String nativeLibraryPath)
Adds native libraries, if not yet added.
static boolean initSingleton()
Documented way to kick off static initialization.
static synchronized final String findLibrary(final String libName)
If isInitialized(true) is false due to lack of executable support only, this method always returns fa...
static TempFileCache getTempFileCache()
static final boolean isAvailable
Static JNI Native Libraries handler.
static final String isValidNativeLibraryName(final String libName, final boolean isLowerCaseAlready)
Comparison of prefix and suffix of the given libName's basename is performed case insensitive
Runtime platform properties derived from PlatformProps and runtime query.