From a151cb84df5b05f88e12ef5f3e270ef807764c33 Mon Sep 17 00:00:00 2001 From: Dr M H B Ariyaratne Date: Wed, 10 Apr 2024 18:12:22 +0530 Subject: [PATCH 1/3] Signed-off-by: Dr M H B Ariyaratne --- .../divudi/bean/common/VersionController.java | 23 ++++++++----------- src/main/webapp/home.xhtml | 1 + 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/divudi/bean/common/VersionController.java b/src/main/java/com/divudi/bean/common/VersionController.java index fcee0816bf..102764aa3b 100644 --- a/src/main/java/com/divudi/bean/common/VersionController.java +++ b/src/main/java/com/divudi/bean/common/VersionController.java @@ -21,28 +21,23 @@ public VersionController() { readFirstLine(); // Load first line content upon bean instantiation } + import java.io.File ; + public void readFirstLine() { try { - // Check if the file exists, if not, create it - java.nio.file.Path path = Paths.get(fileName); + // Adjust the file path as necessary to match your deployment environment + String filePath = System.getProperty("user.dir") + File.separator + fileName; + java.nio.file.Path path = Paths.get(filePath); + if (!Files.exists(path)) { Files.createFile(path); } - // Read the first line from the file - String firstLine = Files.lines(path).findFirst().orElse(null); - if (firstLine != null && !firstLine.isEmpty()) { - // Set systemVersion to the content of the first line - systemVersion = firstLine.trim(); - } else { - // If the first line is empty or the file does not exist, set systemVersion to null - systemVersion = null; - } + String firstLine = Files.lines(path).findFirst().orElse("0.0.0.0"); + systemVersion = firstLine.trim(); } catch (IOException e) { - // Handle IOException by printing the stack trace e.printStackTrace(); - // Set systemVersion to null if an IOException occurs - systemVersion = null; + systemVersion = "0.0.0.0"; // Default version in case of error } } diff --git a/src/main/webapp/home.xhtml b/src/main/webapp/home.xhtml index 0f4bb6407f..bb4af7add8 100644 --- a/src/main/webapp/home.xhtml +++ b/src/main/webapp/home.xhtml @@ -29,6 +29,7 @@ -->
+

Version :

From c55370501810033cb8cb22e71780d86e29a44684 Mon Sep 17 00:00:00 2001 From: Dr M H B Ariyaratne Date: Wed, 10 Apr 2024 18:29:48 +0530 Subject: [PATCH 2/3] Closes #4568 Signed-off-by: Dr M H B Ariyaratne --- VERSION.txt | 1 - src/main/java/com/divudi/bean/common/VersionController.java | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) delete mode 100644 VERSION.txt diff --git a/VERSION.txt b/VERSION.txt deleted file mode 100644 index 787f18dba7..0000000000 --- a/VERSION.txt +++ /dev/null @@ -1 +0,0 @@ -3.0.0.20240410.15 diff --git a/src/main/java/com/divudi/bean/common/VersionController.java b/src/main/java/com/divudi/bean/common/VersionController.java index 102764aa3b..1a3fb02e44 100644 --- a/src/main/java/com/divudi/bean/common/VersionController.java +++ b/src/main/java/com/divudi/bean/common/VersionController.java @@ -5,6 +5,7 @@ import java.nio.file.Files; import java.nio.file.Paths; import java.io.IOException; +import java.io.File; /** * @@ -21,8 +22,6 @@ public VersionController() { readFirstLine(); // Load first line content upon bean instantiation } - import java.io.File ; - public void readFirstLine() { try { // Adjust the file path as necessary to match your deployment environment From 33aaa9a507842b1d26af4800ae4c9796421ab05d Mon Sep 17 00:00:00 2001 From: Dr M H B Ariyaratne Date: Wed, 10 Apr 2024 18:34:49 +0530 Subject: [PATCH 3/3] Signed-off-by: Dr M H B Ariyaratne --- .../divudi/bean/common/VersionController.java | 37 +++++++++++-------- src/main/resources/version.txt | 2 +- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/divudi/bean/common/VersionController.java b/src/main/java/com/divudi/bean/common/VersionController.java index 1a3fb02e44..297f3d4d9c 100644 --- a/src/main/java/com/divudi/bean/common/VersionController.java +++ b/src/main/java/com/divudi/bean/common/VersionController.java @@ -1,11 +1,11 @@ package com.divudi.bean.common; +import java.io.BufferedReader; import javax.inject.Named; import javax.enterprise.context.ApplicationScoped; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.io.IOException; -import java.io.File; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; /** * @@ -15,7 +15,6 @@ @ApplicationScoped public class VersionController { - private final String fileName = "VERSION.txt"; private String systemVersion; // Public vareiable to store the system version read from the file public VersionController() { @@ -24,19 +23,25 @@ public VersionController() { public void readFirstLine() { try { - // Adjust the file path as necessary to match your deployment environment - String filePath = System.getProperty("user.dir") + File.separator + fileName; - java.nio.file.Path path = Paths.get(filePath); - - if (!Files.exists(path)) { - Files.createFile(path); + // Use getClassLoader() to load the VERSION.txt file from src/main/resources + InputStream inputStream = getClass().getClassLoader().getResourceAsStream("VERSION.txt"); + if (inputStream != null) { + try ( BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) { + String firstLine = reader.readLine(); + if (firstLine != null && !firstLine.isEmpty()) { + systemVersion = firstLine.trim(); + } else { + systemVersion = "0.0.0.0"; // Set to a default or indicate unavailable + } + } // InputStream and BufferedReader are auto-closed here + } else { + // Handle case where VERSION.txt does not exist or could not be found + systemVersion = "0.0.0.0"; // Indicate that the version is unavailable } - - String firstLine = Files.lines(path).findFirst().orElse("0.0.0.0"); - systemVersion = firstLine.trim(); - } catch (IOException e) { + } catch (Exception e) { e.printStackTrace(); - systemVersion = "0.0.0.0"; // Default version in case of error + // Handle any exceptions, e.g., file not found, read errors + systemVersion = "0.0.0.0"; // Default version or indicate unavailable } } diff --git a/src/main/resources/version.txt b/src/main/resources/version.txt index 088eda41aa..642bc60c53 100644 --- a/src/main/resources/version.txt +++ b/src/main/resources/version.txt @@ -1 +1 @@ -version +3.0.0.20240410.16