43 private static final String nativeJarTagPackage =
"jau.nativetag";
56 private static final boolean addNativeJarLibsImpl(
final Class<?> classFromJavaJar,
final Uri classJarUri,
58 throws IOException, SecurityException, URISyntaxException
61 final StringBuilder msg =
new StringBuilder();
69 System.err.println(msg.toString());
71 final long t0 =
PERF ? System.currentTimeMillis() : 0;
76 if (
null == jarSubURI) {
77 throw new IllegalArgumentException(
"JarSubURI is null of: "+classJarUri);
83 System.err.printf(
"JNIJarLibrary: addNativeJarLibsImpl: initial: %s -> %s%n", jarSubURI, jarSubUriRoot);
88 System.err.printf(
"JNIJarLibrary: addNativeJarLibsImpl: nativeLibraryPath: %s%n", nativeLibraryPath);
96 System.err.printf(
"JNIJarLibrary: addNativeJarLibsImpl: module: %s -> %s%n", nativeJarBasename, nativeJarURI);
101 }
catch(
final Exception e) {
103 System.err.printf(
"JNIJarLibrary: addNativeJarLibsImpl: Caught %s%n", e.getMessage());
109 final ClassLoader cl = classFromJavaJar.getClassLoader();
113 final URL nativeLibraryURI = cl.getResource(nativeLibraryPath);
114 if (
null != nativeLibraryURI) {
120 System.err.printf(
"JNIJarLibrary: addNativeJarLibsImpl: fat: %s -> %s%n", jarBasename, nativeJarURI);
123 }
catch(
final Exception e) {
125 System.err.printf(
"JNIJarLibrary: addNativeJarLibsImpl: Caught %s%n", e.getMessage());
135 final String moduleName;
137 final String packageName = classFromJavaJar.getPackage().getName();
138 final int idx = packageName.lastIndexOf(
'.');
140 moduleName = packageName.substring(idx+1);
142 moduleName = packageName;
146 final String nativeJarTagClassName = nativeJarTagPackage +
"." + moduleName +
"." + os_and_arch_dot +
".TAG";
149 System.err.printf(
"JNIJarLibrary: addNativeJarLibsImpl: ClassLoader/TAG: Locating module %s, os.and.arch %s: %s%n",
150 moduleName, os_and_arch_dot, nativeJarTagClassName);
154 System.err.printf(
"JNIJarLibrary: addNativeJarLibsImpl: ClassLoader/TAG: %s -> %s%n", nativeJarTagClassName, nativeJarTagClassJarURI);
157 }
catch (
final Exception e ) {
159 System.err.printf(
"JNIJarLibrary: addNativeJarLibsImpl: Caught %s%n", e.getMessage());
167 final long tNow = System.currentTimeMillis() - t0;
168 final long tTotal, tCount;
175 final double tAvrg = tTotal / (double)tCount;
176 System.err.printf(
"JNIJarLibrary: addNativeJarLibsImpl.X: %s / %s -> ok: %b; duration: now %d ms, total %d ms (count %d, avrg %.3f ms)%n",
177 jarBasename, nativeJarBasename, ok, tNow, tTotal, tCount, tAvrg);
252 public static boolean addNativeJarLibs(
final Class<?>[] classesFromJavaJars,
final String singleJarMarker) {
254 final StringBuilder msg =
new StringBuilder();
256 msg.append(
" classesFromJavaJars = ").append(Arrays.asList(classesFromJavaJars)).append(
PlatformProps.
NEWLINE);
259 System.err.println(msg.toString());
264 ok = addNativeJarLibsWithTempJarCache(classesFromJavaJars, singleJarMarker);
266 System.err.println(
"JNIJarLibrary: addNativeJarLibs0: disabled due to uninitialized TempJarCache");
271 private static boolean addNativeJarLibsWithTempJarCache(
final Class<?>[] classesFromJavaJars,
final String singleJarMarker) {
275 boolean done =
false;
278 for (
int i = 0; i < classesFromJavaJars.length; ++i) {
279 final Class<?> c = classesFromJavaJars[i];
284 final ClassLoader cl = c.getClassLoader();
285 final Uri classJarURI = JarUtil.getJarUri(c.getName(), cl);
286 final Uri.Encoded jarName = JarUtil.getJarBasename(classJarURI);
288 if (jarName ==
null) {
292 final Uri.Encoded jarBasename = jarName.substring(0, jarName.indexOf(
".jar"));
295 System.err.printf(
"JNIJarLibrary: jarBasename: %s%n", jarBasename);
303 if (singleJarMarker !=
null) {
304 if (jarBasename.indexOf(singleJarMarker) >= 0) {
309 final Uri.Encoded nativeJarBasename =
310 Uri.Encoded.cast( String.format((Locale)
null,
"%s-natives-%s.jar", jarBasename.get(), PlatformProps.os_and_arch) );
312 ok = JNIJarLibrary.addNativeJarLibsImpl(c, classJarURI, jarName, nativeJarBasename);
317 System.err.printf(
"JNIJarLibrary: addNativeJarLibs0: done: %s%n", jarBasename);
320 }
catch (
final Exception x) {
321 System.err.printf(
"JNIJarLibrary: Caught %s: %s%n", x.getClass().getSimpleName(), x.getMessage());
328 System.err.printf(
"JNIJarLibrary: addNativeJarLibsWhenInitialized: count %d, ok %b%n", count, ok);