Skip to content

Commit

Permalink
Move dubbo versions file from META-INF/versions to META-INF/dubbo-ver…
Browse files Browse the repository at this point in the history
…sion (apache#14247)

* Move dubbo versions file from META-INF/versions to META-INF/dubbo-versions

* Make 'META-INF/dubbo-versions' as constants
  • Loading branch information
refeccd authored Jun 4, 2024
1 parent 473ea36 commit 523a418
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -84,7 +85,8 @@ public final class Version {
}

private static void tryLoadVersionFromResource() throws IOException {
Enumeration<URL> configLoader = Version.class.getClassLoader().getResources("META-INF/versions/dubbo-common");
Enumeration<URL> configLoader =
Version.class.getClassLoader().getResources(CommonConstants.DUBBO_VERSIONS_KEY + "/dubbo-common");
if (configLoader.hasMoreElements()) {
URL url = configLoader.nextElement();
try (BufferedReader reader =
Expand Down Expand Up @@ -312,7 +314,7 @@ private static void checkArtifacts(Set<String> artifactIds) throws IOException {

private static void checkArtifact(String artifactId) throws IOException {
Enumeration<URL> 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 =
Expand Down Expand Up @@ -348,7 +350,7 @@ private static void checkVersion(String artifactId, URL url, String key, String

private static Set<String> loadArtifactIds() throws IOException {
Enumeration<URL> artifactsEnumeration =
Version.class.getClassLoader().getResources("META-INF/versions/.artifacts");
Version.class.getClassLoader().getResources(CommonConstants.DUBBO_VERSIONS_KEY + "/.artifacts");
Set<String> artifactIds = new HashSet<>();
while (artifactsEnumeration.hasMoreElements()) {
URL url = artifactsEnumeration.nextElement();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.regex.Pattern;

public interface CommonConstants {

String DUBBO = "dubbo";

String TRIPLE = "tri";
Expand Down Expand Up @@ -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
*/
Expand All @@ -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";

/**
Expand All @@ -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";
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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;

/**
Expand All @@ -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";
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -145,15 +146,13 @@ public byte[] loadClassData(String className) throws IOException {

@Override
public Enumeration<URL> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -133,7 +135,7 @@ void checkArtifacts() throws DocumentException, IOException {
List<String> 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("#"));
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@
</includes>
</resource>
<resource>
<targetPath>META-INF/versions</targetPath>
<targetPath>META-INF/dubbo-versions</targetPath>
<filtering>false</filtering>
<directory>${maven.multiModuleProjectDirectory}</directory>
<includes>
Expand Down Expand Up @@ -430,7 +430,7 @@
<configuration>
<failOnError>true</failOnError>
<target>
<property name="version_file" value="${project.build.outputDirectory}/META-INF/versions/${project.artifactId}" />
<property name="version_file" value="${project.build.outputDirectory}/META-INF/dubbo-versions/${project.artifactId}" />
<!-- get the current version of dubbo -->
<echo file="${version_file}" message="revision=${revision}${line.separator}" />
<!-- attach the artifact id -->
Expand Down

0 comments on commit 523a418

Please sign in to comment.