Archiviert
13
0

Fix a false positive with the updater

Dieser Commit ist enthalten in:
Dan Mulloy 2016-05-16 17:43:58 -04:00
Ursprung 4330bae47f
Commit 869b457810
2 geänderte Dateien mit 373 neuen und 363 gelöschten Zeilen

Datei anzeigen

@ -57,43 +57,52 @@ public abstract class Updater {
} }
public boolean versionCheck(String title) { public boolean versionCheck(String title) {
if (this.type != UpdateType.NO_VERSION_CHECK) { if (this.type != UpdateType.NO_VERSION_CHECK) {
String version = this.plugin.getDescription().getVersion(); String version = this.plugin.getDescription().getVersion();
boolean devBuild = false; // Extract the version from the response
if (version.contains("-SNAPSHOT") || version.contains("-BETA")) { String[] split = title.split(" ");
devBuild = true; String remote = "Unknown";
version = version.substring(0, version.indexOf("-"));
}
final String[] splitTitle = title.split(" "); if (split.length == 2) { // BukkitDev
String remoteVersion; remote = split[1];
} else if (this instanceof SpigotUpdater) { // Spigot resource
if (splitTitle.length == 2) { remote = split[0];
remoteVersion = splitTitle[1].split("-")[0]; } else { // Misconfigured
} else if (this instanceof SpigotUpdater) {
remoteVersion = splitTitle[0];
} else {
// The file's name did not contain the string 'vVersion' // The file's name did not contain the string 'vVersion'
final String authorInfo = this.plugin.getDescription().getAuthors().size() == 0 ? "" : " (" + this.plugin.getDescription().getAuthors().get(0) + ")"; String authorInfo = this.plugin.getDescription().getAuthors().size() == 0 ? "" : " (" + this.plugin.getDescription().getAuthors().get(0) + ")";
this.plugin.getLogger().warning("The author of this plugin " + authorInfo + " has misconfigured their Auto Update system"); plugin.getLogger().warning("The author of this plugin " + authorInfo + " has misconfigured their Auto Update system");
this.plugin.getLogger().warning("File versions should follow the format 'PluginName VERSION[-SNAPSHOT]'"); plugin.getLogger().warning("File versions should follow the format 'PluginName VERSION[-SNAPSHOT]'");
this.plugin.getLogger().warning("Please notify the author of this error."); plugin.getLogger().warning("Please notify the author of this error.");
this.result = BukkitUpdater.UpdateResult.FAIL_NOVERSION; this.result = BukkitUpdater.UpdateResult.FAIL_NOVERSION;
return false; return false;
} }
// Parse the version // Check if the local version is a dev build
if (remoteVersion.startsWith("v")) {
remoteVersion = remoteVersion.substring(1);
}
MinecraftVersion parsedRemote = new MinecraftVersion(remoteVersion); boolean devBuild = false;
MinecraftVersion parsedCurrent = new MinecraftVersion(plugin.getDescription().getVersion()); if (version.contains("-SNAPSHOT") || version.contains("-BETA")) {
devBuild = true;
version = version.substring(0, version.indexOf("-"));
}
// Remove the v
if (remote.startsWith("v")) {
remote = remote.substring(1);
}
// Remove the build number if it snuck in there
if (version.contains("-b")) {
version = version.substring(0, version.lastIndexOf("-"));
}
// Parse it and our local version
MinecraftVersion parsedRemote = new MinecraftVersion(remote);
MinecraftVersion parsedCurrent = new MinecraftVersion(version);
if (devBuild && parsedRemote.equals(parsedCurrent)) { if (devBuild && parsedRemote.equals(parsedCurrent)) {
// They're using a dev build and this version has been released // They're using a dev build and this version has been released
return !remoteVersion.contains("-BETA") && !remoteVersion.contains("-SNAPSHOT"); return !remote.contains("-BETA") && !remote.contains("-SNAPSHOT");
} }
// The remote version has to be greater // The remote version has to be greater
@ -103,6 +112,7 @@ public abstract class Updater {
return false; return false;
} }
} }
return true; return true;
} }

Datei anzeigen

@ -30,7 +30,7 @@ public class UpdaterTest {
plugin = mock(Plugin.class); plugin = mock(Plugin.class);
String version = System.getProperty("projectVersion"); String version = System.getProperty("projectVersion");
if (version == null) version = "3.7.0-BETA"; if (version == null) version = "4.0.1-SNAPSHOT-b281";
when(plugin.getDescription()).thenReturn(new PluginDescriptionFile("ProtocolLib", version, null)); when(plugin.getDescription()).thenReturn(new PluginDescriptionFile("ProtocolLib", version, null));
when(plugin.getLogger()).thenReturn(Logger.getLogger("ProtocolLib")); when(plugin.getLogger()).thenReturn(Logger.getLogger("ProtocolLib"));
when(plugin.getDataFolder()).thenReturn(null); when(plugin.getDataFolder()).thenReturn(null);