Fixed build time

This commit is contained in:
Oleg Agafonov 2019-01-08 11:00:26 +04:00
parent 503f383963
commit 8a9619bf80
2 changed files with 8 additions and 4 deletions

View file

@ -1,12 +1,13 @@
package mage.util; package mage.util;
import org.apache.log4j.Logger;
import java.net.URL; import java.net.URL;
import java.time.ZoneOffset; import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor; import java.time.temporal.TemporalAccessor;
import java.util.jar.Attributes; import java.util.jar.Attributes;
import java.util.jar.Manifest; import java.util.jar.Manifest;
import org.apache.log4j.Logger;
/** /**
* @author JayDi85 * @author JayDi85
@ -19,6 +20,7 @@ public class JarVersion {
public static String getBuildTime(Class clazz) { public static String getBuildTime(Class clazz) {
// build time info inserted by maven on jar build phase (see root pom.xml) // build time info inserted by maven on jar build phase (see root pom.xml)
String resultFormat = "uuuu-MM-dd HH:mm";
String className = clazz.getSimpleName() + ".class"; String className = clazz.getSimpleName() + ".class";
String classPath = clazz.getResource(className).toString(); String classPath = clazz.getResource(className).toString();
@ -38,10 +40,11 @@ public class JarVersion {
Manifest manifest = new Manifest(new URL(manifestPath).openStream()); Manifest manifest = new Manifest(new URL(manifestPath).openStream());
Attributes attr = manifest.getMainAttributes(); Attributes attr = manifest.getMainAttributes();
String buildTime = attr.getValue("Build-Time"); String buildTime = attr.getValue("Build-Time");
DateTimeFormatter sourceFormatter = DateTimeFormatter.ofPattern("uuuuMMdd-HHmm").withZone(ZoneOffset.UTC); // default maven format: yyyy-MM-dd'T'HH:mm:ss'Z' or see maven.build.timestamp.format in pom file
DateTimeFormatter sourceFormatter = DateTimeFormatter.ofPattern("uuuu-MM-dd'T'HH:mm:ss'Z'").withZone(ZoneOffset.UTC);
TemporalAccessor ta = sourceFormatter.parse(buildTime); TemporalAccessor ta = sourceFormatter.parse(buildTime);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("uuuu-MM-dd HH:mm").withZone(ZoneOffset.UTC); DateTimeFormatter resultFormatter = DateTimeFormatter.ofPattern(resultFormat).withZone(ZoneOffset.UTC);
return formatter.format(ta); return resultFormatter.format(ta);
} catch (Throwable e) { } catch (Throwable e) {
logger.error("Can't read build time in jar manifest for class " + clazz.getName() + " and path " + manifestPath, e); logger.error("Can't read build time in jar manifest for class " + clazz.getName() + " and path " + manifestPath, e);
return JAR_BUILD_TIME_ERROR; return JAR_BUILD_TIME_ERROR;

View file

@ -90,6 +90,7 @@
<properties> <properties>
<mage-version>1.4.32</mage-version> <mage-version>1.4.32</mage-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.build.timestamp.format>yyyy-MM-dd'T'HH:mm:ss'Z'</maven.build.timestamp.format>
</properties> </properties>
<dependencyManagement> <dependencyManagement>