Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signed-off-by: Lawan Samarasekara <[email protected]> #4554

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions src/main/java/com/divudi/bean/common/VersionController.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.nio.file.Files;
import java.nio.file.Paths;
import java.io.IOException;
import java.nio.file.Path;


/**
Expand All @@ -21,27 +20,20 @@
public class VersionController {

private final String fileName = "VERSION.txt";
private String systemVersion = ""; // Public vareiable to store the system version read from the file
private String systemVersion; // Public vareiable to store the system version read from the file

public VersionController() {
//readFirstLine(); // Load first line content upon bean instantiation
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() {
String filePath = "../".repeat(7) + fileName;
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);
String firstLine = Files.lines(Paths.get(filePath)).findFirst().orElse(null);
if (firstLine != null && !firstLine.isEmpty()) {
// Set systemVersion to the content of the first line
systemVersion = firstLine.trim();
Expand Down
Loading