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); } 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; }