Skip to content

Commit abf14cd

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

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

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

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

23+
import org.eclipse.debug.core.DebugEvent;
24+
import org.eclipse.debug.core.DebugPlugin;
25+
import org.eclipse.debug.core.IDebugEventSetListener;
26+
import org.eclipse.debug.core.model.IProcess;
27+
2328
import io.openliberty.tools.eclipse.logging.Trace;
2429
import io.openliberty.tools.eclipse.utils.Utils;
2530

@@ -110,9 +115,36 @@ public Process runProcess(String projectName, String projectPath, String command
110115

111116
projectProcessMap.put(projectName, process);
112117

118+
addTerminateListener(projectName);
119+
113120
return process;
114121
}
115122

123+
private void addTerminateListener(String projectName) {
124+
125+
DebugPlugin.getDefault().addDebugEventListener(new IDebugEventSetListener() {
126+
127+
public void handleDebugEvents(DebugEvent[] events) {
128+
for (int i = 0; i < events.length; i++) {
129+
Object source = events[i].getSource();
130+
131+
if (source instanceof IProcess && events[i].getKind() == DebugEvent.TERMINATE) {
132+
133+
// This is an IProcess terminate event. Check if the IProcess matches
134+
IProcess iProcess = (IProcess) source;
135+
if (projectName.equals(iProcess.getLabel())) {
136+
// We match - Remove from map
137+
projectProcessMap.remove(projectName);
138+
139+
DebugPlugin.getDefault().removeDebugEventListener(this);
140+
}
141+
}
142+
}
143+
}
144+
});
145+
146+
}
147+
116148
/**
117149
* Writes the input data to the running process associated with the input project name.
118150
*

0 commit comments

Comments
 (0)