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 d967259e8bc6..a8675ab27611 100644 --- a/platform/platform-api/src/com/intellij/execution/util/ExecUtil.java +++ b/platform/platform-api/src/com/intellij/execution/util/ExecUtil.java @@ -86,6 +86,7 @@ public class ExecUtil { return process.waitFor(); } + @NotNull public static String loadTemplate(@NotNull final ClassLoader loader, @NotNull final String templateName, @Nullable final Map variables) throws IOException { @@ -110,6 +111,7 @@ public class ExecUtil { return buffer.toString(); } + @NotNull public static File createTempExecutableScript(@NotNull final String prefix, @NotNull final String suffix, @NotNull final String source) throws IOException, ExecutionException { @@ -121,14 +123,22 @@ public class ExecUtil { return tempFile; } + @NotNull public static String getOsascriptPath() { return "/usr/bin/osascript"; } + @NotNull public static String getOpenCommandPath() { return "/usr/bin/open"; } + @NotNull + public static String getWindowsShellName() { + return SystemInfo.isWin2kOrNewer ? "cmd.exe" : "command.com"; + } + + @NotNull public static ProcessOutput execAndGetOutput(@NotNull final List command, @Nullable final String workDir) throws ExecutionException { assert command.size() > 0; @@ -155,15 +165,16 @@ public class ExecUtil { return null; } + @NotNull public static ProcessOutput sudoAndGetOutput(@NotNull final String scriptPath, @NotNull final String prompt) throws IOException, ExecutionException { return sudoAndGetOutput(scriptPath, prompt, null); } /** - * - * @param scriptPath is already escaped filepath + * @param scriptPath is already escaped file path */ + @NotNull public static ProcessOutput sudoAndGetOutput(@NotNull final String scriptPath, @NotNull final String prompt, @Nullable String workDir) throws IOException, ExecutionException { @@ -205,6 +216,7 @@ public class ExecUtil { return SystemInfo.isWindows || SystemInfo.isMac || hasKdeTerminal.getValue() || hasGnomeTerminal.getValue() || hasXTerm.getValue(); } + @NotNull public static List getTerminalCommand(@Nullable final String title, @NotNull final String command) { if (SystemInfo.isWindows) { return Arrays.asList("cmd.exe", "/c", "start", '"' + (title != null ? title : "") + '"', command); diff --git a/platform/platform-api/src/com/intellij/ide/BrowserUtil.java b/platform/platform-api/src/com/intellij/ide/BrowserUtil.java index 9d1843fa7763..66a3be3f83b1 100644 --- a/platform/platform-api/src/com/intellij/ide/BrowserUtil.java +++ b/platform/platform-api/src/com/intellij/ide/BrowserUtil.java @@ -19,7 +19,10 @@ import com.intellij.CommonBundle; import com.intellij.execution.ExecutionException; import com.intellij.execution.configurations.GeneralCommandLine; import com.intellij.execution.util.ExecUtil; -import com.intellij.openapi.application.*; +import com.intellij.openapi.application.Application; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.ModalityState; +import com.intellij.openapi.application.PathManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.Task; @@ -31,7 +34,6 @@ 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; @@ -40,17 +42,24 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; -import java.io.*; +import java.io.File; +import java.io.FilenameFilter; +import java.io.IOException; +import java.io.InputStream; import java.lang.reflect.InvocationTargetException; import java.net.MalformedURLException; import java.net.URL; -import java.util.*; +import java.util.Arrays; +import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; +import static com.intellij.util.containers.ContainerUtil.newSmartList; + public class BrowserUtil { private static final Logger LOG = Logger.getInstance("#" + BrowserUtil.class.getName()); @@ -103,8 +112,9 @@ public class BrowserUtil { } if (url.startsWith("jar:")) { - url = extractFiles(url); - if (url == null) return; + String files = extractFiles(url); + if (files == null) return; + url = files; } if (getGeneralSettingsInstance().isUseDefaultBrowser() && canStartDefaultBrowser()) { @@ -144,13 +154,13 @@ public class BrowserUtil { @NonNls private static List getDefaultBrowserCommand() { if (SystemInfo.isWindows) { - return getOpenBrowserWinCommand(null); + return newSmartList(ExecUtil.getWindowsShellName(), "/c", "start", "\"\""); } else if (SystemInfo.isMac) { - return new SmartList(ExecUtil.getOpenCommandPath()); + return newSmartList(ExecUtil.getOpenCommandPath()); } else if (SystemInfo.isUnix && SystemInfo.hasXdgOpen()) { - return new SmartList("xdg-open"); + return newSmartList("xdg-open"); } return null; @@ -215,31 +225,19 @@ public class BrowserUtil { launchBrowserByCommand(url, getOpenBrowserCommand(browserPath)); } - private static List getOpenBrowserWinCommand(@Nullable String browserPath) { - ArrayList command = new ArrayList(); - command.add(SystemInfo.isWin2kOrNewer ? "cmd.exe" : "command.com"); - command.add("/c"); - command.add("start"); - command.add("\"\""); - if (browserPath != null) { - command.add(browserPath); + @NotNull + public static List getOpenBrowserCommand(@NonNls @NotNull String browserPath) { + if (new File(browserPath).isFile()) { + return newSmartList(browserPath); } - return command; - } - - public static List getOpenBrowserCommand(final @NonNls @NotNull String browserPath) { - if (SystemInfo.isMac && !new File(browserPath).isFile()) { - ArrayList command = new ArrayList(); - command.add(ExecUtil.getOpenCommandPath()); - command.add("-a"); - command.add(browserPath); - return command; + else if (SystemInfo.isMac) { + return newSmartList(ExecUtil.getOpenCommandPath(), "-a", browserPath); } - else if (SystemInfo.isWindows && !new File(browserPath).isFile()) { - return getOpenBrowserWinCommand(browserPath); + else if (SystemInfo.isWindows) { + return newSmartList(ExecUtil.getWindowsShellName(), "/c", "start", "\"\"", browserPath); } else { - return new SmartList(browserPath); + return newSmartList(browserPath); } } @@ -415,6 +413,7 @@ public class BrowserUtil { return true; } + @NotNull protected Action[] createActions() { setOKButtonText(CommonBundle.getYesButtonText()); return new Action[]{getOKAction(), getCancelAction()};