diff --git a/platform/platform-api/src/com/intellij/execution/util/ExecUtil.java b/platform/platform-api/src/com/intellij/execution/util/ExecUtil.java index f753d2500923..cb39f5fd76f6 100644 --- a/platform/platform-api/src/com/intellij/execution/util/ExecUtil.java +++ b/platform/platform-api/src/com/intellij/execution/util/ExecUtil.java @@ -27,9 +27,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.script.ScriptException; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; +import java.io.*; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -103,12 +101,15 @@ public class ExecUtil { } @Nullable - public static String execAndReadLine(@NotNull final List command) { + public static String execAndReadLine(final String... command) { try { - final ProcessOutput output = execAndGetOutput(command, null); - final List lines = output.getStdoutLines(); - if (lines.size() > 0) { - return lines.get(0); + final Process process = new GeneralCommandLine(command).createProcess(); + final BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); + try { + return reader.readLine(); + } + finally { + reader.close(); } } catch (Exception ignored) { } diff --git a/platform/platform-api/src/com/intellij/ide/BrowserUtil.java b/platform/platform-api/src/com/intellij/ide/BrowserUtil.java index 05f3d11df639..efca09d692a7 100644 --- a/platform/platform-api/src/com/intellij/ide/BrowserUtil.java +++ b/platform/platform-api/src/com/intellij/ide/BrowserUtil.java @@ -133,7 +133,7 @@ public class BrowserUtil { if (SystemInfo.isMac || SystemInfo.isWindows) { return true; } - else if (SystemInfo.isUnix && SystemInfo.hasXdgOpen) { + else if (SystemInfo.isUnix && SystemInfo.hasXdgOpen()) { return true; } else if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { @@ -152,7 +152,7 @@ public class BrowserUtil { else if (SystemInfo.isMac) { return new String[]{ExecUtil.getOpenCommandPath()}; } - else if (SystemInfo.isUnix && SystemInfo.hasXdgOpen) { + else if (SystemInfo.isUnix && SystemInfo.hasXdgOpen()) { return new String[]{"xdg-open"}; } diff --git a/platform/platform-impl/src/com/intellij/ide/actions/RevealFileAction.java b/platform/platform-impl/src/com/intellij/ide/actions/RevealFileAction.java index cbfaa06466b8..aa929d43c63b 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/RevealFileAction.java +++ b/platform/platform-impl/src/com/intellij/ide/actions/RevealFileAction.java @@ -41,7 +41,7 @@ public class RevealFileAction extends DumbAwareAction { @NotNull public static String getActionName() { - return SystemInfo.isMac ? "Reveal in Finder" : "Show in " + SystemInfo.nativeFileManagerName; + return SystemInfo.isMac ? "Reveal in Finder" : "Show in " + SystemInfo.getFileManagerName(); } @Override diff --git a/platform/platform-impl/src/com/intellij/ide/actions/ShowFilePathAction.java b/platform/platform-impl/src/com/intellij/ide/actions/ShowFilePathAction.java index c7a065c40589..7d29e02c02a6 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/ShowFilePathAction.java +++ b/platform/platform-impl/src/com/intellij/ide/actions/ShowFilePathAction.java @@ -35,6 +35,7 @@ import com.intellij.openapi.ui.popup.JBPopupFactory; import com.intellij.openapi.ui.popup.ListPopup; import com.intellij.openapi.ui.popup.PopupStep; import com.intellij.openapi.ui.popup.util.BaseListPopupStep; +import com.intellij.openapi.util.NotNullLazyValue; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.vfs.JarFileSystem; @@ -51,11 +52,19 @@ import java.awt.event.MouseEvent; import java.io.File; import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; public class ShowFilePathAction extends AnAction { private static final Logger LOG = Logger.getInstance("#com.intellij.ide.actions.ShowFilePathAction"); + private static NotNullLazyValue hasNautilusV3 = new NotNullLazyValue() { + @NotNull + @Override + protected Boolean compute() { + final String version = ExecUtil.execAndReadLine("nautilus", "--version"); + return version != null && version.startsWith("GNOME nautilus 3"); + } + }; + @Override public void update(final AnActionEvent e) { if (SystemInfo.isMac || !isSupported()) { @@ -166,7 +175,7 @@ public class ShowFilePathAction extends AnAction { public static boolean isSupported() { return SystemInfo.isWindows || Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.OPEN) || - SystemInfo.hasXdgOpen || SystemInfo.hasNautilus; + SystemInfo.hasXdgOpen() || SystemInfo.hasNautilus(); } /** @deprecated use {@linkplain #openFile(java.io.File)} (to remove in IDEA 13) */ @@ -231,7 +240,7 @@ public class ShowFilePathAction extends AnAction { return; } - if (Registry.is("ide.use.nautilus3") && SystemInfo.hasNautilus && hasNautilusV3()) { + if (Registry.is("ide.use.nautilus3") && SystemInfo.hasNautilus() && hasNautilusV3.getValue()) { if (toSelect != null) { new GeneralCommandLine("nautilus", toSelect.getCanonicalPath()).createProcess(); } @@ -242,10 +251,10 @@ public class ShowFilePathAction extends AnAction { } final String path = dir.getCanonicalPath(); - if (SystemInfo.hasXdgOpen) { + if (SystemInfo.hasXdgOpen()) { new GeneralCommandLine("/usr/bin/xdg-open", path).createProcess(); } - else if (SystemInfo.hasNautilus) { + else if (SystemInfo.hasNautilus()) { new GeneralCommandLine("nautilus", path).createProcess(); } else if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.OPEN)) { @@ -256,16 +265,6 @@ public class ShowFilePathAction extends AnAction { } } - private static Boolean hasNautilusV3 = null; - - private static boolean hasNautilusV3() { - if (hasNautilusV3 == null) { - final String version = ExecUtil.execAndReadLine(Arrays.asList("nautilus", "--version")); - hasNautilusV3 = version != null && version.startsWith("GNOME nautilus 3"); - } - return hasNautilusV3; - } - @Nullable private static VirtualFile getFile(final AnActionEvent e) { return PlatformDataKeys.VIRTUAL_FILE.getData(e.getDataContext()); diff --git a/platform/platform-impl/src/com/intellij/ide/actions/ShowLogAction.java b/platform/platform-impl/src/com/intellij/ide/actions/ShowLogAction.java index 1c99f828dcf8..ed5914b49483 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/ShowLogAction.java +++ b/platform/platform-impl/src/com/intellij/ide/actions/ShowLogAction.java @@ -44,6 +44,6 @@ public class ShowLogAction extends AnAction implements DumbAware { @NotNull public static String getActionName() { - return "Reveal Log in " + SystemInfo.nativeFileManagerName; + return "Reveal Log in " + SystemInfo.getFileManagerName(); } } diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/EditorsSplitters.java b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/EditorsSplitters.java index be81bbc8b2ea..20cc6e469da5 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/EditorsSplitters.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/EditorsSplitters.java @@ -166,7 +166,7 @@ public class EditorsSplitters extends JPanel { painter.appendLine("Open a file by name with " + getActionShortcutText("GotoFile")).smaller().withBullet() .appendLine("Open Recent files with " + getActionShortcutText("RecentFiles")).smaller().withBullet() .appendLine("Open Navigation Bar with " + getActionShortcutText("ShowNavBar")).smaller().withBullet() - .appendLine("Drag'n'Drop file(s) here from " + SystemInfo.nativeFileManagerName).smaller().withBullet() + .appendLine("Drag'n'Drop file(s) here from " + SystemInfo.getFileManagerName()).smaller().withBullet() .draw(g, new PairFunction>() { @Override public Pair fun(Integer width, Integer height) { diff --git a/platform/util/src/com/intellij/openapi/util/SystemInfo.java b/platform/util/src/com/intellij/openapi/util/SystemInfo.java index c62c32b6a71e..5921da2f0e62 100644 --- a/platform/util/src/com/intellij/openapi/util/SystemInfo.java +++ b/platform/util/src/com/intellij/openapi/util/SystemInfo.java @@ -51,9 +51,6 @@ public class SystemInfo extends SystemInfoRt { public static final boolean isKDE = _SUN_DESKTOP.contains("kde"); public static final boolean isGnome = _SUN_DESKTOP.contains("gnome"); - public static final boolean hasNautilus = isUnix && new File("/usr/bin/nautilus").canExecute(); - public static final boolean hasXdgOpen = isUnix && new File("/usr/bin/xdg-open").canExecute(); - public static final boolean isMacSystemMenu = isMac && "true".equals(System.getProperty("apple.laf.useScreenMenuBar")); public static final boolean isFileSystemCaseSensitive = SystemInfoRt.isFileSystemCaseSensitive; @@ -65,10 +62,46 @@ public class SystemInfo extends SystemInfoRt { public static final boolean isAMD64 = "amd64".equals(OS_ARCH); public static final boolean isMacIntel64 = isMac && "x86_64".equals(OS_ARCH); - public static final String nativeFileManagerName = isMac ? "Finder" : - isWindows ? "Explorer" : - hasNautilus ? "Nautilus" : - "File Manager"; + /** @deprecated use {@linkplain #hasXdgOpen()} (to remove in IDEA 13) */ + public static final boolean hasXdgOpen = false; + private static final NotNullLazyValue ourHasXdgOpen = new AtomicNotNullLazyValue() { + @NotNull + @Override + protected Boolean compute() { + return isUnix && new File("/usr/bin/xdg-open").canExecute(); + } + }; + public static boolean hasXdgOpen() { + return ourHasXdgOpen.getValue(); + } + + private static final NotNullLazyValue hasNautilus = new AtomicNotNullLazyValue() { + @NotNull + @Override + protected Boolean compute() { + return isUnix && new File("/usr/bin/nautilus").canExecute(); + } + }; + public static boolean hasNautilus() { + return hasNautilus.getValue(); + } + + /** @deprecated use {@linkplain #getFileManagerName()} (to remove in IDEA 13) */ + public static final String nativeFileManagerName = "File Manager"; + private static final NotNullLazyValue ourFileManagerName = new AtomicNotNullLazyValue() { + @NotNull + @Override + protected String compute() { + return isMac ? "Finder" : + isWindows ? "Explorer" : + hasNautilus() ? "Nautilus" : + "File Manager"; + } + }; + @NotNull + public static String getFileManagerName() { + return ourFileManagerName.getValue(); + } /** * Whether IDEA is running under MacOS X version 10.4 or later. diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsGeneralConfigurationPanel.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsGeneralConfigurationPanel.java index 2b1b63bf1b6f..70428d9c5989 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsGeneralConfigurationPanel.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsGeneralConfigurationPanel.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -95,7 +95,8 @@ public class VcsGeneralConfigurationPanel implements SearchableConfigurable { } myPromptsPanel.setSize(myPromptsPanel.getPreferredSize()); - myOnPatchCreation.setName((SystemInfo.isMac ? "Reveal patch in" : "Show patch in ") + SystemInfo.nativeFileManagerName + " after creation:"); + myOnPatchCreation.setName((SystemInfo.isMac ? "Reveal patch in" : "Show patch in ") + + SystemInfo.getFileManagerName() + " after creation:"); } public void apply() throws ConfigurationException {