Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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