From 34717d05d79401856bafd067894915434bf4e1ca Mon Sep 17 00:00:00 2001 From: sougandhs Date: Mon, 11 Nov 2024 16:54:27 +0530 Subject: [PATCH] Ignore HCR Failures for current session #347 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 : https://github.com/eclipse-jdt/eclipse.jdt.debug/issues/347 --- .../internal/debug/ui/DebugUIMessages.java | 1 + .../debug/ui/DebugUIMessages.properties | 1 + .../debug/ui/ErrorDialogWithToggle.java | 26 +++++++++++++++---- .../debug/ui/HotCodeReplaceErrorDialog.java | 11 ++++---- .../debug/ui/JavaHotCodeReplaceListener.java | 18 ++++++++----- .../debug/core/model/JDIDebugTarget.java | 14 +++++++++- 6 files changed, 53 insertions(+), 18 deletions(-) diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/DebugUIMessages.java b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/DebugUIMessages.java index 223d5fa756..e1647cf15f 100644 --- a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/DebugUIMessages.java +++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/DebugUIMessages.java @@ -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; diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/DebugUIMessages.properties b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/DebugUIMessages.properties index e93b81afbd..c57c23c01d 100644 --- a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/DebugUIMessages.properties +++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/DebugUIMessages.properties @@ -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] diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/ErrorDialogWithToggle.java b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/ErrorDialogWithToggle.java index 7524f6411f..45011f2b96 100644 --- a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/ErrorDialogWithToggle.java +++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/ErrorDialogWithToggle.java @@ -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 @@ -15,6 +15,7 @@ import org.eclipse.core.runtime.IStatus; +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; @@ -43,25 +44,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; @@ -76,7 +89,7 @@ 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()); @@ -94,6 +107,9 @@ protected void buttonPressed(int id) { private void storePreference() { fStore.setValue(fPreferenceKey, !getToggleButton().getSelection()); + if (fToggleButton2 != null) { + JDIDebugTarget.debugSessionVariables.put("HCR_ERRORS_IGNORE", fToggleButton2.getSelection()); //$NON-NLS-1$ + } } protected Button getToggleButton() { diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/HotCodeReplaceErrorDialog.java b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/HotCodeReplaceErrorDialog.java index 63511be2e0..237be59e88 100644 --- a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/HotCodeReplaceErrorDialog.java +++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/HotCodeReplaceErrorDialog.java @@ -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 @@ -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; } diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JavaHotCodeReplaceListener.java b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JavaHotCodeReplaceListener.java index 8eaca1ca13..3e60ec6640 100644 --- a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JavaHotCodeReplaceListener.java +++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JavaHotCodeReplaceListener.java @@ -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 @@ -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; @@ -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) */ @@ -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)) + || (boolean) JDIDebugTarget.debugSessionVariables.get("HCR_ERRORS_IGNORE")) {//$NON-NLS-1$ 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 @@ -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; @@ -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) + || (boolean) JDIDebugTarget.debugSessionVariables.get("HCR_ERRORS_IGNORE")) { //$NON-NLS-1$ return; } final Display display= JDIDebugUIPlugin.getStandardDisplay(); @@ -131,6 +135,7 @@ 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() { @@ -138,8 +143,7 @@ public void run() { 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(); } diff --git a/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDIDebugTarget.java b/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDIDebugTarget.java index 528d691dc1..9a95455423 100644 --- a/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDIDebugTarget.java +++ b/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/model/JDIDebugTarget.java @@ -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 @@ -338,6 +338,10 @@ public class JDIDebugTarget extends JDIDebugElement implements */ private final Map objectLabels = new HashMap<>(); + /** + * Preference storage for active debug session. + */ + public static final Map debugSessionVariables = new ConcurrentHashMap<>(); /** * Creates a new JDI debug target for the given virtual machine. * @@ -381,6 +385,7 @@ public JDIDebugTarget(ILaunch launch, VirtualMachine jvm, String name, DebugPlugin.getDefault().getLaunchManager().addLaunchListener(this); DebugPlugin.getDefault().getBreakpointManager() .addBreakpointManagerListener(this); + initializeDebugPrefs(); } @@ -3246,4 +3251,11 @@ public void filterNotLoadedTypes(List resources, List qualifi } } } + + /** + * Initialize all debug session only preferences + */ + public void initializeDebugPrefs() { + debugSessionVariables.put("HCR_ERRORS_IGNORE", false); //$NON-NLS-1$ + } }