summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorMeng Xin Zhu2012-06-19 05:52:00 (EDT)
committer Brian de Alwis2012-07-16 12:47:12 (EDT)
commit6da5f66edbc7469afb2444a30c7b3d15be20085d (patch)
tree52ed9ed0773885c16a92d2ef0f42e38a9da0f836
parent883259041d69dec867e060fe32a471b392d1a595 (diff)
downloadeclipse.platform.ui-6da5f66edbc7469afb2444a30c7b3d15be20085d.zip
eclipse.platform.ui-6da5f66edbc7469afb2444a30c7b3d15be20085d.tar.gz
eclipse.platform.ui-6da5f66edbc7469afb2444a30c7b3d15be20085d.tar.bz2
297273 [Browser] Mac: "Browse" button of dialog to add a web browser doesn't work well
Fix the issue that can not use chrome as external browser, whose path contains space characters
-rw-r--r--bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/ExternalBrowserInstance.java43
1 files changed, 31 insertions, 12 deletions
diff --git a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/ExternalBrowserInstance.java b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/ExternalBrowserInstance.java
index 9a9bb50..e9ce157 100644
--- a/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/ExternalBrowserInstance.java
+++ b/bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/ExternalBrowserInstance.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2011 IBM Corporation and others.
+ * Copyright (c) 2005, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,10 +7,12 @@
*
* Contributors:
* IBM Corporation - Initial API and implementation
+ * Wind River - Fix the issue that failing to launch browser with space in its path
*******************************************************************************/
package org.eclipse.ui.internal.browser;
import java.net.URL;
+import java.util.ArrayList;
import org.eclipse.jface.util.Util;
import org.eclipse.osgi.util.NLS;
@@ -34,24 +36,30 @@ public class ExternalBrowserInstance extends AbstractWebBrowser {
public void openURL(URL url) throws PartInitException {
String urlText = url.toExternalForm();
+ ArrayList<String> cmdOptions = new ArrayList<String>();
String location = browser.getLocation();
- String parameters = browser.getParameters();
+ cmdOptions.add(location);
+ String parameters = browser.getParameters();
Trace
- .trace(
- Trace.FINEST,
- "Launching external Web browser: " + location + " - " + parameters + " - " + urlText); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ .trace(
+ Trace.FINEST,
+ "Launching external Web browser: " + location + " - " + parameters + " - " + urlText); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
String params = WebBrowserUtil.createParameterString(parameters, urlText);
try {
if ( Util.isMac()) {
- location = "open -a " + location; //$NON-NLS-1$
- }
- Trace.trace(Trace.FINEST, "Launching " + location + " " + params); //$NON-NLS-1$//$NON-NLS-2$
- if (params == null || params.length() == 0)
- process = Runtime.getRuntime().exec(location);
- else
- process = Runtime.getRuntime().exec(location + " " + params); //$NON-NLS-1$
+ cmdOptions.add(0, "-a"); //$NON-NLS-1$
+ cmdOptions.add(0, "open"); //$NON-NLS-1$
+ }
+
+ if (!(params == null || params.length() == 0))
+ cmdOptions.add(params);
+
+ String[] cmd = cmdOptions.toArray(new String[cmdOptions.size()]);
+ Trace.trace(Trace.FINEST, "Launching " + join(" ", cmd)); //$NON-NLS-1$//$NON-NLS-2$
+
+ process = Runtime.getRuntime().exec(cmd);
} catch (Exception e) {
Trace.trace(Trace.SEVERE, "Could not launch external browser", e); //$NON-NLS-1$
WebBrowserUtil.openError(NLS.bind(
@@ -72,6 +80,17 @@ public class ExternalBrowserInstance extends AbstractWebBrowser {
thread.start();
}
+ private String join (String delim, String ... data) {
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < data.length; i++) {
+ sb.append(data[i]);
+ if (i >= data.length-1) {break;}
+ sb.append(delim);
+ }
+ return sb.toString();
+ }
+
+
public boolean close() {
try {
process.destroy();