Add git version to log and --version output

This commit is contained in:
Nathan McRae 2025-05-25 23:36:43 -07:00
parent 430b89bdda
commit 392d10c587

View File

@ -36,6 +36,7 @@ import java.util.logging.FileHandler;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.Optional; import java.util.Optional;
import java.util.Properties;
import javafx.application.Application; import javafx.application.Application;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
@ -50,8 +51,6 @@ public class Main extends Application {
public record StartParameters (Optional<NotificationController.NotificationParameters> notification) {} public record StartParameters (Optional<NotificationController.NotificationParameters> notification) {}
private static final Logger logger = Logger.getLogger(Main.class.getName()); private static final Logger logger = Logger.getLogger(Main.class.getName());
// TODO: get git info
private static final String VERSION = "0.0.1";
private static Path configPath = null; private static Path configPath = null;
private static Path statePath = null; private static Path statePath = null;
@ -130,6 +129,14 @@ public class Main extends Application {
primaryStage.titleProperty().bindBidirectional(controller.windowTitle); primaryStage.titleProperty().bindBidirectional(controller.windowTitle);
primaryStage.show(); primaryStage.show();
logger.info("Application started"); logger.info("Application started");
Properties properties = new Properties();
try {
properties.load(getClass().getClassLoader().getResourceAsStream("git.properties"));
logger.info("Application version: " + String.valueOf(properties.get("git.commit.id.full")));
} catch (IOException e) {
logger.log(Level.SEVERE, "Failed to load git information", e);
}
} }
} catch (IOException e) { } catch (IOException e) {
logger.log(Level.SEVERE, "Failed to load main view", e); logger.log(Level.SEVERE, "Failed to load main view", e);
@ -167,7 +174,13 @@ public class Main extends Application {
} }
if (parsedArgs.getVersionFlag()) { if (parsedArgs.getVersionFlag()) {
System.out.println("Numbers Station version " + VERSION); Properties properties = new Properties();
try {
properties.load(Main.class.getClassLoader().getResourceAsStream("git.properties"));
System.out.println(String.valueOf(properties.get("git.commit.id.full")));
} catch (IOException e) {
System.out.println("Failed to get git information");
}
System.exit(0); System.exit(0);
} }