diff --git a/bundles/io.openliberty.tools.eclipse.ui/META-INF/MANIFEST.MF b/bundles/io.openliberty.tools.eclipse.ui/META-INF/MANIFEST.MF index 09b6e000..98bd8541 100644 --- a/bundles/io.openliberty.tools.eclipse.ui/META-INF/MANIFEST.MF +++ b/bundles/io.openliberty.tools.eclipse.ui/META-INF/MANIFEST.MF @@ -25,11 +25,14 @@ Import-Package: org.eclipse.cdt.launch.ui, org.eclipse.core.runtime.jobs, org.eclipse.core.runtime.preferences, org.eclipse.debug.core, + org.eclipse.debug.core.commands, org.eclipse.debug.core.model, org.eclipse.debug.core.sourcelookup, + org.eclipse.debug.internal.core.commands, org.eclipse.debug.internal.ui, org.eclipse.debug.internal.ui.actions, org.eclipse.debug.ui, + org.eclipse.debug.ui.actions, org.eclipse.debug.ui.sourcelookup, org.eclipse.jdi, org.eclipse.jdt.core, diff --git a/bundles/io.openliberty.tools.eclipse.ui/plugin.xml b/bundles/io.openliberty.tools.eclipse.ui/plugin.xml index 0c1921ec..655da175 100644 --- a/bundles/io.openliberty.tools.eclipse.ui/plugin.xml +++ b/bundles/io.openliberty.tools.eclipse.ui/plugin.xml @@ -721,22 +721,15 @@ targetID="org.eclipse.debug.ui.DebugView" id="org.eclipse.debug.ui.debugview.popupMenu"> - - - - + label="Connect Liberty Debugger" + id="io.openliberty.tools.eclipse.debug.popupMenu.reconnect"> + + + diff --git a/bundles/io.openliberty.tools.eclipse.ui/src/io/openliberty/tools/eclipse/debug/DebugModeHandler.java b/bundles/io.openliberty.tools.eclipse.ui/src/io/openliberty/tools/eclipse/debug/DebugModeHandler.java index e7bc9b81..6581b62b 100644 --- a/bundles/io.openliberty.tools.eclipse.ui/src/io/openliberty/tools/eclipse/debug/DebugModeHandler.java +++ b/bundles/io.openliberty.tools.eclipse.ui/src/io/openliberty/tools/eclipse/debug/DebugModeHandler.java @@ -377,8 +377,7 @@ private IDebugTarget createRemoteJDTDebugTarget(ILaunch launch, Project project, throw new CoreException( new Status(IStatus.ERROR, this.getClass(), IJavaLaunchConfigurationConstants.ERR_CONNECTION_FAILED, "", ex)); } - LibertyDebugTarget libertyDebugTarget = new LibertyDebugTarget(launch, remoteVM, hostName + ":" + remoteDebugPortNum, - new RestartDebugger(project, launch, String.valueOf(remoteDebugPortNum))); + LibertyDebugTarget libertyDebugTarget = new LibertyDebugTarget(launch, remoteVM, hostName + ":" + remoteDebugPortNum); // Add hot code replace listener to listen for hot code replace failure. libertyDebugTarget.addHotCodeReplaceListener(new LibertyHotCodeReplaceListener()); @@ -659,32 +658,32 @@ private class DataHolder { boolean closed; } - /** - * This class is used as a callback to DebugModeHandler. LibertyDebugTarget will - * use this to restart the debugger in the event the Liberty server is restarted by dev mode - * or a hot code replace failure occurs. - */ - class RestartDebugger { - - private Project project; - private ILaunch launch; - private String port; - - RestartDebugger(Project project, ILaunch launch, String port) { - this.project = project; - this.launch = launch; - this.port = port; - } - - /** - * Recreate and re-attach the debug target to the running server - */ - public void restart() { - // If dev mode restarted the server, the debug port may have changed and - // we need to read the new value from server.env. At this point, we do not - // know if the debugger restarted due to a HCR failure, a manual disconnect, - // or a dev mode restart, so we need to read the port in all cases. - startDebugAttacher(project, launch, port, true); - } - } + // /** + // * This class is used as a callback to DebugModeHandler. LibertyDebugTarget will + // * use this to restart the debugger in the event the Liberty server is restarted by dev mode + // * or a hot code replace failure occurs. + // */ + // class RestartDebugger { + // + // private Project project; + // private ILaunch launch; + // private String port; + // + // RestartDebugger(Project project, ILaunch launch, String port) { + // this.project = project; + // this.launch = launch; + // this.port = port; + // } + // + // /** + // * Recreate and re-attach the debug target to the running server + // */ + // public void restart() { + // // If dev mode restarted the server, the debug port may have changed and + // // we need to read the new value from server.env. At this point, we do not + // // know if the debugger restarted due to a HCR failure, a manual disconnect, + // // or a dev mode restart, so we need to read the port in all cases. + // startDebugAttacher(project, launch, port, true); + // } + // } } diff --git a/bundles/io.openliberty.tools.eclipse.ui/src/io/openliberty/tools/eclipse/debug/LibertyDebugDisconnectActionDelegate.java b/bundles/io.openliberty.tools.eclipse.ui/src/io/openliberty/tools/eclipse/debug/LibertyDebugDisconnectActionDelegate.java deleted file mode 100644 index 7c81576f..00000000 --- a/bundles/io.openliberty.tools.eclipse.ui/src/io/openliberty/tools/eclipse/debug/LibertyDebugDisconnectActionDelegate.java +++ /dev/null @@ -1,24 +0,0 @@ -package io.openliberty.tools.eclipse.debug; - -import java.util.Arrays; - -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.ILaunch; -import org.eclipse.debug.core.model.IDebugTarget; -import org.eclipse.debug.internal.ui.DebugUIPlugin; -import org.eclipse.debug.internal.ui.actions.AbstractDebugActionDelegate; - -public class LibertyDebugDisconnectActionDelegate extends AbstractDebugActionDelegate { - - @Override - protected void doAction(Object object) throws DebugException { - - ILaunch launch = DebugUIPlugin.getLaunch(object); - for (IDebugTarget target : Arrays.asList(launch.getDebugTargets())) { - if (target instanceof LibertyDebugTarget) { - ((LibertyDebugTarget) target).setRelaunch(false); - } - target.disconnect(); - } - } -} diff --git a/bundles/io.openliberty.tools.eclipse.ui/src/io/openliberty/tools/eclipse/debug/LibertyDebugRelaunchActionDelegate.java b/bundles/io.openliberty.tools.eclipse.ui/src/io/openliberty/tools/eclipse/debug/LibertyDebugReconnectActionDelegate.java similarity index 78% rename from bundles/io.openliberty.tools.eclipse.ui/src/io/openliberty/tools/eclipse/debug/LibertyDebugRelaunchActionDelegate.java rename to bundles/io.openliberty.tools.eclipse.ui/src/io/openliberty/tools/eclipse/debug/LibertyDebugReconnectActionDelegate.java index 66093705..5ac8027b 100644 --- a/bundles/io.openliberty.tools.eclipse.ui/src/io/openliberty/tools/eclipse/debug/LibertyDebugRelaunchActionDelegate.java +++ b/bundles/io.openliberty.tools.eclipse.ui/src/io/openliberty/tools/eclipse/debug/LibertyDebugReconnectActionDelegate.java @@ -2,6 +2,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.debug.core.ILaunch; +import org.eclipse.debug.core.model.IDebugTarget; import org.eclipse.debug.internal.ui.DebugUIPlugin; import org.eclipse.debug.internal.ui.actions.AbstractDebugActionDelegate; @@ -9,7 +10,7 @@ import io.openliberty.tools.eclipse.Project; import io.openliberty.tools.eclipse.ui.launch.StartTab; -public class LibertyDebugRelaunchActionDelegate extends AbstractDebugActionDelegate { +public class LibertyDebugReconnectActionDelegate extends AbstractDebugActionDelegate { @Override protected void doAction(Object object) { @@ -22,16 +23,19 @@ protected void doAction(Object object) { try { projectName = launch.getLaunchConfiguration().getAttribute(StartTab.PROJECT_NAME, ""); } catch (CoreException e) { - // TODO Auto-generated catch block + // TODO - how to handle errors? e.printStackTrace(); } Project project = devModeOps.getProjectModel().getProject(projectName); + // Reconnect debugger if (!devModeOps.isProjectTerminalTabMarkedClosed(projectName)) { devModeOps.debugModeHandler.startDebugAttacher(project, launch, null, true); } + // Remove old debug target + launch.removeDebugTarget((IDebugTarget) object); } } } diff --git a/bundles/io.openliberty.tools.eclipse.ui/src/io/openliberty/tools/eclipse/debug/LibertyDebugTarget.java b/bundles/io.openliberty.tools.eclipse.ui/src/io/openliberty/tools/eclipse/debug/LibertyDebugTarget.java index 510b0ecd..97effa05 100644 --- a/bundles/io.openliberty.tools.eclipse.ui/src/io/openliberty/tools/eclipse/debug/LibertyDebugTarget.java +++ b/bundles/io.openliberty.tools.eclipse.ui/src/io/openliberty/tools/eclipse/debug/LibertyDebugTarget.java @@ -1,5 +1,6 @@ package io.openliberty.tools.eclipse.debug; +import org.eclipse.debug.core.DebugEvent; import org.eclipse.debug.core.ILaunch; import org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget; @@ -7,27 +8,14 @@ import com.sun.jdi.event.VMDeathEvent; import com.sun.jdi.event.VMDisconnectEvent; -import io.openliberty.tools.eclipse.debug.DebugModeHandler.RestartDebugger; - /** * This class is an extension of the JDIDebugTarget and allows the debugger to be restarted * automatically if the VM restarts or a hot code replace failure occurs. */ public class LibertyDebugTarget extends JDIDebugTarget { - private RestartDebugger restartDebugger; - private boolean relaunch; - - public LibertyDebugTarget(ILaunch launch, VirtualMachine jvm, String name, RestartDebugger restartDebugger) { + public LibertyDebugTarget(ILaunch launch, VirtualMachine jvm, String name) { super(launch, jvm, "Liberty Application Debug: " + name, true, true, null, true); - - this.restartDebugger = restartDebugger; - this.relaunch = true; - - } - - public void setRelaunch(boolean relaunch) { - this.relaunch = relaunch; } @Override @@ -49,30 +37,8 @@ protected void disconnected() { if (!isDisconnected()) { setDisconnected(true); cleanup(); - - getLaunch().removeDebugTarget(this); - - // Attempt to restart the debugger - if (relaunch) { - restartDebugger.restart(); - restartDebugger = null; - } + fireChangeEvent(DebugEvent.CONTENT); } - } - - // @Override - // public void disconnect() throws DebugException { - // // If we got here, the user explicitly called "disconnect" on the debugger. - // // We should not try to reconnect in this case but we should allow the user - // // to select "relaunch" which should just reconnect the debugger. - // // Since we cant differentiate between a normal "launch" and a "relaunch", - // // we will set a flag that we will use to determine if we should launch devMode - // // or just reconnect the debugger. - // restartDebugger = null; - // relaunch = true; - // - // super.disconnect(); - // - // } + } } diff --git a/bundles/io.openliberty.tools.eclipse.ui/src/io/openliberty/tools/eclipse/debug/LibertyHotCodeReplaceErrorDialog.java b/bundles/io.openliberty.tools.eclipse.ui/src/io/openliberty/tools/eclipse/debug/LibertyHotCodeReplaceErrorDialog.java index 1ed20449..0b67a557 100644 --- a/bundles/io.openliberty.tools.eclipse.ui/src/io/openliberty/tools/eclipse/debug/LibertyHotCodeReplaceErrorDialog.java +++ b/bundles/io.openliberty.tools.eclipse.ui/src/io/openliberty/tools/eclipse/debug/LibertyHotCodeReplaceErrorDialog.java @@ -12,15 +12,25 @@ *******************************************************************************/ package io.openliberty.tools.eclipse.debug; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; +import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.model.IDebugTarget; import org.eclipse.jdt.internal.debug.ui.DebugUIMessages; import org.eclipse.jdt.internal.debug.ui.HotCodeReplaceErrorDialog; +import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.custom.BusyIndicator; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Shell; +import io.openliberty.tools.eclipse.DevModeOperations; +import io.openliberty.tools.eclipse.Project; +import io.openliberty.tools.eclipse.ui.launch.StartTab; + /** * This class is an extension of the Eclipse JDT HotCodeReplaceErrorDialog. It provides * a custom display when a hot code replace failure occurs allowing for the user to refresh the @@ -43,35 +53,44 @@ protected void createButtonsForButtonBar(Composite parent) { blockMnemonicWithoutModifier(getToggleButton()); } - // /* - // * (non-Javadoc) - // * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int) - // */ - // @Override - // protected void buttonPressed(final int id) { - // if (id == DISCONNECT_ID) { - // final DebugException[] ex = new DebugException[1]; - // final String[] operation = new String[1]; - // ex[0] = null; - // Runnable r = new Runnable() { - // @Override - // public void run() { - // try { - // operation[0] = DebugUIMessages.HotCodeReplaceErrorDialog_6; - // target.disconnect(); - // } catch (Exception e) { - // IStatus errorStatus = new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), e.getMessage(), e); - // ex[0] = new DebugException(errorStatus); - // } - // } - // }; - // BusyIndicator.showWhile(getShell().getDisplay(), r); - // if (ex[0] != null) { - // JDIDebugUIPlugin.statusDialog(NLS.bind(DebugUIMessages.HotCodeReplaceErrorDialog_2, operation), ex[0].getStatus()); - // } - // okPressed(); - // } else { - // super.buttonPressed(id); - // } - // } + /* + * (non-Javadoc) + * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int) + */ + @Override + protected void buttonPressed(final int id) { + if (id == DISCONNECT_ID) { + final CoreException[] ex = new DebugException[1]; + final String[] operation = new String[1]; + ex[0] = null; + Runnable r = new Runnable() { + @Override + public void run() { + try { + operation[0] = DebugUIMessages.HotCodeReplaceErrorDialog_6; + target.disconnect(); + + // Restart the debugger + DevModeOperations devModeOps = DevModeOperations.getInstance(); + + ILaunch launch = target.getLaunch(); + String projectName = launch.getLaunchConfiguration().getAttribute(StartTab.PROJECT_NAME, ""); + Project project = devModeOps.getProjectModel().getProject(projectName); + + launch.removeDebugTarget(target); + devModeOps.debugModeHandler.startDebugAttacher(project, launch, null, true); + } catch (CoreException e) { + ex[0] = e; + } + } + }; + BusyIndicator.showWhile(getShell().getDisplay(), r); + if (ex[0] != null) { + JDIDebugUIPlugin.statusDialog(NLS.bind(DebugUIMessages.HotCodeReplaceErrorDialog_2, operation), ex[0].getStatus()); + } + okPressed(); + } else { + super.buttonPressed(id); + } + } }