Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'target_explorer/plugins/org.eclipse.tm.te.ui.terminals.process/src/org/eclipse/tm/te')
-rw-r--r--target_explorer/plugins/org.eclipse.tm.te.ui.terminals.process/src/org/eclipse/tm/te/ui/terminals/process/ProcessConnector.java425
-rw-r--r--target_explorer/plugins/org.eclipse.tm.te.ui.terminals.process/src/org/eclipse/tm/te/ui/terminals/process/ProcessMonitor.java106
-rw-r--r--target_explorer/plugins/org.eclipse.tm.te.ui.terminals.process/src/org/eclipse/tm/te/ui/terminals/process/ProcessSettings.java162
-rw-r--r--target_explorer/plugins/org.eclipse.tm.te.ui.terminals.process/src/org/eclipse/tm/te/ui/terminals/process/ProcessSettingsPage.java187
-rw-r--r--target_explorer/plugins/org.eclipse.tm.te.ui.terminals.process/src/org/eclipse/tm/te/ui/terminals/process/activator/UIPlugin.java104
-rw-r--r--target_explorer/plugins/org.eclipse.tm.te.ui.terminals.process/src/org/eclipse/tm/te/ui/terminals/process/manager/ConnectorManager.java92
-rw-r--r--target_explorer/plugins/org.eclipse.tm.te.ui.terminals.process/src/org/eclipse/tm/te/ui/terminals/process/nls/Messages.java33
-rw-r--r--target_explorer/plugins/org.eclipse.tm.te.ui.terminals.process/src/org/eclipse/tm/te/ui/terminals/process/nls/Messages.properties6
8 files changed, 1115 insertions, 0 deletions
diff --git a/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.process/src/org/eclipse/tm/te/ui/terminals/process/ProcessConnector.java b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.process/src/org/eclipse/tm/te/ui/terminals/process/ProcessConnector.java
new file mode 100644
index 000000000..da3ec649a
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.process/src/org/eclipse/tm/te/ui/terminals/process/ProcessConnector.java
@@ -0,0 +1,425 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.tm.te.ui.terminals.process;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.StreamTokenizer;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.eclipse.cdt.utils.pty.PTY;
+import org.eclipse.cdt.utils.spawner.ProcessFactory;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.osgi.service.environment.Constants;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.tm.internal.terminal.provisional.api.ISettingsPage;
+import org.eclipse.tm.internal.terminal.provisional.api.ISettingsStore;
+import org.eclipse.tm.internal.terminal.provisional.api.ITerminalControl;
+import org.eclipse.tm.internal.terminal.provisional.api.TerminalState;
+import org.eclipse.tm.te.ui.terminals.process.activator.UIPlugin;
+import org.eclipse.tm.te.ui.terminals.process.nls.Messages;
+import org.eclipse.tm.te.ui.terminals.streams.AbstractStreamsConnector;
+
+/**
+ * Process connector implementation.
+ */
+@SuppressWarnings("restriction")
+public class ProcessConnector extends AbstractStreamsConnector {
+ // Reference to the process settings
+ private final ProcessSettings settings;
+
+ // Reference to the PTY instance.
+ private PTY pty;
+ // Reference to the launched process instance.
+ private Process process;
+ // Reference to the process monitor
+ private ProcessMonitor monitor;
+
+ // The terminal width and height. Initially unknown.
+ private int width = -1;
+ private int height = -1;
+
+ /**
+ * Constructor.
+ */
+ public ProcessConnector() {
+ this(new ProcessSettings());
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param settings The process settings. Must not be <code>null</code>
+ */
+ public ProcessConnector(ProcessSettings settings) {
+ super();
+
+ Assert.isNotNull(settings);
+ this.settings = settings;
+ }
+
+ /**
+ * Returns the process object or <code>null</code> if the
+ * connector is connector.
+ *
+ * @return The process object or <code>null</code>.
+ */
+ public Process getProcess() {
+ return process;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tm.internal.terminal.provisional.api.provider.TerminalConnectorImpl#connect(org.eclipse.tm.internal.terminal.provisional.api.ITerminalControl)
+ */
+ @Override
+ public void connect(ITerminalControl control) {
+ Assert.isNotNull(control);
+ super.connect(control);
+
+ pty = null;
+ width = -1;
+ height = -1;
+
+ try {
+ // Try to determine process and PTY instance from the process settings
+ process = settings.getProcess();
+ pty = settings.getPTY();
+
+ // No process -> create PTY on supported platforms and execute
+ // process image.
+ if (process == null) {
+ if (PTY.isSupported()) {
+ try {
+ pty = new PTY(false);
+ } catch (IOException e) {
+ // PTY not supported on windows
+ }
+ }
+
+ // Build up the command
+ StringBuilder command = new StringBuilder(settings.getImage());
+ String arguments = settings.getArguments();
+ if (arguments != null && !"".equals(arguments.trim())) { //$NON-NLS-1$
+ // Append to the command now
+ command.append(" "); //$NON-NLS-1$
+ command.append(arguments.trim());
+ }
+
+ if (pty != null) {
+ // A PTY is available -> can use the ProcessFactory.
+
+ // Tokenize the command (ProcessFactory takes an array)
+ StreamTokenizer st = new StreamTokenizer(new StringReader(command.toString()));
+ st.resetSyntax();
+ st.whitespaceChars(0, 32);
+ st.whitespaceChars(0xa0, 0xa0);
+ st.wordChars(33, 255);
+ st.quoteChar('"');
+ st.quoteChar('\'');
+
+ List<String> argv = new ArrayList<String>();
+ int ttype = st.nextToken();
+ while (ttype != StreamTokenizer.TT_EOF) {
+ argv.add(st.sval);
+ ttype = st.nextToken();
+ }
+
+ // Execute the process
+ process = ProcessFactory.getFactory().exec(argv.toArray(new String[argv.size()]), getProcessEnvironment(), null, pty);
+ } else {
+ // No PTY -> just execute via the standard Java Runtime implementation.
+ process = Runtime.getRuntime().exec(command.toString());
+ }
+ }
+
+ // connect the streams
+ connectStreams(control, process.getOutputStream(), process.getInputStream(), (pty == null ? process.getErrorStream() : null));
+
+ // Set the terminal control state to CONNECTED
+ control.setState(TerminalState.CONNECTED);
+
+ // Create the process monitor
+ monitor = new ProcessMonitor(this);
+ monitor.startMonitoring();
+ } catch (Exception e) {
+ IStatus status = new Status(IStatus.ERROR, UIPlugin.getUniqueIdentifier(),
+ NLS.bind(Messages.ProcessConnector_error_creatingProcess, e.getLocalizedMessage()), e);
+ UIPlugin.getDefault().getLog().log(status);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tm.internal.terminal.provisional.api.provider.TerminalConnectorImpl#isLocalEcho()
+ */
+ @Override
+ public boolean isLocalEcho() {
+ return settings.isLocalEcho();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tm.internal.terminal.provisional.api.provider.TerminalConnectorImpl#doDisconnect()
+ */
+ @Override
+ public void doDisconnect() {
+ // Dispose the process
+ if (process != null) { process.destroy(); process = null; }
+
+ // Dispose the streams
+ super.doDisconnect();
+
+ // Set the terminal control state to CLOSED.
+ fControl.setState(TerminalState.CLOSED);
+ }
+
+ // ***** Process Connector settings handling *****
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tm.internal.terminal.provisional.api.provider.TerminalConnectorImpl#makeSettingsPage()
+ */
+ @Override
+ public ISettingsPage makeSettingsPage() {
+ return new ProcessSettingsPage(settings);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tm.internal.terminal.provisional.api.provider.TerminalConnectorImpl#getSettingsSummary()
+ */
+ @Override
+ public String getSettingsSummary() {
+ return settings.getImage() != null ? settings.getImage() : ""; //$NON-NLS-1$
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tm.internal.terminal.provisional.api.provider.TerminalConnectorImpl#load(org.eclipse.tm.internal.terminal.provisional.api.ISettingsStore)
+ */
+ @Override
+ public void load(ISettingsStore store) {
+ settings.load(store);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tm.internal.terminal.provisional.api.provider.TerminalConnectorImpl#save(org.eclipse.tm.internal.terminal.provisional.api.ISettingsStore)
+ */
+ @Override
+ public void save(ISettingsStore store) {
+ settings.save(store);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tm.internal.terminal.provisional.api.provider.TerminalConnectorImpl#setTerminalSize(int, int)
+ */
+ @Override
+ public void setTerminalSize(int newWidth, int newHeight) {
+ if (width != newWidth || height != newHeight) {
+ width = newWidth;
+ height = newHeight;
+ if (pty != null) {
+ pty.setTerminalSize(newWidth, newHeight);
+ }
+ }
+ }
+
+ // ***** Process Environment Handling *****
+
+ // Reference to the monitor to lock if determining the native environment
+ private final static Object ENV_GET_MONITOR = new Object();
+
+ // Reference to the native environment once retrieved
+ private static Map<String, String> nativeEnvironment = null;
+ // Reference to the native environment with the case of the variable names preserved
+ private static Map<String, String> nativeEnvironmentCasePreserved = null;
+
+ /**
+ * Returns the specific environment to set for the process to be launched.
+ *
+ * @return The process environment.
+ */
+ private static String[] getProcessEnvironment() {
+ Map<String, String> env = getNativeEnvironment();
+
+ env.put("TERM", "ansi"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ Iterator<Map.Entry<String, String>> iter = env.entrySet().iterator();
+ List<String> strings = new ArrayList<String>(env.size());
+ StringBuffer buffer = null;
+ while (iter.hasNext()) {
+ Map.Entry<String, String>entry = iter.next();
+ buffer = new StringBuffer(entry.getKey());
+ buffer.append('=').append(entry.getValue());
+ strings.add(buffer.toString());
+ }
+
+ return strings.toArray(new String[strings.size()]);
+ }
+
+ /**
+ * Determine the native environment, but returns all environment variable
+ * names in upper case.
+ *
+ * @return The native environment with upper case variable names, or an empty map.
+ */
+ private static Map<String, String> getNativeEnvironment() {
+ synchronized (ENV_GET_MONITOR) {
+ if (nativeEnvironment == null) {
+ Map<String, String> casePreserved = getNativeEnvironmentCasePreserved();
+ if (Platform.getOS().equals(org.eclipse.osgi.service.environment.Constants.OS_WIN32)) {
+ nativeEnvironment = new HashMap<String, String>();
+ Iterator<Map.Entry<String, String>> entries = casePreserved.entrySet().iterator();
+ while (entries.hasNext()) {
+ Map.Entry<String, String> entry = entries.next();
+ nativeEnvironment.put(entry.getKey().toUpperCase(), entry.getValue());
+ }
+ } else {
+ nativeEnvironment = new HashMap<String, String>(casePreserved);
+ }
+ }
+ return new HashMap<String, String>(nativeEnvironment);
+ }
+ }
+
+ /**
+ * Determine the native environment.
+ *
+ * @return The native environment, or an empty map.
+ */
+ private static Map<String, String> getNativeEnvironmentCasePreserved() {
+ synchronized (ENV_GET_MONITOR) {
+ if (nativeEnvironmentCasePreserved == null) {
+ nativeEnvironmentCasePreserved= new HashMap<String, String>();
+ cacheNativeEnvironment(nativeEnvironmentCasePreserved);
+ }
+ return new HashMap<String, String>(nativeEnvironmentCasePreserved);
+ }
+ }
+
+ /**
+ * Query the native environment and store it to the specified cache.
+ *
+ * @param cache The environment cache. Must not be <code>null</code>.
+ */
+ private static void cacheNativeEnvironment(Map<String, String> cache) {
+ Assert.isNotNull(cache);
+
+ try {
+ String nativeCommand = null;
+ boolean isWin9xME = false; // see bug 50567
+ String fileName = null;
+ if (Platform.getOS().equals(Constants.OS_WIN32)) {
+ String osName = System.getProperty("os.name"); //$NON-NLS-1$
+ isWin9xME = osName != null && (osName.startsWith("Windows 9") || osName.startsWith("Windows ME")); //$NON-NLS-1$ //$NON-NLS-2$
+ if (isWin9xME) {
+ // Win 95, 98, and ME
+ // SET might not return therefore we pipe into a file
+ IPath stateLocation = UIPlugin.getDefault().getStateLocation();
+ fileName = stateLocation.toOSString() + File.separator + "env.txt"; //$NON-NLS-1$
+ nativeCommand = "command.com /C set > " + fileName; //$NON-NLS-1$
+ } else {
+ // Win NT, 2K, XP
+ nativeCommand = "cmd.exe /C set"; //$NON-NLS-1$
+ }
+ } else if (!Platform.getOS().equals(Constants.OS_UNKNOWN)) {
+ nativeCommand = "env"; //$NON-NLS-1$
+ }
+ if (nativeCommand == null) { return; }
+ Process process = Runtime.getRuntime().exec(nativeCommand);
+ if (isWin9xME) {
+ // read piped data on Win 95, 98, and ME
+ Properties p = new Properties();
+ File file = new File(fileName);
+ InputStream stream = new BufferedInputStream(new FileInputStream(file));
+ p.load(stream);
+ stream.close();
+ if (!file.delete()) {
+ file.deleteOnExit(); // if delete() fails try again on VM close
+ }
+ for (Enumeration<Object> enumeration = p.keys(); enumeration.hasMoreElements();) {
+ // Win32's environment variables are case insensitive. Put everything
+ // to upper case so that (for example) the "PATH" variable will match
+ // "pAtH" correctly on Windows.
+ String key = (String)enumeration.nextElement();
+ cache.put(key, (String)p.get(key));
+ }
+ } else {
+ // read process directly on other platforms
+ // we need to parse out matching '{' and '}' for function declarations in .bash environments
+ // pattern is [function name]=() { and we must find the '}' on its own line with no trailing ';'
+ InputStream stream = process.getInputStream();
+ InputStreamReader isreader = new InputStreamReader(stream);
+ BufferedReader reader = new BufferedReader(isreader);
+ String line = reader.readLine();
+ String key = null;
+ String value = null;
+ while (line != null) {
+ int func = line.indexOf("=()"); //$NON-NLS-1$
+ if (func > 0) {
+ key = line.substring(0, func);
+ // scan until we find the closing '}' with no following chars
+ value = line.substring(func + 1);
+ while (line != null && !line.equals("}")) { //$NON-NLS-1$
+ line = reader.readLine();
+ if (line != null) {
+ value += line;
+ }
+ }
+ line = reader.readLine();
+ } else {
+ int separator = line.indexOf('=');
+ if (separator > 0) {
+ key = line.substring(0, separator);
+ value = line.substring(separator + 1);
+ line = reader.readLine();
+ if (line != null) {
+ // this line has a '=' read ahead to check next line for '=', might be broken on more
+ // than one line
+ separator = line.indexOf('=');
+ while (separator < 0) {
+ value += line.trim();
+ line = reader.readLine();
+ if (line == null) {
+ // if next line read is the end of the file quit the loop
+ break;
+ }
+ separator = line.indexOf('=');
+ }
+ }
+ }
+ }
+ if (key != null) {
+ cache.put(key, value);
+ key = null;
+ value = null;
+ } else {
+ line = reader.readLine();
+ }
+ }
+ reader.close();
+ }
+ } catch (IOException e) {
+ // Native environment-fetching code failed.
+ // This can easily happen and is not useful to log.
+ }
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.process/src/org/eclipse/tm/te/ui/terminals/process/ProcessMonitor.java b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.process/src/org/eclipse/tm/te/ui/terminals/process/ProcessMonitor.java
new file mode 100644
index 000000000..98c9d6073
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.process/src/org/eclipse/tm/te/ui/terminals/process/ProcessMonitor.java
@@ -0,0 +1,106 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.tm.te.ui.terminals.process;
+
+import org.eclipse.core.runtime.Assert;
+
+
+/**
+ * Process monitor implementation.
+ */
+public class ProcessMonitor {
+ // Reference to the parent process connector
+ private final ProcessConnector processConnector;
+ // Reference to the monitored process
+ private final Process process;
+ // Reference to the monitor thread
+ private Thread thread;
+ // Flag to mark the monitor disposed
+ private boolean disposed;
+
+
+ /**
+ * Constructor.
+ *
+ * @param processConnector The parent process connector. Must not be <code>null</code>.
+ */
+ public ProcessMonitor(ProcessConnector processConnector) {
+ super();
+
+ Assert.isNotNull(processConnector);
+ this.processConnector = processConnector;
+
+ // Query the monitored process for easier access
+ this.process = processConnector.getProcess();
+ }
+
+ /**
+ * Dispose the process monitor.
+ */
+ public void dispose() {
+ // Set the disposed status
+ disposed = true;
+ // Not initialized -> return immediately
+ if (thread == null) return;
+
+ // Copy the reference
+ final Thread oldThread = thread;
+ // Unlink the monitor from the thread
+ thread = null;
+ // And interrupt the writer thread
+ oldThread.interrupt();
+ }
+
+ /**
+ * Starts the terminal output stream monitor.
+ */
+ public void startMonitoring() {
+ // If already initialized -> return immediately
+ if (thread != null) return;
+
+ // Create a new runnable which is constantly reading from the stream
+ Runnable runnable = new Runnable() {
+ @Override
+ public void run() {
+ monitorProcess();
+ }
+ };
+
+ // Create the monitor thread
+ thread = new Thread(runnable, "Terminal Process Monitor Thread"); //$NON-NLS-1$
+
+ // Configure the monitor thread
+ thread.setDaemon(true);
+
+ // Start the processing
+ thread.start();
+ }
+
+ /**
+ * Monitors the associated system process, waiting for it to terminate,
+ * and notifies the associated process monitor's.
+ */
+ @SuppressWarnings("restriction")
+ public void monitorProcess() {
+ // If already disposed -> return immediately
+ if (disposed) return;
+
+ try {
+ // Wait for the monitored process to terminate
+ process.waitFor();
+ } catch (InterruptedException ie) {
+ // clear interrupted state
+ Thread.interrupted();
+ } finally {
+ // Dispose the parent process connector
+ processConnector.disconnect();
+ }
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.process/src/org/eclipse/tm/te/ui/terminals/process/ProcessSettings.java b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.process/src/org/eclipse/tm/te/ui/terminals/process/ProcessSettings.java
new file mode 100644
index 000000000..5976fdfed
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.process/src/org/eclipse/tm/te/ui/terminals/process/ProcessSettings.java
@@ -0,0 +1,162 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.tm.te.ui.terminals.process;
+
+import org.eclipse.cdt.utils.pty.PTY;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.tm.internal.terminal.provisional.api.ISettingsStore;
+import org.eclipse.tm.te.runtime.interfaces.properties.IPropertiesContainer;
+
+/**
+ * Process connector settings implementation.
+ */
+@SuppressWarnings("restriction")
+public class ProcessSettings {
+ // Reference to the process image
+ private String image;
+ // Reference to the process arguments (space separated string)
+ private String arguments;
+ // Reference to the process object
+ private Process process;
+ // Reference to the pseudo terminal object
+ private PTY pty;
+ // Flag to control the local echo (defaults to true if
+ // the PTY is not supported on the current host platform)
+ private boolean localEcho = !PTY.isSupported();
+
+ /**
+ * Sets the process image.
+ *
+ * @param image The process image or <code>null</code>.
+ */
+ public void setImage(String image) {
+ this.image = image;
+ }
+
+ /**
+ * Returns the process image.
+ *
+ * @return The process image or <code>null</code>.
+ */
+ public String getImage() {
+ return image;
+ }
+
+ /**
+ * Sets the process arguments.
+ * <p>
+ * The arguments are space separated. The caller is responsible for
+ * correct quoting.
+ *
+ * @param arguments The process arguments or <code>null</code>.
+ */
+ public void setArguments(String arguments) {
+ this.arguments = arguments;
+ }
+
+ /**
+ * Returns the process arguments.
+ *
+ * @return The process arguments as space separated list or <code>null</code>.
+ */
+ public String getArguments() {
+ return arguments;
+ }
+
+ /**
+ * Sets the process object.
+ *
+ * @param image The process object or <code>null</code>.
+ */
+ public void setProcess(Process process) {
+ this.process = process;
+ }
+
+ /**
+ * Returns the process object.
+ *
+ * @return The process object or <code>null</code>.
+ */
+ public Process getProcess() {
+ return process;
+ }
+
+ /**
+ * Sets the pseudo terminal object.
+ *
+ * @param pty The pseudo terminal or <code>null</code>.
+ */
+ public void setPTY(PTY pty) {
+ this.pty = pty;
+ // If the PTY is set to "null", the local echo will be set to "true"
+ if (pty == null) setLocalEcho(true);
+ }
+
+ /**
+ * Returns the pseudo terminal object.
+ *
+ * @return The pseudo terminal or <code>null</code>.
+ */
+ public PTY getPTY() {
+ return pty;
+ }
+
+ /**
+ * Sets if the process requires a local echo from the
+ * terminal widget.
+ *
+ * @param value Specify <code>true</code> to enable the local echo, <code>false</code> otherwise.
+ */
+ public void setLocalEcho(boolean value) {
+ this.localEcho = value;
+ }
+
+ /**
+ * Returns <code>true</code> if the process requires a local echo
+ * from the terminal widget.
+ *
+ * @return <code>True</code> if local echo is enabled, <code>false</code> otherwise.
+ */
+ public boolean isLocalEcho() {
+ return localEcho;
+ }
+
+ /**
+ * Loads the process settings from the given settings store.
+ *
+ * @param store The settings store. Must not be <code>null</code>.
+ */
+ public void load(ISettingsStore store) {
+ Assert.isNotNull(store);
+ image = store.get("Path", null);//$NON-NLS-1$
+ arguments = store.get("Arguments", null); //$NON-NLS-1$
+ localEcho = Boolean.parseBoolean(store.get("LocalEcho", Boolean.FALSE.toString())); //$NON-NLS-1$
+ if (store instanceof IPropertiesContainer) {
+ process = (Process)((IPropertiesContainer)store).getProperty("Process"); //$NON-NLS-1$
+ pty = (PTY)((IPropertiesContainer)store).getProperty("PTY"); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Saves the process settings to the given settings store.
+ *
+ * @param store The settings store. Must not be <code>null</code>.
+ */
+ public void save(ISettingsStore store) {
+ Assert.isNotNull(store);
+ store.put("Path", image);//$NON-NLS-1$
+ store.put("Arguments", arguments); //$NON-NLS-1$
+ store.put("LocalEcho", Boolean.toString(localEcho)); //$NON-NLS-1$
+ if (store instanceof IPropertiesContainer) {
+ ((IPropertiesContainer)store).setProperty("Process", process); //$NON-NLS-1$
+ ((IPropertiesContainer)store).setProperty("PTY", pty); //$NON-NLS-1$
+ }
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.process/src/org/eclipse/tm/te/ui/terminals/process/ProcessSettingsPage.java b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.process/src/org/eclipse/tm/te/ui/terminals/process/ProcessSettingsPage.java
new file mode 100644
index 000000000..af7a4e60b
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.process/src/org/eclipse/tm/te/ui/terminals/process/ProcessSettingsPage.java
@@ -0,0 +1,187 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.tm.te.ui.terminals.process;
+
+import org.eclipse.cdt.utils.pty.PTY;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.tm.internal.terminal.provisional.api.ISettingsPage;
+import org.eclipse.tm.te.ui.swt.SWTControlUtil;
+import org.eclipse.tm.te.ui.terminals.nls.Messages;
+import org.eclipse.ui.PlatformUI;
+import org.osgi.framework.Bundle;
+
+/**
+ * Process connector settings page implementation.
+ */
+@SuppressWarnings("restriction")
+public class ProcessSettingsPage implements ISettingsPage {
+ private Text processImageSelectorControl;
+ private Button processImageSelectorControlButton;
+ private Text processArgumentsControl;
+ private Button localEchoSelectorControl;
+
+ private final ProcessSettings settings;
+
+ /**
+ * Constructor.
+ *
+ * @param settings
+ */
+ public ProcessSettingsPage(ProcessSettings settings) {
+ super();
+
+ Assert.isNotNull(settings);
+ this.settings = settings;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tm.internal.terminal.provisional.api.ISettingsPage#createControl(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ public void createControl(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ composite.setLayout(new GridLayout());
+ composite.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+ // The entry fields shall be properly aligned
+ Composite panel = new Composite(composite, SWT.NONE);
+ GridLayout layout = new GridLayout(2, false);
+ layout.marginWidth = 0; layout.marginHeight = 0;
+ panel.setLayout(layout);
+ panel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ // Create the process image selector control
+ Label label = new Label(panel, SWT.HORIZONTAL);
+ label.setText(Messages.ProcessSettingsPage_processImagePathSelectorControl_label);
+
+ // Text field and browse button are aligned it their own panel
+ Composite innerPanel = new Composite(panel, SWT.NONE);
+ layout = new GridLayout(2, false);
+ layout.marginWidth = 0; layout.marginHeight = 0;
+ innerPanel.setLayout(layout);
+ innerPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ processImageSelectorControl = new Text(innerPanel, SWT.SINGLE | SWT.BORDER);
+ processImageSelectorControl.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ processImageSelectorControlButton = new Button(innerPanel, SWT.PUSH);
+ processImageSelectorControlButton.setText(Messages.ProcessSettingsPage_processImagePathSelectorControl_button);
+ processImageSelectorControlButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ onBrowseButtonSelected(e);
+ }
+ });
+
+ // Create the process arguments control
+ label = new Label(panel, SWT.HORIZONTAL);
+ label.setText(Messages.ProcessSettingsPage_processArgumentsControl_label);
+
+ processArgumentsControl = new Text(panel, SWT.SINGLE | SWT.BORDER);
+ processArgumentsControl.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ // Create the local echo check box
+ localEchoSelectorControl = new Button(composite, SWT.CHECK);
+ localEchoSelectorControl.setText(Messages.ProcessSettingsPage_localEchoSelectorControl_label);
+ localEchoSelectorControl.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ localEchoSelectorControl.setSelection(!PTY.isSupported());
+
+ // Initialize the control content
+ loadSettings();
+ }
+
+ /**
+ * Called once the user pressed the browse button.
+ *
+ * @param e The selection event or <code>null</code>.
+ */
+ protected void onBrowseButtonSelected(SelectionEvent e) {
+ // Determine the shell
+ Shell shell = e != null ? e.widget.getDisplay().getActiveShell() : PlatformUI.getWorkbench().getDisplay().getActiveShell();
+
+ // create a standard file dialog
+ FileDialog dialog = new FileDialog(shell, SWT.OPEN);
+ dialog.setText(Messages.ProcessSettingsPage_dialogTitle);
+
+ // the dialog should open within the directory of the currently selected
+ // file. If no file has been currently selected, it should open within the
+ // last browsed directory.
+ String selectedFile = SWTControlUtil.getText(processImageSelectorControl);
+ if (selectedFile != null && selectedFile.trim().length() > 0) {
+ IPath filePath = new Path(selectedFile);
+ // If the selected file points to an directory, use the directory as is
+ IPath filterPath = filePath.toFile().isDirectory() ? filePath : filePath.removeLastSegments(1);
+ String filterFileName = filePath.toFile().isDirectory() || !filePath.toFile().exists() ? null : filePath.lastSegment();
+
+ if (!filterPath.isEmpty()) {
+ dialog.setFilterPath(filterPath.toString());
+ }
+ if (filterFileName != null) {
+ dialog.setFileName(filterFileName);
+ }
+ } else {
+ Bundle bundle = Platform.getBundle("org.eclipse.core.resources"); //$NON-NLS-1$
+ if (bundle != null && (bundle.getState() == Bundle.RESOLVED || bundle.getState() == Bundle.ACTIVE)) {
+ dialog.setFilterPath(org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString());
+ }
+ }
+
+ // Open the dialog
+ selectedFile = dialog.open();
+ if (selectedFile != null) {
+ SWTControlUtil.setText(processImageSelectorControl, selectedFile);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tm.internal.terminal.provisional.api.ISettingsPage#saveSettings()
+ */
+ @Override
+ public void saveSettings() {
+ settings.setImage(SWTControlUtil.getText(processImageSelectorControl));
+ settings.setArguments(SWTControlUtil.getText(processArgumentsControl));
+ settings.setLocalEcho(SWTControlUtil.getSelection(localEchoSelectorControl));
+ settings.setProcess(null);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tm.internal.terminal.provisional.api.ISettingsPage#loadSettings()
+ */
+ @Override
+ public void loadSettings() {
+ SWTControlUtil.setText(processImageSelectorControl, settings.getImage());
+ SWTControlUtil.setText(processArgumentsControl, settings.getArguments());
+ SWTControlUtil.setSelection(localEchoSelectorControl, settings.isLocalEcho());
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tm.internal.terminal.provisional.api.ISettingsPage#validateSettings()
+ */
+ @Override
+ public boolean validateSettings() {
+ // The settings are considered valid if the selected process image can be read.
+ String selectedFile = SWTControlUtil.getText(processImageSelectorControl);
+ return selectedFile != null && !"".equals(selectedFile.trim()) && new Path(selectedFile).toFile().canRead(); //$NON-NLS-1$
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.process/src/org/eclipse/tm/te/ui/terminals/process/activator/UIPlugin.java b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.process/src/org/eclipse/tm/te/ui/terminals/process/activator/UIPlugin.java
new file mode 100644
index 000000000..70b538282
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.process/src/org/eclipse/tm/te/ui/terminals/process/activator/UIPlugin.java
@@ -0,0 +1,104 @@
+package org.eclipse.tm.te.ui.terminals.process.activator;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.resource.ImageRegistry;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.tm.te.runtime.tracing.TraceHandler;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class UIPlugin extends AbstractUIPlugin {
+ // The shared instance
+ private static UIPlugin plugin;
+
+ // The trace handler instance
+ private static TraceHandler traceHandler;
+
+ /**
+ * The constructor
+ */
+ public UIPlugin() {
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static UIPlugin getDefault() {
+ return plugin;
+ }
+
+ /**
+ * Convenience method which returns the unique identifier of this plugin.
+ */
+ public static String getUniqueIdentifier() {
+ if (getDefault() != null && getDefault().getBundle() != null) {
+ return getDefault().getBundle().getSymbolicName();
+ }
+ return null;
+ }
+
+ /**
+ * Returns the bundles trace handler.
+ *
+ * @return The bundles trace handler.
+ */
+ public static TraceHandler getTraceHandler() {
+ if (traceHandler == null) {
+ traceHandler = new TraceHandler(getUniqueIdentifier());
+ }
+ return traceHandler;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ @Override
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#initializeImageRegistry(org.eclipse.jface.resource.ImageRegistry)
+ */
+ @Override
+ protected void initializeImageRegistry(ImageRegistry registry) {
+ super.initializeImageRegistry(registry);
+ }
+
+ /**
+ * Loads the image registered under the specified key from the image
+ * registry and returns the <code>Image</code> object instance.
+ *
+ * @param key The key the image is registered with.
+ * @return The <code>Image</code> object instance or <code>null</code>.
+ */
+ public static Image getImage(String key) {
+ return getDefault().getImageRegistry().get(key);
+ }
+
+ /**
+ * Loads the image registered under the specified key from the image
+ * registry and returns the <code>ImageDescriptor</code> object instance.
+ *
+ * @param key The key the image is registered with.
+ * @return The <code>ImageDescriptor</code> object instance or <code>null</code>.
+ */
+ public static ImageDescriptor getImageDescriptor(String key) {
+ return getDefault().getImageRegistry().getDescriptor(key);
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.process/src/org/eclipse/tm/te/ui/terminals/process/manager/ConnectorManager.java b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.process/src/org/eclipse/tm/te/ui/terminals/process/manager/ConnectorManager.java
new file mode 100644
index 000000000..567908f5b
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.process/src/org/eclipse/tm/te/ui/terminals/process/manager/ConnectorManager.java
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.tm.te.ui.terminals.process.manager;
+
+import org.eclipse.cdt.utils.pty.PTY;
+import org.eclipse.core.runtime.Assert;
+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.tm.te.ui.terminals.internal.SettingsStore;
+import org.eclipse.tm.te.ui.terminals.process.ProcessSettings;
+
+
+/**
+ * Process terminal connector manager implementation.
+ */
+@SuppressWarnings("restriction")
+public class ConnectorManager {
+
+ /*
+ * Thread save singleton instance creation.
+ */
+ private static class LazyInstanceHolder {
+ public static ConnectorManager instance = new ConnectorManager();
+ }
+
+ /**
+ * Returns the singleton instance.
+ */
+ public static ConnectorManager getInstance() {
+ return LazyInstanceHolder.instance;
+ }
+
+ /**
+ * Constructor.
+ */
+ ConnectorManager() {
+ super();
+ }
+
+ /**
+ * Creates a terminal connector object based on the given process image
+ * and the corresponding process object.
+ *
+ * @param connectorTypeId Optional ID of the specific process connector implementation to use.
+ * If <code>null</code>, the default process connector will be used.
+ * @param image The process image path. Must not be <code>null</code>.
+ * @param arguments The process arguments or <code>null</code>.
+ * @param process The process. Must not be <code>null</code>.
+ * @param pty The pseudo terminal or <code>null</code>.
+ * @param localEcho <code>True</code> if the terminal widget local echo shall be enabled, <code>false</code> otherwise.
+ *
+ * @return The terminal connector object instance or <code>null</code>.
+ */
+ public ITerminalConnector createProcessConnector(String connectorTypeId, final String image, final String arguments, final Process process, PTY pty, boolean localEcho) {
+ Assert.isTrue(image != null || process != null);
+
+ // Normalize the process connector id
+ if (connectorTypeId == null) connectorTypeId = "org.eclipse.tm.te.ui.terminals.ProcessConnector"; //$NON-NLS-1$
+
+ // 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);
+ // And save the settings to the store
+ processSettings.save(store);
+
+ // Construct the terminal connector instance
+ ITerminalConnector connector = TerminalConnectorExtension.makeTerminalConnector(connectorTypeId);
+ if (connector != null) {
+ // Apply default settings
+ connector.makeSettingsPage();
+ // And load the real settings
+ connector.load(store);
+ }
+
+ return connector;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.process/src/org/eclipse/tm/te/ui/terminals/process/nls/Messages.java b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.process/src/org/eclipse/tm/te/ui/terminals/process/nls/Messages.java
new file mode 100644
index 000000000..c7e9346f3
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.process/src/org/eclipse/tm/te/ui/terminals/process/nls/Messages.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.tm.te.ui.terminals.process.nls;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * Process terminal connector plug-in externalized strings management.
+ */
+public class Messages extends NLS {
+
+ // The plug-in resource bundle name
+ private static final String BUNDLE_NAME = "org.eclipse.tm.te.ui.terminals.process.nls.Messages"; //$NON-NLS-1$
+
+ /**
+ * Static constructor.
+ */
+ static {
+ // Load message values from bundle file
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ // **** Declare externalized string id's down here *****
+
+ public static String ProcessConnector_error_creatingProcess;
+}
diff --git a/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.process/src/org/eclipse/tm/te/ui/terminals/process/nls/Messages.properties b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.process/src/org/eclipse/tm/te/ui/terminals/process/nls/Messages.properties
new file mode 100644
index 000000000..c85fe60a6
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals.process/src/org/eclipse/tm/te/ui/terminals/process/nls/Messages.properties
@@ -0,0 +1,6 @@
+#
+# org.eclipse.tm.te.ui.terminals.process
+# Externalized Strings.
+#
+
+ProcessConnector_error_creatingProcess=Exception when creating process. Possibly caused by: {0}

Back to the top