Implement `java/util/zip/ZipFile.getManifestNum(J)I` native
authorJan Vrany <jan.vrany@labware.com>
Tue, 02 Nov 2021 16:09:46 +0000
changeset 4009 944431c70558
parent 4008 916d24efebb8
child 4010 19843598d34b
Implement `java/util/zip/ZipFile.getManifestNum(J)I` native ...as this is needed by recent OpenJDK 7 (Zulu 7)
JavaNativeMethodImpl_OpenJDK7.st
--- a/JavaNativeMethodImpl_OpenJDK7.st	Wed Feb 17 07:58:28 2021 +0000
+++ b/JavaNativeMethodImpl_OpenJDK7.st	Tue Nov 02 16:09:46 2021 +0000
@@ -1,5 +1,6 @@
 "
  COPYRIGHT (c) 2010-2015 by Jan Vrany, Jan Kurs and Marcel Hlopko
+ COPYRIGHT (c) 2021 LabWare
                             SWING Research Group, Czech Technical University in Prague
 
  This software is furnished under a license and may be used
@@ -25,6 +26,7 @@
 copyright
 "
  COPYRIGHT (c) 2010-2015 by Jan Vrany, Jan Kurs and Marcel Hlopko
+ COPYRIGHT (c) 2021 LabWare
                             SWING Research Group, Czech Technical University in Prague
 
  This software is furnished under a license and may be used
@@ -513,6 +515,37 @@
     "Modified: / 08-02-2013 / 09:45:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
+_java_util_zip_ZipFile_getManifestNum: this _: a1 _: a2 
+
+    <javanative: 'java/util/zip/ZipFile' name: 'getManifestNum(J)I'>
+    "
+    /*
+     * Returns the number of the META-INF/MANIFEST.MF entries, case insensitive.
+     * When this number is greater than 1, JarVerifier will treat a file as
+     * unsigned.
+     */
+    "
+
+    | zip manifest contents |
+
+    zip := self getZipArchiveAt:a1. 
+    manifest := zip findMember: 'META-INF/MANIFEST.MF'.
+    manifest isNil ifTrue: [ ^ 0 ].
+    "Following is very, very simplistic: we simply assume that
+     number of entries is the same as number of lines, which can
+     be wrong. Will see."
+    contents := zip extract: 'META-INF/MANIFEST.MF' asString: true.
+    (contents includes: Character lf) ifTrue: [ 
+        "/ Unix or DOS line ends
+        ^ contents occurrencesOfString:  Character lf asString
+    ] ifFalse: [ 
+        "/ Mac line ends
+        ^ contents occurrencesOfString:  Character return asString
+    ].
+
+    "Modified: / 02-11-2021 / 16:06:44 / Jan Vrany <jan.vrany@labware.com>"
+!
+
 _java_util_zip_ZipFile_open: this _: a1 _: a2 _: a3 _: a4 _: usemmap
 
     <javanative: 'java/util/zip/ZipFile' name: 'open(Ljava/lang/String;IJZ)J'>