mirror of
https://github.com/correl/mage.git
synced 2024-12-29 19:15:06 +00:00
Fixed build time
This commit is contained in:
parent
503f383963
commit
8a9619bf80
2 changed files with 8 additions and 4 deletions
|
@ -1,12 +1,13 @@
|
|||
package mage.util;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.net.URL;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.TemporalAccessor;
|
||||
import java.util.jar.Attributes;
|
||||
import java.util.jar.Manifest;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
* @author JayDi85
|
||||
|
@ -19,6 +20,7 @@ public class JarVersion {
|
|||
|
||||
public static String getBuildTime(Class clazz) {
|
||||
// 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 classPath = clazz.getResource(className).toString();
|
||||
|
||||
|
@ -38,10 +40,11 @@ public class JarVersion {
|
|||
Manifest manifest = new Manifest(new URL(manifestPath).openStream());
|
||||
Attributes attr = manifest.getMainAttributes();
|
||||
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);
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("uuuu-MM-dd HH:mm").withZone(ZoneOffset.UTC);
|
||||
return formatter.format(ta);
|
||||
DateTimeFormatter resultFormatter = DateTimeFormatter.ofPattern(resultFormat).withZone(ZoneOffset.UTC);
|
||||
return resultFormatter.format(ta);
|
||||
} catch (Throwable e) {
|
||||
logger.error("Can't read build time in jar manifest for class " + clazz.getName() + " and path " + manifestPath, e);
|
||||
return JAR_BUILD_TIME_ERROR;
|
||||
|
|
1
pom.xml
1
pom.xml
|
@ -90,6 +90,7 @@
|
|||
<properties>
|
||||
<mage-version>1.4.32</mage-version>
|
||||
<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>
|
||||
|
||||
<dependencyManagement>
|
||||
|
|
Loading…
Reference in a new issue