diff options
author | Manuel Bentele | 2021-07-02 15:32:14 +0200 |
---|---|---|
committer | Manuel Bentele | 2021-07-02 15:32:14 +0200 |
commit | 9c79bfe28db1f3f6ec6801d04a5f4b5226650b20 (patch) | |
tree | 2c98b818ba84253566e825336cea2f01b062a183 /dozentenmodul/src/main/java/org/openslx/dozmod/util/ClientVersion.java | |
parent | [client] Make launchData a byte array; this is opaque data (diff) | |
download | tutor-module-9c79bfe28db1f3f6ec6801d04a5f4b5226650b20.tar.gz tutor-module-9c79bfe28db1f3f6ec6801d04a5f4b5226650b20.tar.xz tutor-module-9c79bfe28db1f3f6ec6801d04a5f4b5226650b20.zip |
[client] Refactor printing of app information from MANIFEST.MF
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.java | 50 |
1 files changed, 3 insertions, 47 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 e7eb31c3..0ac740b2 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/util/ClientVersion.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/util/ClientVersion.java @@ -7,8 +7,6 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.net.URL; import java.nio.charset.StandardCharsets; -import java.util.jar.Attributes; -import java.util.jar.Manifest; import org.apache.commons.io.FileUtils; import org.apache.commons.io.output.ByteArrayOutputStream; @@ -16,6 +14,7 @@ import org.apache.log4j.Logger; import org.openslx.dozmod.App; import org.openslx.dozmod.Branding; import org.openslx.sat.thrift.version.Version; +import org.openslx.util.AppUtil; import org.openslx.util.Json; public class ClientVersion { @@ -100,51 +99,8 @@ public class ClientVersion { * into the fields 'localRevision' and 'localRevisionTime' */ private static void loadLocalVersion() { - Class<ClientVersion> clazz = ClientVersion.class; - String className = clazz.getSimpleName() + ".class"; - String classPath = clazz.getResource(className).toString(); - if (!classPath.startsWith("jar")) { - // Class not from JAR - return; - } - String manifestPath = classPath.replaceAll("![^!]*$", "") + "!/META-INF/MANIFEST.MF"; - Manifest manifest = null; - try (InputStream stream = new URL(manifestPath).openStream()) { - manifest = new Manifest(stream); - } catch (Exception e) { - if (manifest == null) { - LOGGER.error("Could not open MANIFEST", e); - return; - } - } - 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"); - } catch (Exception e) { - LOGGER.warn("Error while reading revision: ", e); - } - try { - manifestRevTime = attributes.getValue("Build-Revision-Timestamp"); - } catch (Exception e) { - LOGGER.warn("Error while reading timestamp: ", e); - } - if (manifestRev != null) { - localRevision = manifestRev; - } - if (manifestRevTime != null) { - try { - // hax since we get milliseconds not seconds - localRevisionTime = Long.valueOf(manifestRevTime) / 1000L; - } catch (NumberFormatException e) { - LOGGER.warn("Build timestamp is not a number!", e); - } - } + localRevision = AppUtil.getRevisionVersion(); + localRevisionTime = AppUtil.getBuildTimestamp(); } /** |