summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/util/ClientVersion.java
diff options
context:
space:
mode:
authorJonathan Bauer2015-09-07 13:51:24 +0200
committerJonathan Bauer2015-09-07 13:51:24 +0200
commit3b5c85048cd5cbb2fe720029854651cdf1172cb1 (patch)
tree08762a25a878212917082fd50941450b10484d6d /dozentenmodul/src/main/java/org/openslx/dozmod/util/ClientVersion.java
parent[client] human readable build date from maven... (diff)
downloadtutor-module-3b5c85048cd5cbb2fe720029854651cdf1172cb1.tar.gz
tutor-module-3b5c85048cd5cbb2fe720029854651cdf1172cb1.tar.xz
tutor-module-3b5c85048cd5cbb2fe720029854651cdf1172cb1.zip
[client] fallback nullcheck for getters
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/util/ClientVersion.java')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/util/ClientVersion.java84
1 files changed, 59 insertions, 25 deletions
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);
}
/**