From d1807e4fcffb08674bf6d7ea8dd91817667a2ba3 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Sun, 13 Nov 2011 19:44:38 +0100 Subject: [PATCH] Do not try to launch fsnotifier on unsupported platforms --- .../openapi/vfs/impl/local/FileWatcher.java | 51 +++++++++++++------ 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/FileWatcher.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/FileWatcher.java index e3ba099108c7..9c0460a085b7 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/FileWatcher.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/FileWatcher.java @@ -247,27 +247,31 @@ public class FileWatcher { shutdownProcess(); - @NonNls final String executableName = SystemInfo.isWindows ? "fsnotifier.exe" - : SystemInfo.isLinux && SystemInfo.isAMD64 ? "fsnotifier64" - : "fsnotifier"; + String execPath = null; - String alternatePathToExecutable = System.getProperty(PROPERTY_WATCHER_EXECUTABLE_PATH); - if (alternatePathToExecutable != null) { - if (!new File(alternatePathToExecutable).isFile()) { - alternatePathToExecutable = null; - } + final String altExecPath = System.getProperty(PROPERTY_WATCHER_EXECUTABLE_PATH); + if (altExecPath != null && new File(altExecPath).isFile()) { + execPath = FileUtil.toSystemDependentName(altExecPath); } - final String pathToExecutable = alternatePathToExecutable != null - ? FileUtil.toSystemDependentName(alternatePathToExecutable) - : PathManager.getBinPath() + File.separatorChar + executableName; - final File exec = new File(pathToExecutable); + + if (execPath == null) { + final String execName; + execName = getExecutableName(); + if (execName == null) { + myFailureShownToTheUser = true; // ignore unsupported platforms + return; + } + execPath = PathManager.getBinPath() + File.separatorChar + execName; + } + + final File exec = new File(execPath); if (!exec.exists()) { - notifyOnFailure("File watcher is not found at path: " + pathToExecutable, null); + notifyOnFailure("File watcher is not found at path: " + execPath, null); return; } if (!exec.canExecute()) { - notifyOnFailure("File watcher is not executable: " + pathToExecutable +"", new NotificationListener() { + notifyOnFailure("File watcher is not executable: " + execPath +"", new NotificationListener() { @Override public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) { ShowFilePathAction.open(exec, exec); @@ -276,9 +280,9 @@ public class FileWatcher { return; } - LOG.info("Starting file watcher: " + pathToExecutable); + LOG.info("Starting file watcher: " + execPath); - notifierProcess = Runtime.getRuntime().exec(new String[]{pathToExecutable}); + notifierProcess = Runtime.getRuntime().exec(new String[]{execPath}); notifierReader = new BufferedReader(new InputStreamReader(notifierProcess.getInputStream())); notifierWriter = new BufferedWriter(new OutputStreamWriter(notifierProcess.getOutputStream())); @@ -294,6 +298,21 @@ public class FileWatcher { } } + @Nullable + private static String getExecutableName() { + if (SystemInfo.isWindows) { + return "fsnotifier.exe"; + } + else if (SystemInfo.isMac) { + return "fsnotifier"; + } + else if (SystemInfo.isLinux) { + return SystemInfo.isAMD64 ? "fsnotifier64" : "fsnotifier"; + } + + return null; + } + private void notifyOnFailure(String cause, @Nullable NotificationListener listener) { if (!myFailureShownToTheUser) { myFailureShownToTheUser = true;