summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Bauer2015-09-07 12:39:04 +0200
committerJonathan Bauer2015-09-07 12:39:04 +0200
commit4eff859b143c824cb93a0497e685182459fa102f (patch)
tree76eefc38fc697170de3e509a450e8887fe642c0f
parent[client] Enable/Disable isactive & internet access (diff)
downloadtutor-module-4eff859b143c824cb93a0497e685182459fa102f.tar.gz
tutor-module-4eff859b143c824cb93a0497e685182459fa102f.tar.xz
tutor-module-4eff859b143c824cb93a0497e685182459fa102f.zip
[client] more work on client update stuff
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java2
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/activity/UpdatePanel.java2
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/CheckUpdateWindow.java15
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/CheckUpdateWindowLayout.java13
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/util/ClientVersion.java167
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/util/OpenLinks.java3
6 files changed, 133 insertions, 69 deletions
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 4e0e18c0..ab52660f 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java
@@ -266,7 +266,7 @@ public abstract class MainWindow {
// at this point we are sure to be logged in with a proper token
// thus we directly check for new version
if (!ClientVersion.isNewest()) {
- addPanel(new UpdatePanel(ClientVersion.getNewVersion()));
+ addPanel(new UpdatePanel(ClientVersion.getRemoteRevision()));
}
// Show main menu by default
showPage(MainMenuWindow.class);
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/activity/UpdatePanel.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/activity/UpdatePanel.java
index c4cf3071..212813f0 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/activity/UpdatePanel.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/activity/UpdatePanel.java
@@ -47,7 +47,7 @@ public class UpdatePanel extends ActivityPanel implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == btnLink) {
- OpenLinks.openWebpage(Link.VMWARE);
+ OpenLinks.openWebpage(Link.DOZMOD);
close();
}
if (e.getSource() == btnClose) {
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/CheckUpdateWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/CheckUpdateWindow.java
index 8e128322..be5d87c9 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/CheckUpdateWindow.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/CheckUpdateWindow.java
@@ -15,6 +15,9 @@ import org.openslx.dozmod.gui.helper.MessageType;
import org.openslx.dozmod.gui.helper.UiFeedback;
import org.openslx.dozmod.gui.window.layout.CheckUpdateWindowLayout;
import org.openslx.dozmod.gui.window.layout.DisclaimerWindowLayout;
+import org.openslx.dozmod.util.ClientVersion;
+import org.openslx.dozmod.util.OpenLinks;
+import org.openslx.dozmod.util.OpenLinks.Link;
/**
* Window for showing the disclaimer.
@@ -26,9 +29,17 @@ public class CheckUpdateWindow extends CheckUpdateWindowLayout implements UiFeed
public CheckUpdateWindow(Frame modalParent) {
super(modalParent);
-
- btnLink.setEnabled(false);
+ lblLocalVersion.setText(ClientVersion.getLocalRevision() + " (" + ClientVersion.getLocalRevTimestamp() + ")");
+ lblRemoteVersion.setText(ClientVersion.getRemoteRevision() + " (" + ClientVersion.getRemoteRevTimestamp() + ")");
+ btnLink.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ OpenLinks.openWebpage(Link.DOZMOD);
+ }
+ });
+ btnLink.setEnabled(!ClientVersion.isNewest());
+ pack();
}
public static void open(Frame modalParent) {
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/CheckUpdateWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/CheckUpdateWindowLayout.java
index d12bbd6e..6567e55e 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/CheckUpdateWindowLayout.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/CheckUpdateWindowLayout.java
@@ -17,6 +17,7 @@ import javax.swing.JTextArea;
import org.openslx.dozmod.gui.Gui;
import org.openslx.dozmod.gui.control.QLabel;
import org.openslx.dozmod.gui.helper.GridManager;
+import org.openslx.dozmod.util.ClientVersion;
import org.openslx.sat.thrift.version.Version;
@@ -29,34 +30,36 @@ public abstract class CheckUpdateWindowLayout extends JDialog {
private final static String closeButtonLabel = "Schließen";
protected static String changelogText = "-";
- protected static QLabel vmwareLink;
protected static JButton btnLink;
protected static JButton btnClose;
protected JScrollPane disclaimerPanel;
protected static JLabel newVersion;
+ protected JLabel lblLocalVersion;
+ protected JLabel lblRemoteVersion;
public CheckUpdateWindowLayout(Frame modalParent) {
super(modalParent, title, modalParent != null ? ModalityType.APPLICATION_MODAL : ModalityType.MODELESS);
setLayout(new BorderLayout());
- setPreferredSize(new Dimension(500, 300));
+ setPreferredSize(new Dimension(600, 400));
// Panel used for creating border. We'll add everything into this.
JPanel borderPanel = new JPanel();
borderPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
add(borderPanel);
-
+ lblLocalVersion = new JLabel("-");
+ lblRemoteVersion = new JLabel("-");
// information before the disclaimer
JPanel infoPanel = new JPanel();
GridManager infoGrid = new GridManager(infoPanel, 4);
infoPanel.setBorder(BorderFactory.createTitledBorder(noticeLabel));
infoGrid.add(new JLabel("Ihre Version"));
infoGrid.add(Box.createHorizontalStrut(10));
- infoGrid.add(new JLabel(String.valueOf(Version.VERSION)));
+ infoGrid.add(lblLocalVersion);
infoGrid.add(Box.createHorizontalGlue()).fill(true, false).expand(true, false);
infoGrid.nextRow();
infoGrid.add(new JLabel("Neueste Version"));
infoGrid.add(Box.createHorizontalStrut(10));
- infoGrid.add(new JLabel(String.valueOf(Version.VERSION)));
+ infoGrid.add(lblRemoteVersion);
infoGrid.add(Box.createHorizontalGlue()).fill(true, false).expand(true, false);
infoGrid.finish(false);
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 a1a86692..f7b75abf 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/util/ClientVersion.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/util/ClientVersion.java
@@ -1,70 +1,75 @@
package org.openslx.dozmod.util;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
import java.net.URL;
-import java.util.Scanner;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
import org.apache.log4j.Logger;
+import com.google.gson.Gson;
+
// ClientVersion is a bad name, TODO find better suited one :)
public class ClientVersion {
private static final Logger LOGGER = Logger.getLogger(ClientVersion.class);
-
- private static String remoteVersion = null;
+
private static Long localRevisionTime = null;
private static Long remoteRevisionTime = null;
- private static String revision = null;
+ private static String localRevision = null;
+ private static String remoteRevision = null;
private static void init() {
- // load local version information from the jar's MANIFEST.MF
- String manifestRev = null;
- String manifestRevTime = null;
- try {
- Attributes attributes = getAttr();
- if (attributes == null)
- return;
- manifestRev = attributes.getValue("Build-Revision");
- manifestRevTime = attributes.getValue("Build-Revision-Timestamp");
- if (manifestRev != null)
- revision = manifestRev;
- if (manifestRevTime != null)
- localRevisionTime = Long.valueOf(manifestRevTime);
- } catch ( NumberFormatException e) {
- LOGGER.warn("Error while reading version: ", e);
- }
- LOGGER.info("Local version timestamp: " + localRevisionTime);
- // load the remote version information
- URL remoteVersionUrl = null;
- Scanner scanner = null;
- try {
- remoteVersionUrl = new URL("http://132.230.4.25/dozmod.version");
- scanner = new Scanner(remoteVersionUrl.openStream());
- } catch (Exception e) {
- // TODO shouldn't happen anyways
- LOGGER.error("Could not download remote version from: " + remoteVersionUrl.getPath(), e);
- }
- // process only one line for now
- Long remoteTime = null;
- if (scanner.hasNextLong()) {
- remoteTime = scanner.nextLong();
+ loadLocalVersion();
+ loadRemoteVersion();
+ }
+ public static long getLocalRevTimestamp() {
+ if (localRevisionTime == null) {
+ init();
+ if (localRevisionTime == null)
+ // fallback for dev purposes...
+ localRevisionTime = 0L;
}
- scanner.close();
- if (remoteTime != null) {
- remoteRevisionTime = remoteTime;
+ return localRevisionTime;
+ }
+ public static long getRemoteRevTimestamp() {
+ if (remoteRevisionTime == null)
+ init();
+ return remoteRevisionTime;
+ }
+ public static String getLocalRevision() {
+ if (localRevision == null) {
+ init();
+ if (localRevision == null)
+ // fallback for dev purposes...
+ localRevision = "dev";
}
- LOGGER.info("Remote version timestamp: " + remoteRevisionTime);
-
+ return localRevision;
+ }
+ public static String getRemoteRevision() {
+ if (remoteRevision == null)
+ init();
+ return remoteRevision;
+ }
+ public static boolean isNewest() {
+ if (localRevisionTime == null || remoteRevisionTime == null)
+ init();
+ // fallback if the above did not work: fail
+ if (localRevisionTime == null || remoteRevisionTime == null)
+ return true;
+ return localRevisionTime >= remoteRevisionTime;
}
- private static Attributes getAttr() {
+ 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();
if (!classPath.startsWith("jar")) {
- // Class not from JAR
- return null;
+ // Class not from JAR
+ return;
}
String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) +
"/META-INF/MANIFEST.MF";
@@ -73,25 +78,69 @@ public class ClientVersion {
manifest = new Manifest(new URL(manifestPath).openStream());
} catch (Exception e) {
LOGGER.error("Could not open MANIFEST", e);
- return null;
+ return;
}
- Attributes attr = manifest.getMainAttributes();
- return attr;
- }
- public static String getNewVersion() {
- return getRevision();
+ Attributes attributes = manifest.getMainAttributes();
+ // if attr are null, then we couldn't open the jar's MANIFEST
+ // since we are probably not in a jar context, just do nothing
+ if (attributes == null)
+ return;
+ String manifestRev = null;
+ String manifestRevTime = null;
+ try {
+ manifestRev = attributes.getValue("Build-Revision");
+ manifestRevTime = attributes.getValue("Build-Revision-Timestamp");
+ } catch (IllegalArgumentException e) {
+ LOGGER.warn("Error while reading version: ", e);
+ return;
+ }
+ if (manifestRev != null)
+ localRevision = manifestRev;
+ if (manifestRevTime != null)
+ localRevisionTime = Long.valueOf(manifestRevTime);
+
+ LOGGER.info("Local revision: " + localRevision);
+ LOGGER.info("Local revision timestamp: " + localRevisionTime);
}
- public static String getRevision() {
- if (revision == null)
- init();
- return revision;
+ // per GSON
+ private static void loadRemoteVersion() {
+ Gson gson = new Gson();
+ String json = null;
+ BufferedReader reader = null;
+ try {
+ URL url = new URL("http://132.230.4.25/dozmod.version");
+ reader = new BufferedReader(new InputStreamReader(url.openStream()));
+ StringBuffer buffer = new StringBuffer();
+ int read;
+ char[] chars = new char[1024];
+ while ((read = reader.read(chars)) != -1)
+ buffer.append(chars, 0, read);
+ json = buffer.toString();
+ } catch (Exception e) {
+ LOGGER.error("Could not fetch remote version", e);
+ return;
+ } finally {
+ if (reader != null)
+ try {
+ reader.close();
+ } catch (IOException e) {
+ }
+ }
+
+ VersionQuery query = gson.fromJson(json, VersionQuery.class);
+ if (query.revision != null)
+ remoteRevision = query.revision;
+ if (query.timestamp != null)
+ remoteRevisionTime = query.timestamp;
+ LOGGER.debug("Remote revision: " + remoteRevision);
+ LOGGER.debug("Remote timestamp: " + remoteRevisionTime);
}
- public static boolean isNewest() {
- if (localRevisionTime == null || remoteRevisionTime == null)
- init();
- if (localRevisionTime == null || remoteRevisionTime == null)
- return true; // hax
- return localRevisionTime >= remoteRevisionTime;
+ /**
+ * Class for GSON json parsing
+ */
+ static class VersionQuery {
+ Long timestamp;
+ String revision;
}
}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/util/OpenLinks.java b/dozentenmodul/src/main/java/org/openslx/dozmod/util/OpenLinks.java
index 0443c2cf..ee2a6bbf 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/util/OpenLinks.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/util/OpenLinks.java
@@ -21,7 +21,8 @@ public class OpenLinks {
VMWARE(
"https://my.vmware.com/de/web/vmware/free#desktop_end_user_computing/vmware_player/6_0%7CPLAYER-603%7Cproduct_downloads"),
INTRO(
- "http://www.hs-offenburg.de/fileadmin/Einrichtungen/hrz/Projekte/bwLehrpool/3_bwLehrpool_-_Image_einbinden_und_starten.pdf");
+ "http://www.hs-offenburg.de/fileadmin/Einrichtungen/hrz/Projekte/bwLehrpool/3_bwLehrpool_-_Image_einbinden_und_starten.pdf"),
+ DOZMOD("http://mltk-services.ruf.uni-freiburg.de/mltk/tutor-module/builds.html");
private final URI uri;