From f88eea315f7d4045155e3313d39d38a203ad564a Mon Sep 17 00:00:00 2001
From: Sven Gothel
Date: Mon, 25 Jan 2021 07:31:26 +0100
Subject: Java import and modularization: Complete jaulib_fat and full JNI lib
bootstraping via PlatformRuntime via PlatformProps (if available)
---
java_pkg/org/jau/pkg/JNIJarLibrary.java | 38 ++++++++---------
java_pkg/org/jau/pkg/JaulibJarSHASum.java | 68 +++++++++++++++++++++++++++++++
2 files changed, 87 insertions(+), 19 deletions(-)
create mode 100644 java_pkg/org/jau/pkg/JaulibJarSHASum.java
(limited to 'java_pkg/org')
diff --git a/java_pkg/org/jau/pkg/JNIJarLibrary.java b/java_pkg/org/jau/pkg/JNIJarLibrary.java
index 0febf68..30d390a 100644
--- a/java_pkg/org/jau/pkg/JNIJarLibrary.java
+++ b/java_pkg/org/jau/pkg/JNIJarLibrary.java
@@ -59,7 +59,7 @@ public class JNIJarLibrary extends JNILibrary {
{
if (DEBUG) {
final StringBuilder msg = new StringBuilder();
- msg.append("JNILibrary: addNativeJarLibsImpl(").append(PlatformProps.NEWLINE);
+ msg.append("JNIJarLibrary: addNativeJarLibsImpl(").append(PlatformProps.NEWLINE);
msg.append(" classFromJavaJar = ").append(classFromJavaJar).append(PlatformProps.NEWLINE);
msg.append(" classJarURI = ").append(classJarUri).append(PlatformProps.NEWLINE);
msg.append(" jarBasename = ").append(jarBasename).append(PlatformProps.NEWLINE);
@@ -80,12 +80,12 @@ public class JNIJarLibrary extends JNILibrary {
final Uri jarSubUriRoot = jarSubURI.getDirectory();
if (DEBUG) {
- System.err.printf("JNILibrary: addNativeJarLibsImpl: initial: %s -> %s%n", jarSubURI, jarSubUriRoot);
+ System.err.printf("JNIJarLibrary: addNativeJarLibsImpl: initial: %s -> %s%n", jarSubURI, jarSubUriRoot);
}
final String nativeLibraryPath = String.format((Locale)null, "natives/%s/", PlatformProps.os_and_arch);
if (DEBUG) {
- System.err.printf("JNILibrary: addNativeJarLibsImpl: nativeLibraryPath: %s%n", nativeLibraryPath);
+ System.err.printf("JNIJarLibrary: addNativeJarLibsImpl: nativeLibraryPath: %s%n", nativeLibraryPath);
}
{
// Attempt-1 a 'one slim native jar file' per 'os.and.arch' layout
@@ -93,14 +93,14 @@ public class JNIJarLibrary extends JNILibrary {
final Uri nativeJarURI = JarUtil.getJarFileUri( jarSubUriRoot.getEncoded().concat(nativeJarBasename) );
if (DEBUG) {
- System.err.printf("JNILibrary: addNativeJarLibsImpl: module: %s -> %s%n", nativeJarBasename, nativeJarURI);
+ System.err.printf("JNIJarLibrary: addNativeJarLibsImpl: module: %s -> %s%n", nativeJarBasename, nativeJarURI);
}
try {
ok = TempJarCache.addNativeLibs(classFromJavaJar, nativeJarURI, nativeLibraryPath);
} catch(final Exception e) {
if(DEBUG) {
- System.err.printf("JNILibrary: addNativeJarLibsImpl: Caught %s%n", e.getMessage());
+ System.err.printf("JNIJarLibrary: addNativeJarLibsImpl: Caught %s%n", e.getMessage());
e.printStackTrace();
}
}
@@ -117,12 +117,12 @@ public class JNIJarLibrary extends JNILibrary {
if( TempJarCache.addNativeLibs(classFromJavaJar, nativeJarURI, nativeLibraryPath) ) {
ok = true;
if (DEBUG) {
- System.err.printf("JNILibrary: addNativeJarLibsImpl: fat: %s -> %s%n", jarBasename, nativeJarURI);
+ System.err.printf("JNIJarLibrary: addNativeJarLibsImpl: fat: %s -> %s%n", jarBasename, nativeJarURI);
}
}
} catch(final Exception e) {
if(DEBUG) {
- System.err.printf("JNILibrary: addNativeJarLibsImpl: Caught %s%n", e.getMessage());
+ System.err.printf("JNIJarLibrary: addNativeJarLibsImpl: Caught %s%n", e.getMessage());
e.printStackTrace();
}
}
@@ -146,17 +146,17 @@ public class JNIJarLibrary extends JNILibrary {
final String nativeJarTagClassName = nativeJarTagPackage + "." + moduleName + "." + os_and_arch_dot + ".TAG"; // TODO: sync with gluegen-cpptasks-base.xml
try {
if(DEBUG) {
- System.err.printf("JNILibrary: addNativeJarLibsImpl: ClassLoader/TAG: Locating module %s, os.and.arch %s: %s%n",
+ System.err.printf("JNIJarLibrary: addNativeJarLibsImpl: ClassLoader/TAG: Locating module %s, os.and.arch %s: %s%n",
moduleName, os_and_arch_dot, nativeJarTagClassName);
}
final Uri nativeJarTagClassJarURI = JarUtil.getJarUri(nativeJarTagClassName, cl);
if (DEBUG) {
- System.err.printf("JNILibrary: addNativeJarLibsImpl: ClassLoader/TAG: %s -> %s%n", nativeJarTagClassName, nativeJarTagClassJarURI);
+ System.err.printf("JNIJarLibrary: addNativeJarLibsImpl: ClassLoader/TAG: %s -> %s%n", nativeJarTagClassName, nativeJarTagClassJarURI);
}
ok = TempJarCache.addNativeLibs(classFromJavaJar, nativeJarTagClassJarURI, nativeLibraryPath);
} catch (final Exception e ) {
if(DEBUG) {
- System.err.printf("JNILibrary: addNativeJarLibsImpl: Caught %s%n", e.getMessage());
+ System.err.printf("JNIJarLibrary: addNativeJarLibsImpl: Caught %s%n", e.getMessage());
e.printStackTrace();
}
}
@@ -173,7 +173,7 @@ public class JNIJarLibrary extends JNILibrary {
perfCount = tCount;
}
final double tAvrg = tTotal / (double)tCount;
- System.err.printf("JNILibrary: addNativeJarLibsImpl.X: %s / %s -> ok: %b; duration: now %d ms, total %d ms (count %d, avrg %.3f ms)%n",
+ System.err.printf("JNIJarLibrary: addNativeJarLibsImpl.X: %s / %s -> ok: %b; duration: now %d ms, total %d ms (count %d, avrg %.3f ms)%n",
jarBasename, nativeJarBasename, ok, tNow, tTotal, tCount, tAvrg);
}
return ok;
@@ -199,7 +199,7 @@ public class JNIJarLibrary extends JNILibrary {
* Generic description:
*
final Class>[] classesFromJavaJars = new Class>[] { Class1.class, Class2.class };
- JNILibrary.addNativeJarLibs(classesFromJavaJars, "-all");
+ JNIJarLibrary.addNativeJarLibs(classesFromJavaJars, "-all");
*
* If Class1.class
is contained in a JAR file which name includes singleJarMarker
, here -all,
* implementation will attempt to resolve the native JAR file as follows:
@@ -238,7 +238,7 @@ public class JNIJarLibrary extends JNILibrary {
if( ReflectionUtil.isClassAvailable(newtFactoryClassName, cl) ) {
classesFromJavaJars[2] = ReflectionUtil.getClass(newtFactoryClassName, false, cl);
}
- JNILibrary.addNativeJarLibs(classesFromJavaJars, "-all");
+ JNIJarLibrary.addNativeJarLibs(classesFromJavaJars, "-all");
*
*
*
@@ -252,7 +252,7 @@ public class JNIJarLibrary extends JNILibrary {
public static boolean addNativeJarLibs(final Class>[] classesFromJavaJars, final String singleJarMarker) {
if(DEBUG) {
final StringBuilder msg = new StringBuilder();
- msg.append("JNILibrary: addNativeJarLibs(").append(PlatformProps.NEWLINE);
+ msg.append("JNIJarLibrary: addNativeJarLibs(").append(PlatformProps.NEWLINE);
msg.append(" classesFromJavaJars = ").append(Arrays.asList(classesFromJavaJars)).append(PlatformProps.NEWLINE);
msg.append(" singleJarMarker = ").append(singleJarMarker).append(PlatformProps.NEWLINE);
msg.append(")");
@@ -263,7 +263,7 @@ public class JNIJarLibrary extends JNILibrary {
if ( TempJarCache.isInitialized(true) ) {
ok = addNativeJarLibsWithTempJarCache(classesFromJavaJars, singleJarMarker);
} else if(DEBUG) {
- System.err.println("JNILibrary: addNativeJarLibs0: disabled due to uninitialized TempJarCache");
+ System.err.println("JNIJarLibrary: addNativeJarLibs0: disabled due to uninitialized TempJarCache");
}
return ok;
}
@@ -292,7 +292,7 @@ public class JNIJarLibrary extends JNILibrary {
final Uri.Encoded jarBasename = jarName.substring(0, jarName.indexOf(".jar"));
if(DEBUG) {
- System.err.printf("JNILibrary: jarBasename: %s%n", jarBasename);
+ System.err.printf("JNIJarLibrary: jarBasename: %s%n", jarBasename);
}
/**
@@ -314,18 +314,18 @@ public class JNIJarLibrary extends JNILibrary {
count++;
}
if (DEBUG && done) {
- System.err.printf("JNILibrary: addNativeJarLibs0: done: %s%n", jarBasename);
+ System.err.printf("JNIJarLibrary: addNativeJarLibs0: done: %s%n", jarBasename);
}
}
} catch (final Exception x) {
- System.err.printf("JNILibrary: Caught %s: %s%n", x.getClass().getSimpleName(), x.getMessage());
+ System.err.printf("JNIJarLibrary: Caught %s: %s%n", x.getClass().getSimpleName(), x.getMessage());
if(DEBUG) {
x.printStackTrace();
}
ok = false;
}
if(DEBUG) {
- System.err.printf("JNILibrary: addNativeJarLibsWhenInitialized: count %d, ok %b%n", count, ok);
+ System.err.printf("JNIJarLibrary: addNativeJarLibsWhenInitialized: count %d, ok %b%n", count, ok);
}
return ok;
}
diff --git a/java_pkg/org/jau/pkg/JaulibJarSHASum.java b/java_pkg/org/jau/pkg/JaulibJarSHASum.java
new file mode 100644
index 0000000..0aa9513
--- /dev/null
+++ b/java_pkg/org/jau/pkg/JaulibJarSHASum.java
@@ -0,0 +1,68 @@
+/**
+ * Author: Sven Gothel
+ * Copyright (c) 2020 Gothel Software e.K.
+ * Copyright (c) 2010 Gothel Software e.K.
+ * Copyright (c) 2010 JogAmp Community
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+package org.jau.pkg;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Pattern;
+
+import org.jau.base.JaulibVersion;
+import org.jau.sec.SHASum;
+
+/**
+ * jaulib definition of {@link TempJarSHASum}'s specialization of {@link SHASum}.
+ *
+ * Implementation uses {@link org.jau.pkg.cache.TempJarCache}.
+ *
+ *
+ * Constructor defines the includes and excludes as used for jaulib {@link SHASum} computation.
+ *
+ */
+public class JaulibJarSHASum extends TempJarSHASum {
+ /**
+ * See {@link JaulibJarSHASum}
+ * @throws SecurityException
+ * @throws IllegalArgumentException
+ * @throws NoSuchAlgorithmException
+ * @throws IOException
+ * @throws URISyntaxException
+ */
+ public JaulibJarSHASum()
+ throws SecurityException, IllegalArgumentException, NoSuchAlgorithmException, IOException, URISyntaxException
+ {
+ super(MessageDigest.getInstance("SHA-256"), JaulibVersion.class, new ArrayList(), new ArrayList());
+ final List excludes = getExcludes();
+ final List includes = getIncludes();
+ final String origin = getOrigin();
+ excludes.add(Pattern.compile(origin+"/jau/sys/android"));
+ includes.add(Pattern.compile(origin+"/org/jau/.*"));
+ includes.add(Pattern.compile(origin+"/jau/.*"));
+ }
+}
\ No newline at end of file
--
cgit v1.2.3