Skip to content

Commit 625f30f

Browse files
eharris369GitHub Enterprise
authored andcommitted
Merge pull request #212 from eharris/204-disconnectDebuggerOnRestart
Issue #204: Disconnect debug target on restart
2 parents 7bf0646 + 2e7a158 commit 625f30f

File tree

5 files changed

+41
-25
lines changed

5 files changed

+41
-25
lines changed

dev/com.ibm.microclimate.core/src/com/ibm/microclimate/core/internal/MCEclipseApplication.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.eclipse.core.runtime.Path;
2727
import org.eclipse.core.runtime.Status;
2828
import org.eclipse.core.runtime.jobs.Job;
29+
import org.eclipse.debug.core.DebugException;
2930
import org.eclipse.debug.core.DebugPlugin;
3031
import org.eclipse.debug.core.ILaunch;
3132
import org.eclipse.debug.core.ILaunchConfiguration;
@@ -106,6 +107,23 @@ public synchronized void setLaunch(ILaunch launch) {
106107
public synchronized ILaunch getLaunch() {
107108
return launch;
108109
}
110+
111+
@Override
112+
public void clearDebugger() {
113+
if (launch != null) {
114+
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
115+
launchManager.removeLaunch(launch);
116+
IDebugTarget debugTarget = launch.getDebugTarget();
117+
if (debugTarget != null && !debugTarget.isDisconnected()) {
118+
try {
119+
debugTarget.disconnect();
120+
} catch (DebugException e) {
121+
MCLogger.logError("An error occurred while disconnecting the debugger for project: " + name, e); //$NON-NLS-1$
122+
}
123+
}
124+
}
125+
setLaunch(null);
126+
}
109127

110128
@Override
111129
public void connectDebugger() {
@@ -123,7 +141,7 @@ protected IStatus run(IProgressMonitor monitor) {
123141
app.setLaunch(launch);
124142
return Status.OK_STATUS;
125143
} catch (Exception e) {
126-
MCLogger.logError("An error occurred while trying to launch the debugger for project: " + app.name);
144+
MCLogger.logError("An error occurred while trying to launch the debugger for project: " + app.name); //$NON-NLS-1$
127145
return new Status(IStatus.ERROR, MicroclimateCorePlugin.PLUGIN_ID,
128146
NLS.bind(Messages.DebugLaunchError, app.name), e);
129147
}
@@ -210,7 +228,7 @@ public void resetValidation() {
210228
try {
211229
project.deleteMarkers(MARKER_TYPE, true, IResource.DEPTH_INFINITE);
212230
} catch (CoreException e) {
213-
MCLogger.logError("Failed to delete existing markers for the " + name + " project.", e);
231+
MCLogger.logError("Failed to delete existing markers for the " + name + " project.", e); //$NON-NLS-1$
214232
}
215233
}
216234
}
@@ -252,7 +270,7 @@ private void validationEvent(int severity, String filePath, String message, Stri
252270
}
253271
}
254272
} catch (CoreException e) {
255-
MCLogger.logError("Failed to create a marker for the " + name + " application: " + message, e);
273+
MCLogger.logError("Failed to create a marker for the " + name + " application: " + message, e); //$NON-NLS-1$
256274
}
257275
}
258276

dev/com.ibm.microclimate.core/src/com/ibm/microclimate/core/internal/MicroclimateApplication.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@ public ProjectCapabilities getProjectCapabilities() {
223223
return projectCapabilities;
224224
}
225225

226+
public void clearDebugger() {
227+
// Override as needed
228+
}
229+
226230
public void connectDebugger() {
227231
// Override as needed
228232
}

dev/com.ibm.microclimate.core/src/com/ibm/microclimate/core/internal/connection/MicroclimateSocket.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ private void onProjectCreation(JSONObject event) throws JSONException {
235235
mcConnection.refreshApps(projectID);
236236
MicroclimateApplication app = mcConnection.getAppByID(projectID);
237237
if (app == null) {
238-
MCLogger.logError("No application found matching the project id for the project creation event: " + projectID);
238+
MCLogger.logError("No application found matching the project id for the project creation event: " + projectID); //$NON-NLS-1$
239239
return;
240240
}
241241
app.setEnabled(true);
@@ -246,7 +246,7 @@ private void onProjectChanged(JSONObject event) throws JSONException {
246246
String projectID = event.getString(MCConstants.KEY_PROJECT_ID);
247247
MicroclimateApplication app = mcConnection.getAppByID(projectID);
248248
if (app == null) {
249-
MCLogger.logError("No application found matching the project id for the project changed event: " + projectID);
249+
MCLogger.logError("No application found matching the project id for the project changed event: " + projectID); //$NON-NLS-1$
250250
return;
251251
}
252252

@@ -322,7 +322,7 @@ private void onProjectRestart(JSONObject event) throws JSONException {
322322
String projectID = event.getString(MCConstants.KEY_PROJECT_ID);
323323
MicroclimateApplication app = mcConnection.getAppByID(projectID);
324324
if (app == null) {
325-
MCLogger.logError("No application found matching the project id for the project restart event: " + projectID);
325+
MCLogger.logError("No application found matching the project id for the project restart event: " + projectID); //$NON-NLS-1$
326326
return;
327327
}
328328

@@ -359,6 +359,9 @@ private void onProjectRestart(JSONObject event) throws JSONException {
359359
StartMode startMode = StartMode.get(event);
360360
app.setStartMode(startMode);
361361

362+
// Make sure no old debugger is running
363+
app.clearDebugger();
364+
362365
if (StartMode.DEBUG_MODES.contains(startMode) && debugPort != -1) {
363366
app.connectDebugger();
364367
}
@@ -368,7 +371,7 @@ private void onProjectClosed(JSONObject event) throws JSONException {
368371
String projectID = event.getString(MCConstants.KEY_PROJECT_ID);
369372
MicroclimateApplication app = mcConnection.getAppByID(projectID);
370373
if (app == null) {
371-
MCLogger.logError("No application found for project being closed: " + projectID);
374+
MCLogger.logError("No application found for project being closed: " + projectID); //$NON-NLS-1$
372375
return;
373376
}
374377
app.setEnabled(false);
@@ -379,15 +382,15 @@ private void onProjectDeletion(JSONObject event) throws JSONException {
379382
String projectID = event.getString(MCConstants.KEY_PROJECT_ID);
380383
MicroclimateApplication app = mcConnection.removeApp(projectID);
381384
if (app == null) {
382-
MCLogger.logError("No application found for project being deleted: " + projectID);
385+
MCLogger.logError("No application found for project being deleted: " + projectID); //$NON-NLS-1$
383386
return;
384387
}
385388
MCUtil.updateConnection(mcConnection);
386389
app.dispose();
387390
}
388391

389392
public void registerSocketConsole(SocketConsole console) {
390-
MCLogger.log("Register socketConsole for projectID " + console.projectID);
393+
MCLogger.log("Register socketConsole for projectID " + console.projectID); //$NON-NLS-1$
391394
this.socketConsoles.add(console);
392395
}
393396

@@ -398,7 +401,7 @@ public void deregisterSocketConsole(SocketConsole console) {
398401
private void onLogUpdate(JSONObject event) throws JSONException {
399402
String projectID = event.getString(MCConstants.KEY_PROJECT_ID);
400403
String logContents = event.getString(MCConstants.KEY_LOGS);
401-
MCLogger.log("Update logs for project " + projectID);
404+
MCLogger.log("Update logs for project " + projectID); //$NON-NLS-1$
402405

403406
for (SocketConsole console : this.socketConsoles) {
404407
if (console.projectID.equals(projectID)) {
@@ -416,7 +419,7 @@ private void onValidationEvent(JSONObject event) throws JSONException {
416419
String projectID = event.getString(MCConstants.KEY_PROJECT_ID);
417420
MicroclimateApplication app = mcConnection.getAppByID(projectID);
418421
if (app == null) {
419-
MCLogger.logError("No application found for project: " + projectID);
422+
MCLogger.logError("No application found for project: " + projectID); //$NON-NLS-1$
420423
return;
421424
}
422425

dev/com.ibm.microclimate.ui/src/com/ibm/microclimate/ui/internal/actions/RestartDebugModeAction.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.eclipse.debug.core.DebugPlugin;
2020
import org.eclipse.debug.core.ILaunch;
2121
import org.eclipse.debug.core.ILaunchManager;
22+
import org.eclipse.debug.core.model.IDebugTarget;
2223
import org.eclipse.jface.action.IAction;
2324
import org.eclipse.jface.dialogs.MessageDialog;
2425
import org.eclipse.jface.viewers.ISelection;
@@ -115,13 +116,8 @@ protected IStatus run(IProgressMonitor monitor) {
115116
}
116117

117118
try {
118-
// Clear out any old launch
119-
ILaunch launch = app.getLaunch();
120-
if (launch != null) {
121-
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
122-
launchManager.removeLaunch(launch);
123-
}
124-
app.setLaunch(null);
119+
// Clear out any old launch and debug target
120+
app.clearDebugger();
125121

126122
// Restart the project in debug mode. The debugger will be attached when the restart result
127123
// event is received from Microclimate.

dev/com.ibm.microclimate.ui/src/com/ibm/microclimate/ui/internal/actions/RestartRunModeAction.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,8 @@ public void run(IAction action) {
6767
}
6868

6969
try {
70-
// Clear out any old launch
71-
ILaunch launch = app.getLaunch();
72-
if (launch != null) {
73-
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
74-
launchManager.removeLaunch(launch);
75-
}
76-
app.setLaunch(null);
70+
// Clear out any old launch and debug target
71+
app.clearDebugger();
7772

7873
// Restart the project in run mode
7974
app.mcConnection.requestProjectRestart(app, StartMode.RUN.startMode);

0 commit comments

Comments
 (0)