From c11a219012f7c308031ca06be791ca902ca2ab2d Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Fri, 28 Dec 2012 16:53:20 +0100 Subject: [PATCH] BrowserUtil cleaned; go away from Desktop API on X Window --- .../src/com/intellij/ide/BrowserUtil.java | 40 +++++-------------- platform/util/src/com/intellij/Patches.java | 12 ++++++ 2 files changed, 22 insertions(+), 30 deletions(-) diff --git a/platform/platform-api/src/com/intellij/ide/BrowserUtil.java b/platform/platform-api/src/com/intellij/ide/BrowserUtil.java index c19643e00dbf..bb751a626711 100644 --- a/platform/platform-api/src/com/intellij/ide/BrowserUtil.java +++ b/platform/platform-api/src/com/intellij/ide/BrowserUtil.java @@ -16,6 +16,7 @@ package com.intellij.ide; import com.intellij.CommonBundle; +import com.intellij.Patches; import com.intellij.execution.ExecutionException; import com.intellij.execution.configurations.GeneralCommandLine; import com.intellij.execution.util.ExecUtil; @@ -65,8 +66,6 @@ import static com.intellij.util.containers.ContainerUtilRt.newArrayList; public class BrowserUtil { private static final Logger LOG = Logger.getInstance(BrowserUtil.class); - private static final boolean TRIM_URLS = !"false".equalsIgnoreCase(System.getProperty("idea.browse.trim.urls")); - // The pattern for 'scheme' mainly according to RFC1738. // We have to violate the RFC since we need to distinguish // real schemes from local Windows paths; The only difference @@ -84,12 +83,7 @@ public class BrowserUtil { public static String getDocURL(String url) { Matcher anchorMatcher = ourAnchorSuffix.matcher(url); - - if (anchorMatcher.find()) { - return anchorMatcher.reset().replaceAll(""); - } - - return url; + return anchorMatcher.find() ? anchorMatcher.reset().replaceAll("") : url; } @Nullable @@ -106,7 +100,7 @@ public class BrowserUtil { } public static void browse(@NotNull URL url) { - launchBrowser(url.toExternalForm()); + browse(url.toExternalForm()); } public static void launchBrowser(@NotNull @NonNls String url) { @@ -122,9 +116,7 @@ public class BrowserUtil { } private static void openOrBrowse(@NotNull @NonNls String url, boolean browse) { - if (TRIM_URLS) { - url = url.trim(); - } + url = url.trim(); if (url.startsWith("jar:")) { String files = extractFiles(url); @@ -197,30 +189,18 @@ public class BrowserUtil { } private static boolean isDesktopActionSupported(Desktop.Action action) { - if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(action)) { - // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6457572 - return !SystemInfo.isWindows || SystemInfo.isJavaVersionAtLeast("1.7"); - } - return false; + return !Patches.SUN_BUG_ID_6457572 && !Patches.SUN_BUG_ID_6486393 && + Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(action); } private static GeneralSettings getGeneralSettingsInstance() { - final GeneralSettings settings = ApplicationManager.getApplication() != null ? GeneralSettings.getInstance() : null; - return settings != null ? settings : new GeneralSettings(); + return ApplicationManager.getApplication() != null ? GeneralSettings.getInstance() : new GeneralSettings(); } public static boolean canStartDefaultBrowser() { - if (SystemInfo.isMac || SystemInfo.isWindows) { - return true; - } - else if (SystemInfo.isUnix && SystemInfo.hasXdgOpen()) { - return true; - } - else if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { - return true; - } - - return false; + return isDesktopActionSupported(Desktop.Action.BROWSE) || + SystemInfo.isMac || SystemInfo.isWindows || + SystemInfo.isUnix && SystemInfo.hasXdgOpen(); } @Nullable diff --git a/platform/util/src/com/intellij/Patches.java b/platform/util/src/com/intellij/Patches.java index 5d696b0a3607..b71ea278c002 100644 --- a/platform/util/src/com/intellij/Patches.java +++ b/platform/util/src/com/intellij/Patches.java @@ -103,4 +103,16 @@ public class Patches { * monitors exists */ public static final boolean SUN_BUG_ID_6209673 = true; + + /** + * Desktop API support on X Window is limited to GNOME (and even there it may work incorrectly). + * See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6486393. + */ + public static final boolean SUN_BUG_ID_6486393 = SystemInfo.isXWindow; + + /** + * Desktop API calls may crash on Windows. + * See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6457572. + */ + public static final boolean SUN_BUG_ID_6457572 = SystemInfo.isWindows && !SystemInfo.isJavaVersionAtLeast("1.7"); }