diff --git a/platform/platform-api/src/com/intellij/ide/BrowserUtil.java b/platform/platform-api/src/com/intellij/ide/BrowserUtil.java index 7f346cef4956..4325ac6c15f8 100644 --- a/platform/platform-api/src/com/intellij/ide/BrowserUtil.java +++ b/platform/platform-api/src/com/intellij/ide/BrowserUtil.java @@ -31,6 +31,7 @@ import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.*; import com.intellij.ui.GuiUtils; +import com.intellij.util.SmartList; import com.intellij.util.io.ZipUtil; import com.intellij.util.ui.OptionsDialog; import org.jetbrains.annotations.NonNls; @@ -43,9 +44,8 @@ import java.io.*; import java.lang.reflect.InvocationTargetException; import java.net.MalformedURLException; import java.net.URL; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; +import java.util.*; +import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.zip.ZipEntry; @@ -108,7 +108,7 @@ public class BrowserUtil { } if (getGeneralSettingsInstance().isUseDefaultBrowser() && canStartDefaultBrowser()) { - final String[] command = getDefaultBrowserCommand(); + final List command = getDefaultBrowserCommand(); if (command != null) { launchBrowserByCommand(url, command); } @@ -142,21 +142,21 @@ public class BrowserUtil { @Nullable @NonNls - private static String[] getDefaultBrowserCommand() { + private static List getDefaultBrowserCommand() { if (SystemInfo.isWindows) { - return new String[]{(SystemInfo.isWindows9x ? "command.com" : "cmd.exe"), "/c", "start", "\"\""}; + return Arrays.asList((SystemInfo.isWindows9x ? "command.com" : "cmd.exe"), "/c", "start", "\"\""); } else if (SystemInfo.isMac) { - return new String[]{ExecUtil.getOpenCommandPath()}; + return new SmartList(ExecUtil.getOpenCommandPath()); } else if (SystemInfo.isUnix && SystemInfo.hasXdgOpen()) { - return new String[]{"xdg-open"}; + return new SmartList("xdg-open"); } return null; } - private static void launchBrowserByCommand(final String url, @NotNull final String[] command) { + private static void launchBrowserByCommand(final String url, @NotNull final List command) { URL curl; try { curl = getURL(url); @@ -215,40 +215,19 @@ public class BrowserUtil { launchBrowserByCommand(url, getOpenBrowserCommand(browserPath)); } - /** - * @deprecated use {@link #getOpenBrowserCommand(String)} instead - */ - @SuppressWarnings({"UnusedDeclaration"}) - public static String[] getOpenBrowserCommand(final @NonNls @NotNull String browserPath, final String... parameters) { - return getOpenBrowserCommand(browserPath); - } - public static String[] getOpenBrowserCommand(final @NonNls @NotNull String browserPath) { - final String[] command; - - if (SystemInfo.isMac) { - if (new File(browserPath).isFile()) { - // versions before 10.6 don't allow to pass command line arguments to browser via 'open' command - // so we use full path to browser executable in such case - command = new String[]{browserPath}; - } - else { - command = new String[]{ExecUtil.getOpenCommandPath(), "-a", browserPath}; - } + public static List getOpenBrowserCommand(final @NonNls @NotNull String browserPath) { + // versions before 10.6 don't allow to pass command line arguments to browser via 'open' command + // so we use full path to browser executable in such case + if (SystemInfo.isMac && !new File(browserPath).isFile()) { + return Arrays.asList(ExecUtil.getOpenCommandPath(), "-a", browserPath); } - else if (SystemInfo.isWindows) { - if (new File(browserPath).isFile()) { - command = new String[]{browserPath}; - } - else { - command = new String[]{(SystemInfo.isWindows9x ? "command.com" : "cmd.exe"), "/c", "start", "\"\"", browserPath}; - } + else if (SystemInfo.isWindows && !new File(browserPath).isFile()) { + return Arrays.asList((SystemInfo.isWindows9x ? "command.com" : "cmd.exe"), "/c", "start", "\"\"", browserPath); } else { - command = new String[]{browserPath}; + return new SmartList(browserPath); } - - return command; } private static void showErrorMessage(final String message, final String title) { @@ -382,7 +361,7 @@ public class BrowserUtil { }); } - return VfsUtil.pathToUrl(FileUtil.toSystemIndependentName(new File(outputDir, targetFileRelativePath).getPath())) + anchor; + return VfsUtilCore.pathToUrl(FileUtil.toSystemIndependentName(new File(outputDir, targetFileRelativePath).getPath())) + anchor; } catch (IOException e) { LOG.warn(e); diff --git a/xml/impl/src/com/intellij/ide/browsers/BrowsersConfiguration.java b/xml/impl/src/com/intellij/ide/browsers/BrowsersConfiguration.java index 3c6b61c8867c..34f6ea0767b4 100644 --- a/xml/impl/src/com/intellij/ide/browsers/BrowsersConfiguration.java +++ b/xml/impl/src/com/intellij/ide/browsers/BrowsersConfiguration.java @@ -27,6 +27,7 @@ import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Conditions; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.ArrayUtil; import com.intellij.util.SystemProperties; import com.intellij.util.containers.ContainerUtil; @@ -41,10 +42,7 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; +import java.util.*; /** * @author spleaner @@ -239,7 +237,8 @@ public class BrowsersConfiguration implements PersistentStateComponent final boolean forceOpenNewInstanceOnMac) { final WebBrowserSettings settings = getBrowserSettings(family); final String path = settings.getPath(); - if (path != null && path.length() > 0) { + String pathCheckResult = checkPath(family, path); + if (pathCheckResult == null) { url = BrowserUtil.escapeUrl(url); try { final BrowserSpecificSettings specificSettings = settings.getBrowserSpecificSettings(); @@ -253,11 +252,15 @@ public class BrowsersConfiguration implements PersistentStateComponent } } else { - Messages.showErrorDialog(XmlBundle.message("browser.path.not.specified", family.getName()), - XmlBundle.message("browser.path.not.specified.title")); + Messages.showErrorDialog(pathCheckResult, XmlBundle.message("browser.path.not.specified.title")); } } + @Nullable + public static String checkPath(BrowserFamily family, String path) { + return StringUtil.isEmpty(path) ? XmlBundle.message("browser.path.not.specified", family.getName()) : null; + } + /** * @deprecated use {@link #launchBrowser(com.intellij.ide.browsers.BrowsersConfiguration.BrowserFamily, String)} instead */ @@ -269,10 +272,10 @@ public class BrowsersConfiguration implements PersistentStateComponent private static void launchBrowser(@NonNls @NotNull String browserPath, String url, final boolean forceOpenNewInstanceOnMac, @NonNls String... browserArgs) throws IOException { - final String[] command = BrowserUtil.getOpenBrowserCommand(browserPath); + final List command = BrowserUtil.getOpenBrowserCommand(browserPath); String[] args = ArrayUtil.append(browserArgs, url); - if (SystemInfo.isMac && ExecUtil.getOpenCommandPath().equals(command[0])) { + if (SystemInfo.isMac && ExecUtil.getOpenCommandPath().equals(command.get(0))) { if (browserArgs.length > 0) { if (BrowserUtil.isOpenCommandSupportArgs()) { args = ArrayUtil.mergeArrays(new String[]{url, "--args"}, browserArgs); @@ -287,11 +290,11 @@ public class BrowsersConfiguration implements PersistentStateComponent } } - final String[] commandLine = ArrayUtil.mergeArrays(command, args); + Collections.addAll(command, args); if (LOG.isDebugEnabled()) { - LOG.debug("Launching browser: " + Arrays.toString(commandLine)); + LOG.debug("Launching browser: " + Arrays.toString(command.toArray())); } - Runtime.getRuntime().exec(commandLine); + new ProcessBuilder(command).start(); } @Nullable