fix firefox debug

use native file choosers — so, our JS Runners now must be async
This commit is contained in:
Vladimir Krivosheev
2014-01-16 16:54:37 +01:00
parent 3942b86f58
commit b941c01706
5 changed files with 122 additions and 23 deletions
@@ -26,6 +26,9 @@ import java.util.LinkedHashSet;
import java.util.Set;
public class ActionCallback implements Disposable {
public static final ActionCallback DONE = new Done();
public static final ActionCallback REJECTED = new Rejected();
private final ExecutionCallback myDone;
private final ExecutionCallback myRejected;
@@ -0,0 +1,74 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.runners;
import com.intellij.execution.ExecutionException;
import com.intellij.execution.ExecutionResult;
import com.intellij.execution.Executor;
import com.intellij.execution.RunManager;
import com.intellij.execution.configurations.*;
import com.intellij.openapi.options.SettingsEditor;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public abstract class BaseProgramRunner<Settings extends RunnerSettings> implements ProgramRunner<Settings> {
@Override
@Nullable
public Settings createConfigurationData(ConfigurationInfoProvider settingsProvider) {
return null;
}
@Override
public void checkConfiguration(RunnerSettings settings, ConfigurationPerRunnerSettings configurationPerRunnerSettings)
throws RuntimeConfigurationException {
}
@Override
public void onProcessStarted(RunnerSettings settings, ExecutionResult executionResult) {
}
@Override
@Nullable
public SettingsEditor<Settings> getSettingsEditor(Executor executor, RunConfiguration configuration) {
return null;
}
@Override
public void execute(@NotNull ExecutionEnvironment environment) throws ExecutionException {
execute(environment, null);
}
@Override
public void execute(@NotNull ExecutionEnvironment environment, @Nullable Callback callback)
throws ExecutionException {
RunProfileState state = environment.getState();
if (state == null) {
return;
}
Project project = environment.getProject();
RunManager.getInstance(project).refreshUsagesList(environment.getRunProfile());
startRunProfile(environment, callback, project, state);
}
protected abstract void startRunProfile(@NotNull ExecutionEnvironment environment,
@Nullable Callback callback,
@NotNull Project project,
@NotNull RunProfileState state) throws ExecutionException;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -74,6 +74,11 @@ public abstract class GenericProgramRunner<Settings extends RunnerSettings> impl
RunManager.getInstance(project).refreshUsagesList(env.getRunProfile());
startRunProfile(env, callback, project, state);
}
protected void startRunProfile(@NotNull ExecutionEnvironment environment, @Nullable final Callback callback, @NotNull Project project, @NotNull RunProfileState state)
throws ExecutionException {
ExecutionManager.getInstance(project).startRunProfile(new RunProfileStarter() {
@Override
public RunContentDescriptor execute(@NotNull Project project,
@@ -81,14 +86,16 @@ public abstract class GenericProgramRunner<Settings extends RunnerSettings> impl
@NotNull RunProfileState state,
@Nullable RunContentDescriptor contentToReuse,
@NotNull ExecutionEnvironment env) throws ExecutionException {
final RunContentDescriptor descriptor = doExecute(project, state, contentToReuse, env);
RunContentDescriptor descriptor = doExecute(project, state, contentToReuse, env);
if (descriptor != null) {
descriptor.setExecutionId(env.getExecutionId());
}
if (callback != null) callback.processStarted(descriptor);
if (callback != null) {
callback.processStarted(descriptor);
}
return descriptor;
}
}, state, env);
}, state, environment);
}
@Nullable
@@ -16,10 +16,12 @@
package com.intellij.ide.browsers.firefox;
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.fileChooser.PathChooserDialog;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.DocumentAdapter;
@@ -58,21 +60,24 @@ public class FirefoxSettingsConfigurable implements Configurable {
}
public static FileChooserDescriptor createProfilesIniChooserDescriptor() {
return new FileChooserDescriptor(true, false, false, false, false, false) {
FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, false, false, false, false) {
@Override
public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
if (!file.isDirectory() && !file.getName().equals(FirefoxUtil.PROFILES_INI_FILE)) {
return false;
}
return super.isFileVisible(file, showHiddenFiles);
public boolean isFileSelectable(VirtualFile file) {
return file.getName().equals(FirefoxUtil.PROFILES_INI_FILE) && super.isFileSelectable(file);
}
};
if (SystemInfo.isMac) {
descriptor.putUserData(PathChooserDialog.NATIVE_MAC_CHOOSER_SHOW_HIDDEN_FILES, Boolean.TRUE);
}
return descriptor;
}
@Override
public JComponent createComponent() {
return myMainPanel;
}
@Override
public boolean isModified() {
return !Comparing.equal(mySettings.getProfile(), getConfiguredProfileName()) ||
!Comparing.equal(mySettings.getProfilesIniPath(), getConfiguredProfileIniPath());
@@ -96,11 +101,13 @@ public class FirefoxSettingsConfigurable implements Configurable {
return selected;
}
@Override
public void apply() throws ConfigurationException {
mySettings.setProfile(getConfiguredProfileName());
mySettings.setProfilesIniPath(getConfiguredProfileIniPath());
}
@Override
public void reset() {
final File defaultFile = FirefoxUtil.getDefaultProfileIniPath();
myDefaultProfilesIniPath = defaultFile != null ? defaultFile.getAbsolutePath() : "";
@@ -121,6 +128,7 @@ public class FirefoxSettingsConfigurable implements Configurable {
final FirefoxProfile defaultProfile = FirefoxUtil.getDefaultProfile(profiles);
myDefaultProfile = defaultProfile != null ? defaultProfile.getName() : null;
for (FirefoxProfile profile : profiles) {
//noinspection unchecked
myProfileCombobox.addItem(profile.getName());
}
if (!profiles.isEmpty()) {
@@ -129,14 +137,17 @@ public class FirefoxSettingsConfigurable implements Configurable {
myLastProfilesIniPath = profilesIniPath;
}
@Override
public void disposeUIResources() {
}
@Override
@Nls
public String getDisplayName() {
return XmlBundle.message("display.name.firefox.settings");
}
@Override
public String getHelpTopic() {
return null;
}
@@ -18,6 +18,7 @@ package com.intellij.ide.browsers.firefox;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.SmartList;
import com.intellij.util.SystemProperties;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -27,7 +28,6 @@ import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -35,7 +35,7 @@ import java.util.List;
* @author nik
*/
public class FirefoxUtil {
private static final Logger LOG = Logger.getInstance("#com.intellij.ide.browsers.firefox.FirefoxUtil");
private static final Logger LOG = Logger.getInstance(FirefoxUtil.class);
@NonNls public static final String PROFILES_INI_FILE = "profiles.ini";
private FirefoxUtil() {
@@ -70,7 +70,7 @@ public class FirefoxUtil {
}
@Nullable
public static FirefoxProfile findProfileByNameOrDefault(@Nullable String name, List<FirefoxProfile> profiles) {
public static FirefoxProfile findProfileByNameOrDefault(@Nullable String name, @NotNull List<FirefoxProfile> profiles) {
for (FirefoxProfile profile : profiles) {
if (profile.getName().equals(name)) {
return profile;
@@ -81,7 +81,9 @@ public class FirefoxUtil {
@Nullable
public static FirefoxProfile getDefaultProfile(List<FirefoxProfile> profiles) {
if (profiles.isEmpty()) return null;
if (profiles.isEmpty()) {
return null;
}
for (FirefoxProfile profile : profiles) {
if (profile.isDefault()) {
@@ -92,15 +94,16 @@ public class FirefoxUtil {
}
@NotNull
public static List<FirefoxProfile> computeProfiles(File profilesFile) {
if (!profilesFile.isFile()) {
public static List<FirefoxProfile> computeProfiles(@Nullable File profilesFile) {
if (profilesFile == null || !profilesFile.isFile()) {
return Collections.emptyList();
}
try {
BufferedReader reader = new BufferedReader(new FileReader(profilesFile));
BufferedReader reader;
reader = new BufferedReader(new FileReader(profilesFile));
try {
final List<FirefoxProfile> profiles = new ArrayList<FirefoxProfile>();
final List<FirefoxProfile> profiles = new SmartList<FirefoxProfile>();
boolean insideProfile = false;
String currentName = null;
String currentPath = null;
@@ -108,7 +111,7 @@ public class FirefoxUtil {
boolean isRelative = false;
boolean eof = false;
while (!eof) {
@NonNls String line = reader.readLine();
String line = reader.readLine();
if (line == null) {
eof = true;
line = "[]";
@@ -131,8 +134,8 @@ public class FirefoxUtil {
final int i = line.indexOf('=');
if (i != -1 && insideProfile) {
@NonNls String name = line.substring(0, i).trim();
@NonNls String value = line.substring(i + 1).trim();
String name = line.substring(0, i).trim();
String value = line.substring(i + 1).trim();
if (name.equalsIgnoreCase("path")) {
currentPath = value;
}
@@ -142,7 +145,8 @@ public class FirefoxUtil {
else if (name.equalsIgnoreCase("default") && value.equals("1")) {
isDefault = true;
}
else if (name.equalsIgnoreCase("isrelative") && value.equals("1")) {
else //noinspection SpellCheckingInspection
if (name.equalsIgnoreCase("isrelative") && value.equals("1")) {
isRelative = true;
}
}
@@ -155,8 +159,8 @@ public class FirefoxUtil {
}
catch (IOException e) {
LOG.info(e);
return Collections.emptyList();
}
return Collections.emptyList();
}
private static File[] getProfilesDirs() {