Author: koen.aers(a)jboss.com
Date: 2012-04-21 07:42:21 -0400 (Sat, 21 Apr 2012)
New Revision: 40397
Modified:
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/ForgeCorePlugin.java
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/process/ForgeAbstractRuntime.java
Log:
JBIDE-11200: Forge process fails to stop
Modified:
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/ForgeCorePlugin.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/ForgeCorePlugin.java 2012-04-21
02:06:55 UTC (rev 40396)
+++
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/ForgeCorePlugin.java 2012-04-21
11:42:21 UTC (rev 40397)
@@ -1,8 +1,13 @@
package org.jboss.tools.forge.core;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.model.IProcess;
import org.osgi.framework.BundleContext;
public class ForgeCorePlugin extends Plugin {
@@ -11,10 +16,34 @@
private static ForgeCorePlugin plugin;
+ private static Thread shutdownHook;
+ private static List<IProcess> processes = new ArrayList<IProcess>();
+
public void start(BundleContext context) throws Exception {
super.start(context);
+ initializeShutdownHook();
plugin = this;
}
+
+ private void initializeShutdownHook() {
+ if (shutdownHook == null) {
+ shutdownHook = new Thread(new Runnable() {
+ @Override
+ public void run() {
+ for (IProcess process : processes) {
+ if (process != null && process.canTerminate()) {
+ try {
+ process.terminate();
+ } catch (DebugException e) {
+ log(e);
+ }
+ }
+ }
+ }
+ });
+ Runtime.getRuntime().addShutdownHook(shutdownHook);
+ }
+ }
public void stop(BundleContext context) throws Exception {
plugin = null;
@@ -33,4 +62,12 @@
return new Status(IStatus.ERROR, PLUGIN_ID, IStatus.INFO, message, exception);
}
+ public static void addForgeProcess(IProcess process) {
+ processes.add(process);
+ }
+
+ public static void removeForgeProcess(IProcess process) {
+ processes.remove(process);
+ }
+
}
Modified:
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/process/ForgeAbstractRuntime.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/process/ForgeAbstractRuntime.java 2012-04-21
02:06:55 UTC (rev 40396)
+++
trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/process/ForgeAbstractRuntime.java 2012-04-21
11:42:21 UTC (rev 40397)
@@ -75,6 +75,7 @@
}
} finally {
if (process != null) {
+ ForgeCorePlugin.addForgeProcess(process);
IStreamsProxy streamsProxy = process.getStreamsProxy();
if (streamsProxy != null) {
IStreamMonitor outputStreamMonitor = streamsProxy.getOutputStreamMonitor();
@@ -155,6 +156,7 @@
}
}
process.terminate();
+ ForgeCorePlugin.removeForgeProcess(process);
}
} catch (DebugException e) {
ForgeCorePlugin.log(e);
@@ -227,6 +229,7 @@
@Override
public void run() {
setNewState(STATE_NOT_RUNNING);
+ ForgeCorePlugin.removeForgeProcess(process);
process = null;
DebugPlugin.getDefault().removeDebugEventListener(terminateListener);
}
Show replies by date