Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore HCR Failures for current session #347 #558

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,8 @@


import org.eclipse.core.runtime.IStatus;
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 All @@ -39,29 +41,45 @@ public class ErrorDialogWithToggle extends ErrorDialog {
* The preference key which is set by the toggle button.
* This key must be a boolean preference in the preference store.
*/
private String fPreferenceKey= null;
private String fPreferenceKey;
/**
* The message displayed to the user, with the toggle button
*/
private String fToggleMessage= null;
private Button fToggleButton= null;
private String fToggleMessage1;
private Button fToggleButton;
/**
* Optional message displayed to the user only applicable for HCR Failure, with the toggle button
*/
private String fToggleMessage2;

private Button fToggleButton2;
/**
* 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) {
SougandhS marked this conversation as resolved.
Show resolved Hide resolved
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 +94,28 @@ 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) {
if (target instanceof JDIDebugTarget jdiTarget) {
jdiTarget.setHcrDebugErrorPref(fToggleButton2.getSelection());
}
}
}

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,10 @@ 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)
* @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 +142,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 @@ -47,9 +48,11 @@ public void hotCodeReplaceSucceeded(IJavaDebugTarget target) {
@Override
public void hotCodeReplaceFailed(final IJavaDebugTarget target, final DebugException exception) {
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))
|| checkFailurePopUpPref(target)) {
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 +104,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 +122,8 @@ public boolean close() {
*/
@Override
public void obsoleteMethods(final IJavaDebugTarget target) {
if (!JDIDebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IJDIPreferencesConstants.PREF_ALERT_OBSOLETE_METHODS)) {
if (!JDIDebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IJDIPreferencesConstants.PREF_ALERT_OBSOLETE_METHODS)
|| checkFailurePopUpPref(target)) {
return;
}
final Display display= JDIDebugUIPlugin.getStandardDisplay();
Expand All @@ -131,19 +135,33 @@ 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();
}
});
}

/**
* Check whether user has enabled or disabled HCR failure error pop up for current debug session
*
* @param target
* IJavaDebugTarget of current debugging session
* @return false if user wishes to see failure pop up, else true if user don't want see pop up
*/
private boolean checkFailurePopUpPref(IJavaDebugTarget target) {
if (target instanceof JDIDebugTarget jdiTarget) {
return jdiTarget.isHcrFailurePopUpEnabled();
}
return false;
}

}
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,31 @@ public class JDIDebugTarget extends JDIDebugElement implements
*/
private final Map<Long, String> objectLabels = new HashMap<>();

/**
* HCR failure alert pref for current debug session.
*/
private volatile boolean hcrDebugErrors = false;

/**
* Returns the hcrDebugErrors boolean to decide whether HCR error pop-up should be shown or not for a debugging session dispatcher per debug
* target.
*
* @return boolean
*/
public boolean isHcrFailurePopUpEnabled() {
return hcrDebugErrors;
}

/**
* Sets the user preference for ignoring error pop-up for a debugging session
*
* @param preference
* Sets true or false for showing pop-up
*/
public void setHcrDebugErrorPref(boolean preference) {
hcrDebugErrors = preference;
}

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

}
Loading