diff --git a/rse/plugins/org.eclipse.rse.services.telnet/.classpath b/rse/plugins/org.eclipse.rse.services.telnet/.classpath
new file mode 100644
index 00000000000..ce73933404a
--- /dev/null
+++ b/rse/plugins/org.eclipse.rse.services.telnet/.classpath
@@ -0,0 +1,7 @@
+
+
June 2, 2006
+The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.
+ +If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was +provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at http://www.eclipse.org.
+ + + \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.telnet/build.properties b/rse/plugins/org.eclipse.rse.services.telnet/build.properties new file mode 100644 index 00000000000..93256781661 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.telnet/build.properties @@ -0,0 +1,16 @@ +############################################################################### +# Copyright (c) 2005, 2007 IBM Corporation 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: +# IBM Corporation - initial API and implementation +############################################################################### +bin.includes = .,\ + META-INF/,\ + about.html,\ + plugin.properties +source.. = src/ +output.. = bin/ diff --git a/rse/plugins/org.eclipse.rse.services.telnet/plugin.properties b/rse/plugins/org.eclipse.rse.services.telnet/plugin.properties new file mode 100644 index 00000000000..5fd0cd18ab5 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.telnet/plugin.properties @@ -0,0 +1,16 @@ +############################################################################### +# Copyright (c) 2000, 2007 IBM Corporation 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: +# Sheldon D'souza (Celunite) - created +############################################################################### + +# NLS_MESSAGEFORMAT_NONE +# NLS_ENCODING=UTF-8 + +pluginName = RSE Telnet Service +providerName = Eclipse.org diff --git a/rse/plugins/org.eclipse.rse.services.telnet/src/org/eclipse/rse/internal/services/telnet/Activator.java b/rse/plugins/org.eclipse.rse.services.telnet/src/org/eclipse/rse/internal/services/telnet/Activator.java new file mode 100644 index 00000000000..7fdb5061d4b --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.telnet/src/org/eclipse/rse/internal/services/telnet/Activator.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2006, 2007 Celunite, 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: + * Sheldon D'souza (Celunite) - initial API and implementation + *******************************************************************************/ +package org.eclipse.rse.internal.services.telnet; + +import org.eclipse.core.runtime.ILog; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.osgi.util.NLS; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.eclipse.rse.services.telnet"; //$NON-NLS-1$ + + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + 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) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + + /** + * Logs an throwable to the log for this plugin. + * @param t the Throwable to be logged. + */ + public void logException(Throwable t) { + ILog log = getLog(); + String id = getBundle().getSymbolicName(); + String message = NLS.bind(TelnetServiceResources.TelnetPlugin_Unexpected_Exception, t.getClass().getName(), t.getLocalizedMessage()); + IStatus status = new Status(IStatus.ERROR, id, 0, message, t); + log.log(status); + } + +} diff --git a/rse/plugins/org.eclipse.rse.services.telnet/src/org/eclipse/rse/internal/services/telnet/ITelnetService.java b/rse/plugins/org.eclipse.rse.services.telnet/src/org/eclipse/rse/internal/services/telnet/ITelnetService.java new file mode 100644 index 00000000000..7da05254918 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.telnet/src/org/eclipse/rse/internal/services/telnet/ITelnetService.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2006, 2007 Celunite, Inc. + * 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: + * Sheldon D'souza (Celunite) - initial API and implementation + *******************************************************************************/ +package org.eclipse.rse.internal.services.telnet; + +/** + * Markup Interface for services using the TelnetConnectorService. + * + * By implementing this interface, services can be recognized + * as operating against an TelnetConnectorService. The interface + * is used as the key in a table for looking up the connector + * service when needed. + */ +public interface ITelnetService { + +} diff --git a/rse/plugins/org.eclipse.rse.services.telnet/src/org/eclipse/rse/internal/services/telnet/ITelnetSessionProvider.java b/rse/plugins/org.eclipse.rse.services.telnet/src/org/eclipse/rse/internal/services/telnet/ITelnetSessionProvider.java new file mode 100644 index 00000000000..f3c858ab7e9 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.telnet/src/org/eclipse/rse/internal/services/telnet/ITelnetSessionProvider.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2006, 2007 IBM Corporation 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 + * + * Initial Contributors: + * The following IBM employees contributed to the Remote System Explorer + * component that contains this file: David McKnight, Kushal Munir, + * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, + * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. + * + * Contributors: + * Sheldon D'souza (Celunite) - adapted from ISshSessionProvider + *******************************************************************************/ +package org.eclipse.rse.internal.services.telnet; + +import org.apache.commons.net.telnet.TelnetClient; + +public interface ITelnetSessionProvider { + + public TelnetClient getTelnetClient(); + + /* Inform the connectorService that a session has been lost. */ + public void handleSessionLost(); +} diff --git a/rse/plugins/org.eclipse.rse.services.telnet/src/org/eclipse/rse/internal/services/telnet/TelnetServiceResources.java b/rse/plugins/org.eclipse.rse.services.telnet/src/org/eclipse/rse/internal/services/telnet/TelnetServiceResources.java new file mode 100644 index 00000000000..5572200111a --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.telnet/src/org/eclipse/rse/internal/services/telnet/TelnetServiceResources.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2006, 2007 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: + * Martin Oberhuber (Wind River) - initial API and implementation + * Sheldon D'souza (Celunite) - adapted form SshServiceResources + *******************************************************************************/ +package org.eclipse.rse.internal.services.telnet; + +import org.eclipse.osgi.util.NLS; + +public class TelnetServiceResources extends NLS { + + private static final String BUNDLE_NAME = "org.eclipse.rse.internal.services.telnet.TelnetServiceResources"; //$NON-NLS-1$ + + public static String TelnetPlugin_Unexpected_Exception; + + public static String TelnetShellService_Description; + + public static String TelnetShellService_Name; + + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, TelnetServiceResources.class); + } + + private TelnetServiceResources(){ + + } +} diff --git a/rse/plugins/org.eclipse.rse.services.telnet/src/org/eclipse/rse/internal/services/telnet/TelnetServiceResources.properties b/rse/plugins/org.eclipse.rse.services.telnet/src/org/eclipse/rse/internal/services/telnet/TelnetServiceResources.properties new file mode 100644 index 00000000000..a44c0f97396 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.telnet/src/org/eclipse/rse/internal/services/telnet/TelnetServiceResources.properties @@ -0,0 +1,18 @@ +################################################################################ +# Copyright (c) 2006, 2007 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: +# Martin Oberhuber (Wind River) - initial API and implementation +# Sheldon D'souza (Celunite) - adapted from SshServiceResources +################################################################################ + +# NLS_MESSAGEFORMAT_VAR +# NLS_ENCODING=UTF-8 + +TelnetPlugin_Unexpected_Exception=Unexpected {0}: {1} +TelnetShellService_Name=Telnet Shell Service +TelnetShellService_Description=Telnet Shell Service Description diff --git a/rse/plugins/org.eclipse.rse.services.telnet/src/org/eclipse/rse/internal/services/telnet/shell/TelnetHostShell.java b/rse/plugins/org.eclipse.rse.services.telnet/src/org/eclipse/rse/internal/services/telnet/shell/TelnetHostShell.java new file mode 100644 index 00000000000..3763aedce19 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.telnet/src/org/eclipse/rse/internal/services/telnet/shell/TelnetHostShell.java @@ -0,0 +1,132 @@ +/******************************************************************************* + * Copyright (c) 2006, 2007 IBM Corporation 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 + * + * Initial Contributors: + * The following IBM employees contributed to the Remote System Explorer + * component that contains this file: David McKnight, Kushal Munir, + * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, + * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. + * + * Contributors: + * Martin Oberhuber (Wind River) - Adapted from LocalHostShell. + * Sheldon D'souza (Celunite) - Adapted from SshHostShell + *******************************************************************************/ +package org.eclipse.rse.internal.services.telnet.shell; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.util.regex.Pattern; + +import org.apache.commons.net.telnet.TelnetClient; +import org.eclipse.rse.internal.services.telnet.ITelnetSessionProvider; +import org.eclipse.rse.services.clientserver.PathUtility; +import org.eclipse.rse.services.shells.AbstractHostShell; +import org.eclipse.rse.services.shells.IHostShell; +import org.eclipse.rse.services.shells.IHostShellOutputReader; + +public class TelnetHostShell extends AbstractHostShell implements IHostShell { + + public static final String SHELL_INVOCATION = ">"; //$NON-NLS-1$ + + private ITelnetSessionProvider fSessionProvider; + private TelnetShellOutputReader fStdoutHandler; + private TelnetShellOutputReader fStderrHandler; + private TelnetShellWriterThread fShellWriter; + + public TelnetHostShell(ITelnetSessionProvider sessionProvider, String initialWorkingDirectory, String commandToRun, String encoding, String[] environment) { + try { + fSessionProvider = sessionProvider; + + + fStdoutHandler = new TelnetShellOutputReader(this, new BufferedReader(new InputStreamReader(sessionProvider.getTelnetClient().getInputStream())), false); + fStderrHandler = new TelnetShellOutputReader(this, null,true); + OutputStream outputStream = sessionProvider.getTelnetClient().getOutputStream(); + //TODO check if encoding or command to execute needs to be considered + //If a command is given, it might be possible to do without a Thread + //Charset cs = Charset.forName(encoding); + //PrintWriter outputWriter = new PrintWriter( + // new BufferedWriter(new OutputStreamWriter(outputStream,cs))); + PrintWriter outputWriter = new PrintWriter(outputStream); + fShellWriter = new TelnetShellWriterThread(outputWriter); + + if (initialWorkingDirectory!=null && initialWorkingDirectory.length()>0 + && !initialWorkingDirectory.equals(".") //$NON-NLS-1$ + && !initialWorkingDirectory.equals("Command Shell") //$NON-NLS-1$ //FIXME workaround for bug 153047 + ) { + writeToShell("cd "+PathUtility.enQuoteUnix(initialWorkingDirectory)); //$NON-NLS-1$ + } else if (SHELL_INVOCATION.equals(commandToRun)) { + writeToShell(getPromptCommand()); + } else if(commandToRun!=null && commandToRun.length()>0) { + writeToShell(commandToRun); + } + } catch(Exception e) { + //TODO Forward exception to RSE properly + e.printStackTrace(); + if (fShellWriter!=null) { + fShellWriter.stopThread(); + fShellWriter = null; + } + } + } + + public String getPromptCommand() { + return "echo $PWD'>'"; //$NON-NLS-1$ + } + + public void exit() { + fShellWriter.stopThread(); + try { + fSessionProvider.getTelnetClient().disconnect(); + } catch (IOException e) { + } + + } + + public IHostShellOutputReader getStandardOutputReader() { + return fStdoutHandler; + } + + public IHostShellOutputReader getStandardErrorReader() { + return fStderrHandler; + } + + public boolean isActive() { + TelnetClient client = fSessionProvider.getTelnetClient(); + if (client!=null ) { + return true; + } + // shell is not active: check for session lost + exit(); + + if (client!=null && !client.isConnected()) { + fSessionProvider.handleSessionLost(); + } + return false; + } + + private static final Pattern cdCommands = Pattern.compile("\\A\\s*(cd|chdir|ls)\\b"); //$NON-NLS-1$ + + public void writeToShell(String command) { + if (isActive()) { + if ("#break".equals(command)) { //$NON-NLS-1$ + command = "\u0003"; //Unicode 3 == Ctrl+C //$NON-NLS-1$ + } else if (cdCommands.matcher(command).find()) { + command += "\r\n" + getPromptCommand(); //$NON-NLS-1$ + } + if (!fShellWriter.sendCommand(command)) { + //exception occurred: terminate writer thread, cancel connection + exit(); + isActive(); + } + } + + } + +} diff --git a/rse/plugins/org.eclipse.rse.services.telnet/src/org/eclipse/rse/internal/services/telnet/shell/TelnetShellOutputReader.java b/rse/plugins/org.eclipse.rse.services.telnet/src/org/eclipse/rse/internal/services/telnet/shell/TelnetShellOutputReader.java new file mode 100644 index 00000000000..f7967fbabca --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.telnet/src/org/eclipse/rse/internal/services/telnet/shell/TelnetShellOutputReader.java @@ -0,0 +1,146 @@ +/******************************************************************************* + * Copyright (c) 2006, 2007 IBM Corporation 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 + * + * Initial Contributors: + * The following IBM employees contributed to the Remote System Explorer + * component that contains this file: David McKnight, Kushal Munir, + * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, + * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. + * + * Contributors: + * Martin Oberhuber (Wind River) - Adapted from LocalShellOutputReader. + * Martin Oberhuber (Wind River) - Added vt100 escape sequence ignoring. + * Sheldon D'souza (Celunite) - Adapted from SshShellOutputReader + *******************************************************************************/ +package org.eclipse.rse.internal.services.telnet.shell; + +import java.io.BufferedReader; +import java.io.IOException; + +import org.eclipse.rse.internal.services.telnet.Activator; +import org.eclipse.rse.services.shells.AbstractHostShellOutputReader; +import org.eclipse.rse.services.shells.IHostOutput; +import org.eclipse.rse.services.shells.IHostShell; +import org.eclipse.rse.services.shells.SimpleHostOutput; + +public class TelnetShellOutputReader extends AbstractHostShellOutputReader { + + + protected BufferedReader fReader; + private String fPromptChars = ">$%#]"; //$NON-NLS-1$ + + public TelnetShellOutputReader(IHostShell hostShell, BufferedReader reader,boolean isErrorReader) { + super(hostShell, isErrorReader); + setName("Telnet ShellOutputReader"+getName()); //$NON-NLS-1$ + fReader = reader; + } + + protected IHostOutput internalReadLine() { + if (fReader == null) { + //Our workaround sets the stderr reader to null, so we never give any stderr output. + //TODO Check if ssh supports some method of having separate stdout and stderr streams + return null; + } + StringBuffer theLine = new StringBuffer(); + StringBuffer theDebugLine = null; + theDebugLine = new StringBuffer(); + int ch; + boolean done = false; + while (!done && !isFinished()) { + try { + ch = fReader.read(); + switch (ch) { + case -1: + case 65535: + if (theLine.length() == 0) // End of Reader + return null; + done = true; + break; + case '\b': //backspace + if(theDebugLine!=null) theDebugLine.append((char)ch); + int len = theLine.length()-1; + if (len>=0) theLine.deleteCharAt(len); + break; + case 13: + if(theDebugLine!=null) theDebugLine.append((char)ch); + break; // Carriage Return: dont append to the buffer + case 10: + if(theDebugLine!=null) theDebugLine.append((char)ch); + done = true; // Newline + break; + case 9: + //Tab: we count tabs at column 8 + //TODO Check: SystemViewRemoteOutputAdapter.translateTabs() also translates + //Therefore this special handling here might be unnecessary + if(theDebugLine!=null) theDebugLine.append((char)ch); + int tabIndex = theLine.length() % 8; + while (tabIndex < 8) { + theLine.append(' '); + tabIndex++; + } + break; + default: + char tch = (char) ch; + if(theDebugLine!=null) theDebugLine.append(tch); + if (!Character.isISOControl(tch)) { + theLine.append(tch); // Any other character + } else if (ch == 27) { + // Escape: ignore next char too + int nch = fReader.read(); + if (theDebugLine!=null) theDebugLine.append((char)nch); + if (nch == 91) { + //vt100 escape sequence: read until end-of-command (skip digits and semicolon) + //e.g. \x1b;13;m --> ignore the entire command, including the trailing m + do { + nch = fReader.read(); + if (theDebugLine!=null) theDebugLine.append((char)nch); + } while (Character.isDigit((char)nch) || nch == ';'); + } + } + } + + // Check to see if the BufferedReader is still ready which means + // there are more characters + // in the Buffer...If not, then we assume it is waiting for + // input. + if (!done && !fReader.ready()) { + // wait to make sure -- max. 500 msec to wait for new chars + // if we are not at a CRLF seems to be appropriate for the + // Pipes and Threads in ssh. + long waitIncrement = 500; + // Check if we think we are at a prompt + int len = theLine.length()-1; + while (len>0 && Character.isSpaceChar(theLine.charAt(len))) { + len--; + } + if (len>=0 && fPromptChars.indexOf(theLine.charAt(len))>=0) { + waitIncrement = 5; //wait only 5 msec if we think it's a prompt + } + try { + Thread.sleep(waitIncrement); + } catch (InterruptedException e) { + } + if (!fReader.ready()) { + done = true; + } + } + } catch (IOException e) { + //FIXME it's dangerous to return null here since this will end + //our reader thread completely... the exception could just be + //temporary, and we should keep running! + Activator.getDefault().logException(e); + return null; + } + } + if (theDebugLine!=null) { + String debugLine = theDebugLine.toString(); + debugLine.compareTo(""); //$NON-NLS-1$ + } + return new SimpleHostOutput(theLine.toString()); + } + +} diff --git a/rse/plugins/org.eclipse.rse.services.telnet/src/org/eclipse/rse/internal/services/telnet/shell/TelnetShellService.java b/rse/plugins/org.eclipse.rse.services.telnet/src/org/eclipse/rse/internal/services/telnet/shell/TelnetShellService.java new file mode 100644 index 00000000000..8a4ca016ef9 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.telnet/src/org/eclipse/rse/internal/services/telnet/shell/TelnetShellService.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * Copyright (c) 2006, 2007 IBM Corporation 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 + * + * Initial Contributors: + * The following IBM employees contributed to the Remote System Explorer + * component that contains this file: David McKnight, Kushal Munir, + * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, + * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. + * + * Contributors: + * Martin Oberhuber (Wind River) - Adapted from LocalShellService. + * Sheldon D'souza (Celunite) - Adapted from SshShellService. + *******************************************************************************/ +package org.eclipse.rse.internal.services.telnet.shell; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.rse.internal.services.telnet.ITelnetService; +import org.eclipse.rse.internal.services.telnet.ITelnetSessionProvider; +import org.eclipse.rse.internal.services.telnet.TelnetServiceResources; +import org.eclipse.rse.services.clientserver.messages.SystemMessage; +import org.eclipse.rse.services.shells.IHostShell; +import org.eclipse.rse.services.shells.IShellService; + +public class TelnetShellService implements ITelnetService, IShellService { + + + private ITelnetSessionProvider fTelnetSessionProvider; + + public TelnetShellService( ITelnetSessionProvider sessionProvider) { + this.fTelnetSessionProvider = sessionProvider; + } + + public String[] getHostEnvironment() { + return new String[0]; + } + + public IHostShell launchShell(String initialWorkingDirectory, + String[] environment, IProgressMonitor monitor) { + String defaultEncoding = System.getProperty("file.encoding"); //$NON-NLS-1$ + return launchShell(initialWorkingDirectory, defaultEncoding, environment, monitor); + } + + public IHostShell launchShell(String initialWorkingDirectory, + String encoding, String[] environment, + IProgressMonitor monitor) { + TelnetHostShell hostShell = new TelnetHostShell(fTelnetSessionProvider, initialWorkingDirectory, TelnetHostShell.SHELL_INVOCATION, encoding, environment); + return hostShell; + } + + public IHostShell runCommand(String initialWorkingDirectory, + String command, String[] environment, IProgressMonitor monitor) { + String defaultEncoding = System.getProperty("file.encoding"); //$NON-NLS-1$ + return runCommand(initialWorkingDirectory, command, defaultEncoding, environment, monitor); + } + + public IHostShell runCommand(String initialWorkingDirectory, + String command, String encoding, String[] environment, + IProgressMonitor monitor) { + TelnetHostShell hostShell = new TelnetHostShell(fTelnetSessionProvider, initialWorkingDirectory, TelnetHostShell.SHELL_INVOCATION, encoding, environment); + return hostShell; + } + + public String getDescription() { + return TelnetServiceResources.TelnetShellService_Description; + } + + public SystemMessage getMessage(String messageID) { + // TODO Auto-generated method stub + return null; + } + + public String getName() { + return TelnetServiceResources.TelnetShellService_Name; + } + + public void initService(IProgressMonitor monitor) { + // TODO Auto-generated method stub + + } + + public void uninitService(IProgressMonitor monitor) { + // TODO Auto-generated method stub + + } + +} diff --git a/rse/plugins/org.eclipse.rse.services.telnet/src/org/eclipse/rse/internal/services/telnet/shell/TelnetShellWriterThread.java b/rse/plugins/org.eclipse.rse.services.telnet/src/org/eclipse/rse/internal/services/telnet/shell/TelnetShellWriterThread.java new file mode 100644 index 00000000000..5e1dd298b8d --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.telnet/src/org/eclipse/rse/internal/services/telnet/shell/TelnetShellWriterThread.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * Copyright (c) 2006, 2007 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: + * Martin Oberhuber (Wind River) - initial API and implementation + * Sheldon D'souza (Celunite) - Adapted from SshShellWriterThread + *******************************************************************************/ +package org.eclipse.rse.internal.services.telnet.shell; + +import java.io.PrintWriter; + +public class TelnetShellWriterThread extends Thread { + + private PrintWriter fOutputWriter; + private String fNextCommand; + private boolean fIsCancelled; + + + /** + * constructor for ssh shell writer thread + * @param outputWriter PrintWriter to write to in separate Thread + */ + public TelnetShellWriterThread(PrintWriter outputWriter) + { + super(); + fOutputWriter = outputWriter; + setName("Telnet ShellWriter"+getName()); //$NON-NLS-1$ + start(); + } + + public synchronized boolean isDone() + { + return fIsCancelled; + } + + public synchronized void stopThread() + { + fIsCancelled = true; + notifyAll(); + } + + /** + * Write command to remote side. Wait until the + * thread takes the command (no queueing). + * @param command to send + * @return boolean true if command was sent ok + */ + public synchronized boolean sendCommand(String command) + { + try { + //In case multiple commands try to send: + //wait until it's our turn + while (!fIsCancelled && fNextCommand!=null) { + wait(); + } + if (!fIsCancelled) { + //Now it's our turn + fNextCommand = command; + notifyAll(); + //Wait until our command is processed + while (!fIsCancelled && fNextCommand!=null) { + wait(); + } + } + } catch(InterruptedException e) { + stopThread(); + } + return !fIsCancelled; + } + + public synchronized void run() + { + try { + while (!fIsCancelled) { + while (fNextCommand==null && !fIsCancelled) { + wait(); + } + if (!fIsCancelled) { + fOutputWriter.println(fNextCommand); + fNextCommand=null; + notifyAll(); + if (fOutputWriter.checkError()) { //flush AND get error + stopThread(); + } + } + } + } catch(InterruptedException e) { + /* no special handling -> close stream */ + } finally { + stopThread(); +// if( fOutputWriter != null ) +// fOutputWriter.close(); + fOutputWriter = null; + } + } + +} diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.telnet/.classpath b/rse/plugins/org.eclipse.rse.subsystems.shells.telnet/.classpath new file mode 100644 index 00000000000..ce73933404a --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.telnet/.classpath @@ -0,0 +1,7 @@ + +June 2, 2006
+The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.
+ +If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was +provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at http://www.eclipse.org.
+ + + \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.telnet/build.properties b/rse/plugins/org.eclipse.rse.subsystems.shells.telnet/build.properties new file mode 100644 index 00000000000..3eb760f0a77 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.telnet/build.properties @@ -0,0 +1,19 @@ +############################################################################### +# Copyright (c) 2005, 2006 IBM Corporation 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: +# IBM Corporation - initial API and implementation +############################################################################### +bin.includes = .,\ + META-INF/,\ + about.html,\ + plugin.properties,\ + icons/,\ + plugin.xml +source.. = src/ +output.. = bin/ +src.includes = about.html diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.telnet/icons/full/obj16/systemcommands_obj.gif b/rse/plugins/org.eclipse.rse.subsystems.shells.telnet/icons/full/obj16/systemcommands_obj.gif new file mode 100644 index 00000000000..061b6e226a9 Binary files /dev/null and b/rse/plugins/org.eclipse.rse.subsystems.shells.telnet/icons/full/obj16/systemcommands_obj.gif differ diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.telnet/icons/full/obj16/systemcommandslive_obj.gif b/rse/plugins/org.eclipse.rse.subsystems.shells.telnet/icons/full/obj16/systemcommandslive_obj.gif new file mode 100644 index 00000000000..3faca447424 Binary files /dev/null and b/rse/plugins/org.eclipse.rse.subsystems.shells.telnet/icons/full/obj16/systemcommandslive_obj.gif differ diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.telnet/plugin.properties b/rse/plugins/org.eclipse.rse.subsystems.shells.telnet/plugin.properties new file mode 100644 index 00000000000..5541b7eae8d --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.telnet/plugin.properties @@ -0,0 +1,20 @@ +################################################################################ +# Copyright (c) 2006 Wind River Systems, Inc. +# 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: +# Martin Oberhuber - initial API and implementation +# Sheldon D'souza - Changes to strings +################################################################################ + +# NLS_MESSAGEFORMAT_NONE +# NLS_ENCODING=UTF-8 + +pluginName = RSE Telnet Shells +providerName = Eclipse.org + +TelnetShellSubsystemName=Telnet Shells +TelnetShellSubsystemDescription=Work with shells and commands on remote systems using the Telnet protocol. diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.telnet/plugin.xml b/rse/plugins/org.eclipse.rse.subsystems.shells.telnet/plugin.xml new file mode 100644 index 00000000000..04aa11a5ce5 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.telnet/plugin.xml @@ -0,0 +1,30 @@ + + + +The class TelnetSubSystemConfiguration is the main factory +for creating a telnet shell subsystem. By deriving from it, extenders +can create their customized telnet shell subsystem configuration which can +then be registered against their system types. A custom +SubSystemConfigurationAdapter can be registered for UI-specific +customizations. Possible customizations include: +