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

This commit is contained in:
zhouhao
2018-12-06 19:16:13 +08:00
parent d3f06132f8
commit df65d6c737
3 changed files with 39 additions and 29 deletions

View File

@@ -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" : "");
}
}

View File

@@ -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;

View File

@@ -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 {