mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-91258
This commit is contained in:
@@ -227,24 +227,6 @@ public class BrowserUtil {
|
||||
return command;
|
||||
}
|
||||
|
||||
public static void addLaunchArgs(List<String> command, String[] launchArgs) {
|
||||
if (launchArgs.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (SystemInfo.isMac && ExecUtil.getOpenCommandPath().equals(command.get(0))) {
|
||||
if (isOpenCommandSupportArgs()) {
|
||||
command.add("--args");
|
||||
}
|
||||
else {
|
||||
LOG.warn("'open' command doesn't allow to pass command line arguments so they will be ignored: " + Arrays.toString(launchArgs));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Collections.addAll(command, launchArgs);
|
||||
}
|
||||
|
||||
public static List<String> getOpenBrowserCommand(final @NonNls @NotNull String browserPath) {
|
||||
if (SystemInfo.isMac && !new File(browserPath).isFile()) {
|
||||
ArrayList<String> command = new ArrayList<String>();
|
||||
|
||||
@@ -25,7 +25,6 @@ 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.SystemProperties;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import com.intellij.util.xmlb.SkipDefaultValuesSerializationFilters;
|
||||
@@ -215,7 +214,7 @@ public class BrowsersConfiguration implements PersistentStateComponent<Element>
|
||||
}
|
||||
|
||||
public static void launchBrowser(final @NotNull BrowserFamily family,
|
||||
@NotNull final String url,
|
||||
@Nullable final String url,
|
||||
final boolean forceOpenNewInstanceOnMac,
|
||||
String... parameters) {
|
||||
UrlOpenerImpl.doLaunchBrowser(family, url, parameters, Conditions.<String>alwaysTrue(), forceOpenNewInstanceOnMac);
|
||||
@@ -229,11 +228,6 @@ public class BrowsersConfiguration implements PersistentStateComponent<Element>
|
||||
UrlOpenerImpl.doLaunchBrowser(family, url, parameters, browserSpecificParametersFilter, forceOpenNewInstanceOnMac);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String checkPath(BrowserFamily family, String path) {
|
||||
return StringUtil.isEmpty(path) ? XmlBundle.message("browser.path.not.specified", family.getName()) : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static BrowserFamily findFamilyByName(@Nullable String name) {
|
||||
for (BrowserFamily family : BrowserFamily.values()) {
|
||||
|
||||
@@ -28,14 +28,10 @@ import org.jetbrains.annotations.Nullable;
|
||||
* @author nik
|
||||
*/
|
||||
public class ChromeSettings extends BrowserSpecificSettings {
|
||||
@NonNls public static final String REMOTE_DEBUGGING_PORT_ARG = "--remote-debugging-port=";
|
||||
@NonNls public static final String USER_DATA_DIR_ARG = "--user-data-dir=";
|
||||
public static final int DEFAULT_REMOTE_SHELL_PORT = 7930;
|
||||
private String myCommandLineOptions = "";
|
||||
private String myUserDataDirectoryPath;
|
||||
private boolean myUseCustomProfile;
|
||||
private boolean myEnableRemoteDebug;
|
||||
private int myRemoteShellPort = DEFAULT_REMOTE_SHELL_PORT;
|
||||
|
||||
public ChromeSettings() {
|
||||
}
|
||||
@@ -51,16 +47,6 @@ public class ChromeSettings extends BrowserSpecificSettings {
|
||||
return myUseCustomProfile;
|
||||
}
|
||||
|
||||
@Tag("enable-remote-debug")
|
||||
public boolean isEnableRemoteDebug() {
|
||||
return myEnableRemoteDebug;
|
||||
}
|
||||
|
||||
@Tag("remote-shell-port")
|
||||
public int getRemoteShellPort() {
|
||||
return myRemoteShellPort;
|
||||
}
|
||||
|
||||
@Tag("command-line-options")
|
||||
public String getCommandLineOptions() {
|
||||
return myCommandLineOptions;
|
||||
@@ -70,14 +56,6 @@ public class ChromeSettings extends BrowserSpecificSettings {
|
||||
myCommandLineOptions = commandLineOptions;
|
||||
}
|
||||
|
||||
public void setEnableRemoteDebug(boolean enableRemoteDebug) {
|
||||
myEnableRemoteDebug = enableRemoteDebug;
|
||||
}
|
||||
|
||||
public void setRemoteShellPort(int remoteShellPort) {
|
||||
myRemoteShellPort = remoteShellPort;
|
||||
}
|
||||
|
||||
public void setUserDataDirectoryPath(String userDataDirectoryPath) {
|
||||
myUserDataDirectoryPath = userDataDirectoryPath;
|
||||
}
|
||||
@@ -89,23 +67,13 @@ public class ChromeSettings extends BrowserSpecificSettings {
|
||||
@NotNull
|
||||
@Override
|
||||
public String[] getAdditionalParameters() {
|
||||
String[] customProfileArg;
|
||||
String[] cliOptions = ParametersList.parse(myCommandLineOptions);
|
||||
if (myUseCustomProfile && myUserDataDirectoryPath != null) {
|
||||
customProfileArg = new String[]{USER_DATA_DIR_ARG + FileUtil.toSystemDependentName(myUserDataDirectoryPath)};
|
||||
return ArrayUtil.mergeArrays(cliOptions, USER_DATA_DIR_ARG + FileUtil.toSystemDependentName(myUserDataDirectoryPath));
|
||||
}
|
||||
else {
|
||||
customProfileArg = ArrayUtil.EMPTY_STRING_ARRAY;
|
||||
return cliOptions;
|
||||
}
|
||||
|
||||
String[] remoteShellArg;
|
||||
if (myEnableRemoteDebug) {
|
||||
remoteShellArg = new String[]{REMOTE_DEBUGGING_PORT_ARG + myRemoteShellPort};
|
||||
}
|
||||
else {
|
||||
remoteShellArg = ArrayUtil.EMPTY_STRING_ARRAY;
|
||||
}
|
||||
|
||||
return ArrayUtil.mergeArrays(ParametersList.parse(myCommandLineOptions), ArrayUtil.mergeArrays(customProfileArg, remoteShellArg));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.ide.browsers.chrome.ChromeSettingsConfigurable">
|
||||
<grid id="27dc6" binding="myMainPanel" layout-manager="GridLayoutManager" row-count="7" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="27dc6" binding="myMainPanel" layout-manager="GridLayoutManager" row-count="5" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="500" height="400"/>
|
||||
@@ -18,7 +18,7 @@
|
||||
</component>
|
||||
<vspacer id="eb956">
|
||||
<constraints>
|
||||
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="e97dd" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="myUserDataDirField">
|
||||
@@ -29,22 +29,6 @@
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="b4c6c" class="javax.swing.JCheckBox" binding="myEnableRemoteDebugCheckBox">
|
||||
<constraints>
|
||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Enable remote &debug on port:"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="72606" class="javax.swing.JTextField" binding="myPortField">
|
||||
<constraints>
|
||||
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="0" indent="2" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="3fc23" class="com.intellij.ui.RawCommandLineEditor" binding="myCommandLineOptionsEditor">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="7" anchor="0" fill="1" indent="2" use-parent-layout="false"/>
|
||||
|
||||
@@ -39,8 +39,6 @@ public class ChromeSettingsConfigurable implements Configurable {
|
||||
private JPanel myMainPanel;
|
||||
private JCheckBox myUseCustomProfileCheckBox;
|
||||
private TextFieldWithBrowseButton myUserDataDirField;
|
||||
private JCheckBox myEnableRemoteDebugCheckBox;
|
||||
private JTextField myPortField;
|
||||
private JLabel myCommandLineOptionsLabel;
|
||||
private RawCommandLineEditor myCommandLineOptionsEditor;
|
||||
private final String myDefaultUserDirPath;
|
||||
@@ -56,12 +54,6 @@ public class ChromeSettingsConfigurable implements Configurable {
|
||||
}
|
||||
});
|
||||
myDefaultUserDirPath = getDefaultUserDataPath();
|
||||
myEnableRemoteDebugCheckBox.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
myPortField.setEnabled(myEnableRemoteDebugCheckBox.isSelected());
|
||||
}
|
||||
});
|
||||
myCommandLineOptionsEditor.setDialogCaption("Chrome Command Line Options");
|
||||
myCommandLineOptionsLabel.setLabelFor(myCommandLineOptionsEditor.getTextField());
|
||||
}
|
||||
@@ -73,9 +65,7 @@ public class ChromeSettingsConfigurable implements Configurable {
|
||||
|
||||
@Override
|
||||
public boolean isModified() {
|
||||
if (myEnableRemoteDebugCheckBox.isSelected() != mySettings.isEnableRemoteDebug()
|
||||
|| !myPortField.getText().equals(String.valueOf(mySettings.getRemoteShellPort()))
|
||||
|| myUseCustomProfileCheckBox.isSelected() != mySettings.isUseCustomProfile()
|
||||
if (myUseCustomProfileCheckBox.isSelected() != mySettings.isUseCustomProfile()
|
||||
|| !myCommandLineOptionsEditor.getText().equals(mySettings.getCommandLineOptions())) {
|
||||
return true;
|
||||
}
|
||||
@@ -93,24 +83,13 @@ public class ChromeSettingsConfigurable implements Configurable {
|
||||
|
||||
@Override
|
||||
public void apply() throws ConfigurationException {
|
||||
try {
|
||||
mySettings.setRemoteShellPort(Integer.parseInt(myPortField.getText()));
|
||||
}
|
||||
catch (NumberFormatException ignored) {
|
||||
throw new ConfigurationException("Port is not integer!");
|
||||
}
|
||||
mySettings.setCommandLineOptions(myCommandLineOptionsEditor.getText());
|
||||
mySettings.setUseCustomProfile(myUseCustomProfileCheckBox.isSelected());
|
||||
mySettings.setUserDataDirectoryPath(getConfiguredUserDataDirPath());
|
||||
mySettings.setEnableRemoteDebug(myEnableRemoteDebugCheckBox.isSelected());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
myEnableRemoteDebugCheckBox.setSelected(mySettings.isEnableRemoteDebug());
|
||||
myPortField.setText(String.valueOf(mySettings.getRemoteShellPort()));
|
||||
myPortField.setEnabled(mySettings.isEnableRemoteDebug());
|
||||
|
||||
myCommandLineOptionsEditor.setText(mySettings.getCommandLineOptions());
|
||||
myUseCustomProfileCheckBox.setSelected(mySettings.isUseCustomProfile());
|
||||
myUserDataDirField.setEnabled(mySettings.isUseCustomProfile());
|
||||
@@ -127,9 +106,6 @@ public class ChromeSettingsConfigurable implements Configurable {
|
||||
if (!myUseCustomProfileCheckBox.isSelected()) {
|
||||
myUseCustomProfileCheckBox.doClick(0);
|
||||
}
|
||||
if (!myEnableRemoteDebugCheckBox.isSelected()) {
|
||||
myEnableRemoteDebugCheckBox.doClick(0);
|
||||
}
|
||||
}
|
||||
|
||||
private static String getDefaultUserDataPath() {
|
||||
|
||||
@@ -31,6 +31,7 @@ import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.xml.XmlBundle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@@ -47,39 +48,48 @@ public class UrlOpenerImpl extends UrlOpener {
|
||||
}
|
||||
|
||||
public static void doLaunchBrowser(final BrowsersConfiguration.BrowserFamily family,
|
||||
@NotNull String url,
|
||||
@Nullable String url,
|
||||
@NotNull String[] additionalParameters,
|
||||
@NotNull Condition<String> browserSpecificParametersFilter,
|
||||
final boolean forceOpenNewInstanceOnMac) {
|
||||
final WebBrowserSettings settings = BrowsersConfiguration.getInstance().getBrowserSettings(family);
|
||||
final String path = settings.getPath();
|
||||
String pathCheckResult = BrowsersConfiguration.checkPath(family, path);
|
||||
if (pathCheckResult == null) {
|
||||
try {
|
||||
BrowserSpecificSettings specificSettings = settings.getBrowserSpecificSettings();
|
||||
List<String> parameters = specificSettings == null
|
||||
? (additionalParameters.length == 0 ? Collections.<String>emptyList() : new ArrayList<String>())
|
||||
: ContainerUtil.findAll(specificSettings.getAdditionalParameters(), browserSpecificParametersFilter);
|
||||
Collections.addAll(parameters, additionalParameters);
|
||||
launchBrowser(path, BrowserUtil.escapeUrl(url), forceOpenNewInstanceOnMac, parameters);
|
||||
}
|
||||
catch (IOException e) {
|
||||
Messages.showErrorDialog(e.getMessage(), XmlBundle.message("browser.error"));
|
||||
}
|
||||
if (StringUtil.isEmpty(path)) {
|
||||
Messages.showErrorDialog(XmlBundle.message("browser.path.not.specified", family.getName()), XmlBundle.message("browser.path.not.specified.title"));
|
||||
return;
|
||||
}
|
||||
else {
|
||||
Messages.showErrorDialog(pathCheckResult, XmlBundle.message("browser.path.not.specified.title"));
|
||||
|
||||
try {
|
||||
BrowserSpecificSettings specificSettings = settings.getBrowserSpecificSettings();
|
||||
List<String> parameters = specificSettings == null
|
||||
? (additionalParameters.length == 0 ? Collections.<String>emptyList() : new ArrayList<String>())
|
||||
: ContainerUtil.findAll(specificSettings.getAdditionalParameters(), browserSpecificParametersFilter);
|
||||
Collections.addAll(parameters, additionalParameters);
|
||||
launchBrowser(path, url == null ? null : BrowserUtil.escapeUrl(url), forceOpenNewInstanceOnMac, parameters);
|
||||
}
|
||||
catch (IOException e) {
|
||||
Messages.showErrorDialog(e.getMessage(), XmlBundle.message("browser.error"));
|
||||
}
|
||||
}
|
||||
|
||||
private static void launchBrowser(String browserPath, String url, boolean forceOpenNewInstanceOnMac, List<String> browserArgs)
|
||||
private static void launchBrowser(String browserPath, @Nullable String url, boolean forceOpenNewInstanceOnMac, List<String> browserArgs)
|
||||
throws IOException {
|
||||
final List<String> command = BrowserUtil.getOpenBrowserCommand(browserPath);
|
||||
List<String> command = BrowserUtil.getOpenBrowserCommand(browserPath);
|
||||
addArgs(command, browserArgs, url, forceOpenNewInstanceOnMac);
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Launching browser: " + StringUtil.join(browserArgs, " "));
|
||||
}
|
||||
new ProcessBuilder(command).start();
|
||||
}
|
||||
|
||||
private static void addArgs(List<String> command, List<String> browserArgs, @Nullable String url, boolean forceOpenNewInstanceOnMac) {
|
||||
if (SystemInfo.isMac && ExecUtil.getOpenCommandPath().equals(command.get(0))) {
|
||||
if (forceOpenNewInstanceOnMac) {
|
||||
command.add("-n");
|
||||
}
|
||||
command.add(url);
|
||||
if (url != null) {
|
||||
command.add(url);
|
||||
}
|
||||
|
||||
if (!browserArgs.isEmpty()) {
|
||||
if (BrowserUtil.isOpenCommandSupportArgs()) {
|
||||
@@ -93,13 +103,10 @@ public class UrlOpenerImpl extends UrlOpener {
|
||||
}
|
||||
}
|
||||
else {
|
||||
command.add(url);
|
||||
if (url != null) {
|
||||
command.add(url);
|
||||
}
|
||||
command.addAll(browserArgs);
|
||||
}
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Launching browser: " + StringUtil.join(browserArgs, " "));
|
||||
}
|
||||
new ProcessBuilder(command).start();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user