mirror of
https://github.com/hs-web/hsweb-framework.git
synced 2026-06-06 22:19:29 +08:00
优化版本解析
This commit is contained in:
@@ -202,18 +202,22 @@ class Version implements Comparable<Version> {
|
||||
if (null == version) {
|
||||
return;
|
||||
}
|
||||
version = version.toLowerCase();
|
||||
|
||||
boolean snapshot = version.toLowerCase().contains("snapshot");
|
||||
version = version.toLowerCase()
|
||||
.replace(".snapshot", "")
|
||||
.replace("-snapshot", "")
|
||||
.replace("-rc", "")
|
||||
.replace("-release", "");
|
||||
String[] ver = version.split("[.]");
|
||||
|
||||
String[] ver = version.split("[-]")[0].split("[.]");
|
||||
Integer[] numberVer = ListUtils.stringArr2intArr(ver);
|
||||
if (numberVer.length < 1 || Arrays.stream(numberVer).anyMatch(Objects::isNull)) {
|
||||
if (numberVer.length == 0) {
|
||||
numberVer = new Integer[]{1, 0, 0};
|
||||
log.warn("解析版本号失败:{},将使用默认版本号:1.0.0,请检查hsweb-starter.js配置内容!", version);
|
||||
}
|
||||
|
||||
for (int i = 0; i < numberVer.length; i++) {
|
||||
if (numberVer[i] == null) {
|
||||
numberVer[i] = 0;
|
||||
}
|
||||
}
|
||||
setVersion(numberVer[0],
|
||||
numberVer.length <= 1 ? 0 : numberVer[1],
|
||||
numberVer.length <= 2 ? 0 : numberVer[2],
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package org.hswebframework.web.starter;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author zhouhao
|
||||
* @since 3.0.8
|
||||
*/
|
||||
public class SystemVersionTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
SystemVersion version = new SystemVersion();
|
||||
|
||||
version.setVersion("3.0-RELEASE");
|
||||
Assert.assertEquals(version.getMajorVersion(), 3);
|
||||
Assert.assertEquals(version.getMinorVersion(), 0);
|
||||
Assert.assertEquals(version.getRevisionVersion(), 0);
|
||||
|
||||
version.setVersion("3.0.1-RELEASE");
|
||||
Assert.assertEquals(version.getMajorVersion(), 3);
|
||||
Assert.assertEquals(version.getMinorVersion(), 0);
|
||||
Assert.assertEquals(version.getRevisionVersion(), 1);
|
||||
version.setVersion("3.2.1-SNAPSHOT");
|
||||
Assert.assertEquals(version.getMajorVersion(), 3);
|
||||
Assert.assertEquals(version.getMinorVersion(), 2);
|
||||
Assert.assertEquals(version.getRevisionVersion(), 1);
|
||||
Assert.assertTrue(version.isSnapshot());
|
||||
|
||||
version.setVersion("3.1.2");
|
||||
Assert.assertEquals(version.getMajorVersion(), 3);
|
||||
Assert.assertEquals(version.getMinorVersion(), 1);
|
||||
Assert.assertEquals(version.getRevisionVersion(), 2);
|
||||
|
||||
version.setVersion("3.1.2.RELEASE");
|
||||
Assert.assertEquals(version.getMajorVersion(), 3);
|
||||
Assert.assertEquals(version.getMinorVersion(), 1);
|
||||
Assert.assertEquals(version.getRevisionVersion(), 2);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user