From 35be6599f1b622cc53711a0ae689c223cc8a84c2 Mon Sep 17 00:00:00 2001 From: Suganya Date: Fri, 22 Jan 2021 19:25:14 +0530 Subject: [PATCH 1/2] Update current version after new installation --- .../ballerinalang/command/util/OSUtils.java | 24 +++++++++++-------- .../ballerinalang/command/util/ToolUtil.java | 13 ++++++---- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/ballerinalang/command/util/OSUtils.java b/src/main/java/org/ballerinalang/command/util/OSUtils.java index c4059d6f..6049f23d 100644 --- a/src/main/java/org/ballerinalang/command/util/OSUtils.java +++ b/src/main/java/org/ballerinalang/command/util/OSUtils.java @@ -100,20 +100,13 @@ public static String getBallerinaVersionFilePath() throws IOException { String userHome = getUserHome(); File ballerinaVersionfile = new File(userHome + File.separator + BALLERINA_HOME_DIR + File.separator + BALLERINA_CONFIG); - - File installerVersionfile = new File(userHome + File.separator - + BALLERINA_HOME_DIR + File.separator + INSTALLER_VERSION); - if (!ballerinaVersionfile.exists()) { ballerinaVersionfile.getParentFile().mkdirs(); ballerinaVersionfile.createNewFile(); - installerVersionfile.createNewFile(); ToolUtil.addExecutablePermissionToFile(ballerinaVersionfile); - ToolUtil.addExecutablePermissionToFile(installerVersionfile); ToolUtil.setVersion(ballerinaVersionfile.getPath(), ToolUtil.getCurrentInstalledBallerinaVersion()); - ToolUtil.setInstallerVersion(installerVersionfile.getPath()); } - return getUserHome() + File.separator + BALLERINA_HOME_DIR + File.separator + BALLERINA_CONFIG; + return userHome + File.separator + BALLERINA_HOME_DIR + File.separator + BALLERINA_CONFIG; } /** @@ -121,8 +114,19 @@ public static String getBallerinaVersionFilePath() throws IOException { * * @return path to the file */ - public static String getInstallerVersionFilePath() { - return getUserHome() + File.separator + BALLERINA_HOME_DIR + File.separator + INSTALLER_VERSION; + public static String getInstallerVersionFilePath() throws IOException { + String userHome = getUserHome(); + File installerVersionfile = new File(userHome + File.separator + + BALLERINA_HOME_DIR + File.separator + INSTALLER_VERSION); + + if (new File(OSUtils.getInstalledInstallerVersionPath()).exists() && !installerVersionfile.exists()) { + installerVersionfile.getParentFile().mkdirs(); + installerVersionfile.createNewFile(); + ToolUtil.addExecutablePermissionToFile(installerVersionfile); + ToolUtil.setInstallerVersion(installerVersionfile.getPath()); + ToolUtil.setVersion(getBallerinaVersionFilePath(), ToolUtil.getCurrentInstalledBallerinaVersion()); + } + return userHome + File.separator + BALLERINA_HOME_DIR + File.separator + INSTALLER_VERSION; } public static String getBallerinaDistListFilePath() { diff --git a/src/main/java/org/ballerinalang/command/util/ToolUtil.java b/src/main/java/org/ballerinalang/command/util/ToolUtil.java index 7fcb9c0f..3439bac1 100644 --- a/src/main/java/org/ballerinalang/command/util/ToolUtil.java +++ b/src/main/java/org/ballerinalang/command/util/ToolUtil.java @@ -89,12 +89,15 @@ public void checkServerTrusted(java.security.cert.X509Certificate[] certs, Strin */ public static String getCurrentBallerinaVersion() { try { - String userVersion = getVersion(OSUtils.getBallerinaVersionFilePath()); - String installerVersion = getInstallerVersion(OSUtils.getInstalledInstallerVersionPath()); - if (!installerVersion.equals(getInstallerVersion(OSUtils.getInstallerVersionFilePath()))) { - setCurrentBallerinaVersion(ToolUtil.getCurrentInstalledBallerinaVersion()); - setInstallerVersion(installerVersion); + String installerVersionFilePath = OSUtils.getInstallerVersionFilePath(); + if (new File(installerVersionFilePath).exists()) { + String installedInstallerVersion = getInstallerVersion(OSUtils.getInstalledInstallerVersionPath()); + if (!installedInstallerVersion.equals(getInstallerVersion(installerVersionFilePath))) { + setCurrentBallerinaVersion(ToolUtil.getCurrentInstalledBallerinaVersion()); + setInstallerVersion(installedInstallerVersion); + } } + String userVersion = getVersion(OSUtils.getBallerinaVersionFilePath()); if (checkDistributionAvailable(userVersion)) { return userVersion; } From e215209796c899f7e8842270b346550260116d4b Mon Sep 17 00:00:00 2001 From: Suganya Date: Fri, 22 Jan 2021 19:49:46 +0530 Subject: [PATCH 2/2] Update current ballerina version during version check --- src/main/java/org/ballerinalang/command/cmd/Command.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/ballerinalang/command/cmd/Command.java b/src/main/java/org/ballerinalang/command/cmd/Command.java index d9d1220e..8a521d88 100644 --- a/src/main/java/org/ballerinalang/command/cmd/Command.java +++ b/src/main/java/org/ballerinalang/command/cmd/Command.java @@ -65,6 +65,7 @@ String getCommandUsageInfo(String commandName) { } public void printVersionInfo() { + ToolUtil.getCurrentBallerinaVersion(); String output = "Update Tool " + ToolUtil.getCurrentToolsVersion() + "\n"; getPrintStream().print(output); }