From 2081e73839895a53a5435666d07fc578ad51cf51 Mon Sep 17 00:00:00 2001 From: James Chu Date: Fri, 6 Oct 2023 17:10:18 +0800 Subject: [PATCH] remove registry --- bin/genmd5sign | 100 ----------- bin/md5java | 102 ----------- zk/build.gradle | 11 +- .../org/zkoss/zk/ui/http/SimpleWebApp.java | 4 - .../java/org/zkoss/zk/ui/http/WebManager.java | 4 - .../org/zkoss/zk/ui/sys/ConfigParser.java | 24 --- .../java/org/zkoss/zk/ui/sys/Registry.java | 163 ------------------ 7 files changed, 1 insertion(+), 407 deletions(-) delete mode 100755 bin/genmd5sign delete mode 100644 bin/md5java delete mode 100644 zk/src/main/java/org/zkoss/zk/ui/sys/Registry.java diff --git a/bin/genmd5sign b/bin/genmd5sign deleted file mode 100755 index 11617bdb8e0..00000000000 --- a/bin/genmd5sign +++ /dev/null @@ -1,100 +0,0 @@ -#!/bin/bash -# genmd5sign -# -# Purpose: -# -# Description: -# -# History: -# Wed Feb 24 17:46:58 CST 2016, Created by jumperchen -# -#Copyright (C) 2016 Potix Corporation. All Rights Reserved. -# -function showhelp -{ - echo "genmd5sign - generate the file md5 from the signclasses" - echo "Copyright (C) 2016 Potix Corporation. All Rights Reserved." - echo - echo "Usage:" - echo " genmd5sign [-h] [dstfl] [classes] [classpath] [build stamp path] [maindir]" - echo - echo "dstfl" - echo " The destination file, if exists, it will be removed first" - echo - echo "classes" - echo " The list of the classes to be output to stdout with md5 format, each of classes is sepecated by a comma ','" - echo " For example," - echo " foo.bar,foo.bar1,foo.bar2" - echo - echo "classpath" - echo " A directory where to put those classes." - echo - echo "build stamp path" - echo " A file path where to output the zk build stamp" - echo - echo "maindir" - echo " The ZK source directory" -} - -if [ "$1" = "--help" ] || [ "$1" = "-h" ] ; then - showhelp - exit 0 -fi -os="$(uname)" - -dstfl=$1 -classes=$2 -debugdir=$3 -build=$4 -maindir=$5 - -mkdir -p "${dstfl%/*}" - -if [ -f $build ] ; then - build=$(cat $build) -elif [ -f $maindir/zk/format ] ; then - build=$(grep '^time=' $maindir/zk/format) - build=${build#time=} - - if [ -f $maindir/zk/codegen/$build ] ; then - build=$(cat $maindir/zk/codegen/$build) - else - echo "the build stamp path is not specified!" - exit -1 - fi -else - echo "the build stamp path is not specified!" - exit -1 -fi - -if [ -f $dstfl ] ; then - rm $dstfl -fi -echo $maindir - -function md5java { - local src="$1" - if [ "$TERM" = "cygwin" ] || [ "$OSTYPE" = "cygwin" ] ; then - # need to parse with cygpath for correct path on cygwin/windows - # also need semi-colon instead of colon for java classpath - java -cp "$maindir/dist/lib/ext/bsh.jar" bsh.Interpreter $(cygpath -mp $maindir/bin/md5java) $src - elif [ "$OSTYPE" = "msys" ] ; then - # MinGW, git-bash - java -cp "$maindir/dist/lib/ext/bsh.jar" bsh.Interpreter $maindir/bin/md5java $src - else - java -cp "$maindir/dist/lib/ext/bsh.jar" bsh.Interpreter $maindir/bin/md5java $src - fi -} - -export IFS="," -echo "Generate md5 sign" -for cls in $classes; do - clsdir=$(echo $cls | sed 's/\./\//g') - filemd5=`md5java "$debugdir/$clsdir.class"` - echo "class => $cls" - echo "output: $filemd5" - filemd5=`md5java "$filemd5$build"` - name=`md5java "$cls"` - # remove line break at the end for windows/cygwin compatility - echo "$(echo $name | tr -d '\r')=$filemd5" >> $dstfl -done diff --git a/bin/md5java b/bin/md5java deleted file mode 100644 index 74215964f70..00000000000 --- a/bin/md5java +++ /dev/null @@ -1,102 +0,0 @@ -String[] args = this.interpreter.get("bsh.args"); -if (args == null || args.length != 1) { - System.err.println("The source string must be specified"); - System.exit(-1); -} - -import java.nio.charset.Charset; -import java.security.MessageDigest; -import java.io.*; - -String md5Hex(String data) { - return encodeHexString(md5(data)); -} - -String md5Hex(InputStream data) throws IOException { - return encodeHexString(md5(data)); -} - -byte[] md5(String data) { - return md5(getBytesUtf8(data)); -} - -byte[] md5(InputStream data) throws IOException { - MessageDigest md = getMd5Digest(); - final byte[] buf = new byte[1024 * 4]; - for (int v; (v = data.read(buf)) >= 0;) { - if (v > 0) - md.update(buf, 0, v); - } - return md.digest(); -} - -byte[] getBytesUtf8(String string) { - return getBytes(string, Charset.forName("UTF-8")); -} - -byte[] getBytes(String string, Charset charset) { - return string == null?null:string.getBytes(charset); -} - -byte[] md5(byte[] data) { - return getMd5Digest().digest(data); -} - -MessageDigest getMd5Digest() { - return getDigest("MD5"); -} - -MessageDigest getDigest(String algorithm) { - try { - return MessageDigest.getInstance(algorithm); - } catch (java.security.NoSuchAlgorithmException var2) { - throw new java.lang.IllegalArgumentException(var2); - } -} - -String encodeHexString(byte[] data) { - return new String(encodeHex(data)); -} - -char[] encodeHex(byte[] data) { - return encodeHex(data, true); -} - -char[] encodeHex(byte[] data, boolean toLowerCase) { - return encodeHex(data, toLowerCase? DIGITS_LOWER : DIGITS_UPPER); -} - -char[] DIGITS_LOWER = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; -char[] DIGITS_UPPER = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; - -char[] encodeHex(byte[] data, char[] toDigits) { - int l = data.length; - char[] out = new char[l << 1]; - int i = 0; - - for(int j = 0; i < l; ++i) { - out[j++] = toDigits[(240 & data[i]) >>> 4]; - out[j++] = toDigits[15 & data[i]]; - } - - return out; -} - -if (args[0].endsWith(".class")) { - InputStream is = null; - try { - is = new FileInputStream(args[0]); - System.out.println(md5Hex(is)); - } catch (Exception e) { - } finally { - if (is != null) { - try { - is.close(); - } catch (IOException e) { - } - } - } -} else { - System.out.println(md5Hex(args[0])); -} - diff --git a/zk/build.gradle b/zk/build.gradle index ac8796d946f..fe0ba49895e 100644 --- a/zk/build.gradle +++ b/zk/build.gradle @@ -51,16 +51,7 @@ task gentime(type: Exec) { commandLine './gentime', "$projectDir/codegen/resources/metainfo/zk/build" } -task genmd5sign() { - doLast { - exec { - workingDir "$rootDir/bin" - commandLine './genmd5sign', "$projectDir/codegen/resources/metainfo/zk/buildsign", "org.zkoss.zk.ui.sys.WebAppFactoryImpl,org.zkoss.zk.ui.http.WebManager,org.zkoss.zk.ui.sys.Registry", "$projectDir/build/classes/java/main", "$projectDir/codegen/resources/metainfo/zk/build", "$rootDir" - } - } -} -genmd5sign.dependsOn(gentime) gentime.mustRunAfter(compileJava) -processResources.dependsOn(genmd5sign) +processResources.dependsOn(gentime) description = 'ZK Kernel' \ No newline at end of file diff --git a/zk/src/main/java/org/zkoss/zk/ui/http/SimpleWebApp.java b/zk/src/main/java/org/zkoss/zk/ui/http/SimpleWebApp.java index 8cbb9583eef..152fd23562c 100644 --- a/zk/src/main/java/org/zkoss/zk/ui/http/SimpleWebApp.java +++ b/zk/src/main/java/org/zkoss/zk/ui/http/SimpleWebApp.java @@ -34,8 +34,6 @@ import org.zkoss.zk.ui.ext.ScopeListener; import org.zkoss.zk.ui.impl.AbstractWebApp; import org.zkoss.zk.ui.impl.ScopeListeners; -import org.zkoss.zk.ui.sys.Registry; -import org.zkoss.zk.ui.sys.WebAppFactoryImpl; import org.zkoss.zk.ui.util.Configuration; /** @@ -56,8 +54,6 @@ public void init(Object context, Configuration config) { throw new IllegalArgumentException("context"); _ctx = (ServletContext) context; super.init(context, config); - - Registry.sign(this, Registry.class, WebManager.class, WebAppFactoryImpl.class); } private final Map _attrs = new AttributesMap() { diff --git a/zk/src/main/java/org/zkoss/zk/ui/http/WebManager.java b/zk/src/main/java/org/zkoss/zk/ui/http/WebManager.java index 450aae45492..e9e526c4b1d 100644 --- a/zk/src/main/java/org/zkoss/zk/ui/http/WebManager.java +++ b/zk/src/main/java/org/zkoss/zk/ui/http/WebManager.java @@ -63,13 +63,11 @@ import org.zkoss.zk.ui.sys.ConfigParser; import org.zkoss.zk.ui.sys.DesktopCtrl; import org.zkoss.zk.ui.sys.ExecutionsCtrl; -import org.zkoss.zk.ui.sys.Registry; import org.zkoss.zk.ui.sys.RequestInfo; import org.zkoss.zk.ui.sys.SessionsCtrl; import org.zkoss.zk.ui.sys.UiFactory; import org.zkoss.zk.ui.sys.WebAppCtrl; import org.zkoss.zk.ui.sys.WebAppFactory; -import org.zkoss.zk.ui.sys.WebAppFactoryImpl; import org.zkoss.zk.ui.sys.WebAppsCtrl; import org.zkoss.zk.ui.util.Configuration; @@ -284,8 +282,6 @@ public WebManager(ServletContext ctx, String updateURI, String resourceURI) { } } } - - Registry.sign(_wapp, Registry.class, WebManager.class, WebAppFactoryImpl.class); } private void checkAndAddExtendlet(String ext, Extendlet extlet) { diff --git a/zk/src/main/java/org/zkoss/zk/ui/sys/ConfigParser.java b/zk/src/main/java/org/zkoss/zk/ui/sys/ConfigParser.java index 56e85e1b1c7..268f63ba02b 100644 --- a/zk/src/main/java/org/zkoss/zk/ui/sys/ConfigParser.java +++ b/zk/src/main/java/org/zkoss/zk/ui/sys/ConfigParser.java @@ -28,7 +28,6 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.Properties; import java.util.Set; import org.slf4j.Logger; @@ -173,34 +172,11 @@ else if (config == null) final XMLResourcesLocator locator = org.zkoss.zk.ui.impl.Utils.getXMLResourcesLocator(); final List xmls = locator.getDependentXMLResources("metainfo/zk/config.xml", "config-name", "depends"); - - Registry reg = Registry.getInstance(); for (XMLResourcesLocator.Resource res : xmls) { if (log.isDebugEnabled()) log.debug("Loading " + res.url); try { if (checkVersion(res.url, res.document)) { - try { - String path = res.url.toExternalForm(); - int end = path.lastIndexOf('/'); // no need to use OS's separator - if (end >= 0) { - InputStream inputStream = null; - try { - path = path.substring(0, end + 1) + Strings.toString(Registry.PREFS_0); - inputStream = new URL(path).openStream(); - if (inputStream != null) { - Properties props = new Properties(); - props.load(inputStream); - for (Map.Entry me : props.entrySet()) - reg.addKeys((String) me.getKey(), (String) me.getValue()); - } - } finally { - if (inputStream != null) - inputStream.close(); - } - } - } catch (Exception ignored) { - } final Element el = res.document.getRootElement(); if (!syscfgLoaded) { parseSubZScriptConfig(el); diff --git a/zk/src/main/java/org/zkoss/zk/ui/sys/Registry.java b/zk/src/main/java/org/zkoss/zk/ui/sys/Registry.java deleted file mode 100644 index 0af978f493f..00000000000 --- a/zk/src/main/java/org/zkoss/zk/ui/sys/Registry.java +++ /dev/null @@ -1,163 +0,0 @@ -/* Registry.java - - Purpose: - - Description: - - History: - 12:41 PM 2/25/16, Created by jumperchen - -Copyright (C) 2016 Potix Corporation. All Rights Reserved. -*/ -package org.zkoss.zk.ui.sys; - -import java.io.IOException; -import java.io.InputStream; -import java.io.UnsupportedEncodingException; -import java.net.URL; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -import org.zkoss.lang.Strings; -import org.zkoss.zk.ui.WebApp; -import org.zkoss.zk.ui.WebApps; -import org.zkoss.zk.ui.impl.AbstractWebApp; - -/** - * A helper class for class registry for internal use only. - * @author jumperchen - * @since 8.0.2 - */ -public class Registry { - private static final Registry INSTANCE = new Registry(); - private final Map keys = new ConcurrentHashMap(10); - private final Map signs = new ConcurrentHashMap(10); - private final Map values = new ConcurrentHashMap(10); - private static final Map BYTE_MAP = new HashMap(10); - - public static final byte[] PREFS_0; - public static final byte[] PREFS_1; - public static final byte[] PREFS_2; - - static { - BYTE_MAP.put(toString(new byte[] { 112, 114, 101, 102, 115, 48 }), - PREFS_0 = new byte[] { 98, 117, 105, 108, 100, 115, 105, 103, 110 }); - BYTE_MAP.put(toString(new byte[] { 112, 114, 101, 102, 115, 49 }), - PREFS_1 = new byte[] { 111, 114, 103, 46, 122, 107, 111, 115, 115, 46, 122, 107, 46, 117, 105, 46, 99, - 108, 105, 101, 110, 116, 46, 110, 111, 116, 105, 99, 101 }); - BYTE_MAP.put(toString(new byte[] { 112, 114, 101, 102, 115, 50 }), - PREFS_2 = new byte[] { 89, 111, 117, 114, 32, 90, 75, 32, 98, 105, 110, 97, 114, 121, 32, 105, 115, 32, - 98, 101, 105, 110, 103, 32, 97, 108, 116, 101, 114, 101, 100, 32, 97, 110, 100, 32, 109, 97, - 121, 32, 110, 111, 116, 32, 119, 111, 114, 107, 32, 97, 115, 32, 101, 120, 112, 101, 99, 116, - 101, 100, 46, 32, 80, 108, 101, 97, 115, 101, 32, 99, 111, 110, 116, 97, 99, 116, 32, 117, 115, - 32, 97, 116, 32, 105, 110, 102, 111, 64, 122, 107, 111, 115, 115, 46, 111, 114, 103, 32, 102, - 111, 114, 32, 97, 115, 115, 105, 115, 116, 97, 110, 99, 101, 46 }); - BYTE_MAP.put(toString(new byte[] { 109, 115, 103, 48 }), - new byte[] { 10, 60, 115, 99, 114, 105, 112, 116, 32, 99, 108, 97, 115, 115, 61, 34, 122, 45, 114, 117, - 110, 111, 110, 99, 101, 34, 32, 116, 121, 112, 101, 61, 34, 116, 101, 120, 116, 47, 106, 97, - 118, 97, 115, 99, 114, 105, 112, 116, 34, 62, 10, 122, 65, 117, 46, 115, 104, 111, 119, 69, 114, - 114, 111, 114, 40, 39, 70, 65, 73, 76, 69, 68, 95, 84, 79, 95, 80, 82, 79, 67, 69, 83, 83, 39, - 44, 32, 39, 37, 49, 36, 115, 39, 44, 39, 37, 50, 36, 115, 39, 41, 59, 10, 60, 47, 115, 99, 114, - 105, 112, 116, 62 }); - } - - private Registry() { - } - - public static Registry getInstance() { - return INSTANCE; - } - - /*package*/ final void addKeys(String key, String value) { - if (key != null && value != null) - signs.put(key, value); - } - - public boolean isValid(Class cls) { - final String key = getKey(cls); - - if (signs.containsKey(key)) { - String value = values.get(key); - if (value == null) { - synchronized (values) { - if (!values.containsKey(key)) { - value = DigestUtilsHelper.md5Hex(loadValue(cls) + AbstractWebApp.getBuildStamp()); - values.put(key, value); - } - } - } - return signs.get(key).equals(value); - } - return false; - } - - public String getKey(Class cls) { - final String name = cls.getName(); - if (!keys.containsKey(name)) { - final String key = DigestUtilsHelper.md5Hex(name); - keys.put(cls.getName(), key); - return key; - } - return keys.get(name); - } - - public String getSign(Class cls) { - return signs.get(getKey(cls)); - } - - // sign the cls to the webapp - public static void sign(WebApp wapp, Class... clses) { - if (wapp == null || "CE".equals(WebApps.getEdition()) - || wapp.getAttribute("org.zkoss.zk.ui.notice") != null) { - for (Class cls : clses) { - if (!INSTANCE.isValid(cls)) { - String sign = INSTANCE.getSign(cls); - String key = Strings.toString(Registry.PREFS_1); - if (sign == null) { - sign = INSTANCE.getKey(cls); - } - if (sign != null) { - if (sign.length() > 8) - sign = sign.substring(0, 9); - } - - wapp.setAttribute(key, gen(Strings.toString(Registry.PREFS_2), sign)); - return; // done - } - } - } - } - - private static String gen(String msg, String error) { - return String.format(toString(BYTE_MAP.get(toString(new byte[] { 109, 115, 103, 48 }))), msg, - error != null ? toString(new byte[] { 69, 114, 114, 111, 114, 58 }) + error : ""); - } - - private synchronized String loadValue(Class cls) { - InputStream is = null; - try { - URL location = cls.getResource( - "/" + cls.getName().replace(".", "/") + toString(new byte[] { 46, 99, 108, 97, 115, 115 })); - is = location.openStream(); - return DigestUtilsHelper.md5Hex(is); - } catch (Exception ignored) { - } finally { - if (is != null) { - try { - is.close(); - } catch (IOException ignored) { - } - } - } - return null; - } - - private static final String toString(byte[] data) { - try { - return new String(data, "UTF-8"); - } catch (UnsupportedEncodingException e) { - return new String(data); - } - } -}