Skip to content

Commit

Permalink
Remove auto-reconnect
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Wisniewski <[email protected]>
  • Loading branch information
awisniew90 committed Jan 8, 2025
1 parent 6136b06 commit b33798e
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 140 deletions.
3 changes: 3 additions & 0 deletions bundles/io.openliberty.tools.eclipse.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 8 additions & 15 deletions bundles/io.openliberty.tools.eclipse.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -721,22 +721,15 @@
targetID="org.eclipse.debug.ui.DebugView"
id="org.eclipse.debug.ui.debugview.popupMenu">

<action
label="Relaunch Liberty"
icon="$nl$/icons/full/elcl16/runlast_co.png"
helpContextId="relaunch_action_context"
class="io.openliberty.tools.eclipse.debug.LibertyDebugRelaunchActionDelegate"
<action
icon="$nl$/icons/openLibertyLogo.png"
class="io.openliberty.tools.eclipse.debug.LibertyDebugReconnectActionDelegate"
menubarPath="launchGroup"
id="io.openliberty.tools.eclipse.debug.popupMenu.relaunch">
</action>
<action
label="Disconnect"
icon="$nl$/icons/full/elcl16/runlast_co.png"
helpContextId="relaunch_action_context"
class="io.openliberty.tools.eclipse.debug.LibertyDebugDisconnectActionDelegate"
menubarPath="launchGroup"
id="io.openliberty.tools.eclipse.debug.popupMenu.disconnect">
</action>
label="Connect Liberty Debugger"
id="io.openliberty.tools.eclipse.debug.popupMenu.reconnect">
</action>

</viewerContribution>
</extension>

</plugin>
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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);
// }
// }
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

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;

import io.openliberty.tools.eclipse.DevModeOperations;
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) {
Expand All @@ -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);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,33 +1,21 @@
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;

import com.sun.jdi.VirtualMachine;
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
Expand All @@ -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();
//
// }

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}
}

0 comments on commit b33798e

Please sign in to comment.