Skip to content

Commit e1faaf8

Browse files
committed
Add terminate event listener for process termination
Signed-off-by: Adam Wisniewski <awisniew@us.ibm.com>
1 parent 49e5f56 commit e1faaf8

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

bundles/io.openliberty.tools.eclipse.ui/src/io/openliberty/tools/eclipse/DevModeOperations.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ public void stop(IProject inputProject) {
408408
processController.writeToProcessStream(projectName, DEVMODE_COMMAND_EXIT);
409409

410410
// Cleanup internal objects.
411-
processController.cleanup(projectName);
411+
cleanupProcess(projectName);
412412

413413
} catch (Exception e) {
414414
String msg = NLS.bind(Messages.stop_general_error, projectName);
@@ -422,6 +422,10 @@ public void stop(IProject inputProject) {
422422
}
423423
}
424424

425+
public void cleanupProcess(String projectName) {
426+
processController.cleanup(projectName);
427+
}
428+
425429
/**
426430
* Runs the tests provided by the application.
427431
*
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package io.openliberty.tools.eclipse.process;
2+
3+
import org.eclipse.debug.core.DebugEvent;
4+
import org.eclipse.debug.core.DebugPlugin;
5+
import org.eclipse.debug.core.IDebugEventSetListener;
6+
import org.eclipse.debug.core.model.IProcess;
7+
8+
import io.openliberty.tools.eclipse.DevModeOperations;
9+
10+
public class LibertyDebugEventListener implements IDebugEventSetListener {
11+
12+
private String projectName;
13+
14+
public LibertyDebugEventListener(String projectName) {
15+
this.projectName = projectName;
16+
}
17+
18+
@Override
19+
public void handleDebugEvents(DebugEvent[] events) {
20+
for (int i = 0; i < events.length; i++) {
21+
Object source = events[i].getSource();
22+
23+
if (source instanceof IProcess && events[i].getKind() == DebugEvent.TERMINATE) {
24+
25+
// This is an IProcess terminate event. Check if the IProcess matches
26+
IProcess iProcess = (IProcess) source;
27+
if (projectName.equals(iProcess.getLabel())) {
28+
// We match - cleanup
29+
DevModeOperations devModeOps = DevModeOperations.getInstance();
30+
devModeOps.cleanupProcess(projectName);
31+
32+
DebugPlugin.getDefault().removeDebugEventListener(this);
33+
}
34+
}
35+
}
36+
}
37+
38+
}

bundles/io.openliberty.tools.eclipse.ui/src/io/openliberty/tools/eclipse/process/ProcessController.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.util.Map;
2121
import java.util.concurrent.ConcurrentHashMap;
2222

23+
import org.eclipse.debug.core.DebugPlugin;
24+
2325
import io.openliberty.tools.eclipse.logging.Trace;
2426
import io.openliberty.tools.eclipse.utils.Utils;
2527

@@ -110,9 +112,17 @@ public Process runProcess(String projectName, String projectPath, String command
110112

111113
projectProcessMap.put(projectName, process);
112114

115+
addTerminateListener(projectName);
116+
113117
return process;
114118
}
115119

120+
private void addTerminateListener(String projectName) {
121+
122+
DebugPlugin.getDefault().addDebugEventListener(new LibertyDebugEventListener(projectName));
123+
124+
}
125+
116126
/**
117127
* Writes the input data to the running process associated with the input project name.
118128
*

0 commit comments

Comments
 (0)