All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/7] Initial commit & functionalities for org.yocto.remote.utils
@ 2013-05-08 17:44 Ioana Grigoropol
  2013-05-08 17:44 ` [PATCH v2 1/7] Move RSEHelper to a separate plugin Ioana Grigoropol
                   ` (6 more replies)
  0 siblings, 7 replies; 9+ messages in thread
From: Ioana Grigoropol @ 2013-05-08 17:44 UTC (permalink / raw)
  To: yocto

- created separate org.yocto.remote.utils plugin
- move all functionality from org.yocto.sdk.remotetools that perform remote actions to org.yocto.remote.utils
- remove all dependencies to RSE Api from org.yocto.sdk.remotetools that are no longer needed

Ioana Grigoropol (7):
  Move RSEHelper to a separate plugin
  Move RemoteShellExec to separate plugin
  Move ShellSession to org.yocto.remote.utils separate plugin
  Move CommonHelper to org.yocto.remote.utils separate plugin
  Move TerminalHandler to org.yocto.remote.utils
  Remove unused TCFTerminalConnectors
  Remove all plugin dependencies to RSE APi from remote tools plugin

 .../org.yocto.remote.utils/META-INF/MANIFEST.MF    |   17 +
 .../src/org/yocto/remote/utils/Activator.java      |    4 +-
 .../src/org/yocto/remote/utils/CommonHelper.java   |   46 +++
 .../src/org/yocto/remote/utils/Messages.java       |   35 ++
 .../src/org/yocto/remote/utils/RSEHelper.java      |  344 ++++++++++++++++
 .../org/yocto/remote/utils/RemoteShellExec.java    |  140 +++++++
 .../src/org/yocto/remote/utils/ShellSession.java   |  327 +++++++++++++++
 .../org/yocto/remote/utils/TerminalHandler.java    |  128 ++++++
 .../org.yocto.sdk.remotetools/META-INF/MANIFEST.MF |   13 +-
 .../org/yocto/sdk/remotetools/CommonHelper.java    |   44 --
 .../src/org/yocto/sdk/remotetools/RSEHelper.java   |  419 --------------------
 .../org/yocto/sdk/remotetools/ShellSession.java    |  341 ----------------
 .../yocto/sdk/remotetools/actions/BaseModel.java   |    4 +-
 .../sdk/remotetools/actions/BaseSettingDialog.java |    2 +-
 .../sdk/remotetools/actions/DialogHandler.java     |    1 +
 .../sdk/remotetools/actions/OprofileModel.java     |    2 +-
 .../sdk/remotetools/actions/SystemtapModel.java    |    2 +-
 .../actions/SystemtapSettingDialog.java            |    2 +-
 .../sdk/remotetools/actions/TerminalHandler.java   |  128 ------
 .../sdk/remotetools/remote/RemoteShellExec.java    |  149 -------
 .../remotetools/views/TCFTerminalConnector.java    |   49 ---
 .../views/TCFTerminalConnectorImpl.java            |   98 -----
 22 files changed, 1053 insertions(+), 1242 deletions(-)
 create mode 100644 plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/CommonHelper.java
 create mode 100644 plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/Messages.java
 create mode 100644 plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/RSEHelper.java
 create mode 100644 plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/RemoteShellExec.java
 create mode 100644 plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/ShellSession.java
 create mode 100644 plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/TerminalHandler.java
 delete mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/CommonHelper.java
 delete mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/RSEHelper.java
 delete mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/ShellSession.java
 delete mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/TerminalHandler.java
 delete mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/remote/RemoteShellExec.java
 delete mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/views/TCFTerminalConnector.java
 delete mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/views/TCFTerminalConnectorImpl.java

-- 
1.7.9.5



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v2 1/7] Move RSEHelper to a separate plugin
  2013-05-08 17:44 [PATCH v2 0/7] Initial commit & functionalities for org.yocto.remote.utils Ioana Grigoropol
@ 2013-05-08 17:44 ` Ioana Grigoropol
  2013-05-08 17:44 ` [PATCH v2 2/7] Move RemoteShellExec to " Ioana Grigoropol
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Ioana Grigoropol @ 2013-05-08 17:44 UTC (permalink / raw)
  To: yocto

- move RSEHelper to newly created separate plugin org.yocto.remote.utils
- clean-up RSEHelper code by removing all unused methods
- moved message strings that are relevant for this plugin to the corresponding class
- modify remotetools plugin to use RSEHelper from org.yocto.remote.utils

Signed-off-by: Ioana Grigoropol <ioanax.grigoropol@intel.com>
---
 .../org.yocto.remote.utils/META-INF/MANIFEST.MF    |   10 +
 .../src/org/yocto/remote/utils/Activator.java      |    4 +-
 .../src/org/yocto/remote/utils/Messages.java       |   35 ++
 .../src/org/yocto/remote/utils/RSEHelper.java      |  344 ++++++++++++++++
 .../org.yocto.sdk.remotetools/META-INF/MANIFEST.MF |    3 +-
 .../src/org/yocto/sdk/remotetools/RSEHelper.java   |  419 --------------------
 .../yocto/sdk/remotetools/actions/BaseModel.java   |    2 +-
 .../sdk/remotetools/actions/BaseSettingDialog.java |    2 +-
 .../sdk/remotetools/actions/TerminalHandler.java   |    2 +-
 .../sdk/remotetools/remote/RemoteShellExec.java    |    2 +-
 10 files changed, 398 insertions(+), 425 deletions(-)
 create mode 100644 plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/Messages.java
 create mode 100644 plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/RSEHelper.java
 delete mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/RSEHelper.java

diff --git a/plugins/org.yocto.remote.utils/META-INF/MANIFEST.MF b/plugins/org.yocto.remote.utils/META-INF/MANIFEST.MF
index eff0356..9616484 100644
--- a/plugins/org.yocto.remote.utils/META-INF/MANIFEST.MF
+++ b/plugins/org.yocto.remote.utils/META-INF/MANIFEST.MF
@@ -8,3 +8,13 @@ Require-Bundle: org.eclipse.ui,
  org.eclipse.core.runtime
 Bundle-ActivationPolicy: lazy
 Bundle-RequiredExecutionEnvironment: JavaSE-1.7
+Import-Package: org.eclipse.rse.core,
+ org.eclipse.rse.core.model,
+ org.eclipse.rse.core.subsystems,
+ org.eclipse.rse.services,
+ org.eclipse.rse.services.files,
+ org.eclipse.rse.services.shells,
+ org.eclipse.rse.subsystems.files.core.servicesubsystem,
+ org.eclipse.rse.subsystems.shells.core.subsystems.servicesubsystem,
+ org.eclipse.rse.subsystems.terminals.core
+Export-Package: org.yocto.remote.utils
diff --git a/plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/Activator.java b/plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/Activator.java
index 047d900..da66a3e 100644
--- a/plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/Activator.java
+++ b/plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/Activator.java
@@ -23,7 +23,7 @@ public class Activator extends AbstractUIPlugin {
 
 	// The shared instance
 	private static Activator plugin;
-	
+
 	/**
 	 * The constructor
 	 */
@@ -34,6 +34,7 @@ public class Activator extends AbstractUIPlugin {
 	 * (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;
@@ -43,6 +44,7 @@ public class Activator extends AbstractUIPlugin {
 	 * (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);
diff --git a/plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/Messages.java b/plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/Messages.java
new file mode 100644
index 0000000..fc696d6
--- /dev/null
+++ b/plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/Messages.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Intel Corporation.
+ * 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:
+ * Intel - initial API and implementation
+ *******************************************************************************/
+package org.yocto.remote.utils;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+
+	private static final String BUNDLE_NAME = "org.yocto.remote.utils.messages"; //$NON-NLS-1$
+
+	public static String ErrorNoSubsystem;
+	public static String ErrorConnectSubsystem;
+
+	public static String InfoDownload;
+	public static String InfoUpload;
+
+	public static String RemoteShellExec_1;
+	public static String RemoteShellExec_2;
+
+	static {
+		// initialize resource bundle
+		NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+	}
+
+	private Messages() {
+	}
+}
diff --git a/plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/RSEHelper.java b/plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/RSEHelper.java
new file mode 100644
index 0000000..e2c8b88
--- /dev/null
+++ b/plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/RSEHelper.java
@@ -0,0 +1,344 @@
+/********************************************************************************
+ * Copyright (c) 2013 MontaVista Software, Inc and Others.
+ * 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:
+ * Anna Dushistova (MontaVista) - initial API and implementation
+ * Lianhao Lu (Intel)			- Modified to add other file operations.
+ * Ioana Grigoropol (Intel)     - Separated remote functionality
+ ********************************************************************************/
+package org.yocto.remote.utils;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.rse.core.IRSECoreStatusCodes;
+import org.eclipse.rse.core.IRSESystemType;
+import org.eclipse.rse.core.RSECorePlugin;
+import org.eclipse.rse.core.model.IHost;
+import org.eclipse.rse.core.model.ISubSystemConfigurationCategories;
+import org.eclipse.rse.core.model.ISystemRegistry;
+import org.eclipse.rse.core.subsystems.ISubSystem;
+import org.eclipse.rse.services.IService;
+import org.eclipse.rse.services.files.IFileService;
+import org.eclipse.rse.services.shells.HostShellProcessAdapter;
+import org.eclipse.rse.services.shells.IHostShell;
+import org.eclipse.rse.services.shells.IShellService;
+import org.eclipse.rse.subsystems.files.core.servicesubsystem.IFileServiceSubSystem;
+import org.eclipse.rse.subsystems.shells.core.subsystems.servicesubsystem.IShellServiceSubSystem;
+import org.eclipse.rse.subsystems.terminals.core.ITerminalServiceSubSystem;
+
+public class RSEHelper {
+	private final static String EXIT_CMD = "exit"; //$NON-NLS-1$
+	private final static String CMD_DELIMITER = ";"; //$NON-NLS-1$
+	
+	public static IHost getRemoteConnectionByName(String remoteConnection) {
+		if (remoteConnection == null)
+			return null;
+		IHost[] connections = RSECorePlugin.getTheSystemRegistry().getHosts();
+		for (int i = 0; i < connections.length; i++)
+			if (connections[i].getAliasName().equals(remoteConnection))
+				return connections[i];
+		return null; // TODO Connection is not found in the list--need to react
+		// somehow, throw the exception?
+
+	}
+
+	public static IService getConnectedRemoteFileService(
+			IHost currentConnection, IProgressMonitor monitor) throws Exception {
+		final ISubSystem subsystem = getFileSubsystem(currentConnection);
+
+		if (subsystem == null)
+			throw new Exception(Messages.ErrorNoSubsystem);
+
+		try {
+			subsystem.connect(monitor, false);
+		} catch (CoreException e) {
+			throw e;
+		} catch (OperationCanceledException e) {
+			throw new CoreException(Status.CANCEL_STATUS);
+		}
+
+		if (!subsystem.isConnected())
+			throw new Exception(Messages.ErrorConnectSubsystem);
+
+		return ((IFileServiceSubSystem) subsystem).getFileService();
+	}
+
+	public static ISubSystem getFileSubsystem(IHost host) {
+		if (host == null)
+			return null;
+		ISubSystem[] subSystems = host.getSubSystems();
+		for (int i = 0; i < subSystems.length; i++) {
+			if (subSystems[i] instanceof IFileServiceSubSystem)
+				return subSystems[i];
+		}
+		return null;
+	}
+
+	public static IService getConnectedShellService(
+			IHost currentConnection, IProgressMonitor monitor) throws Exception {
+		final ISubSystem subsystem = getShellSubsystem(currentConnection);
+
+		if (subsystem == null)
+			throw new Exception(Messages.ErrorNoSubsystem);
+
+		try {
+			subsystem.connect(monitor, false);
+		} catch (CoreException e) {
+			throw e;
+		} catch (OperationCanceledException e) {
+			throw new CoreException(Status.CANCEL_STATUS);
+		}
+
+		if (!subsystem.isConnected())
+			throw new Exception(Messages.ErrorConnectSubsystem);
+
+		return ((IShellServiceSubSystem) subsystem).getShellService();
+	}
+
+	public static ISubSystem getShellSubsystem(IHost host) {
+		if (host == null)
+			return null;
+		ISubSystem[] subSystems = host.getSubSystems();
+		for (int i = 0; i < subSystems.length; i++) {
+			if (subSystems[i] instanceof IShellServiceSubSystem)
+				return subSystems[i];
+		}
+		return null;
+	}
+
+	public static IHost[] getSuitableConnections() {
+
+		//we only get RSE connections with files&cmds subsystem
+		ArrayList <IHost> filConnections = new ArrayList <IHost>(Arrays.asList(RSECorePlugin.getTheSystemRegistry()
+				.getHostsBySubSystemConfigurationCategory(ISubSystemConfigurationCategories.SUBSYSTEM_CATEGORY_FILES))); //$NON-NLS-1$
+
+		ArrayList <IHost> terminalConnections = new ArrayList <IHost>(Arrays.asList(RSECorePlugin.getTheSystemRegistry()
+				.getHostsBySubSystemConfigurationCategory("terminal")));//$NON-NLS-1$
+
+		ArrayList <IHost> shellConnections = new ArrayList <IHost>(Arrays.asList(RSECorePlugin.getTheSystemRegistry()
+				.getHostsBySubSystemConfigurationCategory("shells"))); //$NON-NLS-1$
+
+		Iterator <IHost>iter = filConnections.iterator();
+		while(iter.hasNext()){
+			IHost fileConnection = iter.next();
+			if(!terminalConnections.contains(fileConnection) && !shellConnections.contains(fileConnection)){
+				iter.remove();
+			}
+			IRSESystemType sysType = fileConnection.getSystemType();
+			if (sysType != null && sysType.isEnabled()) {
+				iter.remove();
+			}
+		}
+
+		return filConnections.toArray(new IHost[filConnections.size()]);
+	}
+
+	public static void putRemoteFileInPlugin(IHost connection, String locaPathInPlugin, String remoteExePath,
+			IProgressMonitor monitor) throws Exception {
+
+		assert(connection != null);
+		monitor.beginTask(Messages.InfoUpload, 100);
+
+		IFileService fileService;
+		try {
+			fileService = (IFileService) getConnectedRemoteFileService(
+							connection,
+							new SubProgressMonitor(monitor, 5));
+			InputStream  inputStream = FileLocator.openStream(
+				    Activator.getDefault().getBundle(), new Path(locaPathInPlugin), false);
+			Path remotePath = new Path(remoteExePath);
+
+			//TODO workaround for now
+			//in case the underlying scp file service doesn't support inputStream upload
+			BufferedInputStream bis = new BufferedInputStream(inputStream);
+			File tempFile = File.createTempFile("scp", "temp"); //$NON-NLS-1$ //$NON-NLS-2$
+			FileOutputStream os = new FileOutputStream(tempFile);
+			BufferedOutputStream bos = new BufferedOutputStream(os);
+			byte[] buffer = new byte[1024];
+			int readCount;
+			while( (readCount = bis.read(buffer)) > 0)
+			{
+				bos.write(buffer, 0, readCount);
+			}
+			bos.close();
+			fileService.upload(tempFile, remotePath.removeLastSegments(1)
+					.toString(), remotePath.lastSegment(), true, null, null,
+					new SubProgressMonitor(monitor, 80));
+			// Need to change the permissions to match the original file
+			// permissions because of a bug in upload
+			remoteShellExec(
+					connection,
+					"", "chmod", "+x " + spaceEscapify(remotePath.toString()), new SubProgressMonitor(monitor, 5)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+		} finally {
+			monitor.done();
+		}
+		return;
+	}
+
+	public static void getRemoteFile(IHost connection, String localExePath, String remoteExePath,
+			IProgressMonitor monitor) throws Exception {
+
+		assert(connection!=null);
+		monitor.beginTask(Messages.InfoDownload, 100);
+
+		IFileService fileService;
+		try {
+			fileService = (IFileService) getConnectedRemoteFileService(
+							connection,
+							new SubProgressMonitor(monitor, 10));
+			File file = new File(localExePath);
+			file.deleteOnExit();
+			monitor.worked(5);
+			Path remotePath = new Path(remoteExePath);
+			fileService.download(remotePath.removeLastSegments(1).toString(),
+					remotePath.lastSegment(),file,true, null,
+					new SubProgressMonitor(monitor, 85));
+			// Need to change the permissions to match the original file
+			// permissions because of a bug in upload
+			//RemoteApplication p = remoteShellExec(
+			//		config,
+			//		"", "chmod", "+x " + spaceEscapify(remotePath.toString()), new SubProgressMonitor(monitor, 5)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+			//Thread.sleep(500);
+			//p.destroy();
+
+		} finally {
+			monitor.done();
+		}
+		return;
+	}
+
+	public static ITerminalServiceSubSystem getTerminalSubSystem(
+            IHost connection) {
+        ISystemRegistry systemRegistry = RSECorePlugin.getTheSystemRegistry();
+        ISubSystem[] subsystems = systemRegistry.getSubSystems(connection);
+        for (int i = 0; i < subsystems.length; i++) {
+        	if (subsystems[i] instanceof ITerminalServiceSubSystem) {
+                ITerminalServiceSubSystem subSystem = (ITerminalServiceSubSystem) subsystems[i];
+                return subSystem;
+            }
+        }
+        return null;
+    }
+
+	public static String spaceEscapify(String inputString) {
+		if (inputString == null)
+			return null;
+
+		return inputString.replaceAll(" ", "\\\\ "); //$NON-NLS-1$ //$NON-NLS-2$
+	}
+
+	public static Process remoteShellExec(IHost connection,
+			String prelaunchCmd, String remoteCommandPath, String arguments,
+			IProgressMonitor monitor) throws CoreException {
+
+		monitor.beginTask(NLS.bind(Messages.RemoteShellExec_1,
+				remoteCommandPath, arguments), 10);
+		String realRemoteCommand = arguments == null ? spaceEscapify(remoteCommandPath)
+				: spaceEscapify(remoteCommandPath) + " " + arguments; //$NON-NLS-1$
+
+		String remoteCommand = realRemoteCommand + CMD_DELIMITER + EXIT_CMD;
+
+		if(prelaunchCmd != null) {
+			if (!prelaunchCmd.trim().equals("")) //$NON-NLS-1$
+				remoteCommand = prelaunchCmd + CMD_DELIMITER + remoteCommand;
+		}
+
+		IShellService shellService;
+		Process p = null;
+		try {
+			shellService = (IShellService) getConnectedShellService(
+							connection,
+							new SubProgressMonitor(monitor, 7));
+
+			// This is necessary because runCommand does not actually run the
+			// command right now.
+			String env[] = new String[0];
+			try {
+				IHostShell hostShell = shellService.launchShell(
+						"", env, new SubProgressMonitor(monitor, 3)); //$NON-NLS-1$
+				hostShell.writeToShell(remoteCommand);
+				p = new HostShellProcessAdapter(hostShell);
+			} catch (Exception e) {
+				if (p != null) {
+					p.destroy();
+				}
+				abort(Messages.RemoteShellExec_2, e,
+						IRSECoreStatusCodes.EXCEPTION_OCCURRED);
+			}
+		} catch (Exception e1) {
+			abort(e1.getMessage(), e1,
+					IRSECoreStatusCodes.EXCEPTION_OCCURRED);
+		}
+
+		monitor.done();
+		return p;
+	}
+
+	/**
+	 * Throws a core exception with an error status object built from the given
+	 * message, lower level exception, and error code.
+	 *
+	 * @param message
+	 *            the status message
+	 * @param exception
+	 *            lower level exception associated with the error, or
+	 *            <code>null</code> if none
+	 * @param code
+	 *            error code
+	 */
+	public static void abort(String message, Throwable exception, int code) throws CoreException {
+		IStatus status;
+		if (exception != null) {
+			MultiStatus multiStatus = new MultiStatus(Activator.PLUGIN_ID, code, message, exception);
+			multiStatus.add(new Status(IStatus.ERROR, Activator.PLUGIN_ID, code, exception.getLocalizedMessage(), exception));
+			status = multiStatus;
+		} else {
+			status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, code, message, null);
+		}
+		throw new CoreException(status);
+	}
+	/**
+	 * Checks whether a IHost associated system's is enabled and not a local one
+	 * @param host
+	 * @return
+	 */
+	public static boolean isHostViable(IHost host) {
+		IRSESystemType sysType = host.getSystemType();
+		if (sysType != null && sysType.isEnabled() && !sysType.isLocal())
+			return true;
+		return false;
+	}
+
+	/**
+	 * Ensures that RSECorePlugin is initialized before performing any actions
+	 */
+	public static void waitForRSEInitCompletition() {
+		if (!RSECorePlugin.isInitComplete(RSECorePlugin.INIT_MODEL))
+			try {
+				RSECorePlugin.waitForInitCompletion(RSECorePlugin.INIT_MODEL);
+			} catch (InterruptedException e) {
+				return;
+			}
+	}
+}
diff --git a/plugins/org.yocto.sdk.remotetools/META-INF/MANIFEST.MF b/plugins/org.yocto.sdk.remotetools/META-INF/MANIFEST.MF
index d10a56e..c34ad9e 100644
--- a/plugins/org.yocto.sdk.remotetools/META-INF/MANIFEST.MF
+++ b/plugins/org.yocto.sdk.remotetools/META-INF/MANIFEST.MF
@@ -24,7 +24,8 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Import-Package: org.eclipse.core.resources,
  org.eclipse.debug.internal.ui,
  org.eclipse.rse.shells.ui,
- org.eclipse.ui.forms.widgets
+ org.eclipse.ui.forms.widgets,
+ org.yocto.remote.utils
 Bundle-Vendor: %Bundle-Vendor
 Bundle-ClassPath: lib/json-simple-1.1.1.jar,
  .
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/RSEHelper.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/RSEHelper.java
deleted file mode 100644
index 8d0612a..0000000
--- a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/RSEHelper.java
+++ /dev/null
@@ -1,419 +0,0 @@
-/********************************************************************************
- * Copyright (c) 2009, 2010 MontaVista Software, Inc and Others.
- * 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:
- * Anna Dushistova (MontaVista) - initial API and implementation
- * Lianhao Lu (Intel)			- Modified to add other file operations.
- ********************************************************************************/
-package org.yocto.sdk.remotetools;
-
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Iterator;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.MultiStatus;
-import org.eclipse.core.runtime.OperationCanceledException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.SubProgressMonitor;
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.rse.core.IRSECoreStatusCodes;
-import org.eclipse.rse.core.RSECorePlugin;
-import org.eclipse.rse.core.model.IHost;
-import org.eclipse.rse.core.model.ISubSystemConfigurationCategories;
-import org.eclipse.rse.core.model.ISystemRegistry;
-import org.eclipse.rse.core.subsystems.ISubSystem;
-import org.eclipse.rse.subsystems.shells.core.subsystems.servicesubsystem.IShellServiceSubSystem;
-import org.eclipse.rse.services.IService;
-import org.eclipse.rse.services.files.IFileService;
-import org.eclipse.rse.services.shells.HostShellProcessAdapter;
-import org.eclipse.rse.services.shells.IHostShell;
-import org.eclipse.rse.services.shells.IShellService;
-import org.eclipse.rse.subsystems.files.core.servicesubsystem.IFileServiceSubSystem;
-import org.eclipse.rse.subsystems.terminals.core.ITerminalServiceSubSystem;
-import org.eclipse.rse.core.IRSESystemType;
-
-public class RSEHelper {
-	
-	public static IHost getRemoteConnectionByName(String remoteConnection) {
-		if (remoteConnection == null)
-			return null;
-		IHost[] connections = RSECorePlugin.getTheSystemRegistry().getHosts();
-		for (int i = 0; i < connections.length; i++)
-			if (connections[i].getAliasName().equals(remoteConnection))
-				return connections[i];
-		return null; // TODO Connection is not found in the list--need to react
-		// somehow, throw the exception?
-
-	}
-	
-	public static String getRemoteHostName(String remoteConnection)
-	{
-		final IHost host=getRemoteConnectionByName(remoteConnection);
-		if(host == null)
-			return null;
-		else
-			return host.getHostName();
-	}
-
-	public static IService getConnectedRemoteFileService(
-			IHost currentConnection, IProgressMonitor monitor) throws Exception {
-		final ISubSystem subsystem = getFileSubsystem(currentConnection);
-
-		if (subsystem == null)
-			throw new Exception(Messages.ErrorNoSubsystem);
-
-		try {
-			subsystem.connect(monitor, false);
-		} catch (CoreException e) {
-			throw e;
-		} catch (OperationCanceledException e) {
-			throw new CoreException(Status.CANCEL_STATUS);
-		}
-
-		if (!subsystem.isConnected())
-			throw new Exception(Messages.ErrorConnectSubsystem);
-
-		return ((IFileServiceSubSystem) subsystem).getFileService();
-	}
-
-	public static ISubSystem getFileSubsystem(IHost host) {
-		if (host == null)
-			return null;
-		ISubSystem[] subSystems = host.getSubSystems();
-		for (int i = 0; i < subSystems.length; i++) {
-			if (subSystems[i] instanceof IFileServiceSubSystem)
-				return subSystems[i];
-		}
-		return null;
-	}
-	
-	public static IService getConnectedShellService(
-			IHost currentConnection, IProgressMonitor monitor) throws Exception {
-		final ISubSystem subsystem = getShellSubsystem(currentConnection);
-
-		if (subsystem == null)
-			throw new Exception(Messages.ErrorNoSubsystem);
-
-		try {
-			subsystem.connect(monitor, false);
-		} catch (CoreException e) {
-			throw e;
-		} catch (OperationCanceledException e) {
-			throw new CoreException(Status.CANCEL_STATUS);
-		}
-
-		if (!subsystem.isConnected())
-			throw new Exception(Messages.ErrorConnectSubsystem);
-
-		return ((IShellServiceSubSystem) subsystem).getShellService();
-	}
-	
-	public static ISubSystem getShellSubsystem(IHost host) {
-		if (host == null)
-			return null;
-		ISubSystem[] subSystems = host.getSubSystems();
-		for (int i = 0; i < subSystems.length; i++) {
-			if (subSystems[i] instanceof IShellServiceSubSystem)
-				return subSystems[i];
-		}
-		return null;
-	}
-
-	public static IHost[] getSuitableConnections() {
-		
-		//we only get RSE connections with files&cmds subsystem
-		ArrayList <IHost> filConnections = new ArrayList <IHost>(Arrays.asList(RSECorePlugin.getTheSystemRegistry()
-				.getHostsBySubSystemConfigurationCategory(ISubSystemConfigurationCategories.SUBSYSTEM_CATEGORY_FILES))); //$NON-NLS-1$
-		
-		ArrayList <IHost> terminalConnections = new ArrayList <IHost>(Arrays.asList(RSECorePlugin.getTheSystemRegistry()
-				.getHostsBySubSystemConfigurationCategory("terminal")));//$NON-NLS-1$
-		
-		ArrayList shellConnections = new ArrayList(Arrays.asList(RSECorePlugin.getTheSystemRegistry()
-				.getHostsBySubSystemConfigurationCategory("shells"))); //$NON-NLS-1$
-
-		Iterator <IHost>iter = filConnections.iterator();
-		while(iter.hasNext()){
-			IHost fileConnection = iter.next();
-			if(!terminalConnections.contains(fileConnection) && !shellConnections.contains(fileConnection)){
-				iter.remove();
-			}
-			IRSESystemType sysType = fileConnection.getSystemType();
-			if (sysType != null && sysType.isEnabled()) {
-				iter.remove();
-			}
-		}
-		
-		return (IHost[]) filConnections.toArray(new IHost[filConnections.size()]);
-	}
-	
-	public static void deleteRemoteFile(IHost connection, String remoteExePath,
-			IProgressMonitor monitor) throws Exception {
-		
-		assert(connection!=null);
-		monitor.beginTask(Messages.InfoUpload, 100);
-		
-		IFileService fileService;
-		try {
-			fileService = (IFileService) getConnectedRemoteFileService(
-							connection,
-							new SubProgressMonitor(monitor, 5));
-	
-			Path remotePath = new Path(remoteExePath);
-			if(fileService.getFile(remotePath.removeLastSegments(1).toString(), 
-					remotePath.lastSegment(), 
-					new SubProgressMonitor(monitor, 5)).exists()) {
-				fileService.delete(remotePath.removeLastSegments(1).toString(), 
-						remotePath.lastSegment(), 
-						new SubProgressMonitor(monitor, 10));
-			}
-		} finally {
-			monitor.done();
-		}
-		return;
-	}
-	
-	public static void putRemoteFile(IHost connection, String localExePath, String remoteExePath,
-			IProgressMonitor monitor) throws Exception {
-		
-		assert(connection!=null);
-		monitor.beginTask(Messages.InfoUpload, 100);
-		
-		IFileService fileService;
-		try {
-			fileService = (IFileService) getConnectedRemoteFileService(
-							connection,
-							new SubProgressMonitor(monitor, 5));
-			File file = new File(localExePath);
-			Path remotePath = new Path(remoteExePath);
-			if(fileService.getFile(remotePath.removeLastSegments(1).toString(), 
-					remotePath.lastSegment(), 
-					new SubProgressMonitor(monitor, 5)).exists()) {
-				fileService.delete(remotePath.removeLastSegments(1).toString(), 
-						remotePath.lastSegment(), 
-						new SubProgressMonitor(monitor, 10));
-			}
-			fileService.upload(file, remotePath.removeLastSegments(1)
-					.toString(), remotePath.lastSegment(), true, null, null,
-					new SubProgressMonitor(monitor, 80));
-			// Need to change the permissions to match the original file
-			// permissions because of a bug in upload
-			//RemoteApplication p = remoteShellExec(
-			//		config,
-			//		"", "chmod", "+x " + spaceEscapify(remotePath.toString()), new SubProgressMonitor(monitor, 5)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-			//Thread.sleep(500);
-			//p.destroy();
-			
-		} finally {
-			monitor.done();
-		}
-		return;
-	}
-	
-	public static void putRemoteFileInPlugin(IHost connection, String locaPathInPlugin, String remoteExePath,
-			IProgressMonitor monitor) throws Exception {
-		
-		assert(connection!=null);
-		monitor.beginTask(Messages.InfoUpload, 100);
-		
-		IFileService fileService;
-		try {
-			fileService = (IFileService) getConnectedRemoteFileService(
-							connection,
-							new SubProgressMonitor(monitor, 5));
-			InputStream  inputStream = FileLocator.openStream(
-				    Activator.getDefault().getBundle(), new Path(locaPathInPlugin), false);
-			Path remotePath = new Path(remoteExePath);
-			/*
-			if(!fileService.getFile(remotePath.removeLastSegments(1).toString(), 
-					remotePath.lastSegment(), 
-					new SubProgressMonitor(monitor, 5)).exists()) {
-			}
-			*/
-			/*
-			fileService.upload(inputStream, remotePath.removeLastSegments(1)
-					.toString(), remotePath.lastSegment(), true, null,
-					new SubProgressMonitor(monitor, 80));
-					*/
-			//TODO workaround for now
-			//in case the underlying scp file service doesn't support inputStream upload
-			BufferedInputStream bis = new BufferedInputStream(inputStream);
-			File tempFile = File.createTempFile("scp", "temp"); //$NON-NLS-1$ //$NON-NLS-2$
-			FileOutputStream os = new FileOutputStream(tempFile);
-			BufferedOutputStream bos = new BufferedOutputStream(os);
-			byte[] buffer = new byte[1024];
-			int readCount;
-			while( (readCount = bis.read(buffer)) > 0)
-			{
-				bos.write(buffer, 0, readCount);
-			}
-			bos.close();
-			fileService.upload(tempFile, remotePath.removeLastSegments(1)
-					.toString(), remotePath.lastSegment(), true, null, null,
-					new SubProgressMonitor(monitor, 80));
-			// Need to change the permissions to match the original file
-			// permissions because of a bug in upload
-			remoteShellExec(
-					connection,
-					"", "chmod", "+x " + spaceEscapify(remotePath.toString()), new SubProgressMonitor(monitor, 5)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-			
-		} finally {
-			monitor.done();
-		}
-		return;
-	}
-	
-	public static void getRemoteFile(IHost connection, String localExePath, String remoteExePath,
-			IProgressMonitor monitor) throws Exception {
-		
-		assert(connection!=null);
-		monitor.beginTask(Messages.InfoDownload, 100);
-		
-		IFileService fileService;
-		try {
-			fileService = (IFileService) getConnectedRemoteFileService(
-							connection,
-							new SubProgressMonitor(monitor, 10));
-			File file = new File(localExePath);
-			file.deleteOnExit();
-			monitor.worked(5);
-			Path remotePath = new Path(remoteExePath);
-			fileService.download(remotePath.removeLastSegments(1).toString(), 
-					remotePath.lastSegment(),file,true, null,
-					new SubProgressMonitor(monitor, 85));
-			// Need to change the permissions to match the original file
-			// permissions because of a bug in upload
-			//RemoteApplication p = remoteShellExec(
-			//		config,
-			//		"", "chmod", "+x " + spaceEscapify(remotePath.toString()), new SubProgressMonitor(monitor, 5)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-			//Thread.sleep(500);
-			//p.destroy();
-			
-		} finally {
-			monitor.done();
-		}
-		return;
-	}
-	
-	public static ITerminalServiceSubSystem getTerminalSubSystem(
-            IHost connection) {
-        ISystemRegistry systemRegistry = RSECorePlugin.getTheSystemRegistry();
-        ISubSystem[] subsystems = systemRegistry.getSubSystems(connection);
-        for (int i = 0; i < subsystems.length; i++) {
-        	if (subsystems[i] instanceof ITerminalServiceSubSystem) {
-                ITerminalServiceSubSystem subSystem = (ITerminalServiceSubSystem) subsystems[i];
-                return subSystem;
-            }
-        }
-        return null;
-    }
-	
-	public static String spaceEscapify(String inputString) {
-		if (inputString == null)
-			return null;
-
-		return inputString.replaceAll(" ", "\\\\ "); //$NON-NLS-1$ //$NON-NLS-2$
-	}
-	
-	private final static String EXIT_CMD = "exit"; //$NON-NLS-1$
-	private final static String CMD_DELIMITER = ";"; //$NON-NLS-1$
-	
-	public static Process remoteShellExec(IHost connection,
-			String prelaunchCmd, String remoteCommandPath, String arguments,
-			IProgressMonitor monitor) throws CoreException {
-		
-		monitor.beginTask(NLS.bind(Messages.RemoteShellExec_1,
-				remoteCommandPath, arguments), 10);
-		String realRemoteCommand = arguments == null ? spaceEscapify(remoteCommandPath)
-				: spaceEscapify(remoteCommandPath) + " " + arguments; //$NON-NLS-1$
-
-		String remoteCommand = realRemoteCommand + CMD_DELIMITER + EXIT_CMD;
-
-		if(prelaunchCmd != null) {
-			if (!prelaunchCmd.trim().equals("")) //$NON-NLS-1$
-				remoteCommand = prelaunchCmd + CMD_DELIMITER + remoteCommand;
-		}
-
-		IShellService shellService;
-		Process p = null;
-		try {
-			shellService = (IShellService) getConnectedShellService(
-							connection,
-							new SubProgressMonitor(monitor, 7));
-
-			// This is necessary because runCommand does not actually run the
-			// command right now.
-			String env[] = new String[0];
-			try {
-				IHostShell hostShell = shellService.launchShell(
-						"", env, new SubProgressMonitor(monitor, 3)); //$NON-NLS-1$
-				hostShell.writeToShell(remoteCommand);
-				p = new HostShellProcessAdapter(hostShell);
-			} catch (Exception e) {
-				if (p != null) {
-					p.destroy();
-				}
-				abort(Messages.RemoteShellExec_2, e,
-						IRSECoreStatusCodes.EXCEPTION_OCCURRED);
-			}
-		} catch (Exception e1) {
-			abort(e1.getMessage(), e1,
-					IRSECoreStatusCodes.EXCEPTION_OCCURRED);
-		}
-
-		monitor.done();
-		return p;
-	}
-	
-	/**
-	 * Throws a core exception with an error status object built from the given
-	 * message, lower level exception, and error code.
-	 * 
-	 * @param message
-	 *            the status message
-	 * @param exception
-	 *            lower level exception associated with the error, or
-	 *            <code>null</code> if none
-	 * @param code
-	 *            error code
-	 */
-	public static void abort(String message, Throwable exception, int code) throws CoreException {
-		IStatus status;
-		if (exception != null) {
-			MultiStatus multiStatus = new MultiStatus(Activator.PLUGIN_ID, code, message, exception);
-			multiStatus.add(new Status(IStatus.ERROR, Activator.PLUGIN_ID, code, exception.getLocalizedMessage(), exception));
-			status= multiStatus;
-		} else {
-			status= new Status(IStatus.ERROR, Activator.PLUGIN_ID, code, message, null);
-		}
-		throw new CoreException(status);
-	}
-
-	public static boolean isHostViable(IHost host) {
-		IRSESystemType sysType = host.getSystemType();
-		if (sysType != null && sysType.isEnabled() && !sysType.isLocal())
-			return true;
-		return false;
-	}
-
-	public static void waitForRSEInitCompletition() {
-		if (!RSECorePlugin.isInitComplete(RSECorePlugin.INIT_MODEL))
-			try {
-				RSECorePlugin.waitForInitCompletion(RSECorePlugin.INIT_MODEL);
-			} catch (InterruptedException e) {
-				return;
-			}
-	}
-}
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/BaseModel.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/BaseModel.java
index 2e15e48..08cb873 100644
--- a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/BaseModel.java
+++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/BaseModel.java
@@ -18,7 +18,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.SubProgressMonitor;
 import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.rse.core.model.IHost;
-import org.yocto.sdk.remotetools.RSEHelper;
+import org.yocto.remote.utils.RSEHelper;
 import org.yocto.sdk.remotetools.remote.RemoteShellExec;
 
 abstract public class BaseModel implements IRunnableWithProgress {
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/BaseSettingDialog.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/BaseSettingDialog.java
index 962a20a..7845959 100644
--- a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/BaseSettingDialog.java
+++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/BaseSettingDialog.java
@@ -21,9 +21,9 @@
 
 package org.yocto.sdk.remotetools.actions;
 
+import org.yocto.remote.utils.RSEHelper;
 import org.yocto.sdk.remotetools.Messages;
 import org.yocto.sdk.remotetools.SWTFactory;
-import org.yocto.sdk.remotetools.RSEHelper;
 import org.eclipse.jface.dialogs.Dialog;
 import org.eclipse.jface.dialogs.IDialogConstants;
 import org.eclipse.rse.core.model.IHost;
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/TerminalHandler.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/TerminalHandler.java
index 9e7c169..4ad8688 100644
--- a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/TerminalHandler.java
+++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/TerminalHandler.java
@@ -33,8 +33,8 @@ import org.eclipse.swt.events.DisposeListener;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.tm.internal.terminal.control.ITerminalViewControl;
 import org.eclipse.tm.internal.terminal.provisional.api.ITerminalConnector;
+import org.yocto.remote.utils.RSEHelper;
 import org.yocto.sdk.remotetools.CommonHelper;
-import org.yocto.sdk.remotetools.RSEHelper;
 
 abstract public class TerminalHandler extends AbstractHandler {
 	
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/remote/RemoteShellExec.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/remote/RemoteShellExec.java
index bb4859d..bfcbbfc 100644
--- a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/remote/RemoteShellExec.java
+++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/remote/RemoteShellExec.java
@@ -22,7 +22,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
 //import org.eclipse.tcf.services.IProcesses;
 //import org.eclipse.tcf.util.TCFTask;
 import org.eclipse.rse.core.model.IHost;
-import org.yocto.sdk.remotetools.RSEHelper;
+import org.yocto.remote.utils.RSEHelper;
 
 public class RemoteShellExec {
 	
-- 
1.7.9.5



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 2/7] Move RemoteShellExec to separate plugin
  2013-05-08 17:44 [PATCH v2 0/7] Initial commit & functionalities for org.yocto.remote.utils Ioana Grigoropol
  2013-05-08 17:44 ` [PATCH v2 1/7] Move RSEHelper to a separate plugin Ioana Grigoropol
@ 2013-05-08 17:44 ` Ioana Grigoropol
  2013-05-08 17:44 ` [PATCH v2 3/7] Move ShellSession to org.yocto.remote.utils " Ioana Grigoropol
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Ioana Grigoropol @ 2013-05-08 17:44 UTC (permalink / raw)
  To: yocto

- RemoteShellExec is a wrapper over a remote executiong of a command in a shell and it belongs to org.yocto.remote.utils plugin
- remove RemoteShellExec from remotetools plugin and add it to org.yocto.remote.utils
- modify org.yocto.sdk.remotetools to use implementation from org.yocto.remote.utils

Signed-off-by: Ioana Grigoropol <ioanax.grigoropol@intel.com>
---
 .../org/yocto/remote/utils/RemoteShellExec.java    |  140 ++++++++++++++++++
 .../yocto/sdk/remotetools/actions/BaseModel.java   |    2 +-
 .../sdk/remotetools/remote/RemoteShellExec.java    |  149 --------------------
 3 files changed, 141 insertions(+), 150 deletions(-)
 create mode 100644 plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/RemoteShellExec.java
 delete mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/remote/RemoteShellExec.java

diff --git a/plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/RemoteShellExec.java b/plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/RemoteShellExec.java
new file mode 100644
index 0000000..48b4f4d
--- /dev/null
+++ b/plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/RemoteShellExec.java
@@ -0,0 +1,140 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Intel Corporation.
+ * 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:
+ * Intel - initial API and implementation
+ *******************************************************************************/
+package org.yocto.remote.utils;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.rse.core.model.IHost;
+
+public class RemoteShellExec {
+
+	public static final int
+    STATE_NULL = 0,
+    STATE_RUNNING = 1,
+    STATE_EXITED = 2;
+
+	private final String command;
+	private final IHost host;
+
+	private InputStream fInStream;
+    private OutputStream fOutStream;
+    private InputStream fErrStream;
+    private Process remoteShellProcess;
+
+	private int exitCode = 0;
+	private int status = STATE_NULL;
+
+	private final String RETURN_VALUE_TAG = "org.yocto.sdk.remotetools.RVTAG";
+	private final String RETURN_VALUE_CMD = ";echo \"" + RETURN_VALUE_TAG + "$?\"";
+
+	public RemoteShellExec(IHost host, String command) {
+		assert(host != null);
+		this.host = host;
+		this.command = command;
+	}
+
+	public int getStatus() {
+		return status;
+	}
+
+	public int getExitCode() {
+		return exitCode;
+	}
+
+	private void reset() {
+		fInStream = null;
+		fOutStream = null;
+		fErrStream = null;
+
+		remoteShellProcess = null;
+		exitCode = 0;
+		status = STATE_NULL;
+	}
+
+	public InputStream getInputStream() {
+        return fInStream;
+    }
+
+    public OutputStream getOutputStream() {
+        return fOutStream;
+    }
+
+    public InputStream getErrStream() {
+        return fErrStream;
+    }
+
+	public synchronized void start(String prelaunchCmd, String argument, IProgressMonitor monitor) throws Exception {
+		if(status == STATE_RUNNING)
+				return;
+
+		reset();
+		argument = (argument == null ? RETURN_VALUE_CMD : argument + RETURN_VALUE_CMD);
+		remoteShellProcess = RSEHelper.remoteShellExec(this.host, prelaunchCmd, this.command, argument, monitor);
+		fInStream = remoteShellProcess.getInputStream();
+		fOutStream = remoteShellProcess.getOutputStream();
+		fErrStream = remoteShellProcess.getErrorStream();
+		status = STATE_RUNNING;
+	}
+
+	 public synchronized void terminate() throws Exception {
+		 if(status != STATE_RUNNING || remoteShellProcess != null)
+			 return;
+
+		 remoteShellProcess.destroy();
+		 reset();
+	 }
+
+	 public int waitFor(IProgressMonitor monitor) throws InterruptedException {
+		 while(status == STATE_RUNNING) {
+			 if(monitor != null) {
+	    			if(monitor.isCanceled()) {
+	    				throw new InterruptedException("User Cancelled");
+	    			}
+ 			 }
+
+			 try {
+				 remoteShellProcess.waitFor();
+			 }catch(InterruptedException e){
+				 //get the return value
+				 try {
+					 if(fInStream.available() != 0) {
+						 BufferedReader in = new BufferedReader(new InputStreamReader(fInStream));
+						 String thisline;
+						 int idx;
+						 while((thisline = in.readLine()) != null) {
+							    if(thisline.indexOf(RETURN_VALUE_CMD) == -1) {
+									idx = thisline.indexOf(RETURN_VALUE_TAG);
+									if(idx != -1) {
+										try {
+											exitCode=(new Integer(thisline.substring(idx+RETURN_VALUE_TAG.length()))).intValue();
+										}catch(NumberFormatException e2) {
+										}
+										break;
+									}
+							    }
+						 }
+					 }
+				 }catch(IOException e1) {
+					 //do nothing
+				 }
+			 }finally {
+				 status=STATE_EXITED;
+			 }
+		 }
+		 return exitCode;
+	 }
+}
+
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/BaseModel.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/BaseModel.java
index 08cb873..dacd192 100644
--- a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/BaseModel.java
+++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/BaseModel.java
@@ -19,7 +19,7 @@ import org.eclipse.core.runtime.SubProgressMonitor;
 import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.rse.core.model.IHost;
 import org.yocto.remote.utils.RSEHelper;
-import org.yocto.sdk.remotetools.remote.RemoteShellExec;
+import org.yocto.remote.utils.RemoteShellExec;
 
 abstract public class BaseModel implements IRunnableWithProgress {
 	protected IHost host;
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/remote/RemoteShellExec.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/remote/RemoteShellExec.java
deleted file mode 100644
index bfcbbfc..0000000
--- a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/remote/RemoteShellExec.java
+++ /dev/null
@@ -1,149 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Intel Corporation.
- * 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:
- * Intel - initial API and implementation
- *******************************************************************************/
-package org.yocto.sdk.remotetools.remote;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-//import org.eclipse.tcf.protocol.IToken;
-//import org.eclipse.tcf.services.IStreams;
-//import org.eclipse.tcf.services.IProcesses;
-//import org.eclipse.tcf.util.TCFTask;
-import org.eclipse.rse.core.model.IHost;
-import org.yocto.remote.utils.RSEHelper;
-
-public class RemoteShellExec {
-	
-	public static final int
-    STATE_NULL = 0,
-    STATE_RUNNING = 1,
-    STATE_EXITED = 2;
-	
-	private String command;
-	private IHost host;
-	
-	private InputStream fInStream;
-    private OutputStream fOutStream;
-    private InputStream fErrStream;
-    private Process remoteShellProcess;
-	
-	private int exit_code=0;
-	private int status=STATE_NULL;
-	
-	private String RETURN_VALUE_TAG = "org.yocto.sdk.remotetools.RVTAG";
-	private String RETURN_VALUE_CMD = ";echo \"" + RETURN_VALUE_TAG + "$?\"";
-	
-	public RemoteShellExec(IHost host, String command) {
-		assert(host != null);
-		this.host = host;
-		this.command=command;
-	}
-	
-	public int getStatus()
-	{
-		return status;
-	}
-	
-	public int getExitCode()
-	{
-		return exit_code;
-	}
-	
-	private void reset() {
-		fInStream=null;
-		fOutStream=null;
-		fErrStream=null;
-		
-		remoteShellProcess=null;
-		exit_code=0;
-		status=STATE_NULL;
-	}
-	
-	public InputStream getInputStream() {
-        return fInStream;
-    }
-
-    public OutputStream getOutputStream() {
-        return fOutStream;
-    }
-    
-    public InputStream getErrStream() {
-        return fErrStream;
-    }
-    
-	public synchronized void start(String prelaunchCmd, String argument, IProgressMonitor monitor) throws Exception {
-		if(status == STATE_RUNNING)
-				return;
-	
-		reset();
-		argument = (argument == null ? RETURN_VALUE_CMD : argument + RETURN_VALUE_CMD);
-		remoteShellProcess = RSEHelper.remoteShellExec(this.host, prelaunchCmd, this.command, argument, monitor);
-		fInStream = remoteShellProcess.getInputStream();
-		fOutStream = remoteShellProcess.getOutputStream();
-		fErrStream = remoteShellProcess.getErrorStream();
-		status = STATE_RUNNING;
-	}
-	
-	 public synchronized void terminate() throws Exception {
-		 
-		 if(status != STATE_RUNNING || remoteShellProcess != null)
-			 return;
-		 
-		 remoteShellProcess.destroy();
-		 reset();
-	 }
-	 
-	 public int waitFor(IProgressMonitor monitor) throws InterruptedException {
-		 while(status==STATE_RUNNING) {
-			 if(monitor!=null) {
-	    			if(monitor.isCanceled()) {
-	    				throw new InterruptedException("User Cancelled");
-	    			}
- 			 }
-			 
-			 try {
-				 remoteShellProcess.waitFor();
-			 }catch(InterruptedException e){
-				 //get the return value
-				 try {
-					 if(fInStream.available() != 0) {
-						 BufferedReader in=new BufferedReader(new InputStreamReader(fInStream));
-						 String thisline;
-						 int idx;
-						 while((thisline=in.readLine()) != null) {
-							    if(thisline.indexOf(RETURN_VALUE_CMD)==-1) {
-									idx=thisline.indexOf(RETURN_VALUE_TAG);
-									if(idx != -1) {
-										try {
-											exit_code=(new Integer(thisline.substring(idx+RETURN_VALUE_TAG.length()))).intValue();
-										}catch(NumberFormatException e2) {
-											//
-										}
-										break;
-									}
-							    }
-						 }
-					 }
-				 }catch(IOException e1) {
-					 //do nothing
-				 }
-			 }finally {
-				 status=STATE_EXITED;
-			 }
-		 }
-		 return exit_code;
-	 }
-}
-
-- 
1.7.9.5



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 3/7] Move ShellSession to org.yocto.remote.utils separate plugin
  2013-05-08 17:44 [PATCH v2 0/7] Initial commit & functionalities for org.yocto.remote.utils Ioana Grigoropol
  2013-05-08 17:44 ` [PATCH v2 1/7] Move RSEHelper to a separate plugin Ioana Grigoropol
  2013-05-08 17:44 ` [PATCH v2 2/7] Move RemoteShellExec to " Ioana Grigoropol
@ 2013-05-08 17:44 ` Ioana Grigoropol
  2013-05-08 17:44 ` [PATCH v2 4/7] Move CommonHelper " Ioana Grigoropol
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Ioana Grigoropol @ 2013-05-08 17:44 UTC (permalink / raw)
  To: yocto

- ShellSession is used as a wrapper for a remote shell used for running commands on a remote machine with bitbake environment
- move ShellSession org.yocto.remote.plugin since it is part of remote utilities
- remove shell session class from remotetools plugin
- modify org.yocto.sdk.remotetools to use implementation from org.yocto.remote.utils

Signed-off-by: Ioana Grigoropol <ioanax.grigoropol@intel.com>
---
 .../src/org/yocto/remote/utils/ShellSession.java   |  327 +++++++++++++++++++
 .../org/yocto/sdk/remotetools/ShellSession.java    |  341 --------------------
 .../sdk/remotetools/actions/SystemtapModel.java    |    2 +-
 3 files changed, 328 insertions(+), 342 deletions(-)
 create mode 100644 plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/ShellSession.java
 delete mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/ShellSession.java

diff --git a/plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/ShellSession.java b/plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/ShellSession.java
new file mode 100644
index 0000000..751933f
--- /dev/null
+++ b/plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/ShellSession.java
@@ -0,0 +1,327 @@
+/*****************************************************************************
+ * Copyright (c) 2009 Ken Gilmer
+ * 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:
+ *     Ken Gilmer - initial API and implementation
+ *     Jessica Zhang - Adopt for Yocto Tools plugin
+ *******************************************************************************/
+package org.yocto.remote.utils;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.lang.reflect.InvocationTargetException;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.jface.dialogs.MessageDialog;
+
+public class ShellSession {
+	/**
+	 * Bash shell
+	 */
+	public static final int SHELL_TYPE_BASH = 1;
+	/**
+	 * sh shell
+	 */
+	public static final int SHELL_TYPE_SH = 2;
+	private volatile boolean interrupt = false;
+	/**
+	 * String used to isolate command execution
+	 */
+	public static final String TERMINATOR = "build$";
+	public static final String LT = System.getProperty("line.separator");
+	private Process process;
+
+	private OutputStream pos = null;
+
+	private String shellPath = null;
+	private final String initCmd;
+	private final File root;
+
+	private OutputStreamWriter out;
+
+	public static String getFilePath(String file) throws IOException {
+		File f = new File(file);
+
+		if (!f.exists() || f.isDirectory()) {
+			throw new IOException("Path passed is not a file: " + file);
+		}
+
+		StringBuffer sb = new StringBuffer();
+
+		String elems[] = file.split(File.separator);
+
+		for (int i = 0; i < elems.length - 1; ++i) {
+			sb.append(elems[i]);
+			sb.append(File.separator);
+		}
+
+		return sb.toString();
+	}
+
+	public ShellSession(int shellType, File root, String initCmd, OutputStream out) throws IOException {
+		this.root = root;
+		this.initCmd  = initCmd;
+		if (out == null) {
+			this.out = new OutputStreamWriter(null);
+		} else {
+			this.out = new OutputStreamWriter(out);
+		}
+		if (shellType == SHELL_TYPE_SH) {
+			shellPath = "/bin/sh";
+		}
+		shellPath  = "/bin/bash";
+
+		initializeShell();
+	}
+
+	private void initializeShell() throws IOException {
+		process = Runtime.getRuntime().exec(shellPath);
+		pos = process.getOutputStream();
+
+		if (root != null) {
+			execute("cd " + root.getAbsolutePath());
+		}
+
+		if (initCmd != null) {
+			execute("source " + initCmd);
+		}
+	}
+
+	synchronized
+	public String execute(String command, int[] retCode) throws IOException {
+		String errorMessage = null;
+
+		interrupt = false;
+		out.write(command);
+		out.write(LT);
+
+		sendToProcessAndTerminate(command);
+
+		if (process.getErrorStream().available() > 0) {
+			byte[] msg = new byte[process.getErrorStream().available()];
+
+			process.getErrorStream().read(msg, 0, msg.length);
+			String msg_str = new String(msg);
+			out.write(msg_str);
+			out.write(LT);
+			if (!msg_str.contains("WARNING"))
+				errorMessage = "Error while executing: " + command + LT + new String(msg);
+		}
+
+		BufferedReader br = new BufferedReader(new InputStreamReader(process
+				.getInputStream()));
+
+		StringBuffer sb = new StringBuffer();
+		String line = null;
+
+		while (true) {
+			line = br.readLine();
+			if (line != null) {
+				sb.append(line);
+				sb.append(LT);
+				out.write(line);
+				out.write(LT);
+			}
+			if (line.endsWith(TERMINATOR))
+				break;
+		}
+ 		if (interrupt) {
+			process.destroy();
+			initializeShell();
+			interrupt = false;
+		}else if (line != null && retCode != null) {
+			try {
+				retCode[0]=Integer.parseInt(line.substring(0,line.lastIndexOf(TERMINATOR)));
+			}catch (NumberFormatException e) {
+				throw new IOException("Can NOT get return code" + command + LT + line);
+			}
+		}
+		out.flush();
+		if (errorMessage != null) {
+			throw new IOException(errorMessage);
+		}
+		return sb.toString();
+	}
+
+	synchronized
+	public void execute(String command) throws IOException {
+		interrupt = false;
+		String errorMessage = null;
+
+		sendToProcessAndTerminate(command);
+		boolean cancel = false;
+		try {
+			InputStream is = process.getInputStream();
+			InputStream es = process.getErrorStream();
+			String info;
+			while (!cancel) {
+				info = null;
+				StringBuffer buffer = new StringBuffer();
+				int c;
+				while (is.available() > 0) {
+					c = is.read();
+					char ch = (char) c;
+					buffer.append(ch);
+					if (ch == '\n') {
+						info = buffer.toString();
+						if (!info.trim().endsWith(TERMINATOR)) {
+							out.write(info);
+							out.write(LT);
+							buffer.delete(0, buffer.length());
+						} else {
+							cancel = true;
+							break;
+						}
+					}
+				}
+				while (es.available() > 0) {
+					c = es.read();
+					char ch = (char) c;
+					buffer.append(ch);
+					if (ch == '\n') {
+						info = buffer.toString();
+						if (!info.contains("WARNING"))
+							errorMessage += info;
+						out.write(info);
+						out.write(LT);
+						buffer.delete(0, buffer.length());
+					}
+				}
+			}
+		} catch (IOException e) {
+			try {
+				throw new InvocationTargetException(e);
+			} catch (InvocationTargetException e1) {
+				e1.printStackTrace();
+			}
+		}
+		out.flush();
+		if (errorMessage != null) {
+			throw new IOException(errorMessage);
+		}
+		if (interrupt) {
+			process.destroy();
+			initializeShell();
+			interrupt = false;
+		}
+	}
+	synchronized
+	public boolean ensureKnownHostKey(String user, String host) throws IOException {
+
+		boolean loadKeysMatch = false;
+		boolean accepted = false;
+		Process proc = Runtime.getRuntime().exec("ssh -o LogLevel=DEBUG3 " + user + "@" + host);
+		Pattern patternLoad = Pattern.compile("^debug3: load_hostkeys: loaded (\\d+) keys");
+		Pattern patternAuthSucceeded = Pattern.compile("^debug1: Authentication succeeded.*");
+
+		try {
+			InputStream es = proc.getErrorStream();
+			String info;
+			while (!loadKeysMatch) {
+				info = null;
+				StringBuffer buffer = new StringBuffer();
+				int c;
+				while (es.available() > 0) {
+					c = es.read();
+					char ch = (char) c;
+					buffer.append(ch);
+					if (ch == '\r') {
+						info = buffer.toString().trim();
+						Matcher m = patternLoad.matcher(info);
+						if(m.matches()) {
+							int keys = new Integer(m.group(1));
+							if (keys == 0) {
+								proc.destroy();
+								accepted = MessageDialog.openQuestion(null, "Host authenticity", "The authenticity of host '" + host + "(" + host + ")' can't be established.\nAre you sure you want to continue connecting ?");
+								if (accepted){
+									proc = Runtime.getRuntime().exec("ssh -o StrictHostKeyChecking=no " + user + "@" + host);//add host key to known_hosts
+									try {
+										Thread.sleep(2000); //wait for process to finish
+									} catch (InterruptedException e) {
+										e.printStackTrace();
+									}
+									proc.destroy();
+								} else {
+									MessageDialog.openError(null, "Host authenticity", "Host key verification failed.");
+								}
+							} else {
+								String errorMsg = "";
+								// wait to check if key is the same and authentication succeeds
+								while (es.available() > 0) {
+									c = es.read();
+									ch = (char) c;
+									buffer.append(ch);
+									if (ch == '\r') {
+										info = buffer.toString().trim();
+										Matcher mAuthS = patternAuthSucceeded.matcher(info);
+										if(mAuthS.matches()) {
+											accepted = true;
+											break;
+										} else {
+											if (!info.startsWith("debug"))
+												errorMsg += info + "\n";
+										}
+										try {
+											Thread.sleep(100);
+										} catch (InterruptedException e) {
+											// TODO Auto-generated catch block
+											e.printStackTrace();
+										}
+										buffer.delete(0, buffer.length());
+									}
+								}
+								if (!accepted && !errorMsg.isEmpty())
+									MessageDialog.openError(null, "Host authenticity", errorMsg);
+							}
+							loadKeysMatch = true;
+							break;
+						}
+						buffer.delete(0, buffer.length());
+					}
+				}
+			}
+			es.close();
+		} catch (IOException e) {
+			try {
+				throw new InvocationTargetException(e);
+			} catch (InvocationTargetException e1) {
+				e1.printStackTrace();
+			}
+		}
+		return accepted;
+	}
+
+	/**
+	 * Send command string to shell process and add special terminator string so
+	 * reader knows when output is complete.
+	 *
+	 * @param command
+	 * @throws IOException
+	 */
+	private void sendToProcessAndTerminate(String command) throws IOException {
+		pos.write(command.getBytes());
+		pos.write(LT.getBytes());
+		pos.flush();
+		pos.write("echo $?".getBytes());
+		pos.write(TERMINATOR.getBytes());
+		pos.write(LT.getBytes());
+		pos.flush();
+	}
+
+	/**
+	 * Interrupt any running processes.
+	 */
+	public void interrupt() {
+		interrupt = true;
+	}
+}
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/ShellSession.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/ShellSession.java
deleted file mode 100644
index 5602798..0000000
--- a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/ShellSession.java
+++ /dev/null
@@ -1,341 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2009 Ken Gilmer
- * 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:
- *     Ken Gilmer - initial API and implementation
- *     Jessica Zhang - Adopt for Yocto Tools plugin
- *******************************************************************************/
-package org.yocto.sdk.remotetools;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.lang.reflect.InvocationTargetException;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.eclipse.jface.dialogs.MessageDialog;
-
-public class ShellSession {
-	/**
-	 * Bash shell
-	 */
-	public static final int SHELL_TYPE_BASH = 1;
-	/**
-	 * sh shell
-	 */
-	public static final int SHELL_TYPE_SH = 2;
-	private volatile boolean interrupt = false;
-	/**
-	 * String used to isolate command execution
-	 */
-	//public static final String TERMINATOR = "#234o987dsfkcqiuwey18837032843259d";
-	public static final String TERMINATOR = "build$";
-	public static final String LT = System.getProperty("line.separator");
-	
-	public static String getFilePath(String file) throws IOException {
-		File f = new File(file);
-		
-		if (!f.exists() || f.isDirectory()) {
-			throw new IOException("Path passed is not a file: " + file);
-		}
-		
-		StringBuffer sb = new StringBuffer();
-		
-		String elems[] = file.split(File.separator);
-		
-		for (int i = 0; i < elems.length - 1; ++i) {
-			sb.append(elems[i]);
-			sb.append(File.separator);
-		}
-		
-		return sb.toString();
-	}
-	private Process process;
-
-	private OutputStream pos = null;
-	
-	private String shellPath = null;
-	private final String initCmd;
-	private final File root;
-	
-	private OutputStreamWriter out;
-	
-
-	public ShellSession(int shellType, File root, String initCmd, OutputStream out) throws IOException {
-		this.root = root;
-		this.initCmd  = initCmd;
-		if (out == null) {
-			this.out = new OutputStreamWriter(null);
-		} else {
-			this.out = new OutputStreamWriter(out);
-		}
-		if (shellType == SHELL_TYPE_SH) {
-			shellPath = "/bin/sh";
-		}
-		shellPath  = "/bin/bash";
-		
-		initializeShell();
-	}
-
-	private void initializeShell() throws IOException {
-		process = Runtime.getRuntime().exec(shellPath);
-		pos = process.getOutputStream();
-		
-		if (root != null) {
-			execute("cd " + root.getAbsolutePath());
-		}
-		
-		if (initCmd != null) {
-			execute("source " + initCmd);
-		}
-	}
-
-	synchronized 
-	public String execute(String command, int[] retCode) throws IOException {
-		String errorMessage = null;
-		
-		interrupt = false;
-		out.write(command);
-		out.write(LT);
-		
-		sendToProcessAndTerminate(command);
-
-		if (process.getErrorStream().available() > 0) {
-			byte[] msg = new byte[process.getErrorStream().available()];
-
-			process.getErrorStream().read(msg, 0, msg.length);
-			String msg_str = new String(msg);
-			out.write(msg_str);
-			out.write(LT);
-			if (!msg_str.contains("WARNING"))
-				errorMessage = "Error while executing: " + command + LT + new String(msg);
-		}
-		
-		BufferedReader br = new BufferedReader(new InputStreamReader(process
-				.getInputStream()));
-
-		StringBuffer sb = new StringBuffer();
-		String line = null;
-
-		while (true) {
-			line = br.readLine();
-			if (line != null) {
-				sb.append(line);
-				sb.append(LT);
-				out.write(line);
-				out.write(LT);
-			}
-			if (line.endsWith(TERMINATOR))
-				break;
-		}
- 		if (interrupt) {
-			process.destroy();
-			initializeShell();
-			interrupt = false;
-		}else if (line != null && retCode != null) {
-			try {
-				retCode[0]=Integer.parseInt(line.substring(0,line.lastIndexOf(TERMINATOR)));
-			}catch (NumberFormatException e) {
-				throw new IOException("Can NOT get return code" + command + LT + line);
-			}
-		}
-		out.flush();
-		if (errorMessage != null) {
-			throw new IOException(errorMessage);
-		}
-		return sb.toString();
-	}
-
-	synchronized 
-	public void execute(String command) throws IOException {
-		interrupt = false;
-		String errorMessage = null;
-		
-		sendToProcessAndTerminate(command);
-		boolean cancel = false;
-		try {
-			InputStream is = process.getInputStream();
-			InputStream es = process.getErrorStream();
-			String info;
-			while (!cancel) {
-				info = null;
-				StringBuffer buffer = new StringBuffer();
-				int c;
-				while (is.available() > 0) {
-					c = is.read();
-					char ch = (char) c;
-					buffer.append(ch);
-					if (ch == '\n') {
-						info = buffer.toString();
-						if (!info.trim().endsWith(TERMINATOR)) {
-							out.write(info);
-							out.write(LT);
-							buffer.delete(0, buffer.length());
-						} else {
-							cancel = true;
-							break;
-						}
-					}
-				}
-				while (es.available() > 0) {
-					c = es.read();
-					char ch = (char) c;
-					buffer.append(ch);
-					if (ch == '\n') {
-						info = buffer.toString();
-						if (!info.contains("WARNING"))
-							errorMessage += info;
-						out.write(info);
-						out.write(LT);
-						buffer.delete(0, buffer.length());
-					}
-				}
-			}
-		} catch (IOException e) {
-			try {
-				throw new InvocationTargetException(e);
-			} catch (InvocationTargetException e1) {
-				e1.printStackTrace();
-			}
-		} 
-		out.flush();
-		if (errorMessage != null) {
-			throw new IOException(errorMessage);
-		}
-		if (interrupt) {
-			process.destroy();
-			initializeShell();
-			interrupt = false;
-		}
-	}
-	synchronized
-	public boolean ensureKnownHostKey(String user, String host) throws IOException {
-
-		boolean loadKeysMatch = false;
-		boolean accepted = false;
-		Process proc = Runtime.getRuntime().exec("ssh -o LogLevel=DEBUG3 " + user + "@" + host);
-		Pattern patternLoad = Pattern.compile("^debug3: load_hostkeys: loaded (\\d+) keys");
-		Pattern patternAuthSucceeded = Pattern.compile("^debug1: Authentication succeeded.*");
-
-		try {
-			InputStream es = proc.getErrorStream();
-			String info;
-			while (!loadKeysMatch) {
-				info = null;
-				StringBuffer buffer = new StringBuffer();
-				int c;
-				while (es.available() > 0) {
-					c = es.read();
-					char ch = (char) c;
-					buffer.append(ch);
-					if (ch == '\r') {
-						info = buffer.toString().trim();
-						Matcher m = patternLoad.matcher(info);
-						if(m.matches()) {
-							int keys = new Integer(m.group(1));
-							if (keys == 0) {
-								proc.destroy();
-								accepted = MessageDialog.openQuestion(null, "Host authenticity", "The authenticity of host '" + host + "(" + host + ")' can't be established.\nAre you sure you want to continue connecting ?");
-								if (accepted){
-									proc = Runtime.getRuntime().exec("ssh -o StrictHostKeyChecking=no " + user + "@" + host);//add host key to known_hosts
-									try {
-										Thread.sleep(2000); //wait for process to finish
-									} catch (InterruptedException e) {
-										e.printStackTrace();
-									}
-									proc.destroy();
-								} else {
-									MessageDialog.openError(null, "Host authenticity", "Host key verification failed.");
-								}
-							} else {
-								String errorMsg = "";
-								// wait to check if key is the same and authentication succeeds
-								while (es.available() > 0) {
-									c = es.read();
-									ch = (char) c;
-									buffer.append(ch);
-									if (ch == '\r') {
-										info = buffer.toString().trim();
-										Matcher mAuthS = patternAuthSucceeded.matcher(info);
-										if(mAuthS.matches()) {
-											accepted = true;
-											break;
-										} else {
-											if (!info.startsWith("debug"))
-												errorMsg += info + "\n";
-										}
-										try {
-											Thread.sleep(100);
-										} catch (InterruptedException e) {
-											// TODO Auto-generated catch block
-											e.printStackTrace();
-										}
-										buffer.delete(0, buffer.length());
-									}
-								}
-								if (!accepted && !errorMsg.isEmpty())
-									MessageDialog.openError(null, "Host authenticity", errorMsg);
-							}
-							loadKeysMatch = true;
-							break;
-						}
-						buffer.delete(0, buffer.length());
-					}
-				}
-			}
-			es.close();
-		} catch (IOException e) {
-			try {
-				throw new InvocationTargetException(e);
-			} catch (InvocationTargetException e1) {
-				e1.printStackTrace();
-			}
-		}
-		return accepted;
-	}
-	
-	private void clearErrorStream(InputStream is) {
-	
-		try {
-			byte b[] = new byte[is.available()];
-			is.read(b);			
-			System.out.println("clearing: " + new String(b));
-		} catch (IOException e) {
-			e.printStackTrace();
-			//Ignore any error
-		}
-	}
-
-	/**
-	 * Send command string to shell process and add special terminator string so
-	 * reader knows when output is complete.
-	 * 
-	 * @param command
-	 * @throws IOException
-	 */
-	private void sendToProcessAndTerminate(String command) throws IOException {
-		pos.write(command.getBytes());
-		pos.write(LT.getBytes());
-		pos.flush();
-		pos.write("echo $?".getBytes());
-		pos.write(TERMINATOR.getBytes());
-		pos.write(LT.getBytes());
-		pos.flush();
-	}
-
-	/**
-	 * Interrupt any running processes.
-	 */
-	public void interrupt() {
-		interrupt = true;
-	}
-}
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SystemtapModel.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SystemtapModel.java
index ed8960d..f443e00 100644
--- a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SystemtapModel.java
+++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SystemtapModel.java
@@ -19,7 +19,7 @@ import org.eclipse.ui.console.ConsolePlugin;
 import org.eclipse.ui.console.IConsole;
 import org.eclipse.ui.console.IConsoleManager;
 import org.eclipse.ui.console.MessageConsole;
-import org.yocto.sdk.remotetools.ShellSession;
+import org.yocto.remote.utils.ShellSession;
 
 public class SystemtapModel extends BaseModel {
 	protected static final String DEFAULT_INIT_SCRIPT = "oe-init-build-env";
-- 
1.7.9.5



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 4/7] Move CommonHelper to org.yocto.remote.utils separate plugin
  2013-05-08 17:44 [PATCH v2 0/7] Initial commit & functionalities for org.yocto.remote.utils Ioana Grigoropol
                   ` (2 preceding siblings ...)
  2013-05-08 17:44 ` [PATCH v2 3/7] Move ShellSession to org.yocto.remote.utils " Ioana Grigoropol
@ 2013-05-08 17:44 ` Ioana Grigoropol
  2013-05-08 17:44 ` [PATCH v2 5/7] Move TerminalHandler to org.yocto.remote.utils Ioana Grigoropol
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Ioana Grigoropol @ 2013-05-08 17:44 UTC (permalink / raw)
  To: yocto

- common helper is better suited to org.yocto.remote.utils since it is used for:
   - running commands
   - displaying error dialogs
- remove common helper from remote tools plugin and add it to a separated plugin
- modify org.yocto.sdk.remotetools to use implementation from org.yocto.remote.utils

Signed-off-by: Ioana Grigoropol <ioanax.grigoropol@intel.com>
---
 .../src/org/yocto/remote/utils/CommonHelper.java   |   46 ++++++++++++++++++++
 .../org/yocto/sdk/remotetools/CommonHelper.java    |   44 -------------------
 .../sdk/remotetools/actions/OprofileModel.java     |    2 +-
 .../actions/SystemtapSettingDialog.java            |    2 +-
 .../sdk/remotetools/actions/TerminalHandler.java   |    2 +-
 5 files changed, 49 insertions(+), 47 deletions(-)
 create mode 100644 plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/CommonHelper.java
 delete mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/CommonHelper.java

diff --git a/plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/CommonHelper.java b/plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/CommonHelper.java
new file mode 100644
index 0000000..c01e866
--- /dev/null
+++ b/plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/CommonHelper.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Intel Corporation.
+ * 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:
+ * Intel - initial API and implementation
+ *******************************************************************************/
+package org.yocto.remote.utils;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.swt.widgets.Display;
+
+public class CommonHelper {
+
+	static public boolean isExecAvail(String exec) {
+		boolean ret = false;
+		try {
+			Process p = Runtime.getRuntime().exec(new String[] {"which", exec});
+			p.waitFor();
+			if(p.exitValue() == 0) {
+				ret = true;
+			}
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return ret;
+	}
+
+	public static void showErrorDialog(final String dialogTitle, final String errorMessage, final String reason) {
+		//needs to be run in the ui thread otherwise swt throws invalid thread access
+		Display.getDefault().syncExec(new Runnable() {
+			@Override
+			public void run() {
+				ErrorDialog.openError(null, dialogTitle, errorMessage,
+						new Status(IStatus.ERROR,Activator.PLUGIN_ID,reason));
+			}
+		});
+
+	}
+
+}
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/CommonHelper.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/CommonHelper.java
deleted file mode 100644
index 72a5dfd..0000000
--- a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/CommonHelper.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Intel Corporation.
- * 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:
- * Intel - initial API and implementation
- *******************************************************************************/
-package org.yocto.sdk.remotetools;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.jface.dialogs.ErrorDialog;
-import org.eclipse.swt.widgets.Display;
-
-public class CommonHelper {
-
-	static public boolean isExecAvail(String exec) {
-		boolean ret=false;	
-		try {
-			Process p=Runtime.getRuntime().exec(new String[] {"which",exec});
-			p.waitFor();
-			if(p.exitValue()==0) {
-				ret=true;
-			}
-		} catch (Exception e) {
-			e.printStackTrace();
-		}
-		return ret;
-	}
-	
-	public static void showErrorDialog(final String dialogTitle, final String errorMessage, final String reason) {
-		//needs to be run in the ui thread otherwise swt throws invalid thread access 
-		Display.getDefault().syncExec(new Runnable() {
-			public void run() {
-				ErrorDialog.openError(null, dialogTitle, errorMessage, new Status(IStatus.ERROR,Activator.PLUGIN_ID,reason));
-			}
-		});
-
-	}
-	
-}
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/OprofileModel.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/OprofileModel.java
index c125df7..7fbe7c6 100644
--- a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/OprofileModel.java
+++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/OprofileModel.java
@@ -21,9 +21,9 @@ import org.eclipse.core.runtime.SubProgressMonitor;
 import org.eclipse.jface.preference.IPreferenceStore;
 import org.eclipse.rse.core.model.IHost;
 import org.eclipse.ui.IWorkbenchWindow;
+import org.yocto.remote.utils.CommonHelper;
 import org.yocto.sdk.ide.YoctoSDKPlugin;
 import org.yocto.sdk.ide.preferences.PreferenceConstants;
-import org.yocto.sdk.remotetools.CommonHelper;
 import org.yocto.sdk.remotetools.LocalJob;
 import org.yocto.sdk.remotetools.Messages;
 
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SystemtapSettingDialog.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SystemtapSettingDialog.java
index 8b4703c..c447569 100644
--- a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SystemtapSettingDialog.java
+++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SystemtapSettingDialog.java
@@ -27,8 +27,8 @@ 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.yocto.remote.utils.CommonHelper;
 import org.yocto.sdk.remotetools.Activator;
-import org.yocto.sdk.remotetools.CommonHelper;
 import org.yocto.sdk.remotetools.Messages;
 import org.yocto.sdk.remotetools.SWTFactory;
 
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/TerminalHandler.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/TerminalHandler.java
index 4ad8688..ae04dc9 100644
--- a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/TerminalHandler.java
+++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/TerminalHandler.java
@@ -33,8 +33,8 @@ import org.eclipse.swt.events.DisposeListener;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.tm.internal.terminal.control.ITerminalViewControl;
 import org.eclipse.tm.internal.terminal.provisional.api.ITerminalConnector;
+import org.yocto.remote.utils.CommonHelper;
 import org.yocto.remote.utils.RSEHelper;
-import org.yocto.sdk.remotetools.CommonHelper;
 
 abstract public class TerminalHandler extends AbstractHandler {
 	
-- 
1.7.9.5



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 5/7] Move TerminalHandler to org.yocto.remote.utils
  2013-05-08 17:44 [PATCH v2 0/7] Initial commit & functionalities for org.yocto.remote.utils Ioana Grigoropol
                   ` (3 preceding siblings ...)
  2013-05-08 17:44 ` [PATCH v2 4/7] Move CommonHelper " Ioana Grigoropol
@ 2013-05-08 17:44 ` Ioana Grigoropol
  2013-05-08 17:44 ` [PATCH v2 6/7] Remove unused TCFTerminalConnectors Ioana Grigoropol
  2013-05-08 17:44 ` [PATCH v2 7/7] Remove all plugin dependencies to RSE APi from remote tools plugin Ioana Grigoropol
  6 siblings, 0 replies; 9+ messages in thread
From: Ioana Grigoropol @ 2013-05-08 17:44 UTC (permalink / raw)
  To: yocto

- move TerminalHandler to separate plugin since it performs actions that are best suited for remote utilities
- remove TerminalHandler from remotetools plugin
- modify org.yocto.sdk.remotetools to use implementation from org.yocto.remote.utils

Signed-off-by: Ioana Grigoropol <ioanax.grigoropol@intel.com>
---
 .../org.yocto.remote.utils/META-INF/MANIFEST.MF    |    9 +-
 .../org/yocto/remote/utils/TerminalHandler.java    |  128 ++++++++++++++++++++
 .../sdk/remotetools/actions/DialogHandler.java     |    1 +
 .../sdk/remotetools/actions/TerminalHandler.java   |  128 --------------------
 4 files changed, 137 insertions(+), 129 deletions(-)
 create mode 100644 plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/TerminalHandler.java
 delete mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/TerminalHandler.java

diff --git a/plugins/org.yocto.remote.utils/META-INF/MANIFEST.MF b/plugins/org.yocto.remote.utils/META-INF/MANIFEST.MF
index 9616484..e7afbd0 100644
--- a/plugins/org.yocto.remote.utils/META-INF/MANIFEST.MF
+++ b/plugins/org.yocto.remote.utils/META-INF/MANIFEST.MF
@@ -11,10 +11,17 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.7
 Import-Package: org.eclipse.rse.core,
  org.eclipse.rse.core.model,
  org.eclipse.rse.core.subsystems,
+ org.eclipse.rse.internal.terminals.ui,
+ org.eclipse.rse.internal.terminals.ui.views,
  org.eclipse.rse.services,
  org.eclipse.rse.services.files,
  org.eclipse.rse.services.shells,
+ org.eclipse.rse.services.terminals,
  org.eclipse.rse.subsystems.files.core.servicesubsystem,
  org.eclipse.rse.subsystems.shells.core.subsystems.servicesubsystem,
- org.eclipse.rse.subsystems.terminals.core
+ org.eclipse.rse.subsystems.terminals.core,
+ org.eclipse.rse.subsystems.terminals.core.elements,
+ org.eclipse.rse.ui,
+ org.eclipse.tm.internal.terminal.control,
+ org.eclipse.tm.internal.terminal.provisional.api
 Export-Package: org.yocto.remote.utils
diff --git a/plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/TerminalHandler.java b/plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/TerminalHandler.java
new file mode 100644
index 0000000..e28ae79
--- /dev/null
+++ b/plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/TerminalHandler.java
@@ -0,0 +1,128 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Intel Corporation.
+ * 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:
+ * Intel - initial API and implementation
+ *******************************************************************************/
+package org.yocto.remote.utils;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.rse.core.model.IHost;
+import org.eclipse.rse.internal.terminals.ui.TerminalServiceHelper;
+import org.eclipse.rse.internal.terminals.ui.views.RSETerminalConnector;
+import org.eclipse.rse.internal.terminals.ui.views.TerminalViewTab;
+import org.eclipse.rse.internal.terminals.ui.views.TerminalViewer;
+import org.eclipse.rse.internal.terminals.ui.views.TerminalsUI;
+import org.eclipse.rse.services.terminals.ITerminalShell;
+import org.eclipse.rse.subsystems.terminals.core.ITerminalServiceSubSystem;
+import org.eclipse.rse.subsystems.terminals.core.elements.TerminalElement;
+import org.eclipse.rse.ui.SystemBasePlugin;
+import org.eclipse.swt.custom.CTabItem;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.tm.internal.terminal.control.ITerminalViewControl;
+import org.eclipse.tm.internal.terminal.provisional.api.ITerminalConnector;
+
+abstract public class TerminalHandler extends AbstractHandler {
+
+
+	protected Shell shell;
+
+	protected String changeTerm = "export TERM=vt100;";
+
+	abstract protected String getInitCmd();
+	abstract protected String getConnnectionName();
+	abstract protected String getDialogTitle();
+
+	protected ITerminalShell getTerminalShellFromTab(CTabItem item) {
+        ITerminalShell terminalShell = null;
+        ITerminalViewControl terminalViewControl = (ITerminalViewControl) item
+                .getData(TerminalViewTab.DATA_KEY_CONTROL);
+        ITerminalConnector terminalConnector = terminalViewControl
+                .getTerminalConnector();
+        if (terminalConnector instanceof RSETerminalConnector) {
+            RSETerminalConnector rseTerminalConnector = (RSETerminalConnector) terminalConnector;
+            terminalShell = rseTerminalConnector.getTerminalHostShell();
+        }
+        return terminalShell;
+    }
+
+	protected boolean preProcess(final ITerminalServiceSubSystem terminalSubSystem) {
+		if (!terminalSubSystem.isConnected()) {
+			try {
+				ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
+				dialog.run(true, true, new IRunnableWithProgress(){
+				    @Override
+					public void run(IProgressMonitor monitor) {
+				        monitor.beginTask("Connecting to remote target ...", 100);
+				        try {
+				        terminalSubSystem.connect(new NullProgressMonitor(), false);
+				        monitor.done();
+				        } catch (Exception e) {
+				        	CommonHelper.showErrorDialog("Connection failure", null, e.getMessage());
+				        	monitor.done();
+
+				        }
+				    }
+				});
+			} catch (OperationCanceledException e) {
+				// user canceled, return silently
+				return false;
+			} catch (Exception e) {
+				SystemBasePlugin.logError(e.getLocalizedMessage(), e);
+				return false;
+			}
+		} else
+			return true;
+		return false;
+	}
+
+	public void execute(IHost host) throws ExecutionException {
+
+		final ITerminalServiceSubSystem terminalSubSystem = RSEHelper.getTerminalSubSystem(host);
+
+		if (terminalSubSystem != null) {
+			TerminalsUI terminalsUI = TerminalsUI.getInstance();
+			TerminalViewer viewer = terminalsUI.activateTerminalsView();
+			if (preProcess(terminalSubSystem)) {
+				CTabItem tab = viewer.getTabFolder().createTabItem(
+						terminalSubSystem.getHost(), changeTerm + getInitCmd());
+				//since RSETerminalConnector not exit the shell during the diconnection,
+				//we have manually exit it here
+				try {
+					tab.addDisposeListener(new DisposeListener() {
+						@Override
+						public void widgetDisposed(DisposeEvent e) {
+							Object source = e.getSource();
+							if (source instanceof CTabItem) {
+								CTabItem currentItem = (CTabItem) source;
+								ITerminalShell shell=getTerminalShellFromTab(currentItem);
+								if(shell!=null) {
+									shell.exit();
+								}
+							}
+						}
+					});
+				}catch(Exception e) {
+					e.printStackTrace();
+				}
+				TerminalElement element = TerminalServiceHelper
+						.createTerminalElement(tab, terminalSubSystem);
+				terminalSubSystem.addChild(element);
+
+			}
+		}
+	}
+
+}
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/DialogHandler.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/DialogHandler.java
index d5c3583..ca6d13b 100644
--- a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/DialogHandler.java
+++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/DialogHandler.java
@@ -15,6 +15,7 @@ import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.rse.core.model.IHost;
 import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.handlers.HandlerUtil;
+import org.yocto.remote.utils.TerminalHandler;
 
 abstract public class DialogHandler extends TerminalHandler {
 	
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/TerminalHandler.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/TerminalHandler.java
deleted file mode 100644
index ae04dc9..0000000
--- a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/TerminalHandler.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Intel Corporation.
- * 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:
- * Intel - initial API and implementation
- *******************************************************************************/
-package org.yocto.sdk.remotetools.actions;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.OperationCanceledException;
-import org.eclipse.jface.dialogs.ProgressMonitorDialog;
-import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.rse.core.model.IHost;
-import org.eclipse.rse.internal.terminals.ui.TerminalServiceHelper;
-import org.eclipse.rse.internal.terminals.ui.views.RSETerminalConnector;
-import org.eclipse.rse.internal.terminals.ui.views.TerminalViewTab;
-import org.eclipse.rse.internal.terminals.ui.views.TerminalViewer;
-import org.eclipse.rse.internal.terminals.ui.views.TerminalsUI;
-import org.eclipse.rse.services.terminals.ITerminalShell;
-import org.eclipse.rse.subsystems.terminals.core.ITerminalServiceSubSystem;
-import org.eclipse.rse.subsystems.terminals.core.elements.TerminalElement;
-import org.eclipse.rse.ui.SystemBasePlugin;
-import org.eclipse.swt.custom.CTabItem;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.tm.internal.terminal.control.ITerminalViewControl;
-import org.eclipse.tm.internal.terminal.provisional.api.ITerminalConnector;
-import org.yocto.remote.utils.CommonHelper;
-import org.yocto.remote.utils.RSEHelper;
-
-abstract public class TerminalHandler extends AbstractHandler {
-	
-	
-	protected Shell shell;
-	
-	protected String changeTerm="export TERM=vt100;";
-	
-	abstract protected String getInitCmd();
-	abstract protected String getConnnectionName();
-	abstract protected String getDialogTitle();
-	
-	protected ITerminalShell getTerminalShellFromTab(CTabItem item) {
-        ITerminalShell terminalShell = null;
-        ITerminalViewControl terminalViewControl = (ITerminalViewControl) item
-                .getData(TerminalViewTab.DATA_KEY_CONTROL);
-        ITerminalConnector terminalConnector = terminalViewControl
-                .getTerminalConnector();
-        if (terminalConnector instanceof RSETerminalConnector) {
-            RSETerminalConnector rseTerminalConnector = (RSETerminalConnector) terminalConnector;
-            terminalShell = rseTerminalConnector.getTerminalHostShell();
-        }
-        return terminalShell;
-    }
-
-	protected boolean preProcess(final ITerminalServiceSubSystem terminalSubSystem) {
-		if (!terminalSubSystem.isConnected()) {
-			try {
-				ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
-				dialog.run(true, true, new IRunnableWithProgress(){
-				    public void run(IProgressMonitor monitor) {
-				        monitor.beginTask("Connecting to remote target ...", 100);
-				        try {
-				        terminalSubSystem.connect(new NullProgressMonitor(), false);
-				        monitor.done();
-				        } catch (Exception e) {
-				        	CommonHelper.showErrorDialog("Connection failure", null, e.getMessage());
-				        	monitor.done();
-				        	
-				        }
-				    }
-				});
-			} catch (OperationCanceledException e) {
-				// user canceled, return silently
-				return false;
-			} catch (Exception e) {
-				SystemBasePlugin.logError(e.getLocalizedMessage(), e);
-				return false;
-			}
-		} else
-			return true;
-		return false;
-	}
-	
-	public void execute(IHost host) throws ExecutionException {
-		
-		final ITerminalServiceSubSystem terminalSubSystem = RSEHelper.getTerminalSubSystem(host);
-		
-		if (terminalSubSystem != null) {
-			TerminalsUI terminalsUI = TerminalsUI.getInstance();
-			TerminalViewer viewer = terminalsUI.activateTerminalsView();
-			if (preProcess(terminalSubSystem)) {
-				CTabItem tab = viewer.getTabFolder().createTabItem(
-						terminalSubSystem.getHost(), changeTerm + getInitCmd());
-				//since RSETerminalConnector not exit the shell during the diconnection,
-				//we have manually exit it here
-				try {
-					tab.addDisposeListener(new DisposeListener() {
-						public void widgetDisposed(DisposeEvent e) {
-							Object source = e.getSource();
-							if (source instanceof CTabItem) {
-								CTabItem currentItem = (CTabItem) source;
-								ITerminalShell shell=getTerminalShellFromTab(currentItem);
-								if(shell!=null) {
-									shell.exit();
-								}
-							}
-						}
-					});
-				}catch(Exception e) {
-					e.printStackTrace();
-				}
-				TerminalElement element = TerminalServiceHelper
-						.createTerminalElement(tab, terminalSubSystem);
-				terminalSubSystem.addChild(element);
-
-			}
-		}
-	}
-
-}
-- 
1.7.9.5



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 6/7] Remove unused TCFTerminalConnectors
  2013-05-08 17:44 [PATCH v2 0/7] Initial commit & functionalities for org.yocto.remote.utils Ioana Grigoropol
                   ` (4 preceding siblings ...)
  2013-05-08 17:44 ` [PATCH v2 5/7] Move TerminalHandler to org.yocto.remote.utils Ioana Grigoropol
@ 2013-05-08 17:44 ` Ioana Grigoropol
  2013-05-08 17:44 ` [PATCH v2 7/7] Remove all plugin dependencies to RSE APi from remote tools plugin Ioana Grigoropol
  6 siblings, 0 replies; 9+ messages in thread
From: Ioana Grigoropol @ 2013-05-08 17:44 UTC (permalink / raw)
  To: yocto

- removed TCFTerminalConnector and TCFTerminalConnectorImpl since there are no usages of this classes

Signed-off-by: Ioana Grigoropol <ioanax.grigoropol@intel.com>
---
 .../remotetools/views/TCFTerminalConnector.java    |   49 ----------
 .../views/TCFTerminalConnectorImpl.java            |   98 --------------------
 2 files changed, 147 deletions(-)
 delete mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/views/TCFTerminalConnector.java
 delete mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/views/TCFTerminalConnectorImpl.java

diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/views/TCFTerminalConnector.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/views/TCFTerminalConnector.java
deleted file mode 100644
index 6239136..0000000
--- a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/views/TCFTerminalConnector.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/********************************************************************************
- * Copyright (c) 2008, 2009 MontaVista Software, Inc. and others
- * 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:
- * Anna Dushistova (MontaVista) - initial API and implementation
- * Uwe Stieber (Wind River) - [282996] [terminal][api] Add "hidden" attribute to terminal connector extension point
- ********************************************************************************/
-package org.yocto.sdk.remotetools.views;
-
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.rse.core.model.IHost;
-import org.eclipse.tm.internal.terminal.provisional.api.ITerminalConnector;
-
-public class TCFTerminalConnector extends TCFTerminalConnectorImpl implements ITerminalConnector {
-
-    public TCFTerminalConnector(IHost host) {
-		super(host);
-    }
-
-    public String getId() {
-        return "yocto_tcf_internal_connector"; //$NON-NLS-1$
-    }
-
-    public String getInitializationErrorMessage() {
-        return null;
-    }
-
-    public String getName() {
-        return "yocto_tcf_internal_connector";
-    }
-
-    public boolean isHidden() {
-    	return true;
-    }
-
-    public boolean isInitialized() {
-        return true;
-    }
-
-	public Object getAdapter(Class adapterType) {
-		if (adapterType.isInstance(this))
-			return this;
-		return Platform.getAdapterManager().getAdapter(this, adapterType);
-	}
-
-}
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/views/TCFTerminalConnectorImpl.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/views/TCFTerminalConnectorImpl.java
deleted file mode 100644
index 105ca62..0000000
--- a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/views/TCFTerminalConnectorImpl.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/********************************************************************************
- * Copyright (c) 2008 MontaVista Software, Inc.
- * 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:
- * Anna Dushistova (MontaVista) - initial API and implementation
- * Yu-Fen Kuo (MontaVista)      - [227572] RSE Terminal doesn't reset the "connected" state when the shell exits
- * Anna Dushistova (MontaVista) - [228577] [rseterminal] Clean up RSE Terminal impl
- ********************************************************************************/
-package org.yocto.sdk.remotetools.views;
-
-import java.io.InputStream;
-import java.io.OutputStream;
-
-import org.eclipse.rse.core.model.IHost;
-import org.eclipse.tm.internal.terminal.provisional.api.ITerminalControl;
-import org.eclipse.tm.internal.terminal.provisional.api.provider.TerminalConnectorImpl;
-
-public class TCFTerminalConnectorImpl extends TerminalConnectorImpl {
-	
-    private OutputStream fOutputStream;
-    private InputStream fInputStream;
-    IHost host;
-//TODO    private RSETerminalConnectionThread fConnection;
-//TODO    private ITerminalShell shell;
-
-    public TCFTerminalConnectorImpl(IHost host) {
-        super();
-        this.host = host;
-    }
-    /* TODO
-    public void connect(ITerminalControl control) {
-    	super.connect(control);
-        fConnection = new RSETerminalConnectionThread(this, control);
-        fConnection.start();
-    }
-
-    public void doDisconnect() {
-        fConnection.disconnect();
-        if (getInputStream() != null) {
-            try {
-                getInputStream().close();
-            } catch (Exception exception) {
-            	RSECorePlugin.getDefault().getLogger().logError("Error while closing input stream", exception); //$NON-NLS-1$
-            }
-        }
-
-        if (getTerminalToRemoteStream() != null) {
-            try {
-                getTerminalToRemoteStream().close();
-            } catch (Exception exception) {
-            	RSECorePlugin.getDefault().getLogger().logError("Error while closing terminal-to-remote stream", exception); //$NON-NLS-1$
-            }
-        }
-    }
-*/
-    public OutputStream getTerminalToRemoteStream() {
-        return fOutputStream;
-    }
-
-    public String getSettingsSummary() {
-        return "RSE: " + host.getName();
-    }
-/* TODO
-    public boolean isLocalEcho() {
-        return shell.isLocalEcho();
-    }
-
-    public void setTerminalSize(int newWidth, int newHeight) {
-    	if(shell != null)
-    	{	
-            shell.setTerminalSize(newWidth, newHeight);
-    	}    
-    }
-
-    public InputStream getInputStream() {
-        return fInputStream;
-    }
-
-    public void setOutputStream(OutputStream outputStream) {
-        fOutputStream = outputStream;
-    }
-
-    public void setInputStream(InputStream inputStream) {
-        fInputStream = inputStream;
-    }
-
-    public void setTerminalHostShell(ITerminalShell shell) {
-        this.shell = shell;
-    }
-
-    public ITerminalShell getTerminalHostShell() {
-        return shell;
-    }
-*/
-}
-- 
1.7.9.5



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 7/7] Remove all plugin dependencies to RSE APi from remote tools plugin
  2013-05-08 17:44 [PATCH v2 0/7] Initial commit & functionalities for org.yocto.remote.utils Ioana Grigoropol
                   ` (5 preceding siblings ...)
  2013-05-08 17:44 ` [PATCH v2 6/7] Remove unused TCFTerminalConnectors Ioana Grigoropol
@ 2013-05-08 17:44 ` Ioana Grigoropol
  6 siblings, 0 replies; 9+ messages in thread
From: Ioana Grigoropol @ 2013-05-08 17:44 UTC (permalink / raw)
  To: yocto

- removed all plugin dependencies to the RSE API & kept only the ones needed for GUI actions and Terminal views

Signed-off-by: Ioana Grigoropol <ioanax.grigoropol@intel.com>
---
 .../org.yocto.sdk.remotetools/META-INF/MANIFEST.MF |   10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/plugins/org.yocto.sdk.remotetools/META-INF/MANIFEST.MF b/plugins/org.yocto.sdk.remotetools/META-INF/MANIFEST.MF
index c34ad9e..5147c1a 100644
--- a/plugins/org.yocto.sdk.remotetools/META-INF/MANIFEST.MF
+++ b/plugins/org.yocto.sdk.remotetools/META-INF/MANIFEST.MF
@@ -7,16 +7,10 @@ Bundle-Activator: org.yocto.sdk.remotetools.Activator
 Require-Bundle: org.eclipse.ui,
  org.eclipse.core.runtime,
  org.eclipse.rse.core;bundle-version="3.0.0",
- org.eclipse.rse.services;bundle-version="3.0.0",
- org.eclipse.rse.subsystems.files.core;bundle-version="3.0.0",
- org.eclipse.rse.ui;bundle-version="3.0.0",
  org.yocto.sdk.ide,
- org.eclipse.tm.terminal;bundle-version="3.0.1",
- org.eclipse.rse.subsystems.terminals.core;bundle-version="[1.0.0,2.0.0)",
  org.eclipse.rse.terminals.ui;bundle-version="1.0.100",
  org.eclipse.cdt;bundle-version="7.0.0",
  org.eclipse.linuxtools.tmf.core;bundle-version="0.4.0",
- org.eclipse.rse.subsystems.shells.core,
  org.eclipse.ui.ide;bundle-version="3.8.0",
  org.eclipse.ui.console;bundle-version="3.5.100"
 Bundle-ActivationPolicy: lazy
@@ -24,6 +18,10 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Import-Package: org.eclipse.core.resources,
  org.eclipse.debug.internal.ui,
  org.eclipse.rse.shells.ui,
+ org.eclipse.rse.ui.actions,
+ org.eclipse.tm.internal.terminal.control,
+ org.eclipse.tm.internal.terminal.control.actions,
+ org.eclipse.tm.internal.terminal.provisional.api,
  org.eclipse.ui.forms.widgets,
  org.yocto.remote.utils
 Bundle-Vendor: %Bundle-Vendor
-- 
1.7.9.5



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 7/7] Remove all plugin dependencies to RSE APi from remote tools plugin
  2013-05-09  7:46 [PATCH 00/12] Refactor Remote tools plugin & create Remote Utils separate plugin Ioana Grigoropol
@ 2013-05-09  7:47 ` Ioana Grigoropol
  0 siblings, 0 replies; 9+ messages in thread
From: Ioana Grigoropol @ 2013-05-09  7:47 UTC (permalink / raw)
  To: yocto

- removed all plugin dependencies to the RSE API & kept only the ones needed for GUI actions and Terminal views

Signed-off-by: Ioana Grigoropol <ioanax.grigoropol@intel.com>
---
 .../org.yocto.sdk.remotetools/META-INF/MANIFEST.MF |   10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/plugins/org.yocto.sdk.remotetools/META-INF/MANIFEST.MF b/plugins/org.yocto.sdk.remotetools/META-INF/MANIFEST.MF
index c34ad9e..5147c1a 100644
--- a/plugins/org.yocto.sdk.remotetools/META-INF/MANIFEST.MF
+++ b/plugins/org.yocto.sdk.remotetools/META-INF/MANIFEST.MF
@@ -7,16 +7,10 @@ Bundle-Activator: org.yocto.sdk.remotetools.Activator
 Require-Bundle: org.eclipse.ui,
  org.eclipse.core.runtime,
  org.eclipse.rse.core;bundle-version="3.0.0",
- org.eclipse.rse.services;bundle-version="3.0.0",
- org.eclipse.rse.subsystems.files.core;bundle-version="3.0.0",
- org.eclipse.rse.ui;bundle-version="3.0.0",
  org.yocto.sdk.ide,
- org.eclipse.tm.terminal;bundle-version="3.0.1",
- org.eclipse.rse.subsystems.terminals.core;bundle-version="[1.0.0,2.0.0)",
  org.eclipse.rse.terminals.ui;bundle-version="1.0.100",
  org.eclipse.cdt;bundle-version="7.0.0",
  org.eclipse.linuxtools.tmf.core;bundle-version="0.4.0",
- org.eclipse.rse.subsystems.shells.core,
  org.eclipse.ui.ide;bundle-version="3.8.0",
  org.eclipse.ui.console;bundle-version="3.5.100"
 Bundle-ActivationPolicy: lazy
@@ -24,6 +18,10 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Import-Package: org.eclipse.core.resources,
  org.eclipse.debug.internal.ui,
  org.eclipse.rse.shells.ui,
+ org.eclipse.rse.ui.actions,
+ org.eclipse.tm.internal.terminal.control,
+ org.eclipse.tm.internal.terminal.control.actions,
+ org.eclipse.tm.internal.terminal.provisional.api,
  org.eclipse.ui.forms.widgets,
  org.yocto.remote.utils
 Bundle-Vendor: %Bundle-Vendor
-- 
1.7.9.5



^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2013-05-09  8:07 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-08 17:44 [PATCH v2 0/7] Initial commit & functionalities for org.yocto.remote.utils Ioana Grigoropol
2013-05-08 17:44 ` [PATCH v2 1/7] Move RSEHelper to a separate plugin Ioana Grigoropol
2013-05-08 17:44 ` [PATCH v2 2/7] Move RemoteShellExec to " Ioana Grigoropol
2013-05-08 17:44 ` [PATCH v2 3/7] Move ShellSession to org.yocto.remote.utils " Ioana Grigoropol
2013-05-08 17:44 ` [PATCH v2 4/7] Move CommonHelper " Ioana Grigoropol
2013-05-08 17:44 ` [PATCH v2 5/7] Move TerminalHandler to org.yocto.remote.utils Ioana Grigoropol
2013-05-08 17:44 ` [PATCH v2 6/7] Remove unused TCFTerminalConnectors Ioana Grigoropol
2013-05-08 17:44 ` [PATCH v2 7/7] Remove all plugin dependencies to RSE APi from remote tools plugin Ioana Grigoropol
2013-05-09  7:46 [PATCH 00/12] Refactor Remote tools plugin & create Remote Utils separate plugin Ioana Grigoropol
2013-05-09  7:47 ` [PATCH v2 7/7] Remove all plugin dependencies to RSE APi from remote tools plugin Ioana Grigoropol

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.