Make update checking more robust
Dieser Commit ist enthalten in:
Ursprung
cc4d035b63
Commit
a88b919e60
@ -94,6 +94,20 @@
|
||||
<finalName>ProtocolLib</finalName>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.10</version>
|
||||
<configuration>
|
||||
<systemProperties>
|
||||
<property>
|
||||
<name>projectVersion</name>
|
||||
<value>${project.version}</value>
|
||||
</property>
|
||||
</systemProperties>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
@ -150,7 +150,7 @@ public class ProtocolLibrary extends JavaPlugin {
|
||||
|
||||
// Updater
|
||||
private Updater updater;
|
||||
private static boolean UPDATES_DISABLED;
|
||||
public static boolean UPDATES_DISABLED;
|
||||
|
||||
// Logger
|
||||
private static Logger logger;
|
||||
@ -754,8 +754,4 @@ public class ProtocolLibrary extends JavaPlugin {
|
||||
public static void log(Level level, String message, Throwable ex) {
|
||||
logger.log(level, message, ex);
|
||||
}
|
||||
|
||||
public void disableUpdates() {
|
||||
UPDATES_DISABLED = true;
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,8 @@ import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.error.Report;
|
||||
import com.comphenix.protocol.utility.Closer;
|
||||
@ -34,12 +36,10 @@ import com.google.common.base.Charsets;
|
||||
*/
|
||||
|
||||
public final class SpigotUpdater extends Updater {
|
||||
private ProtocolLibrary plugin;
|
||||
private String remoteVersion;
|
||||
|
||||
public SpigotUpdater(ProtocolLibrary plugin, UpdateType type, boolean announce) {
|
||||
public SpigotUpdater(Plugin plugin, UpdateType type, boolean announce) {
|
||||
super(plugin, type, announce);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -78,7 +78,7 @@ public final class SpigotUpdater extends Updater {
|
||||
plugin.getLogger().log(Level.WARNING, "Failed to check for updates: " + ex);
|
||||
}
|
||||
|
||||
plugin.disableUpdates();
|
||||
ProtocolLibrary.UPDATES_DISABLED = true;
|
||||
} finally {
|
||||
// Invoke the listeners on the main thread
|
||||
for (Runnable listener : listeners) {
|
||||
|
@ -56,7 +56,7 @@ public abstract class Updater {
|
||||
this.announce = announce;
|
||||
}
|
||||
|
||||
protected boolean versionCheck(String title) {
|
||||
public boolean versionCheck(String title) {
|
||||
if (this.type != UpdateType.NO_VERSION_CHECK) {
|
||||
String version = this.plugin.getDescription().getVersion();
|
||||
|
||||
@ -84,6 +84,10 @@ public abstract class Updater {
|
||||
}
|
||||
|
||||
// Parse the version
|
||||
if (remoteVersion.startsWith("v")) {
|
||||
remoteVersion = remoteVersion.substring(1);
|
||||
}
|
||||
|
||||
MinecraftVersion parsedRemote = new MinecraftVersion(remoteVersion);
|
||||
MinecraftVersion parsedCurrent = new MinecraftVersion(plugin.getDescription().getVersion());
|
||||
|
||||
|
@ -12,9 +12,9 @@ import java.util.logging.Logger;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.updater.Updater.UpdateType;
|
||||
|
||||
/**
|
||||
@ -23,10 +23,23 @@ import com.comphenix.protocol.updater.Updater.UpdateType;
|
||||
|
||||
public class UpdaterTest {
|
||||
private static final int BUKKIT_DEV_ID = 45564;
|
||||
private static Plugin plugin;
|
||||
|
||||
@BeforeClass
|
||||
public static void preparePlugin() {
|
||||
Server server = mock(Server.class);
|
||||
when(server.getUpdateFolder()).thenReturn(null);
|
||||
|
||||
plugin = mock(Plugin.class);
|
||||
when(plugin.getDescription()).thenReturn(new PluginDescriptionFile("ProtocolLib", System.getProperty("projectVersion"), null));
|
||||
when(plugin.getLogger()).thenReturn(Logger.getLogger("ProtocolLib"));
|
||||
when(plugin.getDataFolder()).thenReturn(null);
|
||||
when(plugin.getServer()).thenReturn(server);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpigotUpdater() {
|
||||
SpigotUpdater updater = new SpigotUpdater(null, UpdateType.NO_DOWNLOAD, true);
|
||||
SpigotUpdater updater = new SpigotUpdater(plugin, UpdateType.NO_DOWNLOAD, true);
|
||||
|
||||
String remote = null;
|
||||
|
||||
@ -38,19 +51,12 @@ public class UpdaterTest {
|
||||
}
|
||||
|
||||
System.out.println("Determined remote Spigot version: " + remote);
|
||||
|
||||
updater.versionCheck(remote);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBukkitUpdater() {
|
||||
Server server = mock(Server.class);
|
||||
when(server.getUpdateFolder()).thenReturn(null);
|
||||
|
||||
Plugin plugin = mock(Plugin.class);
|
||||
when(plugin.getDescription()).thenReturn(new PluginDescriptionFile("ProtocolLib", ProtocolLibrary.class.getPackage().getImplementationVersion(), null));
|
||||
when(plugin.getLogger()).thenReturn(Logger.getLogger("ProtocolLib"));
|
||||
when(plugin.getDataFolder()).thenReturn(null);
|
||||
when(plugin.getServer()).thenReturn(server);
|
||||
|
||||
BukkitUpdater updater = new BukkitUpdater(plugin, BUKKIT_DEV_ID, null, UpdateType.NO_DOWNLOAD, true);
|
||||
if (! updater.read()) {
|
||||
fail("Failed to check for updates");
|
||||
@ -58,5 +64,7 @@ public class UpdaterTest {
|
||||
|
||||
String remote = updater.getLatestName();
|
||||
System.out.println("Determined remote Bukkit Dev version: " + remote);
|
||||
|
||||
updater.versionCheck(remote);
|
||||
}
|
||||
}
|
In neuem Issue referenzieren
Einen Benutzer sperren