From 523a4189b8a7233c926eab1218daf627a3e870b8 Mon Sep 17 00:00:00 2001 From: liaozan <378024053@qq.com> Date: Tue, 4 Jun 2024 22:59:16 +0800 Subject: [PATCH] Move dubbo versions file from META-INF/versions to META-INF/dubbo-version (#14247) * Move dubbo versions file from META-INF/versions to META-INF/dubbo-versions * Make 'META-INF/dubbo-versions' as constants --- .../java/org/apache/dubbo/common/Version.java | 8 +++--- .../common/constants/CommonConstants.java | 26 +++++++++++++++++-- .../dubbo/common/version/VersionTest.java | 9 +++---- .../org/apache/dubbo/dependency/FileTest.java | 4 ++- pom.xml | 4 +-- 5 files changed, 38 insertions(+), 13 deletions(-) diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/Version.java b/dubbo-common/src/main/java/org/apache/dubbo/common/Version.java index 90f2b707045..5c436fd3459 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/Version.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/Version.java @@ -16,6 +16,7 @@ */ package org.apache.dubbo.common; +import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.utils.StringUtils; @@ -84,7 +85,8 @@ public final class Version { } private static void tryLoadVersionFromResource() throws IOException { - Enumeration configLoader = Version.class.getClassLoader().getResources("META-INF/versions/dubbo-common"); + Enumeration configLoader = + Version.class.getClassLoader().getResources(CommonConstants.DUBBO_VERSIONS_KEY + "/dubbo-common"); if (configLoader.hasMoreElements()) { URL url = configLoader.nextElement(); try (BufferedReader reader = @@ -312,7 +314,7 @@ private static void checkArtifacts(Set artifactIds) throws IOException { private static void checkArtifact(String artifactId) throws IOException { Enumeration artifactEnumeration = - Version.class.getClassLoader().getResources("META-INF/versions/" + artifactId); + Version.class.getClassLoader().getResources(CommonConstants.DUBBO_VERSIONS_KEY + artifactId); while (artifactEnumeration.hasMoreElements()) { URL url = artifactEnumeration.nextElement(); try (BufferedReader reader = @@ -348,7 +350,7 @@ private static void checkVersion(String artifactId, URL url, String key, String private static Set loadArtifactIds() throws IOException { Enumeration artifactsEnumeration = - Version.class.getClassLoader().getResources("META-INF/versions/.artifacts"); + Version.class.getClassLoader().getResources(CommonConstants.DUBBO_VERSIONS_KEY + "/.artifacts"); Set artifactIds = new HashSet<>(); while (artifactsEnumeration.hasMoreElements()) { URL url = artifactsEnumeration.nextElement(); diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java index e0264994180..704b30c74cd 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java @@ -24,6 +24,7 @@ import java.util.regex.Pattern; public interface CommonConstants { + String DUBBO = "dubbo"; String TRIPLE = "tri"; @@ -267,12 +268,14 @@ public interface CommonConstants { String $INVOKE = "$invoke"; String $INVOKE_ASYNC = "$invokeAsync"; + String GENERIC_PARAMETER_DESC = "Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;"; /** * echo call */ String $ECHO = "$echo"; + /** * package version in the manifest */ @@ -283,12 +286,19 @@ public interface CommonConstants { int MAX_PROXY_COUNT = 65535; String MONITOR_KEY = "monitor"; + String BACKGROUND_KEY = "background"; + String CLUSTER_KEY = "cluster"; + String USERNAME_KEY = "username"; + String PASSWORD_KEY = "password"; + String HOST_KEY = "host"; + String PORT_KEY = "port"; + String DUBBO_IP_TO_BIND = "DUBBO_IP_TO_BIND"; /** @@ -308,21 +318,29 @@ public interface CommonConstants { String SHUTDOWN_WAIT_SECONDS_KEY = "dubbo.service.shutdown.wait.seconds"; String SHUTDOWN_WAIT_KEY = "dubbo.service.shutdown.wait"; + String DUBBO_PROTOCOL = "dubbo"; String DUBBO_LABELS = "dubbo.labels"; + String DUBBO_ENV_KEYS = "dubbo.env.keys"; String CONFIG_CONFIGFILE_KEY = "config-file"; + String CONFIG_ENABLE_KEY = "highest-priority"; + String CONFIG_NAMESPACE_KEY = "namespace"; + String CHECK_KEY = "check"; String BACKLOG_KEY = "backlog"; String HEARTBEAT_EVENT = null; + String MOCK_HEARTBEAT_EVENT = "H"; + String READONLY_EVENT = "R"; + String WRITEABLE_EVENT = "W"; String REFERENCE_FILTER_KEY = "reference.filter"; @@ -459,6 +477,7 @@ public interface CommonConstants { String REGISTRY_DELAY_NOTIFICATION_KEY = "delay-notification"; String CACHE_CLEAR_TASK_INTERVAL = "dubbo.application.url.cache.task.interval"; + String CACHE_CLEAR_WAITING_THRESHOLD = "dubbo.application.url.cache.clear.waiting"; String CLUSTER_INTERCEPTOR_COMPATIBLE_KEY = "dubbo.application.cluster.interceptor.compatible"; @@ -615,17 +634,18 @@ public interface CommonConstants { String SERVICE_EXECUTOR = "service-executor"; String EXECUTOR_MANAGEMENT_MODE = "executor-management-mode"; + String EXECUTOR_MANAGEMENT_MODE_DEFAULT = "default"; + String EXECUTOR_MANAGEMENT_MODE_ISOLATION = "isolation"; /** - * * used in JVMUtil.java ,Control stack print lines, default is 32 lines - * */ String DUBBO_JSTACK_MAXLINE = "dubbo.jstack-dump.max-line"; String ENCODE_IN_IO_THREAD_KEY = "encode.in.io"; + boolean DEFAULT_ENCODE_IN_IO_THREAD = false; /** @@ -648,4 +668,6 @@ public interface CommonConstants { String DUBBO2_COMPACT_ENABLE = "dubbo.compact.enable"; String ZOOKEEPER_ENSEMBLE_TRACKER_KEY = "zookeeper.ensemble.tracker"; + + String DUBBO_VERSIONS_KEY = "META-INF/dubbo-versions"; } diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/version/VersionTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/version/VersionTest.java index 69dd5dbb08d..0c37dc79c77 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/version/VersionTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/version/VersionTest.java @@ -17,6 +17,7 @@ package org.apache.dubbo.common.version; import org.apache.dubbo.common.Version; +import org.apache.dubbo.common.constants.CommonConstants; import java.io.FileInputStream; import java.io.IOException; @@ -110,7 +111,7 @@ private static Class reloadVersionClass() throws ClassNotFoundException { ClassLoader classLoader = new ClassLoader(originClassLoader) { @Override public Class loadClass(String name) throws ClassNotFoundException { - if (name.equals("org.apache.dubbo.common.Version")) { + if ("org.apache.dubbo.common.Version".equals(name)) { return findClass(name); } return super.loadClass(name); @@ -145,15 +146,13 @@ public byte[] loadClassData(String className) throws IOException { @Override public Enumeration getResources(String name) throws IOException { - - if (name.equals("META-INF/versions/dubbo-common")) { + if (name.equals(CommonConstants.DUBBO_VERSIONS_KEY + "/dubbo-common")) { return super.getResources("META-INF/test-versions/dubbo-common"); } return super.getResources(name); } }; - Class versionClass = classLoader.loadClass("org.apache.dubbo.common.Version"); - return versionClass; + return classLoader.loadClass("org.apache.dubbo.common.Version"); } @Test diff --git a/dubbo-test/dubbo-test-modules/src/test/java/org/apache/dubbo/dependency/FileTest.java b/dubbo-test/dubbo-test-modules/src/test/java/org/apache/dubbo/dependency/FileTest.java index 209a25ff585..be443f2c944 100644 --- a/dubbo-test/dubbo-test-modules/src/test/java/org/apache/dubbo/dependency/FileTest.java +++ b/dubbo-test/dubbo-test-modules/src/test/java/org/apache/dubbo/dependency/FileTest.java @@ -16,6 +16,8 @@ */ package org.apache.dubbo.dependency; +import org.apache.dubbo.common.constants.CommonConstants; + import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -133,7 +135,7 @@ void checkArtifacts() throws DocumentException, IOException { List artifactIdsInRoot = IOUtils.readLines( this.getClass() .getClassLoader() - .getResource("META-INF/versions/.artifacts") + .getResource(CommonConstants.DUBBO_VERSIONS_KEY + "/.artifacts") .openStream(), StandardCharsets.UTF_8); artifactIdsInRoot.removeIf(s -> s.startsWith("#")); diff --git a/pom.xml b/pom.xml index 472134a92a0..52e9cf3eb40 100644 --- a/pom.xml +++ b/pom.xml @@ -253,7 +253,7 @@ - META-INF/versions + META-INF/dubbo-versions false ${maven.multiModuleProjectDirectory} @@ -430,7 +430,7 @@ true - +