From 3b5c85048cd5cbb2fe720029854651cdf1172cb1 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Mon, 7 Sep 2015 13:51:24 +0200 Subject: [client] fallback nullcheck for getters --- .../java/org/openslx/dozmod/gui/MainWindow.java | 1 + .../org/openslx/dozmod/util/ClientVersion.java | 84 +++++++++++++++------- 2 files changed, 60 insertions(+), 25 deletions(-) (limited to 'dozentenmodul/src/main/java/org/openslx') diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java index ab52660f..7fc7cae1 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java @@ -378,6 +378,7 @@ public abstract class MainWindow { JMenuItem updateCheckItem = new JMenuItem("Software-Aktualisierung"); cascadeAboutMenu.add(disclaimerItem); cascadeAboutMenu.add(virtualizerNoticeItem); + cascadeAboutMenu.addSeparator(); cascadeAboutMenu.add(updateCheckItem); menuBar.add(Box.createHorizontalGlue()); diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/util/ClientVersion.java b/dozentenmodul/src/main/java/org/openslx/dozmod/util/ClientVersion.java index beb96bb2..9a124b17 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/util/ClientVersion.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/util/ClientVersion.java @@ -23,8 +23,27 @@ public class ClientVersion { private static void init() { loadLocalVersion(); - loadRemoteVersion(); + loadRemoteVersion("http://132.230.4.25/dozmod.version"); } + + + /** + * Gets the local revision id if loading it worked, "???" otherwise. + * + * @return id as String + */ + public static String getLocalRevision() { + if (localRevision == null) { + init(); + if (localRevision == null) + // fallback for dev purposes... + localRevision = "???"; + } + return localRevision; + } + /** + * @return + */ public static long getLocalRevTimestamp() { if (localRevisionTime == null) { init(); @@ -34,25 +53,37 @@ public class ClientVersion { } return localRevisionTime; } - public static long getRemoteRevTimestamp() { - if (remoteRevisionTime == null) - init(); - return remoteRevisionTime; - } - public static String getLocalRevision() { - if (localRevision == null) { + /** + * Gets the revision id of the latest remote version + * + * @return id as String if loading worked, "-" otherwise + */ + public static String getRemoteRevision() { + if (remoteRevision == null) { init(); - if (localRevision == null) - // fallback for dev purposes... - localRevision = "dev"; + if (remoteRevision == null) + remoteRevision = "-"; } - return localRevision; + return remoteRevision; } - public static String getRemoteRevision() { - if (remoteRevision == null) + /** + * Gets the timestamp of the latest remote version + * + * @return timestamp as Long if loading it worked, 0L otherwise + */ + public static long getRemoteRevTimestamp() { + if (remoteRevisionTime == null) { init(); - return remoteRevision; + if (remoteRevisionTime == null) + return 0L; + } + return remoteRevisionTime; } + /** + * Checks if we are running latest bwSuite version + * + * @return true if there is no newer version, false otherwise + */ public static boolean isNewest() { if (localRevisionTime == null || remoteRevisionTime == null) init(); @@ -61,9 +92,11 @@ public class ClientVersion { return true; return localRevisionTime >= remoteRevisionTime; } - + /** + * Loads the local version information from the jar's MANIFEST.MF + * into the fields 'localRevision' and 'localRevisionTime' + */ private static void loadLocalVersion() { - // load local version information from the jar's MANIFEST.MF Class clazz = ClientVersion.class; String className = clazz.getSimpleName() + ".class"; String classPath = clazz.getResource(className).toString(); @@ -101,17 +134,20 @@ public class ClientVersion { // hax since we get milliseconds not seconds localRevisionTime = localRevisionTime / 1000L; } - - LOGGER.info("Local revision: " + localRevision); - LOGGER.info("Local revision timestamp: " + localRevisionTime); } - // per GSON - private static void loadRemoteVersion() { + /** + * Loads the given UrlString as JSON and saves the remote information + * into fields 'remoteRevision' and 'remoteRevisionTime' + * + * The remote JSON should have 'timestamp' and 'revision', like: + * { "timestamp": 1, "revision": 2 } + */ + private static void loadRemoteVersion(final String urlString) { Gson gson = new Gson(); String json = null; BufferedReader reader = null; try { - URL url = new URL("http://132.230.4.25/dozmod.version"); + URL url = new URL(urlString); reader = new BufferedReader(new InputStreamReader(url.openStream())); StringBuffer buffer = new StringBuffer(); int read; @@ -137,8 +173,6 @@ public class ClientVersion { // seconds timestamp here... remoteRevisionTime = query.timestamp; } - LOGGER.debug("Remote revision: " + remoteRevision); - LOGGER.debug("Remote timestamp: " + remoteRevisionTime); } /** -- cgit v1.2.3-55-g7522