diff --git a/src/main/java/org/ballerinalang/command/util/OSUtils.java b/src/main/java/org/ballerinalang/command/util/OSUtils.java index 88e6c48a..804433c1 100644 --- a/src/main/java/org/ballerinalang/command/util/OSUtils.java +++ b/src/main/java/org/ballerinalang/command/util/OSUtils.java @@ -204,7 +204,7 @@ private static boolean isWindows() { return OS.contains("win"); } - private static boolean isMac() { + public static boolean isMac() { return OS.contains("mac"); } diff --git a/src/main/java/org/ballerinalang/command/util/ToolUtil.java b/src/main/java/org/ballerinalang/command/util/ToolUtil.java index 7fe03c1c..9502f9b4 100644 --- a/src/main/java/org/ballerinalang/command/util/ToolUtil.java +++ b/src/main/java/org/ballerinalang/command/util/ToolUtil.java @@ -566,8 +566,12 @@ private static void downloadAndSetupDependency(HttpURLConnection conn, PrintStre zipFile = Paths.get(zipFileLocation).toFile(); downloadFile(conn, zipFileLocation, dependency, printStream); unzip(zipFileLocation, dependencyLocation); - addExecutablePermissionToFile(new File(dependencyLocation + File.separator + dependency - + File.separator + "bin" + File.separator + "java")); + if(OSUtils.isMac()) { + addExecutablePermissionToDirectory(dependencyLocation + File.separator + dependency); + } else { + addExecutablePermissionToFile(new File(dependencyLocation + File.separator + dependency + + File.separator + "bin" + File.separator + "java")); + } if (zipFile.exists()) { zipFile.delete(); } @@ -800,4 +804,15 @@ public static String getTypeName(String version) { return preview; } } + + private static void addExecutablePermissionToDirectory(String filePath) { + Process process; + try { + process = Runtime.getRuntime().exec("chmod -R 755 " + filePath); + process.waitFor(); + } catch (InterruptedException | IOException e) { + throw ErrorUtil.createCommandException("permission denied: you do not have write access to '" + filePath + + "'"); + } + } }