Process factories

When a launch configuration launches its program, it is responsible for invoking the executable program in the requested mode. The implementation for a launch will depend on the specifics of each launch configuration, but most plug-ins will build a command line and call a runtime exec to start the program. The DebugPlugin class implements a convenience method for invoking a runtime exec and handling the possible exceptions. Clients can specify the command line and working directory for the exec.

Process p = DebugPlugin.exec(cmdLine, workingDirectory);

Once the java.lang.Process for the executing program has been created, it needs to be managed by the debug plug-in. For starters, the process needs to be associated with the ILaunch that represents the launched program. The debug plug-in defines a wrapper for a system process, IProcess, that allows clients to access the associated ILaunch and assign their own named attributes to the process. In addition, IProcess, defines a label for the process and associates an IStreamsProxy with the process that gives clients access to the input, output, and error streams of the system process. This process wrapper can also be created using a utility method in DebugPlugin.

IProcess process= DebugPlugin.newProcess(launch, p, "My Process);

A map of named attributes can also be supplied.

Many plug-ins can simply rely on the utility methods in DebugPlugin for launching the system process and wrapping it in an IProcess. For those plug-ins that need more control in the creation of the wrapper, a process factory can be associated with a launch configuration. The process factory is used to create an IProcess that meets the special needs of the plug-in. The process factory is referenced by id, and should be stored in the DebugPlugin.ATTR_PROCESS_FACTORY_ID attribute of the launch configuration.

The association between the process factory id and the class that implements it is made using the org.eclipse.debug.core.processFactories extension point.

The following example shows how the Ant plug-in sets up a process factory for its launches:

<extension point="org.eclipse.debug.core.processFactories">
	<processFactory
		class="org.eclipse.ant.internal.ui.launchConfigurations.RemoteAntProcessFactory"
		id="org.eclipse.ant.ui.remoteAntProcessFactory">
	</processFactory>
</extension>

It is the responsibility of the registering plug-in to store the process factory id in the proper launch configuration attribute.