From 9c79bfe28db1f3f6ec6801d04a5f4b5226650b20 Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Fri, 2 Jul 2021 15:32:14 +0200 Subject: [client] Refactor printing of app information from MANIFEST.MF --- dozentenmodul/pom.xml | 13 +++--- .../src/main/java/org/openslx/dozmod/App.java | 20 ++------- .../src/main/java/org/openslx/dozmod/Config.java | 4 +- .../org/openslx/dozmod/util/ClientVersion.java | 50 ++-------------------- 4 files changed, 14 insertions(+), 73 deletions(-) diff --git a/dozentenmodul/pom.xml b/dozentenmodul/pom.xml index 027520e7..d19d2995 100755 --- a/dozentenmodul/pom.xml +++ b/dozentenmodul/pom.xml @@ -15,7 +15,6 @@ UTF-8 org.openslx.dozmod.App - yyyy.MM.dd HH:mm @@ -58,14 +57,16 @@ package create - create-timestamp false false - revision.timestamp + UTC + build.time + revision.branch + revision.version @@ -109,9 +110,9 @@ true - ${maven.build.timestamp} - ${buildNumber} - ${revision.timestamp} + ${build.time} + ${revision.branch} + ${revision.version} diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/App.java b/dozentenmodul/src/main/java/org/openslx/dozmod/App.java index 7e13be8d..fb1f4c86 100755 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/App.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/App.java @@ -36,9 +36,9 @@ import org.openslx.dozmod.gui.helper.I18n; import org.openslx.dozmod.gui.helper.Language; import org.openslx.dozmod.gui.helper.MessageType; import org.openslx.dozmod.util.ClientVersion; -import org.openslx.dozmod.util.FormatHelper; import org.openslx.dozmod.util.ProxyConfigurator; import org.openslx.thrifthelper.ThriftManager; +import org.openslx.util.AppUtil; import org.openslx.util.Util; public class App { @@ -67,7 +67,6 @@ public class App { final File logFile = new File(logFilePath); if (logFile.exists() && !logFile.isDirectory()) { // we have one, rename it to 'bwSuite.log.old' - LOGGER.info("renaming old log file"); try { File oldFile = new File(logFilePath + ".old"); oldFile.delete(); @@ -129,20 +128,6 @@ public class App { return logFilePath; } - - public static void logHeader(String logFilePath) - { - LOGGER.info("Starting logging to: " + logFilePath); - LOGGER.info(Branding.getApplicationName() + " Version: " + ClientVersion.getLocalRevision()); - LOGGER.info(" " + FormatHelper.longDate(ClientVersion.getLocalRevTimestamp())); - LOGGER.info("os.name: " + System.getProperty("os.name")); - LOGGER.info("java.specification.vendor: " + System.getProperty("java.specification.vendor")); - LOGGER.info("java.specification.name: " + System.getProperty("java.specification.name")); - LOGGER.info("java.specification.version: " + System.getProperty("java.specification.version")); - LOGGER.info("java.version: " + System.getProperty("java.version")); - LOGGER.info("java.vm.version: " + System.getProperty("java.vm.version")); - LOGGER.info("java.runtime.version: " + System.getProperty("java.runtime.version")); - } public static void main(final String[] args) throws InvocationTargetException, InterruptedException { @@ -176,7 +161,8 @@ public class App { } final String logFilePath = setupFileLogger(); - logHeader(logFilePath); + AppUtil.logHeader(LOGGER, Branding.getApplicationName(), App.class.getPackage().getImplementationVersion()); + LOGGER.info("Starting logging to " + logFilePath); // Setting the locale if (!setPreferredLanguage()) { diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/Config.java b/dozentenmodul/src/main/java/org/openslx/dozmod/Config.java index a0e41689..d3a561c9 100755 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/Config.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/Config.java @@ -67,8 +67,6 @@ public class Config { String configPath = null; // Determine OS - String osName = System.getProperty("os.name").toLowerCase(); - LOGGER.info("Machine's OS: " + osName); if (OsHelper.isWindows()) { // Windows machine. Use the environment variable 'APPDATA' which // should point to a path similar to: @@ -96,7 +94,7 @@ public class Config { // Check if the directory exists. if (!configFile.getParentFile().exists()) { - LOGGER.info("Folder " + configFile.getParentFile() + " does not exist, creating it."); + LOGGER.debug("Folder " + configFile.getParentFile() + " does not exist, creating it."); // Does not, create it if (!configFile.getParentFile().mkdirs()) { throw new IOException("Could not create '" + configFile.getParentFile() + "'."); 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 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(); } /** -- cgit v1.2.3-55-g7522