Skip to content

Commit

Permalink
Ignore HCR Failures for current session #347
Browse files Browse the repository at this point in the history
Adds a checkbox to the HCR error alert box that allows users to ignore
HCR failures only for the current debug session, rather than applying it
to all future debug sessions.

Fixes : #347
  • Loading branch information
SougandhS committed Dec 3, 2024
1 parent a9a5f80 commit 42d462f
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public class DebugUIMessages extends NLS {
public static String JDIDebugUIPlugin_The_target_VM_does_not_support_hot_code_replace_1;
public static String JDIDebugUIPlugin_3;
public static String JDIDebugUIPlugin_4;
public static String JDIDebugUIPlugin_5;

public static String JDIModelPresentation__No_explicit_return_value__30;
public static String JDIModelPresentation__conditional__2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ JDIDebugUIPlugin_Stepping_may_be_hazardous_1=The virtual machine was unable to r
JDIDebugUIPlugin_The_target_VM_does_not_support_hot_code_replace_1=The target VM does not support hot code replace
JDIDebugUIPlugin_3=Do not show error &when hot code replace is not supported
JDIDebugUIPlugin_0=Warning
JDIDebugUIPlugin_5=Ignore errors in current session

JDIModelPresentation__No_explicit_return_value__30=(No explicit return value)
JDIModelPresentation__conditional__2=[conditional]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2011 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -15,6 +15,10 @@


import org.eclipse.core.runtime.IStatus;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.model.IDebugTarget;
import org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.preference.IPreferenceStore;
Expand Down Expand Up @@ -43,25 +47,37 @@ public class ErrorDialogWithToggle extends ErrorDialog {
/**
* The message displayed to the user, with the toggle button
*/
private String fToggleMessage= null;
private String fToggleMessage1 = null;
private String fToggleMessage2 = null;
private Button fToggleButton= null;
private Button fToggleButton2 = null;
/**
* The preference store which will be affected by the toggle button
*/
IPreferenceStore fStore= null;

public ErrorDialogWithToggle(Shell parentShell, String dialogTitle, String message, IStatus status, String preferenceKey, String toggleMessage1, String toggleMessage2, IPreferenceStore store) {
super(parentShell, dialogTitle, message, status, IStatus.WARNING | IStatus.ERROR | IStatus.INFO);
fStore = store;
fPreferenceKey = preferenceKey;
fToggleMessage1 = toggleMessage1;
fToggleMessage2 = toggleMessage2;
}
public ErrorDialogWithToggle(Shell parentShell, String dialogTitle, String message, IStatus status, String preferenceKey, String toggleMessage, IPreferenceStore store) {
super(parentShell, dialogTitle, message, status, IStatus.WARNING | IStatus.ERROR | IStatus.INFO);
fStore= store;
fPreferenceKey= preferenceKey;
fToggleMessage= toggleMessage;
fToggleMessage1= toggleMessage;
}

@Override
protected Control createDialogArea(Composite parent) {
Composite dialogComposite= (Composite) super.createDialogArea(parent);
dialogComposite.setFont(parent.getFont());
setToggleButton(createCheckButton(dialogComposite, fToggleMessage));
setToggleButton(createCheckButton(dialogComposite, fToggleMessage1));
if (fToggleMessage2 != null) {
fToggleButton2 = createCheckButton(dialogComposite, fToggleMessage2);
}
getToggleButton().setSelection(!fStore.getBoolean(fPreferenceKey));
applyDialogFont(dialogComposite);
return dialogComposite;
Expand All @@ -76,24 +92,30 @@ private Button createCheckButton(Composite parent, String label) {
button.setText(label);

GridData data = new GridData(SWT.NONE);
data.horizontalSpan= 2;
data.horizontalSpan = 2;
data.horizontalAlignment= GridData.CENTER;
button.setLayoutData(data);
button.setFont(parent.getFont());

return button;
}

@Override
protected void buttonPressed(int id) {
protected void buttonPressed(int id, IDebugTarget target) {
if (id == IDialogConstants.OK_ID) { // was the OK button pressed?
storePreference();
storePreference(target);
}
super.buttonPressed(id);
}

private void storePreference() {
private void storePreference(IDebugTarget target) {
fStore.setValue(fPreferenceKey, !getToggleButton().getSelection());
if (fToggleButton2 != null) {
try {
JDIDebugTarget.hcrDebugSessionErrors.put(target.getName(), fToggleButton2.getSelection());
} catch (DebugException e) {
DebugPlugin.log(e);
}
}
}

protected Button getToggleButton() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2015 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -47,11 +47,12 @@ public class HotCodeReplaceErrorDialog extends ErrorDialogWithToggle {
/**
* Creates a new dialog which can terminate, disconnect or restart the given debug target.
*
* @param target the debug target
* @see ErrorDialogWithToggle#ErrorDialogWithToggle(Shell, String, String, IStatus, String, String, IPreferenceStore)
* @param target
* the debug target
* @see ErrorDialogWithToggle#ErrorDialogWithToggle(Shell, String, String, IStatus, String, String,String, IPreferenceStore)
*/
public HotCodeReplaceErrorDialog(Shell parentShell, String dialogTitle, String message, IStatus status, String preferenceKey, String toggleMessage, IPreferenceStore store, IDebugTarget target) {
super(parentShell, dialogTitle, message, status, preferenceKey, toggleMessage, store);
public HotCodeReplaceErrorDialog(Shell parentShell, String dialogTitle, String message, IStatus status, String preferenceKey, String toggleMessage, String toggleMessage2, IPreferenceStore store, IDebugTarget target) {
super(parentShell, dialogTitle, message, status, preferenceKey, toggleMessage, toggleMessage2, store);
this.target = target;
}

Expand Down Expand Up @@ -143,7 +144,7 @@ public void run() {
}
okPressed();
} else {
super.buttonPressed(id);
super.buttonPressed(id, target);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2015 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -22,6 +22,7 @@
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.jdt.debug.core.IJavaDebugTarget;
import org.eclipse.jdt.debug.core.IJavaHotCodeReplaceListener;
import org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget;
import org.eclipse.jdt.internal.debug.ui.snippeteditor.ScrapbookLauncher;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.osgi.util.NLS;
Expand All @@ -33,7 +34,7 @@ public class JavaHotCodeReplaceListener implements IJavaHotCodeReplaceListener {
private HotCodeReplaceErrorDialog fHotCodeReplaceFailedErrorDialog = null;

private final ILabelProvider fLabelProvider= DebugUITools.newDebugModelPresentation();

private final String toggleMessage = DebugUIMessages.JDIDebugUIPlugin_5;
/**
* @see IJavaHotCodeReplaceListener#hotCodeReplaceSucceeded(IJavaDebugTarget)
*/
Expand All @@ -46,10 +47,19 @@ public void hotCodeReplaceSucceeded(IJavaDebugTarget target) {
*/
@Override
public void hotCodeReplaceFailed(final IJavaDebugTarget target, final DebugException exception) {

boolean failurePopUp;
try {
failurePopUp = JDIDebugTarget.hcrDebugSessionErrors.getOrDefault(target.getName(), false);
} catch (DebugException e) {
failurePopUp = false;
}
if ((exception != null &&!JDIDebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IJDIPreferencesConstants.PREF_ALERT_HCR_FAILED)) ||
((exception == null) && !JDIDebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IJDIPreferencesConstants.PREF_ALERT_HCR_NOT_SUPPORTED))) {
((exception == null) && !JDIDebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IJDIPreferencesConstants.PREF_ALERT_HCR_NOT_SUPPORTED))
|| failurePopUp) {
return;
}

// do not report errors for snippet editor targets
// that do not support HCR. HCR is simulated by using
// a new class loader for each evaluation
Expand Down Expand Up @@ -101,7 +111,7 @@ public void run() {
}
}
Shell shell= JDIDebugUIPlugin.getActiveWorkbenchShell();
fHotCodeReplaceFailedErrorDialog = new HotCodeReplaceErrorDialog(shell, title, message, status, preference, alertMessage, JDIDebugUIPlugin.getDefault().getPreferenceStore(), target) {
fHotCodeReplaceFailedErrorDialog = new HotCodeReplaceErrorDialog(shell, title, message, status, preference, alertMessage, toggleMessage, JDIDebugUIPlugin.getDefault().getPreferenceStore(), target) {
@Override
public boolean close() {
fHotCodeReplaceFailedErrorDialog = null;
Expand All @@ -119,7 +129,14 @@ public boolean close() {
*/
@Override
public void obsoleteMethods(final IJavaDebugTarget target) {
if (!JDIDebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IJDIPreferencesConstants.PREF_ALERT_OBSOLETE_METHODS)) {
boolean failurePopUp;
try {
failurePopUp = JDIDebugTarget.hcrDebugSessionErrors.getOrDefault(target.getName(), false);
} catch (DebugException e) {
failurePopUp = false;
}
if (!JDIDebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IJDIPreferencesConstants.PREF_ALERT_OBSOLETE_METHODS)
|| failurePopUp) {
return;
}
final Display display= JDIDebugUIPlugin.getStandardDisplay();
Expand All @@ -131,15 +148,15 @@ public void obsoleteMethods(final IJavaDebugTarget target) {
final String message= NLS.bind(DebugUIMessages.JDIDebugUIPlugin__0__contains_obsolete_methods_1, new Object[] {vmName});
final IStatus status= new Status(IStatus.WARNING, JDIDebugUIPlugin.getUniqueIdentifier(), IStatus.WARNING, DebugUIMessages.JDIDebugUIPlugin_Stepping_may_be_hazardous_1, null);
final String toggleMessage= DebugUIMessages.JDIDebugUIPlugin_2;
final String toggleMessage2= DebugUIMessages.JDIDebugUIPlugin_5;
display.asyncExec(new Runnable() {
@Override
public void run() {
if (display.isDisposed()) {
return;
}
Shell shell= JDIDebugUIPlugin.getActiveWorkbenchShell();
HotCodeReplaceErrorDialog dialog= new HotCodeReplaceErrorDialog(shell, dialogTitle, message, status, IJDIPreferencesConstants.PREF_ALERT_OBSOLETE_METHODS,
toggleMessage, JDIDebugUIPlugin.getDefault().getPreferenceStore(), target);
HotCodeReplaceErrorDialog dialog = new HotCodeReplaceErrorDialog(shell, dialogTitle, message, status, IJDIPreferencesConstants.PREF_ALERT_OBSOLETE_METHODS, toggleMessage, toggleMessage2, JDIDebugUIPlugin.getDefault().getPreferenceStore(), target);
dialog.setBlockOnOpen(false);
dialog.open();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2017 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -338,6 +338,11 @@ public class JDIDebugTarget extends JDIDebugElement implements
*/
private final Map<Long, String> objectLabels = new HashMap<>();

/**
* HCR failure alert pref for current debug session.
*/
public static final Map<String, Boolean> hcrDebugSessionErrors = new ConcurrentHashMap<>();

/**
* Creates a new JDI debug target for the given virtual machine.
*
Expand Down Expand Up @@ -3246,4 +3251,5 @@ public void filterNotLoadedTypes(List<IResource> resources, List<String> qualifi
}
}
}

}

0 comments on commit 42d462f

Please sign in to comment.