making backend version public

This commit is contained in:
rusefi 2020-07-24 15:16:20 -04:00
parent fde4b2455f
commit 984d852178
5 changed files with 42 additions and 30 deletions

View File

@ -1,8 +1,35 @@
package com.rusefi;
import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.concurrent.atomic.AtomicReference;
public class rusEFIVersion {
public static final int CONSOLE_VERSION = 20200723;
public static AtomicReference<String> firmwareVersion = new AtomicReference<>("N/A");
public static long classBuildTimeMillis() {
Class<?> clazz = rusEFIVersion.class;
URL resource = clazz.getResource(clazz.getSimpleName() + ".class");
if (resource == null) {
throw new IllegalStateException("Failed to find class file for class: " +
clazz.getName());
}
if (resource.getProtocol().equals("file")) {
try {
return new File(resource.toURI()).lastModified();
} catch (URISyntaxException e) {
return 0;
}
} else if (resource.getProtocol().equals("jar")) {
String path = resource.getPath();
return new File(path.substring(5, path.indexOf("!"))).lastModified();
} else {
throw new IllegalArgumentException("Unhandled url protocol: " +
resource.getProtocol() + " for class: " +
clazz.getName() + " resource: " + resource.toString());
}
}
}

View File

@ -31,7 +31,7 @@ public class Launcher extends rusEFIVersion {
*/
public static void main(final String[] args) throws Exception {
log.info("rusEFI UI console " + CONSOLE_VERSION);
log.info("Compiled " + new Date(ConsoleTools.classBuildTimeMillis()));
log.info("Compiled " + new Date(rusEFIVersion.classBuildTimeMillis()));
log.info("\n\n");
PersistentConfiguration.registerShutdownHook();

View File

@ -292,26 +292,6 @@ public class ConsoleTools {
Online.upload(new File(Online.outputXmlFileName), authToken);
}
public static long classBuildTimeMillis() throws URISyntaxException, IllegalStateException, IllegalArgumentException {
Class<?> clazz = ConsoleTools.class;
URL resource = clazz.getResource(clazz.getSimpleName() + ".class");
if (resource == null) {
throw new IllegalStateException("Failed to find class file for class: " +
clazz.getName());
}
if (resource.getProtocol().equals("file")) {
return new File(resource.toURI()).lastModified();
} else if (resource.getProtocol().equals("jar")) {
String path = resource.getPath();
return new File(path.substring(5, path.indexOf("!"))).lastModified();
} else {
throw new IllegalArgumentException("Unhandled url protocol: " +
resource.getProtocol() + " for class: " +
clazz.getName() + " resource: " + resource.toString());
}
}
static void detect(String[] strings) throws IOException, InterruptedException {
String autoDetectedPort = autoDetectPort();
if (autoDetectedPort == null) {

View File

@ -96,15 +96,14 @@ public class Backend implements Closeable {
new Monitoring(this).showStatistics,
new FkRegex(ProxyClient.VERSION_PATH, ProxyClient.BACKEND_VERSION),
new FkRegex("/", new RsHtml("<html><body>\n" +
"<a href='https://rusefi.com/online/'>rusEFI Online</a>\n" +
"<br/>\n" +
"<a href='" + Monitoring.STATUS + "'>Status</a>\n" +
"<br/>\n" +
"<a href='" + ProxyClient.VERSION_PATH + "'>Version</a>\n" +
"<a href='" + ProxyClient.LIST_CONTROLLERS_PATH + "'>Controllers</a>\n" +
"<a href='" + ProxyClient.LIST_APPLICATIONS_PATH + "'>Applications</a>\n" +
"<br/>\n" +
"<br/>\n" +
"<br/><a href='https://rusefi.com/online/'>rusEFI Online</a>\n" +
"<br/><br/><br/>\n" +
"<img src='https://rusefi.com/style/rusefi_online_color.png'/>" +
"<br/><br/><br/>\n" +
"<br/><br/><br/><a href='" + Monitoring.STATUS + "'>Status</a>\n" +
"<br/><br/><br/><a href='" + ProxyClient.VERSION_PATH + "'>Version</a>\n" +
"<br/><br/><br/><a href='" + ProxyClient.LIST_CONTROLLERS_PATH + "'>Controllers</a>\n" +
"<br/><br/><br/><a href='" + ProxyClient.LIST_APPLICATIONS_PATH + "'>Applications</a>\n" +
"</body></html>\n"))
), httpPort
).start(() -> isClosed);

View File

@ -1,5 +1,7 @@
package com.rusefi.server;
import com.rusefi.rusEFIVersion;
import com.rusefi.tools.online.ProxyClient;
import org.takes.Take;
import org.takes.facets.fork.FkRegex;
import org.takes.rs.RsJson;
@ -9,6 +11,7 @@ import javax.json.JsonObjectBuilder;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;
import java.util.Date;
public class Monitoring {
public static final String STATUS = "/status";
@ -39,6 +42,9 @@ public class Monitoring {
builder.add("serverPortForControllers", backend.serverPortForControllers);
builder.add("applicationsCount", backend.getApplicationsCount());
builder.add("controllersCount", backend.getControllersCount());
builder.add("backend version", ProxyClient.BACKEND_VERSION);
builder.add("framework version", rusEFIVersion.CONSOLE_VERSION);
builder.add("compiled", new Date(rusEFIVersion.classBuildTimeMillis()).toString());
return new RsJson(builder.build());
}