'possible VM hang' warning on hotswap

This commit is contained in:
Eugene Zhuravlev
2011-08-08 20:51:56 +02:00
parent 30cafdab85
commit 594d4d47d2
5 changed files with 70 additions and 5 deletions
@@ -26,6 +26,7 @@ import java.awt.*;
public class DebuggerHotswapConfigurable implements SearchableConfigurable {
private JCheckBox myHotswapInBackground;
private JCheckBox myCbCompileBeforeHotswap;
private JCheckBox myCbHangWarningEnabled;
private JRadioButton myRbAlways;
private JRadioButton myRbNever;
private JRadioButton myRbAsk;
@@ -34,6 +35,7 @@ public class DebuggerHotswapConfigurable implements SearchableConfigurable {
final DebuggerSettings settings = DebuggerSettings.getInstance();
myHotswapInBackground.setSelected(settings.HOTSWAP_IN_BACKGROUND);
myCbCompileBeforeHotswap.setSelected(settings.COMPILE_BEFORE_HOTSWAP);
myCbHangWarningEnabled.setSelected(settings.HOTSWAP_HANG_WARNING_ENABLED);
if(DebuggerSettings.RUN_HOTSWAP_ALWAYS.equals(settings.RUN_HOTSWAP_AFTER_COMPILE)) {
myRbAlways.setSelected(true);
@@ -53,6 +55,7 @@ public class DebuggerHotswapConfigurable implements SearchableConfigurable {
private void getSettingsTo(DebuggerSettings settings) {
settings.HOTSWAP_IN_BACKGROUND = myHotswapInBackground.isSelected();
settings.COMPILE_BEFORE_HOTSWAP = myCbCompileBeforeHotswap.isSelected();
settings.HOTSWAP_HANG_WARNING_ENABLED = myCbHangWarningEnabled.isSelected();
if (myRbAlways.isSelected()) {
settings.RUN_HOTSWAP_AFTER_COMPILE = DebuggerSettings.RUN_HOTSWAP_ALWAYS;
@@ -97,12 +100,14 @@ public class DebuggerHotswapConfigurable implements SearchableConfigurable {
final JPanel panel = new JPanel(new GridBagLayout());
myCbCompileBeforeHotswap = new JCheckBox(DebuggerBundle.message("label.debugger.hotswap.configurable.compile.before.hotswap"));
myCbHangWarningEnabled = new JCheckBox(DebuggerBundle.message("label.debugger.hotswap.configurable.enable.vm.hang.warning"));
myHotswapInBackground = new JCheckBox(DebuggerBundle.message("label.debugger.hotswap.configurable.hotswap.background"));
myRbAlways = new JRadioButton(DebuggerBundle.message("label.debugger.hotswap.configurable.always"));
myRbNever = new JRadioButton(DebuggerBundle.message("label.debugger.hotswap.configurable.never"));
myRbAsk = new JRadioButton(DebuggerBundle.message("label.debugger.hotswap.configurable.ask"));
panel.add(myCbCompileBeforeHotswap, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(4, 0, 0, 0), 0, 0));
panel.add(myCbHangWarningEnabled, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(4, 0, 0, 0), 0, 0));
panel.add(myHotswapInBackground, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(4, 0, 0, 0), 0, 0));
int cbLeftOffset = 0;
@@ -64,6 +64,7 @@ public class DebuggerSettings implements JDOMExternalizable, NamedComponent, Clo
public String EVALUATION_DIALOG_TYPE;
public String RUN_HOTSWAP_AFTER_COMPILE;
public boolean COMPILE_BEFORE_HOTSWAP;
public boolean HOTSWAP_HANG_WARNING_ENABLED = true;
public volatile boolean WATCH_RETURN_VALUES = false;
public volatile boolean AUTO_VARIABLES_MODE = false;
@@ -145,6 +146,7 @@ public class DebuggerSettings implements JDOMExternalizable, NamedComponent, Clo
SKIP_CONSTRUCTORS == secondSettings.SKIP_CONSTRUCTORS &&
SKIP_GETTERS == secondSettings.SKIP_GETTERS &&
COMPILE_BEFORE_HOTSWAP == secondSettings.COMPILE_BEFORE_HOTSWAP &&
HOTSWAP_HANG_WARNING_ENABLED == secondSettings.HOTSWAP_HANG_WARNING_ENABLED &&
(RUN_HOTSWAP_AFTER_COMPILE != null ? RUN_HOTSWAP_AFTER_COMPILE.equals(secondSettings.RUN_HOTSWAP_AFTER_COMPILE) : secondSettings.RUN_HOTSWAP_AFTER_COMPILE == null) &&
DebuggerUtilsEx.filterEquals(mySteppingFilters, secondSettings.mySteppingFilters);
}
@@ -15,6 +15,7 @@
*/
package com.intellij.debugger.ui;
import com.intellij.CommonBundle;
import com.intellij.debugger.DebuggerBundle;
import com.intellij.debugger.DebuggerManagerEx;
import com.intellij.debugger.impl.DebuggerSession;
@@ -32,12 +33,16 @@ import com.intellij.openapi.compiler.CompilerTopics;
import com.intellij.openapi.components.ProjectComponent;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.Ref;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.util.PairFunction;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.messages.MessageBus;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -111,6 +116,19 @@ public class HotSwapUIImpl extends HotSwapUI implements ProjectComponent{
myListeners.remove(listener);
}
private boolean shouldDisplayHangWarning(DebuggerSettings settings, List<DebuggerSession> sessions) {
if (!settings.HOTSWAP_HANG_WARNING_ENABLED) {
return false;
}
// todo: return false if yourkit agent is inactive
for (DebuggerSession session : sessions) {
if (session.isPaused()) {
return true;
}
}
return false;
}
private void hotSwapSessions(final List<DebuggerSession> sessions) {
final boolean shouldAskBeforeHotswap = myAskBeforeHotswap;
myAskBeforeHotswap = true;
@@ -118,7 +136,10 @@ public class HotSwapUIImpl extends HotSwapUI implements ProjectComponent{
// need this because search with PSI is perormed during hotswap
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
final String runHotswap = DebuggerSettings.getInstance().RUN_HOTSWAP_AFTER_COMPILE;
final DebuggerSettings settings = DebuggerSettings.getInstance();
final String runHotswap = settings.RUN_HOTSWAP_AFTER_COMPILE;
final boolean shouldDisplayHangWarning = shouldDisplayHangWarning(settings, sessions);
if (shouldAskBeforeHotswap && DebuggerSettings.RUN_HOTSWAP_NEVER.equals(runHotswap)) {
return;
}
@@ -139,13 +160,34 @@ public class HotSwapUIImpl extends HotSwapUI implements ProjectComponent{
application.invokeLater(new Runnable() {
public void run() {
if (shouldAskBeforeHotswap && !DebuggerSettings.RUN_HOTSWAP_ALWAYS.equals(runHotswap)) {
final RunHotswapDialog dialog = new RunHotswapDialog(myProject, sessions);
final RunHotswapDialog dialog = new RunHotswapDialog(myProject, sessions, shouldDisplayHangWarning);
dialog.show();
if (!dialog.isOK()) {
return;
}
modifiedClasses.keySet().retainAll(dialog.getSessionsToReload());
}
else {
if (shouldDisplayHangWarning) {
final int answer = Messages.showCheckboxMessageDialog(
DebuggerBundle.message("hotswap.dialog.hang.warning"),
DebuggerBundle.message("hotswap.dialog.title"),
new String[]{CommonBundle.getContinueButtonText(), CommonBundle.getCancelButtonText()},
CommonBundle.message("dialog.options.do.not.show"),
false, 1, 1, Messages.getWarningIcon(),
new PairFunction<Integer, JCheckBox, Integer>() {
@Override
public Integer fun(Integer exitCode, JCheckBox cb) {
settings.HOTSWAP_HANG_WARNING_ENABLED = !cb.isSelected();
return exitCode;
}
}
);
if (answer == DialogWrapper.CANCEL_EXIT_CODE) {
return;
}
}
}
if (!modifiedClasses.isEmpty()) {
final HotSwapProgressImpl progress = new HotSwapProgressImpl(myProject);
@@ -15,15 +15,16 @@
*/
package com.intellij.debugger.ui;
import com.intellij.CommonBundle;
import com.intellij.debugger.DebuggerBundle;
import com.intellij.debugger.impl.DebuggerSession;
import com.intellij.debugger.settings.DebuggerSettings;
import com.intellij.debugger.DebuggerBundle;
import com.intellij.ide.util.ElementsChooser;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.MultiLineLabelUI;
import com.intellij.ui.IdeBorderFactory;
import com.intellij.util.ui.OptionsDialog;
import com.intellij.util.ui.UIUtil;
import com.intellij.CommonBundle;
import javax.swing.*;
import java.awt.*;
@@ -41,9 +42,11 @@ import java.util.List;
public class RunHotswapDialog extends OptionsDialog {
private final JPanel myPanel;
private final ElementsChooser<SessionItem> myElementsChooser;
private final boolean myDisplayHangWarning;
public RunHotswapDialog(Project project, java.util.List<DebuggerSession> sessions) {
public RunHotswapDialog(Project project, List<DebuggerSession> sessions, boolean displayHangWarning) {
super(project);
myDisplayHangWarning = displayHangWarning;
myPanel = new JPanel(new BorderLayout());
final List<SessionItem> items = new ArrayList<SessionItem>(sessions.size());
for (DebuggerSession session : sessions) {
@@ -110,6 +113,16 @@ public class RunHotswapDialog extends OptionsDialog {
label.setIcon(icon);
label.setIconTextGap(7);
}
if (myDisplayHangWarning) {
final JLabel warningLabel = new JLabel(DebuggerBundle.message("hotswap.dialog.hang.warning"));
warningLabel.setUI(new MultiLineLabelUI());
final Icon warningIcon = UIUtil.getWarningIcon();
if (warningIcon != null) {
warningLabel.setIcon(warningIcon);
warningLabel.setIconTextGap(7);
}
panel.add(warningLabel, BorderLayout.SOUTH);
}
return panel;
}