Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'target_explorer/plugins/org.eclipse.tcf.te.ui.terminals.local/src/org/eclipse/tcf/te/ui/terminals/local/launcher/LocalLauncherDelegate.java')
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui.terminals.local/src/org/eclipse/tcf/te/ui/terminals/local/launcher/LocalLauncherDelegate.java164
1 files changed, 164 insertions, 0 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.terminals.local/src/org/eclipse/tcf/te/ui/terminals/local/launcher/LocalLauncherDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.terminals.local/src/org/eclipse/tcf/te/ui/terminals/local/launcher/LocalLauncherDelegate.java
index d3fde5c3d..0314402c3 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui.terminals.local/src/org/eclipse/tcf/te/ui/terminals/local/launcher/LocalLauncherDelegate.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.terminals.local/src/org/eclipse/tcf/te/ui/terminals/local/launcher/LocalLauncherDelegate.java
@@ -14,9 +14,13 @@ import java.net.InetAddress;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
+import org.eclipse.cdt.utils.pty.PTY;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IPath;
@@ -28,14 +32,21 @@ import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.tcf.te.core.terminals.TerminalServiceFactory;
import org.eclipse.tcf.te.core.terminals.interfaces.ITerminalService;
import org.eclipse.tcf.te.core.terminals.interfaces.ITerminalService.Done;
+import org.eclipse.tcf.te.core.terminals.interfaces.ITerminalServiceOutputStreamMonitorListener;
+import org.eclipse.tcf.te.core.terminals.interfaces.constants.ILineSeparatorConstants;
import org.eclipse.tcf.te.core.terminals.interfaces.constants.ITerminalsConnectorConstants;
import org.eclipse.tcf.te.ui.terminals.interfaces.IConfigurationPanel;
import org.eclipse.tcf.te.ui.terminals.interfaces.IConfigurationPanelContainer;
import org.eclipse.tcf.te.ui.terminals.interfaces.IMementoHandler;
+import org.eclipse.tcf.te.ui.terminals.internal.SettingsStore;
import org.eclipse.tcf.te.ui.terminals.launcher.AbstractLauncherDelegate;
import org.eclipse.tcf.te.ui.terminals.local.activator.UIPlugin;
import org.eclipse.tcf.te.ui.terminals.local.controls.LocalWizardConfigurationPanel;
import org.eclipse.tcf.te.ui.terminals.local.showin.interfaces.IPreferenceKeys;
+import org.eclipse.tcf.te.ui.terminals.process.ProcessSettings;
+import org.eclipse.tm.internal.terminal.provisional.api.ISettingsStore;
+import org.eclipse.tm.internal.terminal.provisional.api.ITerminalConnector;
+import org.eclipse.tm.internal.terminal.provisional.api.TerminalConnectorExtension;
import org.eclipse.ui.ISelectionService;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.WorkbenchEncoding;
@@ -44,6 +55,7 @@ import org.osgi.framework.Bundle;
/**
* Serial launcher delegate implementation.
*/
+@SuppressWarnings("restriction")
public class LocalLauncherDelegate extends AbstractLauncherDelegate {
private final IMementoHandler mementoHandler = new LocalMementoHandler();
@@ -207,4 +219,156 @@ public class LocalLauncherDelegate extends AbstractLauncherDelegate {
}
return super.getAdapter(adapter);
}
+
+ /**
+ * Returns the default shell to launch. Looks at the environment
+ * variable "SHELL" first before assuming some default default values.
+ *
+ * @return The default shell to launch.
+ */
+ private final File defaultShell() {
+ String shell = null;
+ if (Platform.OS_WIN32.equals(Platform.getOS())) {
+ if (System.getenv("ComSpec") != null && !"".equals(System.getenv("ComSpec").trim())) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ shell = System.getenv("ComSpec").trim(); //$NON-NLS-1$
+ } else {
+ shell = "cmd.exe"; //$NON-NLS-1$
+ }
+ }
+ if (shell == null) {
+ if (System.getenv("SHELL") != null && !"".equals(System.getenv("SHELL").trim())) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ shell = System.getenv("SHELL").trim(); //$NON-NLS-1$
+ } else {
+ shell = "/bin/sh"; //$NON-NLS-1$
+ }
+ }
+
+ return new File(shell);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.terminals.interfaces.ILauncherDelegate#createTerminalConnector(java.util.Map)
+ */
+ @Override
+ public ITerminalConnector createTerminalConnector(Map<String, Object> properties) {
+ Assert.isNotNull(properties);
+
+ // Check for the terminal connector id
+ String connectorId = (String)properties.get(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID);
+ if (connectorId == null) connectorId = "org.eclipse.tcf.te.ui.terminals.local.LocalConnector"; //$NON-NLS-1$
+
+ // Extract the process properties using defaults
+ String image;
+ if (!properties.containsKey(ITerminalsConnectorConstants.PROP_PROCESS_PATH)
+ || properties.get(ITerminalsConnectorConstants.PROP_PROCESS_PATH) == null) {
+ File defaultShell = defaultShell();
+ image = defaultShell.isAbsolute() ? defaultShell.getAbsolutePath() : defaultShell.getPath();
+ } else {
+ image = (String)properties.get(ITerminalsConnectorConstants.PROP_PROCESS_PATH);
+ }
+
+ // Determine if a PTY will be used
+ boolean isUsingPTY = (properties.get(ITerminalsConnectorConstants.PROP_PROCESS_OBJ) == null && PTY.isSupported(PTY.Mode.TERMINAL))
+ || properties.get(ITerminalsConnectorConstants.PROP_PTY_OBJ) instanceof PTY;
+
+ boolean localEcho = false;
+ if (!properties.containsKey(ITerminalsConnectorConstants.PROP_LOCAL_ECHO)
+ || !(properties.get(ITerminalsConnectorConstants.PROP_LOCAL_ECHO) instanceof Boolean)) {
+ // On Windows, turn on local echo by default if no PTY is used (bug 433645)
+ if (Platform.OS_WIN32.equals(Platform.getOS())) {
+ localEcho = !isUsingPTY;
+ }
+ } else {
+ localEcho = ((Boolean)properties.get(ITerminalsConnectorConstants.PROP_LOCAL_ECHO)).booleanValue();
+ }
+
+ String lineSeparator = null;
+ if (!properties.containsKey(ITerminalsConnectorConstants.PROP_LINE_SEPARATOR)
+ || !(properties.get(ITerminalsConnectorConstants.PROP_LINE_SEPARATOR) instanceof String)) {
+ // No line separator will be set if a PTY is used
+ if (!isUsingPTY) {
+ lineSeparator = Platform.OS_WIN32.equals(Platform.getOS()) ? ILineSeparatorConstants.LINE_SEPARATOR_CRLF : ILineSeparatorConstants.LINE_SEPARATOR_LF;
+ }
+ } else {
+ lineSeparator = (String)properties.get(ITerminalsConnectorConstants.PROP_LINE_SEPARATOR);
+ }
+
+ String arguments = (String)properties.get(ITerminalsConnectorConstants.PROP_PROCESS_ARGS);
+ Process process = (Process)properties.get(ITerminalsConnectorConstants.PROP_PROCESS_OBJ);
+ PTY pty = (PTY)properties.get(ITerminalsConnectorConstants.PROP_PTY_OBJ);
+ ITerminalServiceOutputStreamMonitorListener[] stdoutListeners = (ITerminalServiceOutputStreamMonitorListener[])properties.get(ITerminalsConnectorConstants.PROP_STDOUT_LISTENERS);
+ ITerminalServiceOutputStreamMonitorListener[] stderrListeners = (ITerminalServiceOutputStreamMonitorListener[])properties.get(ITerminalsConnectorConstants.PROP_STDERR_LISTENERS);
+ String workingDir = (String)properties.get(ITerminalsConnectorConstants.PROP_PROCESS_WORKING_DIR);
+
+ String[] envp = null;
+ if (properties.containsKey(ITerminalsConnectorConstants.PROP_PROCESS_ENVIRONMENT) &&
+ properties.get(ITerminalsConnectorConstants.PROP_PROCESS_ENVIRONMENT) != null &&
+ properties.get(ITerminalsConnectorConstants.PROP_PROCESS_ENVIRONMENT) instanceof String[]){
+ envp = (String[])properties.get(ITerminalsConnectorConstants.PROP_PROCESS_ENVIRONMENT);
+ }
+
+ // Set the ECLIPSE_HOME and ECLIPSE_WORKSPACE environment variables
+ List<String> envpList = new ArrayList<String>();
+ if (envp != null) envpList.addAll(Arrays.asList(envp));
+
+ // ECLIPSE_HOME
+ String eclipseHomeLocation = System.getProperty("eclipse.home.location"); //$NON-NLS-1$
+ if (eclipseHomeLocation != null) {
+ try {
+ URI uri = URIUtil.fromString(eclipseHomeLocation);
+ File f = URIUtil.toFile(uri);
+ envpList.add("ECLIPSE_HOME=" + f.getAbsolutePath()); //$NON-NLS-1$
+ } catch (URISyntaxException e) { /* ignored on purpose */ }
+ }
+
+ // ECLIPSE_WORKSPACE
+ Bundle bundle = Platform.getBundle("org.eclipse.core.resources"); //$NON-NLS-1$
+ if (bundle != null && (bundle.getState() == Bundle.RESOLVED || bundle.getState() == Bundle.ACTIVE)) {
+ if (org.eclipse.core.resources.ResourcesPlugin.getWorkspace() != null
+ && org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot() != null
+ && org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot().getLocation() != null) {
+ envpList.add("ECLIPSE_WORKSPACE=" + org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString()); //$NON-NLS-1$
+ }
+ }
+
+ // Convert back into a string array
+ envp = envpList.toArray(new String[envpList.size()]);
+
+ Assert.isTrue(image != null || process != null);
+
+ // Construct the terminal settings store
+ ISettingsStore store = new SettingsStore();
+
+ // Construct the process settings
+ ProcessSettings processSettings = new ProcessSettings();
+ processSettings.setImage(image);
+ processSettings.setArguments(arguments);
+ processSettings.setProcess(process);
+ processSettings.setPTY(pty);
+ processSettings.setLocalEcho(localEcho);
+ processSettings.setLineSeparator(lineSeparator);
+ processSettings.setStdOutListeners(stdoutListeners);
+ processSettings.setStdErrListeners(stderrListeners);
+ processSettings.setWorkingDir(workingDir);
+ processSettings.setEnvironment(envp);
+
+ if (properties.containsKey(ITerminalsConnectorConstants.PROP_PROCESS_MERGE_ENVIRONMENT)) {
+ Object value = properties.get(ITerminalsConnectorConstants.PROP_PROCESS_MERGE_ENVIRONMENT);
+ processSettings.setMergeWithNativeEnvironment(value instanceof Boolean ? ((Boolean)value).booleanValue() : false);
+ }
+
+ // And save the settings to the store
+ processSettings.save(store);
+
+ // Construct the terminal connector instance
+ ITerminalConnector connector = TerminalConnectorExtension.makeTerminalConnector(connectorId);
+ if (connector != null) {
+ // Apply default settings
+ connector.makeSettingsPage();
+ // And load the real settings
+ connector.load(store);
+ }
+
+ return connector;
+ }
}

Back to the top