Rewrite plugin version checker.
This commit removes the old version checker that used the DBO resource page and replaces it with a custom checker that uses the "legacy" Spigot resource API. The Spigot API is much more lightweight and doesn't require any sort of parsing. The new version checker uses a simple cache, keeping version checks fresh for up to one hour, reducing the need to go fishing on every op login. The cache resets on restarts, though, but this is acceptable. Note that no attempt has been made to ensure correctness on multiple, consecutive invocations when the cache is stale. If a cache refresh is initiated, all update checks invoked before the cache refresh has ended will behave as if no update is available. This is acceptable, because update checks are non-essential, the time frame is extremely narrow, and the most common result of an update check is "no updates available", since the amount of update checks made is vastly greater than the amount of updates released.
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
package com.garbagemule.MobArena;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class PluginVersionCheckTest {
|
||||
|
||||
@Parameterized.Parameters
|
||||
public static Collection<Object[]> data() {
|
||||
return Arrays.asList(new Object[][] {
|
||||
// Patch: local < remote
|
||||
{ "1.1.1", "1.1.2", true },
|
||||
// Patch: local > remote
|
||||
{ "1.1.2", "1.1.1", false },
|
||||
// Patch: equal
|
||||
{ "1.1.2", "1.1.2", false },
|
||||
|
||||
// Minor: local < remote
|
||||
{ "1.1.1", "1.2.1", true },
|
||||
{ "1.1.2", "1.2.1", true },
|
||||
// Minor: local > remote
|
||||
{ "1.2.1", "1.1.1", false },
|
||||
{ "1.2.1", "1.1.2", false },
|
||||
// Minor: equal
|
||||
{ "1.2.1", "1.2.1", false },
|
||||
{ "1.2.2", "1.2.2", false },
|
||||
|
||||
// Major: local < remote
|
||||
{ "1.1.1", "2.1.1", true },
|
||||
{ "1.1.2", "2.1.1", true },
|
||||
{ "1.2.1", "2.1.1", true },
|
||||
{ "1.2.2", "2.1.1", true },
|
||||
// Major: local > remote
|
||||
{ "2.1.1", "1.1.1", false },
|
||||
{ "2.1.1", "1.1.2", false },
|
||||
{ "2.1.1", "1.2.1", false },
|
||||
{ "2.1.1", "1.2.2", false },
|
||||
// Major: equal
|
||||
{ "2.1.1", "2.1.1", false },
|
||||
{ "2.2.1", "2.2.1", false },
|
||||
{ "2.2.2", "2.2.2", false },
|
||||
|
||||
// Incomplete: local < remote
|
||||
{ "1", "1.1.1", true },
|
||||
{ "1.1", "1.1.1", true },
|
||||
{ "1.1.1", "2" , true },
|
||||
{ "1.1.1", "1.2" , true },
|
||||
// Incomplete: local > remote
|
||||
{ "1.1.1", "1", false },
|
||||
{ "1.1.1", "1.1", false },
|
||||
{ "2" , "1.1.1", false },
|
||||
{ "1.2" , "1.1.1", false },
|
||||
|
||||
// Snapshot: local < remote
|
||||
{ "1.1.1-SNAPSHOT", "1.1.2", true },
|
||||
{ "1.1.1-SNAPSHOT", "1.2.1", true },
|
||||
{ "1.1.1-SNAPSHOT", "2.1.1", true },
|
||||
// Snapshot: local > remote
|
||||
{ "1.1.2-SNAPSHOT", "1.1.1", false },
|
||||
{ "1.2.1-SNAPSHOT", "1.1.1", false },
|
||||
{ "2.1.1-SNAPSHOT", "1.1.1", false },
|
||||
// Snapshot: equal
|
||||
{ "1.1.2-SNAPSHOT", "1.1.2", true },
|
||||
{ "1.2.1-SNAPSHOT", "1.2.1", true },
|
||||
{ "2.1.1-SNAPSHOT", "2.1.1", true },
|
||||
});
|
||||
}
|
||||
|
||||
@Parameterized.Parameter
|
||||
public String local;
|
||||
|
||||
@Parameterized.Parameter(1)
|
||||
public String remote;
|
||||
|
||||
@Parameterized.Parameter(2)
|
||||
public boolean expected;
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
boolean actual = PluginVersionCheck.lessThan(local, remote);
|
||||
|
||||
assertEquals("Expected " + local + " < " + remote + "?", expected, actual);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user