Skip to contentSkip to conversation

0/8] Split refactoring of RemoteHelper

RFC New Ioana Grigoropol 1 participant 9 messages Jun 7, 2013

lore
Share & tools
lore
#0 lore raw

- this set of patches replaces patch 2/9 from first batch of patches

Ioana Grigoropol (8):
Move ICommandResponseHandler to org.yocto.remote.utils Add YoctoCommand utility class
Add CommandResponseHandler implementation of ICommandResponseHandler Add ConsoleRunnable utility class
Add ConsoleHelper utility class
Add OutputProcessor utility class
Add CommandOutputProcessor utilty class
Refactor RemoteHelper class

 .../yocto/bc/bitbake/ICommandResponseHandler.java  |   15 --
 .../org.yocto.remote.utils/META-INF/MANIFEST.MF    |    8 +-
 .../yocto/remote/utils/CommandOutputProcessor.java |   43 ++++
 .../yocto/remote/utils/CommandResponseHandler.java |   44 ++++
 .../org/yocto/remote/utils/CommandRunnable.java    |   44 ++++
 .../src/org/yocto/remote/utils/ConsoleHelper.java  |   38 +++
 .../org/yocto/remote/utils/ConsoleRunnable.java    |   47 ++++
 .../remote/utils/ICommandResponseHandler.java      |   15 ++
 .../org/yocto/remote/utils/OutputProcessor.java    |  112 +++++++++
 .../src/org/yocto/remote/utils/RemoteHelper.java   |  255 ++++++++++++++++----
 .../src/org/yocto/remote/utils/RemoteMachine.java  |  202 ++++++++++++++++
 .../src/org/yocto/remote/utils/YoctoCommand.java   |   63 +++++
 12 files changed, 822 insertions(+), 64 deletions(-)
 delete mode 100644 plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/ICommandResponseHandler.java
 create mode 100644 plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/CommandOutputProcessor.java
 create mode 100644 plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/CommandResponseHandler.java
 create mode 100644 plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/CommandRunnable.java
 create mode 100644 plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/ConsoleHelper.java
 create mode 100644 plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/ConsoleRunnable.java
 create mode 100644 plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/ICommandResponseHandler.java
 create mode 100644 plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/OutputProcessor.java
 create mode 100644 plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/RemoteMachine.java
 create mode 100644 plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/YoctoCommand.java
Signature · 1 line
1.7.9.5
#1 lore raw

RFC v2 1/1 1/8] Move ICommandResponseHandler to org.yocto.remote.utils

---
 .../yocto/bc/bitbake/ICommandResponseHandler.java  |   15 ---------------
 .../remote/utils/ICommandResponseHandler.java      |   15 +++++++++++++++
 2 files changed, 15 insertions(+), 15 deletions(-)
 delete mode 100644 plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/ICommandResponseHandler.java
 create mode 100644 plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/ICommandResponseHandler.java
plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/ICommandResponseHandler.java deleted +0 -15
deleted file mode 100644
index 4c44352..0000000
@@ -1,15 +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
- *******************************************************************************/
-package org.yocto.bc.bitbake;
-
-public interface ICommandResponseHandler {
-	public void response(String line, boolean isError);
-}
plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/ICommandResponseHandler.java new file +15 -0
new file mode 100644
index 0000000..f135dde
@@ -0,0 +1,15 @@
+/*****************************************************************************
+ * Copyright (c) 2013 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
+ *******************************************************************************/
+package org.yocto.remote.utils;
+
+public interface ICommandResponseHandler {
+	public void response(String line, boolean isError);
+}
Signature · 1 line
1.7.9.5
#2 lore raw

RFC v2 1/1 2/8] Add YoctoCommand utility class

In reply to Ioana Grigoropol

- YoctoCommand wraps all information needed for running a remote command
- the actual command string
- the command arguments
- the directory in which to run the remote command
- a ProcessStreamBuffer that will store the output of running this particular command
- this class will simplify the process of running a remote command by wrapping all needed data into one object

---
 .../src/org/yocto/remote/utils/YoctoCommand.java   |   63 ++++++++++++++++++++
 1 file changed, 63 insertions(+)
 create mode 100644 plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/YoctoCommand.java
plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/YoctoCommand.java new file +63 -0
new file mode 100644
index 0000000..b37d526
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * 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:
+ * Ioana Grigoropol(Intel) - initial API and implementation
+ *******************************************************************************/
+package org.yocto.remote.utils;
+
+
+public class YoctoCommand {
+	private String command;
+	private String initialDirectory;
+	private String arguments;
+	private ProcessStreamBuffer processBuffer;
+
+	public YoctoCommand(String command, String initialDirectory, String arguments){
+		this.setCommand(command);
+		this.setInitialDirectory(initialDirectory);
+		this.setArguments(arguments);
+		this.setProcessBuffer(new ProcessStreamBuffer(false));
+	}
+
+	public String getCommand() {
+		return command;
+	}
+
+	public void setCommand(String command) {
+		this.command = command;
+	}
+
+	public String getInitialDirectory() {
+		return initialDirectory;
+	}
+
+	public void setInitialDirectory(String initialDirectory) {
+		this.initialDirectory = initialDirectory;
+	}
+
+	public String getArguments() {
+		return arguments;
+	}
+
+	public void setArguments(String arguments) {
+		this.arguments = arguments;
+	}
+
+	public ProcessStreamBuffer getProcessBuffer() {
+		return processBuffer;
+	}
+
+	public void setProcessBuffer(ProcessStreamBuffer processBuffer) {
+		this.processBuffer = processBuffer;
+	}
+
+	@Override
+	public String toString() {
+		return command + " " + arguments;
+	}
+}
Signature · 1 line
1.7.9.5
#3 lore raw

RFC v2 1/1 3/8] Add CommandResponseHandler implementation of ICommandResponseHandler

In reply to Ioana Grigoropol

- plain implementation of ICommandResponseHandler interface that prints all lines to the console stream

---
 .../org.yocto.remote.utils/META-INF/MANIFEST.MF    |    3 +-
 .../yocto/remote/utils/CommandResponseHandler.java |   44 ++++++++++++++++++++
 2 files changed, 46 insertions(+), 1 deletion(-)
 create mode 100644 plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/CommandResponseHandler.java
plugins/org.yocto.remote.utils/META-INF/MANIFEST.MF +2 -1
index c7b57fe..e31d557 100644
@@ -23,5 +23,6 @@ Import-Package: org.eclipse.rse.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
+ org.eclipse.tm.internal.terminal.provisional.api,
+ org.eclipse.ui.console
 Export-Package: org.yocto.remote.utils
plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/CommandResponseHandler.java new file +44 -0

45 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#4 lore raw

RFC v2 1/1 4/8] Add ConsoleRunnable utility class

In reply to Ioana Grigoropol

- Console Runnable implements Runnable and is charge to display the specified console in the Console View

---
 .../org/yocto/remote/utils/ConsoleRunnable.java    |   47 ++++++++++++++++++++
 1 file changed, 47 insertions(+)
 create mode 100644 plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/ConsoleRunnable.java
plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/ConsoleRunnable.java new file +47 -0
new file mode 100644
index 0000000..e5fe666
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * 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:
+ * Ioana Grigoropol(Intel) - initial API and implementation
+ *******************************************************************************/
+package org.yocto.remote.utils;
+
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.console.IConsoleConstants;
+import org.eclipse.ui.console.IConsoleView;
+import org.eclipse.ui.console.MessageConsole;
+
+public class ConsoleRunnable implements Runnable{
+	MessageConsole console;
+	ConsoleRunnable (MessageConsole console){
+		this.console = console;
+	}
+	@Override
+	public void run() {
+		IWorkbench wb = PlatformUI.getWorkbench();
+		if (wb == null)
+			return;
+		IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
+		if (win == null)
+			return;
+		IWorkbenchPage page = win.getActivePage();
+		if (page == null)
+			return;
+		String id = IConsoleConstants.ID_CONSOLE_VIEW;
+		try {
+			IConsoleView view = (IConsoleView) page.showView(id);
+			if (view == null)
+				return;
+			view.display(console);
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+	}
+}
\ No newline at end of file
Signature · 1 line
1.7.9.5
#5 lore raw

RFC v2 1/1 5/8] Add ConsoleHelper utility class

In reply to Ioana Grigoropol

- ConsoleHelper class is to be used in order to find a console by a specified name and display it in the view (using ConsoleRunnble) on the GUI thread

---
 .../src/org/yocto/remote/utils/ConsoleHelper.java  |   38 ++++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100644 plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/ConsoleHelper.java
plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/ConsoleHelper.java new file +38 -0
new file mode 100644
index 0000000..9c5c244
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * 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:
+ * Ioana Grigoropol(Intel) - initial API and implementation
+ *******************************************************************************/
+package org.yocto.remote.utils;
+
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.console.ConsolePlugin;
+import org.eclipse.ui.console.IConsole;
+import org.eclipse.ui.console.IConsoleManager;
+import org.eclipse.ui.console.MessageConsole;
+
+public class ConsoleHelper {
+	public static final String YOCTO_CONSOLE = "Yocto Project Console";
+
+	public static MessageConsole findConsole(String name) {
+		ConsolePlugin plugin = ConsolePlugin.getDefault();
+		IConsoleManager conMan = plugin.getConsoleManager();
+		IConsole[] existing = conMan.getConsoles();
+		for (int i = 0; i < existing.length; i++)
+			if (name.equals(existing[i].getName()))
+				return (MessageConsole) existing[i];
+		// no console found, so create a new one
+		MessageConsole myConsole = new MessageConsole(name, null);
+		conMan.addConsoles(new IConsole[] { myConsole });
+		return myConsole;
+	}
+
+	public static void showConsole(MessageConsole console){
+		Display.getDefault().syncExec(new ConsoleRunnable(console));
+	}
+}
Signature · 1 line
1.7.9.5
#6 lore raw

RFC v2 1/1 6/8] Add OutputProcessor utility class

In reply to Ioana Grigoropol

- OutputProcessor class is a stub class that will be used for processing the output of a remote command
- the main method of this class is processOutput()
- in this method, we retrieve the bufferes needed for output and error processing (from the host shell) (using locks for local, and none for remote, as dictated by the upstream)
- call processing for each buffer (output and error) using processBuffer method
- the processing of each buffer is basically done in the same way & the difference stands:
- in the way we determine the end of the line
- in the processing of a single line
- in order to provide a fully customizable approach for processing the output each of the methods that differ are left as abstract
- each line(output or error) is printed in the console and stored in the underlying ProcessStreamBuffer

---
 .../org.yocto.remote.utils/META-INF/MANIFEST.MF    |    2 +
 .../org/yocto/remote/utils/OutputProcessor.java    |  112 ++++++++++++++++++++
 .../src/org/yocto/remote/utils/RemoteHelper.java   |    2 +
 3 files changed, 116 insertions(+)
 create mode 100644 plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/OutputProcessor.java
plugins/org.yocto.remote.utils/META-INF/MANIFEST.MF +2 -0
index e31d557..408e33a 100644
@@ -11,6 +11,8 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Import-Package: org.eclipse.rse.core,
  org.eclipse.rse.core.model,
  org.eclipse.rse.core.subsystems,
+ org.eclipse.rse.internal.services.local.shells,
+ org.eclipse.rse.internal.services.shells,
  org.eclipse.rse.internal.terminals.ui,
  org.eclipse.rse.internal.terminals.ui.views,
  org.eclipse.rse.services,
plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/OutputProcessor.java new file +112 -0

113 lines not on this page · raw message

plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/RemoteHelper.java +2 -0
index a1e9a08..4d4f047 100644
@@ -49,6 +49,8 @@ import org.eclipse.rse.subsystems.terminals.core.ITerminalServiceSubSystem;
 public class RemoteHelper {
 	private final static String EXIT_CMD = "exit"; //$NON-NLS-1$
 	private final static String CMD_DELIMITER = ";"; //$NON-NLS-1$
+	public static final String TERMINATOR = "234o987dsfkcqiuwey18837032843259d";//$NON-NLS-1$
+	public static final int TOTALWORKLOAD = 100;
 
 	public static IHost getRemoteConnectionByName(String remoteConnection) {
 		if (remoteConnection == null)
Signature · 1 line
1.7.9.5
#7 lore raw

RFC v2 1/1 7/8] Add CommandOutputProcessor utilty class

In reply to Ioana Grigoropol

- this is a simple implementation of the OutputProcessor abstract class
- splitting the error and output lines is done by '\n' character

---
 .../yocto/remote/utils/CommandOutputProcessor.java |   43 ++++++++++++++++++++
 1 file changed, 43 insertions(+)
 create mode 100644 plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/CommandOutputProcessor.java
plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/CommandOutputProcessor.java new file +43 -0
new file mode 100644
index 0000000..081e6d4
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * 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:
+ * Ioana Grigoropol(Intel) - initial API and implementation
+ *******************************************************************************/
+package org.yocto.remote.utils;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.rse.services.shells.IHostShell;
+
+public class CommandOutputProcessor extends OutputProcessor {
+
+	public CommandOutputProcessor(IProgressMonitor monitor,
+			IHostShell hostShell, CommandResponseHandler cmdHandler, String task) {
+		super(monitor, hostShell, cmdHandler, task);
+	}
+
+	@Override
+	protected boolean isErrChStop(char ch) {
+		return (ch == '\n');
+	}
+
+	@Override
+	protected boolean isOutChStop(char ch) {
+		return (ch == '\n');
+	}
+
+	@Override
+	protected void processOutputBufferLine(char ch, String str) {
+		processBuffer.addOutputLine(str);
+	}
+
+	@Override
+	protected void processErrorBufferLine(char ch, String str) {
+		processBuffer.addErrorLine(str);
+	}
+
+}
Signature · 1 line
1.7.9.5
#8 lore raw

RFC v2 1/1 8/8] Refactor RemoteHelper class

In reply to Ioana Grigoropol

- added utility class CommandRunnable that will be used for running a remote command in a different thread & processing the output
- add RemoteMachine utility class
- RemoteMachine class holds all the information needed for a remote/local machine
- environment map of all variables in the remote env
- message console & command response handler to log the commands ran against the remote machine and their output
- the host connection use to connect to the remote machine
- the connected subsytem of the remote system and its file service(needed for any operations on the file system)
- all the information that is stored in the RemoteMachine makes it easier to map connections to remote machines

RemoteHelper:
- refactor helper to be used as a lazy singleton class-> all fields are initialized upon demand
- refactor helper to group all fields that are machine specific togheter:
- added map for storing connection->remote machine associations
- retrieve console for remote machine implementation instead of using a different one for each invocation
- retrieve command response handler for the remote machine instead of using one global one
- retrive file service for particular remote machine given the connection
- retrieve connected shell service for the remote machine given the connection
- refactor helper to be able to run commands on remote hosts in a synchronous way (wait for the command to finish, process output/error)
- run all commands using CommandRunnable wrapper(handleRunCommandRemote method)
- added methods for:
- creating a new URI given a parent URI
- retrieving remote input stream for a specific file
- checking if a file exists on the remote host
- retriving a remote IHostFile
- retrieve remote directory content
- retrieve connection for given URI

---
 .../org.yocto.remote.utils/META-INF/MANIFEST.MF    |    3 +
 .../org/yocto/remote/utils/CommandRunnable.java    |   44 ++++
 .../src/org/yocto/remote/utils/RemoteHelper.java   |  253 ++++++++++++++++----
 .../src/org/yocto/remote/utils/RemoteMachine.java  |  202 ++++++++++++++++
 4 files changed, 454 insertions(+), 48 deletions(-)
 create mode 100644 plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/CommandRunnable.java
 create mode 100644 plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/RemoteMachine.java
plugins/org.yocto.remote.utils/META-INF/MANIFEST.MF +3 -0
index 408e33a..06d14f8 100644
@@ -16,10 +16,13 @@ Import-Package: org.eclipse.rse.core,
  org.eclipse.rse.internal.terminals.ui,
  org.eclipse.rse.internal.terminals.ui.views,
  org.eclipse.rse.services,
+ org.eclipse.rse.services.clientserver.messages,
  org.eclipse.rse.services.files,
  org.eclipse.rse.services.shells,
  org.eclipse.rse.services.terminals,
+ org.eclipse.rse.subsystems.files.core.model,
  org.eclipse.rse.subsystems.files.core.servicesubsystem,
+ org.eclipse.rse.subsystems.files.core.subsystems,
  org.eclipse.rse.subsystems.shells.core.subsystems.servicesubsystem,
  org.eclipse.rse.subsystems.terminals.core,
  org.eclipse.rse.subsystems.terminals.core.elements,
plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/CommandRunnable.java new file +44 -0

44 lines not on this page · raw message

plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/RemoteHelper.java +205 -48

315 lines not on this page · raw message

plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/RemoteMachine.java new file +202 -0

202 lines not on this page · raw message

Signature · 1 line
1.7.9.5