summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-06-20 20:07:20 +0300
committerPaul Buetow <paul@buetow.org>2025-06-20 20:07:20 +0300
commit32882ca8582a102b9357e8d7f2c313d52c568977 (patch)
treeaa0449c9c4c0d92a019d44caa84f9a24c8510098 /src/main
parent530d671353dfcfee74cdd16660105ffefa0784e9 (diff)
Implement dynamic version injection from pom.xml
- Create version.properties resource file with Maven placeholders - Enable Maven resource filtering for version.properties - Add VSVersionInfo utility class to read version at runtime - Update VSDefaultPrefs to use dynamic version instead of hardcoded - Version now shows "Distributed Systems Simulator 1.0.1-SNAPSHOT" - Includes build timestamp for better traceability The version in the title bar is now automatically updated from the pom.xml version during the build process. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/prefs/VSDefaultPrefs.java3
-rw-r--r--src/main/java/utils/VSVersionInfo.java108
-rw-r--r--src/main/resources/version.properties7
3 files changed, 117 insertions, 1 deletions
diff --git a/src/main/java/prefs/VSDefaultPrefs.java b/src/main/java/prefs/VSDefaultPrefs.java
index a723117..217144e 100644
--- a/src/main/java/prefs/VSDefaultPrefs.java
+++ b/src/main/java/prefs/VSDefaultPrefs.java
@@ -2,6 +2,7 @@ package prefs;
import java.awt.Color;
import java.awt.event.KeyEvent;
+import utils.VSVersionInfo;
/**
* The class VSDefaultPrefs, makes sure that the simulator has its default
@@ -81,7 +82,7 @@ public class VSDefaultPrefs extends VSSerializablePrefs {
initString("lang.message.recv", "Message received");
initString("lang.message.sent", "Message sent");
initString("lang.mode.expert", "Expert mode");
- initString("lang.name", "Distributed Systems Simulator 1.2-beta");
+ initString("lang.name", VSVersionInfo.getFullVersionString());
initString("lang.ok", "OK");
initString("lang.open", "Open");
initString("lang.pause", "Pause");
diff --git a/src/main/java/utils/VSVersionInfo.java b/src/main/java/utils/VSVersionInfo.java
new file mode 100644
index 0000000..24b9461
--- /dev/null
+++ b/src/main/java/utils/VSVersionInfo.java
@@ -0,0 +1,108 @@
+package utils;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+/**
+ * Provides version information for the application.
+ * This class reads version details from a properties file that is
+ * populated at build time by Maven resource filtering.
+ *
+ * @author Paul C. Buetow
+ */
+public final class VSVersionInfo {
+
+ private static final String VERSION_FILE = "/version.properties";
+ private static final Properties versionProps = new Properties();
+ private static boolean loaded = false;
+
+ /** Private constructor to prevent instantiation */
+ private VSVersionInfo() {}
+
+ /**
+ * Loads version properties from the resource file.
+ * This method is called automatically on first access.
+ */
+ private static synchronized void loadProperties() {
+ if (loaded) {
+ return;
+ }
+
+ try (InputStream is = VSVersionInfo.class.getResourceAsStream(VERSION_FILE)) {
+ if (is != null) {
+ versionProps.load(is);
+ loaded = true;
+ } else {
+ // Fallback values if properties file not found
+ versionProps.setProperty("app.version", "Unknown");
+ versionProps.setProperty("app.name", "DS-Sim");
+ versionProps.setProperty("app.description", "Distributed Systems Simulator");
+ loaded = true;
+ }
+ } catch (IOException e) {
+ // Fallback values on error
+ versionProps.setProperty("app.version", "Unknown");
+ versionProps.setProperty("app.name", "DS-Sim");
+ versionProps.setProperty("app.description", "Distributed Systems Simulator");
+ loaded = true;
+ }
+ }
+
+ /**
+ * Gets the application version from Maven project version.
+ *
+ * @return the version string (e.g., "1.0.1-SNAPSHOT")
+ */
+ public static String getVersion() {
+ if (!loaded) {
+ loadProperties();
+ }
+ return versionProps.getProperty("app.version", "Unknown");
+ }
+
+ /**
+ * Gets the application name from Maven project name.
+ *
+ * @return the application name
+ */
+ public static String getName() {
+ if (!loaded) {
+ loadProperties();
+ }
+ return versionProps.getProperty("app.name", "DS-Sim");
+ }
+
+ /**
+ * Gets the application description from Maven project description.
+ *
+ * @return the application description
+ */
+ public static String getDescription() {
+ if (!loaded) {
+ loadProperties();
+ }
+ return versionProps.getProperty("app.description", "Distributed Systems Simulator");
+ }
+
+ /**
+ * Gets the build timestamp.
+ *
+ * @return the build timestamp or "Unknown" if not available
+ */
+ public static String getBuildTimestamp() {
+ if (!loaded) {
+ loadProperties();
+ }
+ return versionProps.getProperty("build.timestamp", "Unknown");
+ }
+
+ /**
+ * Gets the full version string including name and version.
+ *
+ * @return formatted version string (e.g., "Distributed Systems Simulator 1.0.1-SNAPSHOT")
+ */
+ public static String getFullVersionString() {
+ return String.format("Distributed Systems Simulator %s", getVersion());
+ }
+} \ No newline at end of file
diff --git a/src/main/resources/version.properties b/src/main/resources/version.properties
new file mode 100644
index 0000000..dc3a55f
--- /dev/null
+++ b/src/main/resources/version.properties
@@ -0,0 +1,7 @@
+# Version information generated at build time
+# This file is processed by Maven resource filtering
+app.version=${project.version}
+app.name=${project.name}
+app.description=${project.description}
+build.timestamp=${maven.build.timestamp}
+maven.build.timestamp.format=yyyy-MM-dd HH:mm:ss \ No newline at end of file