Archiviert
13
0

Made the auto-update-checker suggest channels to server administrators if they're upgrading past their preferred channel.

Dieser Commit ist enthalten in:
Nathan Adams 2012-03-01 16:04:18 +00:00
Ursprung a5be079797
Commit eb934c760d
5 geänderte Dateien mit 101 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -175,6 +175,7 @@ public final class CraftServer implements Server {
updater = new AutoUpdater(new BukkitDLUpdaterService(configuration.getString("auto-updater.host")), getLogger(), configuration.getString("auto-updater.preferred-channel"));
updater.setEnabled(configuration.getBoolean("auto-updater.enabled"));
updater.setSuggestChannels(configuration.getBoolean("auto-updater.suggest-channels"));
updater.getOnBroken().addAll(configuration.getStringList("auto-updater.on-broken"));
updater.getOnUpdate().addAll(configuration.getStringList("auto-updater.on-update"));
updater.check(serverVersion);

Datei anzeigen

@ -10,6 +10,23 @@ public class ArtifactDetails {
private String version;
private Date created;
private FileDetails file;
private ChannelDetails channel;
public ChannelDetails getChannel() {
return channel;
}
public void setChannel(ChannelDetails channel) {
this.channel = channel;
}
public boolean isIsBroken() {
return isBroken;
}
public void setIsBroken(boolean isBroken) {
this.isBroken = isBroken;
}
public FileDetails getFile() {
return file;
@ -78,4 +95,34 @@ public class ArtifactDetails {
this.url = url;
}
}
public static class ChannelDetails {
private String name;
private String slug;
private int priority;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getPriority() {
return priority;
}
public void setPriority(int priority) {
this.priority = priority;
}
public String getSlug() {
return slug;
}
public void setSlug(String slug) {
this.slug = slug;
}
}
}

Datei anzeigen

@ -16,6 +16,7 @@ public class AutoUpdater {
private boolean enabled;
private ArtifactDetails current = null;
private ArtifactDetails latest = null;
private boolean suggestChannels = true;
public AutoUpdater(BukkitDLUpdaterService service, Logger log, String channel) {
this.service = service;
@ -35,6 +36,14 @@ public class AutoUpdater {
this.enabled = isEnabled;
}
public boolean shouldSuggestChannels() {
return suggestChannels;
}
public void setSuggestChannels(boolean suggestChannels) {
this.suggestChannels = suggestChannels;
}
public List<String> getOnBroken() {
return onBroken;
}
@ -100,6 +109,17 @@ public class AutoUpdater {
log.severe("Unfortunately, there is not yet a newer version suitable for your server. We would advise you wait an hour or two, or try out a dev build.");
log.severe("----- ------------------- -----");
} else if ((current != null) && (shouldSuggestChannels())) {
ArtifactDetails.ChannelDetails prefChan = service.getChannel(channel, "preferred channel details");
if ((prefChan != null) && (current.getChannel().getPriority() < prefChan.getPriority())) {
log.info("----- Bukkit Auto Updater -----");
log.info("It appears that you're running a " + current.getChannel().getName() + ", when you've specified in bukkit.yml that you prefer to run " + prefChan.getName() + "s.");
log.info("If you would like to be kept informed about new " + current.getChannel().getName() + " releases, it is recommended that you change 'preferred-channel' in your bukkit.yml to '" + current.getChannel().getSlug() + "'.");
log.info("With that set, you will be told whenever a new version is available for download, so that you can always keep up to date and secure with the latest fixes.");
log.info("If you would like to disable this warning, simply set 'suggest-channels' to false in bukkit.yml.");
log.info("----- ------------------- -----");
}
}
}
}.start();

Datei anzeigen

@ -13,7 +13,8 @@ import java.util.logging.Level;
import java.util.logging.Logger;
public class BukkitDLUpdaterService {
private static final String API_PREFIX = "/api/1.0/downloads/projects/craftbukkit/view/";
private static final String API_PREFIX_ARTIFACT = "/api/1.0/downloads/projects/craftbukkit/view/";
private static final String API_PREFIX_CHANNEL = "/api/1.0/downloads/channels/";
private static final DateDeserializer dateDeserializer = new DateDeserializer();
private final String host;
@ -34,7 +35,7 @@ public class BukkitDLUpdaterService {
}
public ArtifactDetails fetchArtifact(String slug) throws UnsupportedEncodingException, IOException {
URL url = new URL("http", host, API_PREFIX + slug);
URL url = new URL("http", host, API_PREFIX_ARTIFACT + slug);
InputStreamReader reader = null;
try {
@ -50,6 +51,35 @@ public class BukkitDLUpdaterService {
}
}
public ArtifactDetails.ChannelDetails getChannel(String slug, String name) {
try {
return fetchChannel(slug);
} catch (UnsupportedEncodingException ex) {
Logger.getLogger(BukkitDLUpdaterService.class.getName()).log(Level.WARNING, "Could not get " + name + ": " + ex.getClass().getSimpleName());
} catch (IOException ex) {
Logger.getLogger(BukkitDLUpdaterService.class.getName()).log(Level.WARNING, "Could not get " + name + ": " + ex.getClass().getSimpleName());
}
return null;
}
public ArtifactDetails.ChannelDetails fetchChannel(String slug) throws UnsupportedEncodingException, IOException {
URL url = new URL("http", host, API_PREFIX_CHANNEL + slug);
InputStreamReader reader = null;
try {
reader = new InputStreamReader(url.openStream());
Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, dateDeserializer).setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
ArtifactDetails.ChannelDetails fromJson = gson.fromJson(reader, ArtifactDetails.ChannelDetails.class);
return fromJson;
} finally {
if (reader != null) {
reader.close();
}
}
}
static class DateDeserializer implements JsonDeserializer<Date> {
private static final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

Datei anzeigen

@ -31,6 +31,7 @@ auto-updater:
on-update: [warn-console, warn-ops]
preferred-channel: rb
host: dl.bukkit.org
suggest-channels: true
aliases:
# icanhasbukkit:
# - version