diff --git a/ProtocolLib/pom.xml b/ProtocolLib/pom.xml index 72526a99..898dadc9 100644 --- a/ProtocolLib/pom.xml +++ b/ProtocolLib/pom.xml @@ -94,6 +94,20 @@ ProtocolLib + + + org.apache.maven.plugins + maven-surefire-plugin + 2.10 + + + + projectVersion + ${project.version} + + + + diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java b/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java index 1582de8b..8b76526e 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java @@ -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; - } } diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/updater/SpigotUpdater.java b/ProtocolLib/src/main/java/com/comphenix/protocol/updater/SpigotUpdater.java index 17b4604a..0e4e4e09 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/updater/SpigotUpdater.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/updater/SpigotUpdater.java @@ -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) { diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/updater/Updater.java b/ProtocolLib/src/main/java/com/comphenix/protocol/updater/Updater.java index bf91a441..0eded245 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/updater/Updater.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/updater/Updater.java @@ -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()); diff --git a/ProtocolLib/src/test/java/com/comphenix/protocol/updater/UpdaterTest.java b/ProtocolLib/src/test/java/com/comphenix/protocol/updater/UpdaterTest.java index 4ac0eef8..60c9a9af 100644 --- a/ProtocolLib/src/test/java/com/comphenix/protocol/updater/UpdaterTest.java +++ b/ProtocolLib/src/test/java/com/comphenix/protocol/updater/UpdaterTest.java @@ -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); } } \ No newline at end of file