blob: fc78d60dee1c394ccaa99e9998d3974335ee54a4 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
/*******************************************************************************
* Copyright (c) 2015 Wind River Systems, Inc. and others. All rights reserved.
* This program and the accompanying materials are made available under the terms
* of the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Wind River Systems - initial API and implementation
*******************************************************************************/
package org.eclipse.tcf.te.ui.terminals.process;
import java.util.Map;
import org.eclipse.cdt.utils.pty.PTY;
import org.eclipse.core.runtime.Assert;
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.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.internal.SettingsStore;
import org.eclipse.tcf.te.ui.terminals.launcher.AbstractLauncherDelegate;
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;
/**
* Process launcher delegate implementation.
*/
@SuppressWarnings("restriction")
public class ProcessLauncherDelegate extends AbstractLauncherDelegate {
/* (non-Javadoc)
* @see org.eclipse.tcf.te.ui.terminals.interfaces.ILauncherDelegate#needsUserConfiguration()
*/
@Override
public boolean needsUserConfiguration() {
return false;
}
/* (non-Javadoc)
* @see org.eclipse.tcf.te.ui.terminals.interfaces.ILauncherDelegate#getPanel(org.eclipse.tcf.te.ui.terminals.interfaces.IConfigurationPanelContainer)
*/
@Override
public IConfigurationPanel getPanel(IConfigurationPanelContainer container) {
return null;
}
/* (non-Javadoc)
* @see org.eclipse.tcf.te.ui.terminals.interfaces.ILauncherDelegate#execute(java.util.Map, org.eclipse.tcf.te.core.terminals.interfaces.ITerminalService.Done)
*/
@Override
public void execute(Map<String, Object> properties, Done done) {
Assert.isNotNull(properties);
// Get the terminal service
ITerminalService terminal = TerminalServiceFactory.getService();
// If not available, we cannot fulfill this request
if (terminal != null) {
terminal.openConsole(properties, done);
}
}
/* (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.ProcessConnector"; //$NON-NLS-1$
// Extract the process properties
String image = (String)properties.get(ITerminalsConnectorConstants.PROP_PROCESS_PATH);
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);
Object value = properties.get(ITerminalsConnectorConstants.PROP_LOCAL_ECHO);
boolean localEcho = value instanceof Boolean ? ((Boolean)value).booleanValue() : false;
String lineSeparator = (String)properties.get(ITerminalsConnectorConstants.PROP_LINE_SEPARATOR);
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);
}
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)) {
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;
}
}
|