Added cards database cleanup on new builds/releases run (client/server sides);

This commit is contained in:
Oleg Agafonov 2018-12-21 23:11:43 +04:00
parent 20d5bfc3c9
commit 20a3b0b777
6 changed files with 83 additions and 15 deletions

View file

@ -1,50 +0,0 @@
package mage.utils;
import org.apache.log4j.Logger;
import java.net.URL;
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
/**
* @author JayDi85
*/
public class JarVersion {
private static final Logger logger = Logger.getLogger(JarVersion.class);
private static final String JAR_BUILD_TIME_FROM_CLASSES = "runtime";
private static final String JAR_BUILD_TIME_ERROR = "n/a";
public static String getBuildTime(Class clazz) {
// build time info inserted by maven on jar build phase (see root pom.xml)
String className = clazz.getSimpleName() + ".class";
String classPath = clazz.getResource(className).toString();
// https://stackoverflow.com/a/1273432/1276632
String manifestPath;
if (classPath.startsWith("jar")) {
// jar source
manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) + "/META-INF/MANIFEST.MF";
} else {
// dir source (e.g. IDE's debug)
// it's can be generated by runtime, but need extra code and performance: https://stackoverflow.com/questions/34674073/how-to-generate-manifest-mf-file-during-compile-phase
// manifestPath = classPath.substring(0, classPath.lastIndexOf("/" + className)) + "/META-INF/MANIFEST.MF";
return JAR_BUILD_TIME_FROM_CLASSES;
}
try {
Manifest manifest = new Manifest(new URL(manifestPath).openStream());
Attributes attr = manifest.getMainAttributes();
String buildTime = attr.getValue("Build-Time");
Instant instant = Instant.parse(buildTime);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm").withZone(ZoneOffset.UTC);
return formatter.format(instant);
} 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;
}
}
}

View file

@ -1,5 +1,7 @@
package mage.utils;
import mage.util.JarVersion;
import java.io.Serializable;
/**