Skip to content

Commit

Permalink
dubbox升级dubbo版本的兼容性问题 (#3996)
Browse files Browse the repository at this point in the history
Fixes #3537
  • Loading branch information
beiwei30 authored and chickenlj committed May 8, 2019
1 parent 455d29a commit 5fd41d7
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions dubbo-common/src/main/java/org/apache/dubbo/common/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
*/
public final class Version {
private static final Logger logger = LoggerFactory.getLogger(Version.class);

private static final Pattern PREFIX_DIGITS_PATTERN = Pattern.compile("^([0-9]*).*");

// Dubbo RPC protocol version, for compatibility, it must not be between 2.0.10 ~ 2.6.2
Expand Down Expand Up @@ -104,6 +104,11 @@ public static boolean isSupportResponseAttachment(String version) {
return false;
}

// 2.8.x is reserved for dubbox
if (iVersion >= 2080000 && iVersion < 2090000) {
return false;
}

return iVersion >= LOWEST_VERSION_FOR_RESPONSE_ATTACHMENT;
}

Expand Down Expand Up @@ -157,19 +162,19 @@ public static String getVersion(Class<?> cls, String defaultVersion) {
return version;
}
}

// guess version fro jar file name if nothing's found from MANIFEST.MF
CodeSource codeSource = cls.getProtectionDomain().getCodeSource();
if (codeSource == null) {
logger.info("No codeSource for class " + cls.getName() + " when getVersion, use default version " + defaultVersion);
return defaultVersion;
}
}

String file = codeSource.getLocation().getFile();
if (!StringUtils.isEmpty(file) && file.endsWith(".jar")) {
version = getFromFile(file);
}

// return default version if no version info is found
return StringUtils.isEmpty(version) ? defaultVersion : version;
} catch (Throwable e) {
Expand All @@ -185,19 +190,19 @@ public static String getVersion(Class<?> cls, String defaultVersion) {
private static String getFromFile(String file) {
// remove suffix ".jar": "path/to/group-module-x.y.z"
file = file.substring(0, file.length() - 4);

// remove path: "group-module-x.y.z"
int i = file.lastIndexOf('/');
if (i >= 0) {
file = file.substring(i + 1);
}

// remove group: "module-x.y.z"
i = file.indexOf("-");
if (i >= 0) {
file = file.substring(i + 1);
}

// remove module: "x.y.z"
while (file.length() > 0 && !Character.isDigit(file.charAt(0))) {
i = file.indexOf("-");
Expand Down

0 comments on commit 5fd41d7

Please sign in to comment.