Skip to contentSkip to conversation

Adapt remote bb plugin code & fix remaining issues

PATCH In review Ioana Grigoropol 2 participants 7 messages May 23, 2013 – May 24, 2013

lore
Share & tools
lore
#0 lore raw

cover Adapt remote bb plugin code & fix remaining issues

- adapted remote bitbake commander project code to use upstream changes in the LocalHostShell code
- added fixes for recipe parsing
- added fixes for messages displayed during git clone

Ioana Grigoropol (4):
Adapt usage of LocalHostShell lock and reader to upstream changes Fix recipe parsing when using Remote host
Refactor processing of commands output
Customize Output processor for git clone command and fix message
display

 plugins/org.yocto.bc.ui/META-INF/MANIFEST.MF       |    1 +
 .../bc/remote/utils/CommandOutputProcessor.java    |   33 +++++++
 .../org/yocto/bc/remote/utils/CommandRunnable.java |    7 +-
 .../org/yocto/bc/remote/utils/OutputProcessor.java |  102 ++++++++++++++++++++
 .../yocto/bc/remote/utils/ProcessStreamBuffer.java |   13 ++-
 .../org/yocto/bc/remote/utils/RemoteHelper.java    |   65 +------------
 .../org/yocto/bc/remote/utils/RemoteMachine.java   |   13 +--
 .../org/yocto/bc/remote/utils/YoctoCommand.java    |    2 +-
 .../bc/remote/utils/YoctoRunnableWithProgress.java |   31 +++++-
 9 files changed, 181 insertions(+), 86 deletions(-)
 create mode 100644 plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/CommandOutputProcessor.java
 create mode 100644 plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/OutputProcessor.java
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 1/4 Adapt usage of LocalHostShell lock and reader to upstream changes

---
 .../org/yocto/bc/remote/utils/RemoteHelper.java    |   27 +++++++++++++++-----
 1 file changed, 21 insertions(+), 6 deletions(-)
plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/RemoteHelper.java +21 -6
index 507ac54..87c8637 100644
@@ -35,6 +35,7 @@ import org.eclipse.rse.core.RSECorePlugin;
 import org.eclipse.rse.core.model.IHost;
 import org.eclipse.rse.core.model.ISystemRegistry;
 import org.eclipse.rse.core.subsystems.ISubSystem;
+import org.eclipse.rse.internal.services.local.shells.LocalHostShell;
 import org.eclipse.rse.services.IService;
 import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
 import org.eclipse.rse.services.files.IFileService;
@@ -87,18 +88,31 @@ public class RemoteHelper {
 		if (hostShell == null)
 			throw new Exception("An error has occured while trying to run remote command!");
 
-		Lock lock = hostShell.getLock();
-		lock.lock();
+		Lock lock = null;
+		if (hostShell instanceof LocalHostShell) {
+			lock = ((LocalHostShell)hostShell).getLock();
+			lock.lock();
+		}
 		ProcessStreamBuffer processBuffer = new ProcessStreamBuffer();
 		
-		BufferedReader inbr = hostShell.getReader(false);
-		BufferedReader errbr = hostShell.getReader(true);
+		BufferedReader inbr = null;
+		BufferedReader errbr = null;
+
+		if (hostShell instanceof LocalHostShell) {
+			inbr = ((LocalHostShell)hostShell).getReader(false);
+			errbr = ((LocalHostShell)hostShell).getReader(true);
+		} else {
+			Process p = new HostShellProcessAdapter(hostShell);
+			inbr = new BufferedReader(new InputStreamReader(p.getInputStream()));
+			errbr = new BufferedReader(new InputStreamReader(p.getErrorStream()));
+		}
 		
 		boolean cancel = false;
 		while (!cancel) {
 			if(monitor.isCanceled()) {
 				cancel = true;
-				lock.unlock();
+				if (lock != null)
+					lock.unlock();
 				throw new InterruptedException("User Cancelled");
 			}
 			StringBuffer buffer = new StringBuffer();
@@ -135,7 +149,8 @@ public class RemoteHelper {
 				}
 			cancel = true;
 		}
-		lock.unlock();
+		if (lock != null)
+			lock.unlock();
 		return processBuffer;
 	}
 	
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH 2/4 Fix recipe parsing when using Remote host

In reply to Ioana Grigoropol

- when running a remote command on a remote target, the TerminalServiceHostShell implementation is used for the HostShell(instead of the LocalHostShell)
- in this case, the shell does not have two readers (input, error), and instead it only offers one reader for both of the streams
- in the current implementation, the error stream is parsed first because it makes more sense to check for errors before trying to parse the output of the command
- in the remote case, since all output(error and output) will be sent to the same reader, the needed output of the command will be parsed as error and the output will be empty
- in order to fix this, we should look at the error lines resulted after running a remote command if we are using a remote target

---
 plugins/org.yocto.bc.ui/META-INF/MANIFEST.MF       |    1 +
 .../yocto/bc/remote/utils/ProcessStreamBuffer.java |   13 ++++++++++---
 .../org/yocto/bc/remote/utils/RemoteHelper.java    |    7 ++-----
 .../org/yocto/bc/remote/utils/RemoteMachine.java   |    6 ------
 .../org/yocto/bc/remote/utils/YoctoCommand.java    |    2 +-
 5 files changed, 14 insertions(+), 15 deletions(-)
plugins/org.yocto.bc.ui/META-INF/MANIFEST.MF +1 -0
index 4e57f33..68fc49e 100644
@@ -30,6 +30,7 @@ Import-Package: org.eclipse.cdt.managedbuilder.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.services,
  org.eclipse.rse.services.clientserver.messages,
  org.eclipse.rse.services.files,
plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/ProcessStreamBuffer.java +10 -3
index e0d502c..73d0805 100644
@@ -8,8 +8,10 @@ public class ProcessStreamBuffer {
 	private static final String WHITESPACES = "\\s+";
 	List<String> errorLines;
 	List<String> outputLines;
+	boolean isTerminal;
 
-	ProcessStreamBuffer(){
+	ProcessStreamBuffer(boolean isTerminal){
+		this.isTerminal = isTerminal;
 		errorLines = new ArrayList<String>();
 		outputLines = new ArrayList<String>();
 	}
@@ -56,8 +58,13 @@ public class ProcessStreamBuffer {
 	}
 
 	public String getOutputLineContaining(String arg, String pattern) {
-		for (int i = outputLines.size() - 1; i >= 0; i--){
-			String line = outputLines.get(i);
+		List<String> lines = null;
+		if (isTerminal)
+			lines = errorLines;
+		else
+			lines = outputLines;
+		for (int i = lines.size() - 1; i >= 0; i--){
+			String line = lines.get(i);
 			if (line.contains(arg)) {
 				String[] tokens = line.split("\\s+");
 				if (Pattern.matches(pattern,  tokens[0])) {
plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/RemoteHelper.java +2 -5
index 87c8637..5b82e13 100644
@@ -36,6 +36,7 @@ import org.eclipse.rse.core.model.IHost;
 import org.eclipse.rse.core.model.ISystemRegistry;
 import org.eclipse.rse.core.subsystems.ISubSystem;
 import org.eclipse.rse.internal.services.local.shells.LocalHostShell;
+import org.eclipse.rse.internal.services.shells.TerminalServiceHostShell;
 import org.eclipse.rse.services.IService;
 import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
 import org.eclipse.rse.services.files.IFileService;
@@ -76,10 +77,6 @@ public class RemoteHelper {
 		return getRemoteMachine(connection).getCmdHandler();
 	}
 
-	public static ProcessStreamBuffer getProcessBuffer(IHost connection) {
-		return getRemoteMachine(connection).getProcessBuffer();
-	}
-
 	public static IHostShell getHostShell(IHost connection) {
 		return getRemoteMachine(connection).getHostShell();
 	}
@@ -93,7 +90,7 @@ public class RemoteHelper {
 			lock = ((LocalHostShell)hostShell).getLock();
 			lock.lock();
 		}
-		ProcessStreamBuffer processBuffer = new ProcessStreamBuffer();
+		ProcessStreamBuffer processBuffer = new ProcessStreamBuffer(hostShell instanceof TerminalServiceHostShell);
 		
 		BufferedReader inbr = null;
 		BufferedReader errbr = null;
plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/RemoteMachine.java +0 -6
index 52bc011..14501e4 100644
@@ -165,12 +165,6 @@ public class RemoteMachine {
 		return null;
 	}
 
-	public ProcessStreamBuffer getProcessBuffer() {
-		if (processBuffer == null)
-			processBuffer = new ProcessStreamBuffer();
-		return processBuffer;
-	}
-
 	public IHost getConnection() {
 		return connection;
 	}
plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/YoctoCommand.java +1 -1
index 0fd4f32..9375806 100644
@@ -11,7 +11,7 @@ public class YoctoCommand {
 		this.setCommand(command);
 		this.setInitialDirectory(initialDirectory);
 		this.setArguments(arguments);
-		this.setProcessBuffer(new ProcessStreamBuffer());
+		this.setProcessBuffer(new ProcessStreamBuffer(false));
 	}
 
 	public String getCommand() {
Signature · 1 line
1.7.9.5
#3 lore raw

PATCH 3/4 Refactor processing of commands output

In reply to Ioana Grigoropol

- refactored the processing of commands output in order to offer a more extensible and abstract output processor that can be easily customized as needed for different purposes
- the newly introduced OutputProcessor will offer:
- a method for processing the buffer it receives(either error or output)
- abstract methods for processing an output or error lines
- abstract methods for deciding when an line(output or error) has ended by searching for a specific character

---
 .../bc/remote/utils/CommandOutputProcessor.java    |   33 +++++++
 .../org/yocto/bc/remote/utils/CommandRunnable.java |    7 +-
 .../org/yocto/bc/remote/utils/OutputProcessor.java |  102 ++++++++++++++++++++
 .../org/yocto/bc/remote/utils/RemoteHelper.java    |   77 +--------------
 .../org/yocto/bc/remote/utils/RemoteMachine.java   |    7 +-
 .../bc/remote/utils/YoctoRunnableWithProgress.java |    2 +-
 6 files changed, 140 insertions(+), 88 deletions(-)
 create mode 100644 plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/CommandOutputProcessor.java
 create mode 100644 plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/OutputProcessor.java
plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/CommandOutputProcessor.java new file +33 -0
new file mode 100644
index 0000000..4da33a4
@@ -0,0 +1,33 @@
+package org.yocto.bc.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);
+	}
+
+}
plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/CommandRunnable.java +1 -6
index 7406f50..f1ab9b1 100644
@@ -1,13 +1,8 @@
 package org.yocto.bc.remote.utils;
 
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-import java.util.concurrent.locks.Lock;
-
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.rse.core.model.IHost;
-import org.eclipse.rse.services.shells.HostShellProcessAdapter;
 import org.eclipse.rse.services.shells.IHostShell;
 
 public class CommandRunnable implements Runnable{
@@ -28,7 +23,7 @@ public class CommandRunnable implements Runnable{
 	public void run() {
 		try {
 			hostShell = RemoteHelper.runCommandRemote(connection, cmd, monitor);
-			cmd.setProcessBuffer(RemoteHelper.processOutput(monitor, hostShell, cmdHandler, new char[]{'\n'}));
+			cmd.setProcessBuffer(RemoteHelper.processOutput(monitor, hostShell, cmdHandler));
 		} catch (CoreException e) {
 			e.printStackTrace();
 		} catch (Exception e) {
plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/OutputProcessor.java new file +102 -0

103 lines not on this page · raw message

plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/RemoteHelper.java +2 -75

105 lines not on this page · raw message

plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/RemoteMachine.java +1 -6
index 14501e4..0b9ca3b 100644
@@ -1,12 +1,9 @@
 package org.yocto.bc.remote.utils;
 
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.concurrent.locks.Lock;
 
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
@@ -19,7 +16,6 @@ import org.eclipse.rse.core.subsystems.ISubSystem;
 import org.eclipse.rse.internal.services.local.shells.LocalShellService;
 import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
 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;
@@ -35,7 +31,6 @@ public class RemoteMachine {
 	private CommandResponseHandler cmdHandler;
 	private IHostShell hostShell;
 	private IShellService shellService;
-	private ProcessStreamBuffer processBuffer;
 	private IHost connection;
 
 	private ISubSystem fileSubSystem;
@@ -79,7 +74,7 @@ public class RemoteMachine {
 			try {
 				SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, 3);
 				IHostShell hostShell = shellService.runCommand("", "env" + " ; echo " + RemoteHelper.TERMINATOR + "; exit;", new String[]{}, subMonitor);
-				buffer = RemoteHelper.processOutput(subMonitor, hostShell, cmdHandler, new char[]{'\n'});
+				buffer = RemoteHelper.processOutput(subMonitor, hostShell, cmdHandler);
 				for(int i = 0; i < buffer.getOutputLines().size(); i++) {
 					String out = buffer.getOutputLines().get(i);
 					String[] tokens = out.split("=");
plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/YoctoRunnableWithProgress.java +1 -1
index e748be7..7eb7172 100644
@@ -98,7 +98,7 @@ public class YoctoRunnableWithProgress implements IRunnableWithProgress {
 		public void run() {
 			try {
 				hostShell = RemoteHelper.runCommandRemote(this.connection, command, monitor);
-				command.setProcessBuffer(RemoteHelper.processOutput(monitor, hostShell, cmdHandler, new char[]{'\n', '\r'}));
+				command.setProcessBuffer(RemoteHelper.processOutput(monitor, hostShell, cmdHandler));
 			} catch (CoreException e) {
 				e.printStackTrace();
 			} catch (Exception e) {
Signature · 1 line
1.7.9.5
#4 lore raw

PATCH 4/4 Customize Output processor for git clone command and fix message display

In reply to Ioana Grigoropol

- in the particular case of creating a new bitbake project by cloning, the whole process is started from the context of the project wizard which is in charge of updating the monitor of the command
- since the transfer is redirected to the RemoteHelper, somehow along the way the reference of the wizard monitor is lost and the messages are not displayed correctly
- in order to fix this, the parsing is done locally inside the appropiate context & using a customization of the abstract OutputProcessor

---
 .../bc/remote/utils/YoctoRunnableWithProgress.java |   31 +++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)
plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/YoctoRunnableWithProgress.java +30 -1
index 7eb7172..4005554 100644
@@ -80,7 +80,36 @@ public class YoctoRunnableWithProgress implements IRunnableWithProgress {
 			e.printStackTrace();
 		}
 	}
+	class YoctoRunnableOutputProcessor extends OutputProcessor{
 
+		public YoctoRunnableOutputProcessor(IProgressMonitor monitor,
+				IHostShell hostShell, CommandResponseHandler cmdHandler,
+				String task) {
+			super(monitor, hostShell, cmdHandler, task);
+		}
+		@Override
+		protected boolean isErrChStop(char ch) {
+			return (ch == '\n' || ch == '\r');
+		}
+
+		@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.addOutputLine(str);
+			if (ch == '\r')
+				reportProgress(str);
+		}
+
+	}
 
 	class YoctoThread implements Runnable{
 		private IHost connection;
@@ -98,7 +127,7 @@ public class YoctoRunnableWithProgress implements IRunnableWithProgress {
 		public void run() {
 			try {
 				hostShell = RemoteHelper.runCommandRemote(this.connection, command, monitor);
-				command.setProcessBuffer(RemoteHelper.processOutput(monitor, hostShell, cmdHandler));
+				command.setProcessBuffer(new YoctoRunnableOutputProcessor(monitor, hostShell, cmdHandler, taskName).processOutput());
 			} catch (CoreException e) {
 				e.printStackTrace();
 			} catch (Exception e) {
Signature · 1 line
1.7.9.5
#5 lore raw
In reply to Ioana Grigoropol

Hi Ioana,

Since we're doing the overall refactor and this part for bitbake commander need to adopt the remote.util changes that's underway, and windows-build branch shouldn't be the one that we use. Please incorporate this change to bitbake commander change to use the remote.util tool.

Thanks
Jessica

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Ioana Grigoropol
Sent: Thursday, May 23, 2013 7:39 AM
To: [email protected]
Subject: [yocto] [eclipse-poky][branch:windows-build][PATCH 0/4] Adapt remote bb plugin code & fix remaining issues

- adapted remote bitbake commander project code to use upstream changes in the LocalHostShell code
- added fixes for recipe parsing
- added fixes for messages displayed during git clone

Ioana Grigoropol (4):
Adapt usage of LocalHostShell lock and reader to upstream changes Fix recipe parsing when using Remote host
Refactor processing of commands output
Customize Output processor for git clone command and fix message
display

 plugins/org.yocto.bc.ui/META-INF/MANIFEST.MF       |    1 +
 .../bc/remote/utils/CommandOutputProcessor.java    |   33 +++++++
 .../org/yocto/bc/remote/utils/CommandRunnable.java |    7 +-
 .../org/yocto/bc/remote/utils/OutputProcessor.java |  102 ++++++++++++++++++++
 .../yocto/bc/remote/utils/ProcessStreamBuffer.java |   13 ++-
 .../org/yocto/bc/remote/utils/RemoteHelper.java    |   65 +------------
 .../org/yocto/bc/remote/utils/RemoteMachine.java   |   13 +--
 .../org/yocto/bc/remote/utils/YoctoCommand.java    |    2 +-
 .../bc/remote/utils/YoctoRunnableWithProgress.java |   31 +++++-
 9 files changed, 181 insertions(+), 86 deletions(-)  create mode 100644 plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/CommandOutputProcessor.java
 create mode 100644 plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/OutputProcessor.java

--
1.7.9.5

_______________________________________________
yocto mailing list
[email protected]
https://lists.yoctoproject.org/listinfo/yocto

#6 lore raw

Hi Jessica,

These changes can be applied independently on the windows-build branch, and I have sent the patches to make sure that this part works properly before merging them to a common remote plugin assuming that everything works. Since I will porting these utilities to the remote plugin, I think that it is important to have the original source of the code separted.

Ioana
________________________________________
From: Zhang, Jessica
Sent: Thursday, May 23, 2013 9:46 PM
To: Grigoropol, IoanaX; [email protected]
Subject: RE: [yocto] [eclipse-poky][branch:windows-build][PATCH 0/4] Adapt remote bb plugin code & fix remaining issues

Hi Ioana,

Since we're doing the overall refactor and this part for bitbake commander need to adopt the remote.util changes that's underway, and windows-build branch shouldn't be the one that we use. Please incorporate this change to bitbake commander change to use the remote.util tool.

Thanks
Jessica

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Ioana Grigoropol
Sent: Thursday, May 23, 2013 7:39 AM
To: [email protected]
Subject: [yocto] [eclipse-poky][branch:windows-build][PATCH 0/4] Adapt remote bb plugin code & fix remaining issues

- adapted remote bitbake commander project code to use upstream changes in the LocalHostShell code
- added fixes for recipe parsing
- added fixes for messages displayed during git clone

Ioana Grigoropol (4):
Adapt usage of LocalHostShell lock and reader to upstream changes Fix recipe parsing when using Remote host
Refactor processing of commands output
Customize Output processor for git clone command and fix message
display

 plugins/org.yocto.bc.ui/META-INF/MANIFEST.MF       |    1 +
 .../bc/remote/utils/CommandOutputProcessor.java    |   33 +++++++
 .../org/yocto/bc/remote/utils/CommandRunnable.java |    7 +-
 .../org/yocto/bc/remote/utils/OutputProcessor.java |  102 ++++++++++++++++++++
 .../yocto/bc/remote/utils/ProcessStreamBuffer.java |   13 ++-
 .../org/yocto/bc/remote/utils/RemoteHelper.java    |   65 +------------
 .../org/yocto/bc/remote/utils/RemoteMachine.java   |   13 +--
 .../org/yocto/bc/remote/utils/YoctoCommand.java    |    2 +-
 .../bc/remote/utils/YoctoRunnableWithProgress.java |   31 +++++-
 9 files changed, 181 insertions(+), 86 deletions(-)  create mode 100644 plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/CommandOutputProcessor.java
 create mode 100644 plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/OutputProcessor.java

--
1.7.9.5

_______________________________________________
yocto mailing list
[email protected]
https://lists.yoctoproject.org/listinfo/yocto