Skip to content

Commit

Permalink
Add actions to disconnect and reconnect manually
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Wisniewski <[email protected]>
  • Loading branch information
awisniew90 committed Jan 3, 2025
1 parent 81b9dbe commit 6136b06
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 3 deletions.
2 changes: 2 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 @@ -27,6 +27,8 @@ Import-Package: org.eclipse.cdt.launch.ui,
org.eclipse.debug.core,
org.eclipse.debug.core.model,
org.eclipse.debug.core.sourcelookup,
org.eclipse.debug.internal.ui,
org.eclipse.debug.internal.ui.actions,
org.eclipse.debug.ui,
org.eclipse.debug.ui.sourcelookup,
org.eclipse.jdi,
Expand Down
26 changes: 26 additions & 0 deletions bundles/io.openliberty.tools.eclipse.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -713,4 +713,30 @@
name="Liberty">
</page>
</extension>

<extension
point="org.eclipse.ui.popupMenus">

<viewerContribution
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"
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>
</viewerContribution>
</extension>
</plugin>
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public class DevModeOperations {
/**
* Handles debug mode processing.
*/
private DebugModeHandler debugModeHandler;
public DebugModeHandler debugModeHandler;

/**
* The instance of this class.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.openliberty.tools.eclipse.debug;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunch;
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 {

@Override
protected void doAction(Object object) {
ILaunch launch = DebugUIPlugin.getLaunch(object);

if (launch != null) {
DevModeOperations devModeOps = DevModeOperations.getInstance();

String projectName = "";
try {
projectName = launch.getLaunchConfiguration().getAttribute(StartTab.PROJECT_NAME, "");
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

Project project = devModeOps.getProjectModel().getProject(projectName);

if (!devModeOps.isProjectTerminalTabMarkedClosed(projectName)) {
devModeOps.debugModeHandler.startDebugAttacher(project, launch, null, true);
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@
public class LibertyDebugTarget extends JDIDebugTarget {

private RestartDebugger restartDebugger;
private boolean relaunch;

public LibertyDebugTarget(ILaunch launch, VirtualMachine jvm, String name, RestartDebugger restartDebugger) {
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 @@ -44,9 +51,28 @@ protected void disconnected() {
cleanup();

getLaunch().removeDebugTarget(this);
restartDebugger.restart();
restartDebugger = null;

// Attempt to restart the debugger
if (relaunch) {
restartDebugger.restart();
restartDebugger = null;
}
}
}

// @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 @@ -70,6 +70,8 @@ public void launch(ILaunchConfiguration configuration, String mode, ILaunch laun
IWorkbench workbench = PlatformUI.getWorkbench();
Display display = workbench.getDisplay();

// if (launch ==)

// Launch dev mode.
display.syncExec(new Runnable() {
public void run() {
Expand Down

0 comments on commit 6136b06

Please sign in to comment.