mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Plugin downloader: use version comparator aware of semantic versioning (IDEA-141034).
This commit is contained in:
+2
-1
@@ -35,6 +35,7 @@ import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.PathUtil;
|
||||
import com.intellij.util.io.HttpRequests;
|
||||
import com.intellij.util.io.ZipUtil;
|
||||
import com.intellij.util.text.VersionComparatorUtil;
|
||||
import org.apache.http.client.utils.URIBuilder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -199,7 +200,7 @@ public class PluginDownloader {
|
||||
}
|
||||
|
||||
public static int comparePluginVersions(String newPluginVersion, String oldPluginVersion) {
|
||||
return StringUtil.compareVersionNumbers(newPluginVersion, oldPluginVersion);
|
||||
return VersionComparatorUtil.compare(newPluginVersion, oldPluginVersion);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -31,14 +31,22 @@ public class VersionCompareTest extends TestCase {
|
||||
return PluginDownloader.comparePluginVersions(v1, v2);
|
||||
}
|
||||
|
||||
public void testEqual () {
|
||||
public static void ascending(String... versions) {
|
||||
assertTrue(versions.length > 1);
|
||||
for (int i = 0; i < versions.length - 1; i++) {
|
||||
assertTrue(versions[i] + " is greater then " + versions[i + 1],
|
||||
compareVersions(versions[i], versions[i + 1]) < 0);
|
||||
}
|
||||
}
|
||||
|
||||
public void testEqual() {
|
||||
String v1 = "0.0.1";
|
||||
String v2 = "0.0.1";
|
||||
|
||||
assertTrue("Version is not equal", compareVersions(v1, v2) == 0);
|
||||
}
|
||||
|
||||
public void testGreat () {
|
||||
public void testGreat() {
|
||||
String v1 = "0.0.2";
|
||||
String v2 = "0.0.1";
|
||||
|
||||
@@ -46,7 +54,7 @@ public class VersionCompareTest extends TestCase {
|
||||
compareVersions(v1, v2) > 0);
|
||||
}
|
||||
|
||||
public void testLess () {
|
||||
public void testLess() {
|
||||
String v1 = "0.0.1";
|
||||
String v2 = "0.0.2";
|
||||
|
||||
@@ -54,7 +62,7 @@ public class VersionCompareTest extends TestCase {
|
||||
compareVersions(v1, v2) < 0);
|
||||
}
|
||||
|
||||
public void testGreatDiff () {
|
||||
public void testGreatDiff() {
|
||||
String v1 = "0.0.2.0";
|
||||
String v2 = "0.0.1.0";
|
||||
|
||||
@@ -62,7 +70,7 @@ public class VersionCompareTest extends TestCase {
|
||||
compareVersions(v1, v2) > 0);
|
||||
}
|
||||
|
||||
public void testLessDiff () {
|
||||
public void testLessDiff() {
|
||||
String v1 = "0.0.1.1";
|
||||
String v2 = "0.0.2.0";
|
||||
|
||||
@@ -76,7 +84,7 @@ public class VersionCompareTest extends TestCase {
|
||||
|
||||
assertEquals(0, compareVersions("1.0.0", "1.0."));
|
||||
assertEquals(0, compareVersions("1.0.0", "1."));
|
||||
|
||||
|
||||
assertEquals(0, compareVersions("1.0.", "1.0.0"));
|
||||
assertEquals(0, compareVersions("1.", "1.0.0"));
|
||||
|
||||
@@ -92,7 +100,7 @@ public class VersionCompareTest extends TestCase {
|
||||
assertTrue(compareVersions("1.0.01", "1") > 0);
|
||||
}
|
||||
|
||||
public void testWord () {
|
||||
public void testWord() {
|
||||
String v1 = "0.0.1a";
|
||||
String v2 = "0.0.2";
|
||||
|
||||
@@ -100,7 +108,7 @@ public class VersionCompareTest extends TestCase {
|
||||
compareVersions(v1, v2) < 0);
|
||||
}
|
||||
|
||||
public void testNewest () {
|
||||
public void testNewest() {
|
||||
String serverVer = "1.0.10";
|
||||
String userVer = "1.0.9";
|
||||
|
||||
@@ -112,5 +120,35 @@ public class VersionCompareTest extends TestCase {
|
||||
assertTrue(compareVersions("3.6.2", "3.7") < 0);
|
||||
assertTrue(compareVersions("3.7.1", "3.13.4") < 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* See http://semver.org/
|
||||
*/
|
||||
public void testSemver() {
|
||||
ascending("0.1.2", "0.1.11", "0.1.11-2", "1.0.0-alpha", "1.0.0-alpha.1", "1.0.0-beta",
|
||||
"1.0.0-beta.2", "1.0.0-beta.11", "1.0.0-rc.1", "1.0.0");
|
||||
}
|
||||
|
||||
// Some real world examples from IDEA plugin repository
|
||||
|
||||
public void testPythonPlugin() {
|
||||
ascending("3.1 Beta", "3.1 Beta 2", "3.1", "3.1.1.134.1462", "3.4.Beta.135.1",
|
||||
"3.4.135.21", "4.0 Beta 139.3", "4.0 Beta 139.58", "4.0.12",
|
||||
"4.1 141.4 EAP", "4.1 141.39 EAP", "4.5 141.82"
|
||||
);
|
||||
}
|
||||
|
||||
public void testRubyPlugin() {
|
||||
assertTrue(compareVersions("7.1.0.20150520", "7.1.0.20150501") > 0);
|
||||
}
|
||||
|
||||
public void testScalaPlugin() {
|
||||
assertTrue(compareVersions("1.3.3.16-14.1", "1.3.3.15-14.1") > 0);
|
||||
}
|
||||
|
||||
public void testBashPlugin() {
|
||||
assertTrue(compareVersions("1.1beta16", "1.1beta8") > 0);
|
||||
assertTrue(compareVersions("1.5.0.142-beta2", "1.5.0.142-beta1") > 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user