From af8ed0a6917222736fcf15f18edc57d20b127317 Mon Sep 17 00:00:00 2001 From: Lawan Samarasekara Date: Wed, 10 Apr 2024 01:28:53 +0530 Subject: [PATCH] Signed-off-by: Lawan Samarasekara --- .github/workflows/create_version.yml | 4 +- .../divudi/bean/common/VersionController.java | 64 +++++++++++++++++++ .../webapp/resources/template/template.xhtml | 2 +- 3 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/divudi/bean/common/VersionController.java diff --git a/.github/workflows/create_version.yml b/.github/workflows/create_version.yml index f4cd491b04..0be3fc76b8 100644 --- a/.github/workflows/create_version.yml +++ b/.github/workflows/create_version.yml @@ -53,9 +53,9 @@ jobs: run: | sed -i "s/Current Version:.*/Current Version: 3.0.0.${{ steps.current_date.outputs.date }}.${{ steps.increment_counter.outputs.counter }} (This line will be automatically updated to reflect the latest version)/" README.md - - name: Update template.xhtml + - name: Update VersionController.java run: | - sed -i "s| V\..*\"\/| V\.3\.0\.0\.${{ steps.current_date.outputs.date }}\.${{ steps.increment_counter.outputs.counter }}\"\/|" src/main/webapp/resources/template/template.xhtml + sed -i "s/private String systemVersion = \".*\";/private String systemVersion = \"3.0.0.${{ steps.current_date.outputs.date }}.${{ steps.increment_counter.outputs.counter }}\";/" src/main/java/com/divudi/bean/common/VersionController.java - name: Set Git user name and email run: | diff --git a/src/main/java/com/divudi/bean/common/VersionController.java b/src/main/java/com/divudi/bean/common/VersionController.java new file mode 100644 index 0000000000..c40c1903ff --- /dev/null +++ b/src/main/java/com/divudi/bean/common/VersionController.java @@ -0,0 +1,64 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/JSF/JSFManagedBean.java to edit this template + */ +package com.divudi.bean.common; + +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.nio.file.Path; + + +/** + * + * @author L C J Samarasekara + */ +@Named +@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() { + //readFirstLine(); // Load first line content upon bean instantiation + } + + /** + * Reads the first line of the text file and checks if it contains the system version. + */ + public void readFirstLine() { + try { + // Get the root directory of the application + Path rootDirectory = Paths.get("").toAbsolutePath(); + + // Construct the file path to VERSION.txt by navigating from the root directory + Path versionFilePath = rootDirectory.resolve(fileName); + + System.out.println("versionFilePath = " + versionFilePath); + + // Read the first line from the file + String firstLine = Files.lines(versionFilePath).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 "0.0.0.0" + systemVersion = "0.0.0.0"; + } + } catch (IOException e) { + // Handle IOException by printing the stack trace + e.printStackTrace(); + // Set systemVersion to "0.0.0.0" if an IOException occurs + systemVersion = "0.0.0.0"; + } +} + + // Getter for systemVersion (to make it accessible from XHTML) + public String getSystemVersion() { + return systemVersion; + } +} diff --git a/src/main/webapp/resources/template/template.xhtml b/src/main/webapp/resources/template/template.xhtml index 84ea2c5d63..b310e8340a 100644 --- a/src/main/webapp/resources/template/template.xhtml +++ b/src/main/webapp/resources/template/template.xhtml @@ -103,7 +103,7 @@
|
-
+