Skip to content

Commit

Permalink
Merge pull request #4553 from hmislk/Issue#4547
Browse files Browse the repository at this point in the history
Issue#4547
  • Loading branch information
DARKDRAGON-LK authored Apr 9, 2024
2 parents 54a076f + af8ed0a commit ff3e899
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/create_version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
64 changes: 64 additions & 0 deletions src/main/java/com/divudi/bean/common/VersionController.java
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
*/
@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;
}
}
2 changes: 1 addition & 1 deletion src/main/webapp/resources/template/template.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
<h5><h:outputLabel style="text-transform: uppercase" class="text-left" value="#{sessionController.loggedUser.department.name}"/></h5>
<h6 class="mx-2">|</h6>
<h6><h:outputLabel value="#{sessionController.loggedUser.name}"/></h6>
<h6><h:outputLabel class="text-left" value="&emsp;V.3.0.0.20240409.1"/emsp;V.3.0.0.20240409.1"/emsp;V.3.0.0.20240410003738.1"/emsp;V.3.0.0.20240410.2"/></h6>
<h6><h:outputLabel class="text-left" value="&emsp;V.#{versionController.systemVersion}"/></h6>
</div>
</div>

Expand Down

0 comments on commit ff3e899

Please sign in to comment.