[jbosstools-commits] JBoss Tools SVN: r41669 - in trunk/forge/plugins/org.jboss.tools.forge.core: src/org/jboss/tools/forge/core and 1 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Mon Jun 4 06:19:37 EDT 2012


Author: koen.aers at jboss.com
Date: 2012-06-04 06:19:36 -0400 (Mon, 04 Jun 2012)
New Revision: 41669

Added:
   trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/process/ForgeProcessFactory.java
   trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/process/ForgeRuntimeProcess.java
   trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/process/IForgeLaunchConfiguration.java
Modified:
   trunk/forge/plugins/org.jboss.tools.forge.core/plugin.xml
   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
   trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/process/ForgeLaunchHelper.java
Log:
JBIDE-12085: Make sure launching Forge creates a ForgeRuntimeProcess subclass of the default RuntimeProcess

Modified: trunk/forge/plugins/org.jboss.tools.forge.core/plugin.xml
===================================================================
--- trunk/forge/plugins/org.jboss.tools.forge.core/plugin.xml	2012-06-04 09:43:31 UTC (rev 41668)
+++ trunk/forge/plugins/org.jboss.tools.forge.core/plugin.xml	2012-06-04 10:19:36 UTC (rev 41669)
@@ -7,5 +7,11 @@
             class="org.jboss.tools.forge.core.preferences.ForgePreferencesInitializer">
       </initializer>
    </extension>
-
+   <extension
+         point="org.eclipse.debug.core.processFactories">
+         <processFactory 
+	        id="org.jboss.tools.forge.core.process.ForgeProcessFactory"
+         	class="org.jboss.tools.forge.core.process.ForgeProcessFactory">
+         </processFactory>
+   </extension>
 </plugin>

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-06-04 09:43:31 UTC (rev 41668)
+++ trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/ForgeCorePlugin.java	2012-06-04 10:19:36 UTC (rev 41669)
@@ -3,6 +3,7 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Plugin;
 import org.eclipse.core.runtime.Status;
@@ -12,22 +13,22 @@
 
 public class ForgeCorePlugin extends Plugin {
 
-	public static final String PLUGIN_ID = "org.jboss.tools.forge.core"; 
+	public static final String PLUGIN_ID = "org.jboss.tools.forge.core";
 
 	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() {			
+			shutdownHook = new Thread(new Runnable() {
 				@Override
 				public void run() {
 					for (IProcess process : processes) {
@@ -55,19 +56,36 @@
 	}
 
 	public static void log(Throwable t) {
-		getDefault().getLog().log(newErrorStatus("Error logged from Forge Core Plugin: ", t)); 
+		getDefault().getLog().log(
+				newErrorStatus("Error logged from Forge Core Plugin: ", t));
 	}
-	
+
 	private static IStatus newErrorStatus(String message, Throwable exception) {
-		return new Status(IStatus.ERROR, PLUGIN_ID, IStatus.INFO, message, exception);
+		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);
 	}
-	
+
+	public static void log(IStatus status) {
+		ResourcesPlugin.getPlugin().getLog().log(status);
+	}
+
+	public static void logErrorMessage(String message) {
+		log(IStatus.ERROR, message);
+	}
+
+	public static void logInfoMessage(String message) {
+		log(IStatus.INFO, message);
+	}
+
+	private static void log(int status, String message) {
+		log(new Status(status, PLUGIN_ID, status, message, null));
+	}
 }

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-06-04 09:43:31 UTC (rev 41668)
+++ trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/process/ForgeAbstractRuntime.java	2012-06-04 10:19:36 UTC (rev 41669)
@@ -51,7 +51,7 @@
 			if (process != null) {
 				setNewState(STATE_STARTING);
 				DebugPlugin.getDefault().addDebugEventListener(terminateListener);
-				IStreamsProxy streamsProxy = process.getStreamsProxy();
+				IStreamsProxy streamsProxy = getStreamsProxy();
 				if (streamsProxy != null) {
 					IStreamMonitor streamMonitor = streamsProxy.getOutputStreamMonitor();
 					if (streamMonitor != null) {
@@ -76,7 +76,7 @@
 		} finally {
 			if (process != null) {
 				ForgeCorePlugin.addForgeProcess(process);
-				IStreamsProxy streamsProxy = process.getStreamsProxy();
+				IStreamsProxy streamsProxy = getStreamsProxy();
 				if (streamsProxy != null) {
 					IStreamMonitor outputStreamMonitor = streamsProxy.getOutputStreamMonitor();
 					if (outputStreamMonitor != null) {
@@ -91,7 +91,7 @@
 	public String sendCommand(String str) {
 		String result = null;
 		if (process != null && !process.isTerminated()) {
-			IStreamsProxy streamsProxy = process.getStreamsProxy();
+			IStreamsProxy streamsProxy = getStreamsProxy();
 			if (streamsProxy != null) {
 				IStreamMonitor streamMonitor = streamsProxy.getOutputStreamMonitor();
 				if (streamMonitor != null) {
@@ -122,7 +122,7 @@
 	
 	public void sendInput(String str) {
 		if (process != null && !process.isTerminated()) {
-			IStreamsProxy streamProxy = process.getStreamsProxy();
+			IStreamsProxy streamProxy = getStreamsProxy();
 			if (streamProxy != null) {
 				try {
 					streamProxy.write(str);
@@ -148,7 +148,7 @@
 	private void terminate() {
 		try {
 			if (process != null) {
-				IStreamsProxy streamsProxy = process.getStreamsProxy();
+				IStreamsProxy streamsProxy = getStreamsProxy();
 				if (streamsProxy != null) {
 					IStreamMonitor streamMonitor = streamsProxy.getOutputStreamMonitor();
 					if (streamMonitor != null) {
@@ -169,6 +169,13 @@
 		propertyChangeSupport.firePropertyChange(PROPERTY_STATE, oldState, state);
 	}
 	
+	private IStreamsProxy getStreamsProxy() {
+		if (process instanceof ForgeRuntimeProcess) {
+			return ((ForgeRuntimeProcess) process).getForgeStreamsProxy();
+		}
+		return process.getStreamsProxy();
+	}
+
 	public void addPropertyChangeListener(PropertyChangeListener propertyChangeListener) {
 		propertyChangeSupport.addPropertyChangeListener(propertyChangeListener);
 	}
@@ -188,7 +195,7 @@
 	private class StartupListener implements IStreamListener {
 		@Override
 		public void streamAppended(String text, IStreamMonitor monitor) {
-			process.getStreamsProxy().getOutputStreamMonitor().removeListener(this);
+			getStreamsProxy().getOutputStreamMonitor().removeListener(this);
 			setNewState(STATE_RUNNING);
 		}		
 	}

Modified: trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/process/ForgeLaunchHelper.java
===================================================================
--- trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/process/ForgeLaunchHelper.java	2012-06-04 09:43:31 UTC (rev 41668)
+++ trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/process/ForgeLaunchHelper.java	2012-06-04 10:19:36 UTC (rev 41669)
@@ -12,6 +12,7 @@
 import org.eclipse.debug.core.ILaunchConfiguration;
 import org.eclipse.debug.core.ILaunchConfigurationType;
 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.core.ILaunchListener;
 import org.eclipse.debug.core.ILaunchManager;
 import org.eclipse.debug.core.model.IProcess;
 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
@@ -32,10 +33,12 @@
 			ILaunchConfiguration[] configurations = LAUNCH_MANAGER.getLaunchConfigurations(JAVA_LAUNCH_CONFIGURATION_TYPE);
 			for (int i = 0; i < configurations.length; i++) {
 				ILaunchConfiguration configuration = configurations[i];
-				String configName = configuration.getName();
-				if (configName.startsWith(name)) {
-					configuration.delete();
-					break;
+				if (configuration != null && configuration.exists()) {
+					String configName = configuration.getName();
+					if (configName.startsWith(name)) {
+						configuration.delete();
+						break;
+					}
 				}
 			}
 		} catch (CoreException e) {
@@ -47,7 +50,6 @@
 		IProcess result = null;
 		String launchConfigurationName = name + System.currentTimeMillis();
 		ILaunch launch = doLaunch(launchConfigurationName, location);
-		removeLaunchConfiguration(launchConfigurationName);
 		if (launch != null) {
 			IProcess[] processes = launch.getProcesses();
 			if (processes.length == 1) {
@@ -62,7 +64,8 @@
 		ILaunchConfigurationWorkingCopy workingCopy = createWorkingCopy(launchConfigurationName, location);
 		if (workingCopy != null) {
 			try {
-				launch = workingCopy.doSave().launch(ILaunchManager.RUN_MODE, null, false, false);
+				LAUNCH_MANAGER.addLaunchListener(new ForgeLaunchListener(launchConfigurationName));
+				launch = workingCopy.doSave().launch(ILaunchManager.RUN_MODE, null, false, true);
 			} catch (CoreException e) {
 				ForgeCorePlugin.log(new RuntimeException("Problem while launching working copy.", e));
 			}
@@ -77,6 +80,7 @@
 		try {
 			String launchConfigurationName = name + System.currentTimeMillis();
 			result = JAVA_LAUNCH_CONFIGURATION_TYPE.newInstance(null, launchConfigurationName);
+			result.setAttribute(DebugPlugin.ATTR_PROCESS_FACTORY_ID, IForgeLaunchConfiguration.ID_FORGE_PROCESS_FACTORY);
 			result.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, "org.jboss.modules.Main");
 			result.setAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, WORKING_DIR.getAbsolutePath());
 			result.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, createVmArguments(location));
@@ -147,4 +151,27 @@
 		return "-cp " + encloseWithDoubleQuotesIfNeeded(location + File.separator + "jboss-modules.jar");
 	}
 	
+	static class ForgeLaunchListener implements ILaunchListener {
+		String launchConfigurationName;
+
+		public ForgeLaunchListener(String launchConfigruationName) {
+			this.launchConfigurationName = launchConfigruationName;
+		}
+
+		@Override
+		public void launchAdded(ILaunch launch) {
+		}
+
+		@Override
+		public void launchChanged(ILaunch launch) {
+		}
+
+		@Override
+		public void launchRemoved(ILaunch launch) {
+			if (launch.getLaunchConfiguration().getName().startsWith(launchConfigurationName)) {
+				ForgeLaunchHelper.removeLaunchConfiguration(launchConfigurationName);
+				LAUNCH_MANAGER.removeLaunchListener(this);
+			}
+		}
+	}
 }

Added: trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/process/ForgeProcessFactory.java
===================================================================
--- trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/process/ForgeProcessFactory.java	                        (rev 0)
+++ trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/process/ForgeProcessFactory.java	2012-06-04 10:19:36 UTC (rev 41669)
@@ -0,0 +1,21 @@
+package org.jboss.tools.forge.core.process;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.IProcessFactory;
+import org.eclipse.debug.core.model.IProcess;
+
+public class ForgeProcessFactory implements IProcessFactory {
+
+	@SuppressWarnings({ "rawtypes", "unchecked" })
+	@Override
+	public IProcess newProcess(ILaunch launch, Process process, String label, Map attributes) {
+		if (attributes == null) {
+			attributes = new HashMap(1);
+		}
+		attributes.put(IProcess.ATTR_PROCESS_TYPE, IForgeLaunchConfiguration.ID_FORGE_PROCESS_TYPE);
+		return new ForgeRuntimeProcess(launch, process, label, attributes);
+	}
+}


Property changes on: trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/process/ForgeProcessFactory.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Added: trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/process/ForgeRuntimeProcess.java
===================================================================
--- trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/process/ForgeRuntimeProcess.java	                        (rev 0)
+++ trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/process/ForgeRuntimeProcess.java	2012-06-04 10:19:36 UTC (rev 41669)
@@ -0,0 +1,24 @@
+package org.jboss.tools.forge.core.process;
+
+import java.util.Map;
+
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.model.IStreamsProxy;
+import org.eclipse.debug.core.model.RuntimeProcess;
+
+public class ForgeRuntimeProcess extends RuntimeProcess {
+
+	public ForgeRuntimeProcess(ILaunch launch, Process process, String name, Map<Object, Object> attributes) {
+		super(launch, process, name, attributes);
+	}
+
+	@Override
+	public IStreamsProxy getStreamsProxy() {
+		return null;
+	}
+
+	public IStreamsProxy getForgeStreamsProxy() {
+		return super.getStreamsProxy();
+	}
+	
+}


Property changes on: trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/process/ForgeRuntimeProcess.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Added: trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/process/IForgeLaunchConfiguration.java
===================================================================
--- trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/process/IForgeLaunchConfiguration.java	                        (rev 0)
+++ trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/process/IForgeLaunchConfiguration.java	2012-06-04 10:19:36 UTC (rev 41669)
@@ -0,0 +1,8 @@
+package org.jboss.tools.forge.core.process;
+
+public interface IForgeLaunchConfiguration {
+
+	public static String ID_FORGE_PROCESS_FACTORY = "org.jboss.tools.forge.core.process.ForgeProcessFactory";
+	public static String ID_FORGE_PROCESS_TYPE = "org.jboss.tools.forge.forgeProcess";
+	
+}


Property changes on: trunk/forge/plugins/org.jboss.tools.forge.core/src/org/jboss/tools/forge/core/process/IForgeLaunchConfiguration.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain



More information about the jbosstools-commits mailing list