Browse Source

修复升级依赖版本错误问题

zhouhao 6 years ago
parent
commit
df65d6c737

+ 21 - 28
hsweb-starter/hsweb-spring-boot-starter/src/main/java/org/hswebframework/web/starter/SystemVersion.java

@@ -89,23 +89,23 @@ public class SystemVersion extends Version {
         /**
          * @see SystemVersion#name
          */
-        String name = "name";
+        String name            = "name";
         /**
          * @see SystemVersion#comment
          */
-        String comment = "comment";
+        String comment         = "comment";
         /**
          * @see SystemVersion#website
          */
-        String website = "website";
+        String website         = "website";
         /**
          * @see SystemVersion#majorVersion
          */
-        String majorVersion = "majorVersion";
+        String majorVersion    = "majorVersion";
         /**
          * @see SystemVersion#minorVersion
          */
-        String minorVersion = "minorVersion";
+        String minorVersion    = "minorVersion";
         /**
          * @see SystemVersion#revisionVersion
          */
@@ -113,7 +113,7 @@ public class SystemVersion extends Version {
         /**
          * @see SystemVersion#snapshot
          */
-        String snapshot = "snapshot";
+        String snapshot        = "snapshot";
 
         /**
          * @see SystemVersion#frameworkVersion
@@ -183,13 +183,13 @@ public class SystemVersion extends Version {
 
 @Slf4j
 class Version implements Comparable<Version> {
-    protected String name;
-    protected String comment;
-    protected String website;
-    protected int majorVersion = 1;
-    protected int minorVersion = 0;
-    protected int revisionVersion = 0;
-    protected boolean snapshot = false;
+    protected String  name;
+    protected String  comment;
+    protected String  website;
+    protected int     majorVersion    = 1;
+    protected int     minorVersion    = 0;
+    protected int     revisionVersion = 0;
+    protected boolean snapshot        = false;
 
     public void setVersion(int major, int minor, int revision, boolean snapshot) {
         this.majorVersion = major;
@@ -293,13 +293,7 @@ class Version implements Comparable<Version> {
                 return -1;
             }
             if (o.getMinorVersion() == this.getMinorVersion()) {
-                if (o.getRevisionVersion() > this.getRevisionVersion()) {
-                    return -1;
-                }
-                if (o.getRevisionVersion() == this.getRevisionVersion()) {
-                    return 0;
-                }
-                return 1;
+                return Integer.compare(this.getRevisionVersion(), o.getRevisionVersion());
             } else {
                 return 1;
             }
@@ -309,18 +303,17 @@ class Version implements Comparable<Version> {
     }
 
     public String versionToString() {
-        return new StringBuilder()
-                .append(majorVersion).append(".")
-                .append(minorVersion).append(".")
-                .append(revisionVersion).append(snapshot ? "-SNAPSHOT" : "").toString();
+        return String.valueOf(majorVersion) + "." +
+                minorVersion + "." +
+                revisionVersion + (snapshot ? "-SNAPSHOT" : "");
     }
 
     @Override
     public String toString() {
-        return new StringBuilder(name).append(" version ")
-                .append(majorVersion).append(".")
-                .append(minorVersion).append(".")
-                .append(revisionVersion).append(snapshot ? "-SNAPSHOT" : "").toString();
+        return name + " version " +
+                majorVersion + "." +
+                minorVersion + "." +
+                revisionVersion + (snapshot ? "-SNAPSHOT" : "");
     }
 
 }

+ 1 - 1
hsweb-starter/hsweb-spring-boot-starter/src/main/java/org/hswebframework/web/starter/init/SystemInitialize.java

@@ -111,7 +111,7 @@ public class SystemInitialize {
                         installer.doInstall(getScriptContext());
                     }
                     //更新依赖
-                    if (installed == null || installed.compareTo(dependency) > 0) {
+                    if (installed == null || installed.compareTo(dependency) < 0) {
                         installer.doUpgrade(getScriptContext(), installed);
                     }
                     return dependency;

+ 17 - 0
hsweb-starter/hsweb-spring-boot-starter/src/test/java/org/hswebframework/web/starter/InstallTests.java

@@ -31,6 +31,7 @@ import org.hswebframework.expands.script.engine.DynamicScriptEngine;
 import org.hswebframework.expands.script.engine.DynamicScriptEngineFactory;
 import org.hswebframework.web.starter.init.simple.SimpleDependencyInstaller;
 import org.hswebframework.utils.file.FileUtils;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.slf4j.LoggerFactory;
@@ -76,6 +77,22 @@ public class InstallTests {
         database = new SimpleDatabase(databaseMetaData, sqlExecutor);
     }
 
+    @Test
+    public void testVersion() {
+        SystemVersion version = new SystemVersion();
+        version.setVersion("3.0.0");
+
+        SystemVersion version2 = new SystemVersion();
+        version2.setVersion("3.0.1");
+
+        SystemVersion version4 = new SystemVersion();
+        version4.setVersion("3.0.2");
+
+        Assert.assertEquals(version.compareTo(version2), -1);
+
+        Assert.assertEquals(version.compareTo(version4), -1);
+    }
+
     @Test
     public void testInstall() throws Exception {